@Override public ProgramController.State call() throws Exception { return controller.getState(); } }, 30, TimeUnit.SECONDS);
@Override public List<RuntimeInfo> listAll(ProgramType... types) { List<RuntimeInfo> runningPrograms = new ArrayList<>(); for (ProgramType type : types) { for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) { ProgramController.State programState = entry.getValue().getController().getState(); if (programState.isDone()) { continue; } runningPrograms.add(entry.getValue()); } } return runningPrograms; }
@Override public List<RuntimeInfo> listAll(ProgramType... types) { List<RuntimeInfo> runningPrograms = new ArrayList<>(); for (ProgramType type : types) { for (Map.Entry<RunId, RuntimeInfo> entry : list(type).entrySet()) { ProgramController.State programState = entry.getValue().getController().getState(); if (programState.isDone()) { continue; } runningPrograms.add(entry.getValue()); } } return runningPrograms; }
@Override public ProgramController.State call() throws Exception { Throwable t = errorCause.get(); if (t != null) { Throwables.propagateIfInstanceOf(t, Exception.class); throw Throwables.propagate(t); } return controller.getState(); } }, 30, TimeUnit.SECONDS);
@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."); }
@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}/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."); }
while (!controller.getState().equals(ProgramController.State.COMPLETED)) { TimeUnit.MILLISECONDS.sleep(100);