private ProgramController addStateChangeListener(ProgramController controller) { controller.addListener(new StateChangeListener(controller.getProgramRunId(), null, programStateWriter), Threads.SAME_THREAD_EXECUTOR); return controller; }
@Override public ProgramController.State call() throws Exception { return controller.getState(); } }, 30, TimeUnit.SECONDS);
@Override public ListenableFuture<?> apply(ProgramController input) { return input.stop(); } })).get();
@Override public void handleCommand(Command command) throws Exception { // need to make sure controller exists before handling the command if (ProgramCommands.SUSPEND.equals(command)) { controllerFuture.get().suspend().get(); return; } if (ProgramCommands.RESUME.equals(command)) { controllerFuture.get().resume().get(); return; } if (ProgramOptionConstants.INSTANCES.equals(command.getCommand())) { int instances = Integer.parseInt(command.getOptions().get("count")); controllerFuture.get().command(ProgramOptionConstants.INSTANCES, instances).get(); return; } LOG.warn("Ignore unsupported command: " + command); }
controller.addListener(new AbstractListener() { } catch (InterruptedException e) { try { Futures.getUnchecked(controller.stop()); } catch (Throwable t) {
private void monitorComponents() { for (ProgramController controller : components.values()) { controller.addListener(new AbstractListener() { @Override public void completed() { if (liveComponents.decrementAndGet() == 0) { // If at least one of the components failed with an error, then set the state to ERROR if (errorCause != null) { setError(errorCause); } else { complete(); } } } @Override public void error(Throwable cause) { // Make a note that a component failed with an error errorCause = cause; // If the live component count goes to zero, then set the state of the controller to ERROR if (liveComponents.decrementAndGet() == 0) { setError(cause); } } }, Threads.SAME_THREAD_EXECUTOR); } }
@POST @Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/suspend") public void suspendWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception { ProgramId id = new ProgramId(namespaceId, appId, ProgramType.WORKFLOW, workflowName); ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.list(id).get(RunIds.fromString(runId)); if (runtimeInfo == null) { throw new NotFoundException(id.run(runId)); } ProgramController controller = runtimeInfo.getController(); if (controller.getState() == ProgramController.State.SUSPENDED) { throw new ConflictException("Program run already suspended"); } controller.suspend().get(); responder.sendString(HttpResponseStatus.OK, "Program run suspended."); }
@POST @Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/resume") public void resumeWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception { ProgramId id = new ProgramId(namespaceId, appId, ProgramType.WORKFLOW, workflowName); ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.list(id).get(RunIds.fromString(runId)); if (runtimeInfo == null) { throw new NotFoundException(id.run(runId)); } ProgramController controller = runtimeInfo.getController(); if (controller.getState() == ProgramController.State.ALIVE) { throw new ConflictException("Program is already running"); } controller.resume().get(); responder.sendString(HttpResponseStatus.OK, "Program run resumed."); }
List<ListenableFuture<ProgramController>> futures = Lists.newArrayListWithCapacity(liveCount - newCount); for (int instanceId = liveCount - 1; instanceId >= newCount; instanceId--) { futures.add(components.remove(runnableName, instanceId).stop()); entry.getValue().command(ProgramOptionConstants.INSTANCES, newCount);
private void add(RuntimeInfo runtimeInfo) { Lock lock = runtimeInfosLock.writeLock(); lock.lock(); try { runtimeInfos.put(runtimeInfo.getType(), runtimeInfo.getController().getRunId(), runtimeInfo); } finally { lock.unlock(); } }
@Override public ListenableFuture<?> apply(ProgramController controller) { return controller.command(ProgramOptionConstants.INSTANCES, newInstanceCount); } })).get();
@Override public ListenableFuture<?> apply(ProgramController controller) { return controller.resume(); } })).get();
@Override public ListenableFuture<ProgramController> apply(ProgramController input) { return input.suspend(); } })).get();
controller.addListener(new AbstractListener() { } catch (InterruptedException e) { try { Futures.getUnchecked(controller.stop()); } catch (Throwable t) {
private void monitorComponents() { for (ProgramController controller : components.values()) { controller.addListener(new AbstractListener() { @Override public void completed() { if (liveComponents.decrementAndGet() == 0) { // If at least one of the components failed with an error, then set the state to ERROR if (errorCause != null) { setError(errorCause); } else { complete(); } } } @Override public void error(Throwable cause) { // Make a note that a component failed with an error errorCause = cause; // If the live component count goes to zero, then set the state of the controller to ERROR if (liveComponents.decrementAndGet() == 0) { setError(cause); } } }, Threads.SAME_THREAD_EXECUTOR); } }
@Override public void handleCommand(Command command) throws Exception { // need to make sure controller exists before handling the command if (ProgramCommands.SUSPEND.equals(command)) { controllerFuture.get().suspend().get(); return; } if (ProgramCommands.RESUME.equals(command)) { controllerFuture.get().resume().get(); return; } if (ProgramOptionConstants.INSTANCES.equals(command.getCommand())) { int instances = Integer.parseInt(command.getOptions().get("count")); controllerFuture.get().command(ProgramOptionConstants.INSTANCES, instances).get(); return; } LOG.warn("Ignore unsupported command: " + command); }
@POST @Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/suspend") public void suspendWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception { ProgramId id = new ProgramId(namespaceId, appId, ProgramType.WORKFLOW, workflowName); ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.list(id).get(RunIds.fromString(runId)); if (runtimeInfo == null) { throw new NotFoundException(id.run(runId)); } ProgramController controller = runtimeInfo.getController(); if (controller.getState() == ProgramController.State.SUSPENDED) { throw new ConflictException("Program run already suspended"); } controller.suspend().get(); responder.sendString(HttpResponseStatus.OK, "Program run suspended."); }
@POST @Path("/apps/{app-id}/workflows/{workflow-name}/runs/{run-id}/resume") public void resumeWorkflowRun(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-name") String workflowName, @PathParam("run-id") String runId) throws Exception { ProgramId id = new ProgramId(namespaceId, appId, ProgramType.WORKFLOW, workflowName); ProgramRuntimeService.RuntimeInfo runtimeInfo = runtimeService.list(id).get(RunIds.fromString(runId)); if (runtimeInfo == null) { throw new NotFoundException(id.run(runId)); } ProgramController controller = runtimeInfo.getController(); if (controller.getState() == ProgramController.State.ALIVE) { throw new ConflictException("Program is already running"); } controller.resume().get(); responder.sendString(HttpResponseStatus.OK, "Program run resumed."); }
List<ListenableFuture<ProgramController>> futures = Lists.newArrayListWithCapacity(liveCount - newCount); for (int instanceId = liveCount - 1; instanceId >= newCount; instanceId--) { futures.add(components.remove(runnableName, instanceId).stop()); entry.getValue().command(ProgramOptionConstants.INSTANCES, newCount);