/** * 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); } }
/** * 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); } }
@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."); }
@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); } }
@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); } }
@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); } }
/** * 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); }
private void verifyResponse(HttpResponse httpResponse) throws ConflictException { if (httpResponse.getResponseCode() == 409) { throw new ConflictException(httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } if (httpResponse.getResponseCode() != 200) { throw new HandlerException(HttpResponseStatus.valueOf(httpResponse.getResponseCode()), httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } } }
private void verifyResponse(HttpResponse httpResponse) throws ConflictException { if (httpResponse.getResponseCode() == 409) { throw new ConflictException(httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } if (httpResponse.getResponseCode() != 200) { throw new HandlerException(HttpResponseStatus.valueOf(httpResponse.getResponseCode()), httpResponse.getResponseBodyAsString(Charsets.UTF_8)); } } }
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)); throw new ConflictException(String.format("Program %s is already running", programId));
/** * Updates the properties of a dataset. * * @param instance the dataset to update * @param properties properties to set * @throws NotFoundException if the dataset is not found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void update(DatasetId instance, Map<String, String> properties) throws NotFoundException, IOException, UnauthenticatedException, ConflictException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(instance.getParent(), String.format("data/datasets/%s/properties", instance.getDataset())); HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(properties)).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(instance); } else if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) { throw new ConflictException(response.getResponseBodyAsString()); } }
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)); throw new ConflictException(String.format("Program %s is already running", programId));
@Override public DatasetCreationResponse update(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props, DatasetSpecification existing) throws Exception { DatasetType type = client.getDatasetType(typeMeta, null, new ConstantClassLoaderProvider()); if (type == null) { throw new IllegalArgumentException("Dataset type cannot be instantiated for provided type meta: " + typeMeta); } try { DatasetSpecification spec = type.reconfigure(datasetInstanceId.getEntityName(), props, existing); DatasetAdmin admin = type.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec); if (admin instanceof Updatable) { ((Updatable) admin).update(existing); } else { admin.create(); } if (spec.getDescription() == null && existing.getDescription() != null) { spec.setDescription(existing.getDescription()); } return new DatasetCreationResponse(spec, null); } catch (IncompatibleUpdateException e) { throw new ConflictException(e.getMessage()); } }
@Override public DatasetCreationResponse update(DatasetId datasetInstanceId, DatasetTypeMeta typeMeta, DatasetProperties props, DatasetSpecification existing) throws Exception { DatasetType type = client.getDatasetType(typeMeta, null, new ConstantClassLoaderProvider()); if (type == null) { throw new IllegalArgumentException("Dataset type cannot be instantiated for provided type meta: " + typeMeta); } try { DatasetSpecification spec = type.reconfigure(datasetInstanceId.getEntityName(), props, existing); DatasetAdmin admin = type.getAdmin(DatasetContext.from(datasetInstanceId.getNamespace()), spec); if (admin instanceof Updatable) { ((Updatable) admin).update(existing); } else { admin.create(); } if (spec.getDescription() == null && existing.getDescription() != null) { spec.setDescription(existing.getDescription()); } return new DatasetCreationResponse(spec, null); } catch (IncompatibleUpdateException e) { throw new ConflictException(e.getMessage()); } }