Search in sources :

Example 1 with StateNode

use of com.continuuity.weave.internal.state.StateNode in project weave by continuuity.

the class ZKServiceDecorator method doStart.

@Override
protected void doStart() {
    callbackExecutor = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("message-callback"));
    Futures.addCallback(createLiveNode(), new FutureCallback<String>() {

        @Override
        public void onSuccess(String result) {
            // Create nodes for states and messaging
            StateNode stateNode = new StateNode(ServiceController.State.STARTING);
            final ListenableFuture<List<String>> createFuture = Futures.allAsList(ZKOperations.ignoreError(zkClient.create(getZKPath("messages"), null, CreateMode.PERSISTENT), KeeperException.NodeExistsException.class, null), zkClient.create(getZKPath("state"), encodeStateNode(stateNode), CreateMode.PERSISTENT));
            createFuture.addListener(new Runnable() {

                @Override
                public void run() {
                    try {
                        createFuture.get();
                        // Starts the decorated service
                        decoratedService.addListener(createListener(), Threads.SAME_THREAD_EXECUTOR);
                        decoratedService.start();
                    } catch (Exception e) {
                        notifyFailed(e);
                    }
                }
            }, Threads.SAME_THREAD_EXECUTOR);
        }

        @Override
        public void onFailure(Throwable t) {
            notifyFailed(t);
        }
    });
}
Also used : StateNode(com.continuuity.weave.internal.state.StateNode) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) KeeperException(org.apache.zookeeper.KeeperException) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with StateNode

use of com.continuuity.weave.internal.state.StateNode 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));
}
Also used : StateNode(com.continuuity.weave.internal.state.StateNode) JsonObject(com.google.gson.JsonObject) ServiceController(com.continuuity.weave.api.ServiceController)

Example 3 with StateNode

use of com.continuuity.weave.internal.state.StateNode in project weave by continuuity.

the class ControllerTest method getController.

private WeaveController getController(ZKClient zkClient, RunId runId) {
    WeaveController controller = new AbstractWeaveController(runId, zkClient, ImmutableList.<LogHandler>of()) {

        @Override
        public void kill() {
        // No-op
        }

        @Override
        protected void instanceNodeUpdated(NodeData nodeData) {
        // No-op
        }

        @Override
        protected void stateNodeUpdated(StateNode stateNode) {
        // No-op
        }

        @Override
        public ResourceReport getResourceReport() {
            return null;
        }
    };
    controller.startAndWait();
    return controller;
}
Also used : StateNode(com.continuuity.weave.internal.state.StateNode) WeaveController(com.continuuity.weave.api.WeaveController) NodeData(com.continuuity.weave.zookeeper.NodeData)

Aggregations

StateNode (com.continuuity.weave.internal.state.StateNode)3 ServiceController (com.continuuity.weave.api.ServiceController)1 WeaveController (com.continuuity.weave.api.WeaveController)1 NodeData (com.continuuity.weave.zookeeper.NodeData)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 JsonObject (com.google.gson.JsonObject)1 KeeperException (org.apache.zookeeper.KeeperException)1