/** * Deletes all {@link DatasetModuleMeta dataset modules} in the specified {@link NamespaceId namespace}. */ @Override public void deleteAll(NamespaceId namespaceId) throws Exception { if (NamespaceId.SYSTEM.equals(namespaceId)) { throw new UnsupportedOperationException(String.format("Cannot delete modules from '%s' namespace.", namespaceId)); } ensureNamespaceExists(namespaceId); try { typeManager.deleteModules(namespaceId); } catch (DatasetModuleConflictException e) { throw new ConflictException(e.getMessage(), e); } }
output.add(new BatchProgramResult(program, HttpResponseStatus.BAD_REQUEST.code(), e.getMessage())); } catch (ConflictException e) { output.add(new BatchProgramResult(program, HttpResponseStatus.CONFLICT.code(), e.getMessage()));
/** * Deletes all {@link DatasetModuleMeta dataset modules} in the specified {@link NamespaceId namespace}. */ @Override public void deleteAll(NamespaceId namespaceId) throws Exception { if (NamespaceId.SYSTEM.equals(namespaceId)) { throw new UnsupportedOperationException(String.format("Cannot delete modules from '%s' namespace.", namespaceId)); } ensureNamespaceExists(namespaceId); try { typeManager.deleteModules(namespaceId); } catch (DatasetModuleConflictException e) { throw new ConflictException(e.getMessage(), e); } }
throw new BadRequestException(e.getMessage()); } catch (ConflictException e) { responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage()); } catch (NotFoundException | UnauthorizedException e) { throw e;
@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."); }
throw new BadRequestException(e.getMessage()); } catch (ConflictException e) { responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage()); } catch (NotFoundException | UnauthorizedException e) { throw e;
@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."); }
output.add(new BatchProgramResult(program, HttpResponseStatus.BAD_REQUEST.code(), e.getMessage())); } catch (ConflictException e) { output.add(new BatchProgramResult(program, HttpResponseStatus.CONFLICT.code(), e.getMessage()));
@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."); }
responder.sendString(HttpResponseStatus.FORBIDDEN, e.getMessage()); } catch (ConflictException e) { responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage()); } catch (Exception e) { LOG.error("Deploy failure", e);
@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."); }
responder.sendString(HttpResponseStatus.FORBIDDEN, e.getMessage()); } catch (ConflictException e) { responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage()); } catch (Exception e) { LOG.error("Deploy failure", e);
@Override public void disableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreAndQueueTxRunnable<Void, Exception>) (store, queue) -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SCHEDULED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already disabled"); } timeSchedulerService.suspendProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SUSPENDED); queue.markJobsForDeletion(scheduleId, System.currentTimeMillis()); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage()); } catch (ConflictException e) { responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage()); } catch (UnauthorizedException e) { responder.sendString(HttpResponseStatus.FORBIDDEN, e.getMessage());
@Override public void enableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreTxRunnable<Void, Exception>) store -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SUSPENDED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already enabled"); } timeSchedulerService.resumeProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SCHEDULED); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
responder.sendString(HttpResponseStatus.NOT_FOUND, e.getMessage()); } catch (ConflictException e) { responder.sendString(HttpResponseStatus.CONFLICT, e.getMessage()); } catch (UnauthorizedException e) { responder.sendString(HttpResponseStatus.FORBIDDEN, e.getMessage());
@Override public void enableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreTxRunnable<Void, Exception>) store -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SUSPENDED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already enabled"); } timeSchedulerService.resumeProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SCHEDULED); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
@Override public void disableSchedule(ScheduleId scheduleId) throws NotFoundException, ConflictException { checkStarted(); try { execute((StoreAndQueueTxRunnable<Void, Exception>) (store, queue) -> { ProgramScheduleRecord record = store.getScheduleRecord(scheduleId); if (ProgramScheduleStatus.SCHEDULED != record.getMeta().getStatus()) { throw new ConflictException("Schedule '" + scheduleId + "' is already disabled"); } timeSchedulerService.suspendProgramSchedule(record.getSchedule()); store.updateScheduleStatus(scheduleId, ProgramScheduleStatus.SUSPENDED); queue.markJobsForDeletion(scheduleId, System.currentTimeMillis()); return null; }, Exception.class); } catch (NotFoundException | ConflictException e) { throw e; } catch (SchedulerException e) { // TODO: [CDAP-11574] temporarily catch the SchedulerException and throw RuntimeException. throw new RuntimeException("Exception occurs when enabling schedule " + scheduleId, e); } catch (Exception e) { throw Throwables.propagate(e); } }
/** * Starts a Program with the specified argument overrides. * * @param programId the {@link ProgramId} to start/stop * @param overrides the arguments to override in the program's configured user arguments before starting * @param debug {@code true} if the program is to be started in debug mode, {@code false} otherwise * @return {@link RunId} * @throws ConflictException if the specified program is already running, and if concurrent runs are not allowed * @throws NotFoundException if the specified program or the app it belongs to is not found in the specified namespace * @throws IOException if there is an error starting the program * @throws UnauthorizedException if the logged in user is not authorized to start the program. To start a program, * a user requires {@link Action#EXECUTE} on the program * @throws Exception if there were other exceptions checking if the current user is authorized to start the program */ public synchronized RunId run(ProgramId programId, Map<String, String> overrides, boolean debug) throws Exception { authorizationEnforcer.enforce(programId, authenticationContext.getPrincipal(), Action.EXECUTE); if (isConcurrentRunsInSameAppForbidden(programId.getType()) && !isStoppedInSameProgram(programId)) { throw new ConflictException(String.format("Program %s is already running in an version of the same application", programId)); } if (!isStopped(programId) && !isConcurrentRunsAllowed(programId.getType())) { throw new ConflictException(String.format("Program %s is already running", programId)); } Map<String, String> sysArgs = propertiesResolver.getSystemProperties(Id.Program.fromEntityId(programId)); Map<String, String> userArgs = propertiesResolver.getUserProperties(Id.Program.fromEntityId(programId)); if (overrides != null) { userArgs.putAll(overrides); } return runInternal(programId, userArgs, sysArgs, debug); }
/** * Starts a Program with the specified argument overrides. * * @param programId the {@link ProgramId} to start/stop * @param overrides the arguments to override in the program's configured user arguments before starting * @param debug {@code true} if the program is to be started in debug mode, {@code false} otherwise * @return {@link RunId} * @throws ConflictException if the specified program is already running, and if concurrent runs are not allowed * @throws NotFoundException if the specified program or the app it belongs to is not found in the specified namespace * @throws IOException if there is an error starting the program * @throws UnauthorizedException if the logged in user is not authorized to start the program. To start a program, * a user requires {@link Action#EXECUTE} on the program * @throws Exception if there were other exceptions checking if the current user is authorized to start the program */ public synchronized RunId run(ProgramId programId, Map<String, String> overrides, boolean debug) throws Exception { authorizationEnforcer.enforce(programId, authenticationContext.getPrincipal(), Action.EXECUTE); if (isConcurrentRunsInSameAppForbidden(programId.getType()) && !isStoppedInSameProgram(programId)) { throw new ConflictException(String.format("Program %s is already running in an version of the same application", programId)); } if (!isStopped(programId) && !isConcurrentRunsAllowed(programId.getType())) { throw new ConflictException(String.format("Program %s is already running", programId)); } Map<String, String> sysArgs = propertiesResolver.getSystemProperties(Id.Program.fromEntityId(programId)); Map<String, String> userArgs = propertiesResolver.getUserProperties(Id.Program.fromEntityId(programId)); if (overrides != null) { userArgs.putAll(overrides); } return runInternal(programId, userArgs, sysArgs, debug); }