use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class ZKServiceDecoratorTest method testStateTransition.
@Test
public void testStateTransition() throws InterruptedException, ExecutionException, TimeoutException {
InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
zkServer.startAndWait();
try {
final String namespace = Joiner.on('/').join("/weave", RunIds.generate(), "runnables", "Runner1");
final ZKClientService zkClient = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
zkClient.startAndWait();
zkClient.create(namespace, null, CreateMode.PERSISTENT).get();
try {
JsonObject content = new JsonObject();
content.addProperty("containerId", "container-123");
content.addProperty("host", "localhost");
RunId runId = RunIds.generate();
final Semaphore semaphore = new Semaphore(0);
ZKServiceDecorator service = new ZKServiceDecorator(ZKClients.namespace(zkClient, namespace), runId, Suppliers.ofInstance(content), new AbstractIdleService() {
@Override
protected void startUp() throws Exception {
Preconditions.checkArgument(semaphore.tryAcquire(5, TimeUnit.SECONDS), "Fail to start");
}
@Override
protected void shutDown() throws Exception {
Preconditions.checkArgument(semaphore.tryAcquire(5, TimeUnit.SECONDS), "Fail to stop");
}
});
final String runnablePath = namespace + "/" + runId.getId();
final AtomicReference<String> stateMatch = new AtomicReference<String>("STARTING");
watchDataChange(zkClient, runnablePath + "/state", semaphore, stateMatch);
Assert.assertEquals(Service.State.RUNNING, service.start().get(5, TimeUnit.SECONDS));
stateMatch.set("STOPPING");
Assert.assertEquals(Service.State.TERMINATED, service.stop().get(5, TimeUnit.SECONDS));
} finally {
zkClient.stopAndWait();
}
} finally {
zkServer.stopAndWait();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class RuntimeSpecificationCodec method serialize.
@Override
public JsonElement serialize(RuntimeSpecification src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
json.addProperty("name", src.getName());
json.add("runnable", context.serialize(src.getRunnableSpecification(), WeaveRunnableSpecification.class));
json.add("resources", context.serialize(src.getResourceSpecification(), ResourceSpecification.class));
json.add("files", context.serialize(src.getLocalFiles(), new TypeToken<Collection<LocalFile>>() {
}.getType()));
return json;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class RuntimeSpecificationCodec method deserialize.
@Override
public RuntimeSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
String name = jsonObj.get("name").getAsString();
WeaveRunnableSpecification runnable = context.deserialize(jsonObj.get("runnable"), WeaveRunnableSpecification.class);
ResourceSpecification resources = context.deserialize(jsonObj.get("resources"), ResourceSpecification.class);
Collection<LocalFile> files = context.deserialize(jsonObj.get("files"), new TypeToken<Collection<LocalFile>>() {
}.getType());
return new DefaultRuntimeSpecification(name, runnable, resources, files);
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class StackTraceElementCodec method serialize.
@Override
public JsonElement serialize(StackTraceElement src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject jsonObj = new JsonObject();
jsonObj.addProperty("className", src.getClassName());
jsonObj.addProperty("method", src.getMethodName());
jsonObj.addProperty("file", src.getFileName());
jsonObj.addProperty("line", src.getLineNumber());
return jsonObj;
}
use of org.apache.beam.vendor.grpc.v1p43p2.com.google.gson.JsonObject in project weave by continuuity.
the class StateNodeCodec method deserialize.
@Override
public StateNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObj = json.getAsJsonObject();
ServiceController.State state = ServiceController.State.valueOf(jsonObj.get("state").getAsString());
String errorMessage = jsonObj.has("errorMessage") ? jsonObj.get("errorMessage").getAsString() : null;
return new StateNode(state, errorMessage, context.<StackTraceElement[]>deserialize(jsonObj.get("stackTraces"), StackTraceElement[].class));
}
Aggregations