Skip to content

first draft of Bulk API and retrieve tests #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions bulk-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id("java-library")
id("com.vanniktech.maven.publish")
id("signing")
}

repositories {
mavenCentral()
}

val javadocConfig by configurations.creating {
extendsFrom(configurations.testImplementation.get())
}

dependencies {
api(project(":core"))

implementation(libs.gson)

// Use JUnit test framework.
testImplementation(libs.junit)
testImplementation(libs.gson)
}

val jvmVersion = extra["jvmVersion"] as String
val specsVersion = extra["specsVersion"] as String

java {
sourceCompatibility = JavaVersion.toVersion(jvmVersion)
targetCompatibility = JavaVersion.toVersion(jvmVersion)
}
tasks.register<Javadoc>("myJavadoc") {
source = sourceSets.main.get().allJava
classpath = javadocConfig
options {
require(this is StandardJavadocDocletOptions)
addStringOption("link", "https://docs.oracle.com/javase/8/docs/api/")
addStringOption("link", "https://alexanderpann.github.io/mps-openapi-doc/javadoc_2021.2/")
}
}

val isReleaseVersion = !(version as String).endsWith("SNAPSHOT")

tasks.register<Jar>("javadocJar") {
dependsOn("myJavadoc")
from(tasks.getByName("myJavadoc")/*.destinationDir*/)
archiveClassifier.set("javadoc")
}

tasks.register<Jar>("sourcesJar") {
archiveClassifier.set("sources")
// See https://discuss.gradle.org/t/why-subproject-sourceset-dirs-project-sourceset-dirs/7376/5
// Without the closure, parent sources are used for children too
from(sourceSets.getByName("main").java.srcDirs)
}

mavenPublishing {
coordinates(
groupId = "io.lionweb.lionweb-java",
artifactId = "lionweb-java-${specsVersion}-" + project.name,
version = project.version as String,
)

pom {
name.set("lionweb-java-" + project.name)
description.set("LionWeb Bulk API")
version = project.version as String
packaging = "jar"
url.set("https://github.com/LionWeb-io/lionweb-java")

scm {
connection.set("scm:git:https://github.com/LionWeb-io/lionweb-java.git")
developerConnection.set("scm:git:[email protected]:LionWeb-io/lionweb-java.git")
url.set("https://github.com/LionWeb-io/lionweb-java.git")
}

licenses {
license {
name.set("Apache Licenve V2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0")
distribution.set("repo")
}
}

// The developers entry is strictly required by Maven Central
developers {
developer {
id.set("ftomassetti")
name.set("Federico Tomassetti")
email.set("[email protected]")
}
developer {
id.set("dslmeinte")
name.set("Meinte Boersma")
email.set("[email protected]")
}
developer {
id.set("enikao")
name.set("Niko Stotz")
email.set("[email protected]")
}
}
}
publishToMavenCentral(SonatypeHost.S01, true)
signAllPublications()
}
18 changes: 18 additions & 0 deletions bulk-api/src/main/java/io/lionweb/api/bulk/BulkException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.lionweb.api.bulk;

public class BulkException extends RuntimeException {
public BulkException() {
}

public BulkException(String message) {
super(message);
}

public BulkException(String message, Throwable cause) {
super(message, cause);
}

public BulkException(Throwable cause) {
super(cause);
}
}
22 changes: 22 additions & 0 deletions bulk-api/src/main/java/io/lionweb/api/bulk/IBulk.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.lionweb.api.bulk;

import io.lionweb.lioncore.java.serialization.data.SerializedChunk;

import java.util.List;

public interface IBulk {
// @Nonnull
SerializedChunk partitions() throws BulkException;

// @Nonnull
SerializedChunk retrieve(List<String> nodeIds, /*@Nullable*/ Integer depthLimit) throws BulkException;

// @Nonnull
void store(/*@Nonnull*/ SerializedChunk nodes, /*@Nullable*/ StoreMode mode) throws BulkException;

// @Nonnull
void delete(List<String> nodeIds) throws BulkException;

// @Nonnull
List<String> ids(/*@Nonnull*/ Integer count) throws BulkException;
}
7 changes: 7 additions & 0 deletions bulk-api/src/main/java/io/lionweb/api/bulk/StoreMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.lionweb.api.bulk;

public enum StoreMode {
REPLACE,
CREATE,
UPDATE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.lionweb.api.bulk.lowlevel;

import io.lionweb.lioncore.java.serialization.data.SerializedChunk;

import java.util.List;
//import javax.annotation.Nonnull;
//import javax.annotation.Nullable;

public interface IBulkLowlevel<C extends ILowlevelConfig> {
// @Nonnull
IPartitionsResponse partitions();

// @Nonnull
IRetrieveResponse retrieve(List<String> nodeIds, /*@Nullable*/ String depthLimit);

// @Nonnull
IStoreResponse store(/*@Nonnull*/ SerializedChunk nodes, /*@Nullable*/ String mode);

// @Nonnull
IDeleteResponse delete(List<String> nodeIds);

// @Nonnull
IIdsResponse ids(/*@Nonnull*/ String count);

// @Nonnull
C getConfig();

void setConfig(/*@Nonnull*/ C config);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.lionweb.api.bulk.lowlevel;

import java.util.List;

public interface IDeleteResponse extends ILowlevelResponse {
/**
* Whether there was an issue with the nodeIds parameter.
*/
boolean isValidNodeIds();

/**
* Requested node ids unknown to the repository.
*/
List<String> getUnknownNodeIds();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.lionweb.api.bulk.lowlevel;

import java.util.List;

public interface IIdsResponse extends ILowlevelResponse {
/**
* Retrieved available (i.e. free, usable, reserved for this client) ids, if successful.
*/
List<String> getIds();

/**
* Whether there was an issue with the count parameter.
*/
boolean isValidCount();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.lionweb.api.bulk.lowlevel;

public interface ILowlevelConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.lionweb.api.bulk.lowlevel;

public interface ILowlevelResponse {
boolean isOk();

//@Nonnull
String getErrorMessage();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.lionweb.api.bulk.lowlevel;

import io.lionweb.lioncore.java.serialization.data.SerializedChunk;

public interface IPartitionsResponse extends ILowlevelResponse {
/**
* Retrieved partition nodes, if successful.
*/
// @Nonnull
SerializedChunk getResult();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.lionweb.api.bulk.lowlevel;

import io.lionweb.lioncore.java.serialization.data.SerializedChunk;

import java.util.List;

public interface IRetrieveResponse extends ILowlevelResponse {
/**
* Retrieved nodes, if successful.
*/
// @Nonnull
SerializedChunk getResult();

/**
* Whether there was an issue with the nodeIds parameter.
*/
boolean isValidNodeIds();

/**
* Whether there was an issue with the depthLimit parameter.
*/
boolean isValidDepthLimit();

/**
* Requested node ids unknown to the repository.
*/
List<String> getUnknownNodeIds();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.lionweb.api.bulk.lowlevel;

public interface IStoreResponse extends ILowlevelResponse {
/**
* Whether there was an issue with the nodes parameter.
*/
boolean isValidNodes();

/**
* Whether there was an issue with the mode parameter.
*/
boolean isValidMode();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package io.lionweb.api.bulk.wrapper;

import io.lionweb.api.bulk.BulkException;
import io.lionweb.api.bulk.IBulk;
import io.lionweb.api.bulk.StoreMode;
import io.lionweb.api.bulk.lowlevel.*;
import io.lionweb.lioncore.java.serialization.data.SerializedChunk;

import java.util.List;
import java.util.Objects;

public class BulkLowlevelWrapper implements IBulk {
private final IBulkLowlevel lowlevel;

public BulkLowlevelWrapper(/*@Nonnull*/ IBulkLowlevel lowlevel) {
this.lowlevel = lowlevel;
}

@Override
public SerializedChunk partitions() throws BulkException {
IPartitionsResponse response = lowlevel.partitions();

if(response.isOk()) {
Objects.requireNonNull(response.getResult());
return response.getResult();
}

throw new BulkException(response.getErrorMessage());
}

@Override
public SerializedChunk retrieve(List<String> nodeIds, Integer depthLimit) throws BulkException {
Objects.requireNonNull(nodeIds);
nodeIds.forEach(Objects::requireNonNull);

IRetrieveResponse response = lowlevel.retrieve(nodeIds, Objects.toString(depthLimit, null));

if(response.isOk()) {
Objects.requireNonNull(response.getResult());
return response.getResult();
}

throw new BulkException(response.getErrorMessage());
}

@Override
public void store(SerializedChunk nodes, StoreMode mode) throws BulkException {
Objects.requireNonNull(nodes);
String modeString = mode !=null ? mode.name().toLowerCase() : null;
IStoreResponse response = lowlevel.store(nodes, modeString);

if(response.isOk()) {
return;
}

throw new BulkException(response.getErrorMessage());
}

@Override
public void delete(List<String> nodeIds) throws BulkException {
Objects.requireNonNull(nodeIds);
nodeIds.forEach(Objects::requireNonNull);

IDeleteResponse response = lowlevel.delete(nodeIds);

if(response.isOk()) {
return;
}

throw new BulkException(response.getErrorMessage());
}

@Override
public List<String> ids(Integer count) throws BulkException {
Objects.requireNonNull(count);

IIdsResponse response = lowlevel.ids(count.toString());

if(response.isOk()) {
Objects.requireNonNull(response.getIds());
response.getIds().forEach(Objects::requireNonNull);
return response.getIds();
}

throw new BulkException(response.getErrorMessage());
}
}
Loading