use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class WorkflowHttpHandler method resumeWorkflowRun.
@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.");
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ApplicationLifecycleService method removeApplication.
/**
* Delete an application specified by appId.
*
* @param appId the {@link ApplicationId} of the application to be removed
* @throws Exception
*/
public void removeApplication(final ApplicationId appId) throws Exception {
ensureNoRunningPrograms(appId);
ApplicationSpecification spec = store.getApplication(appId);
if (spec == null) {
throw new NotFoundException(appId.toId());
}
// if the application has only one version, do full deletion, else only delete the specified version
if (store.getAllAppVersions(appId).size() == 1) {
deleteApp(appId, spec);
return;
}
deleteAppVersion(appId, spec);
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramLifecycleService method getProgramStatus.
/**
* Returns the program status.
* @param programId the id of the program for which the status call is made
* @return the status of the program
* @throws NotFoundException if the application to which this program belongs was not found
*/
public ProgramStatus getProgramStatus(ProgramId programId) throws Exception {
// check that app exists
ApplicationId appId = programId.getParent();
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new NotFoundException(appId);
}
return getExistingAppProgramStatus(appSpec, programId);
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramLifecycleService method issueStop.
/**
* Issues a command to stop the specified {@link RunId} of the specified {@link ProgramId} and returns a
* {@link ListenableFuture} with the {@link ProgramController} for it.
* Clients can wait for completion of the {@link ListenableFuture}.
*
* @param programId the {@link ProgramId program} to issue a stop for
* @param runId the runId of the program run to stop. If null, all runs of the program as returned by
* {@link ProgramRuntimeService} are stopped.
* @return a list of {@link ListenableFuture} with a {@link ProgramController} that clients can wait on for stop
* to complete.
* @throws NotFoundException if the app, program or run was not found
* @throws BadRequestException if an attempt is made to stop a program that is either not running or
* was started by a workflow
* @throws UnauthorizedException if the user issuing the command is not authorized to stop the program. To stop a
* program, a user requires {@link Action#EXECUTE} permission on the program.
*/
public List<ListenableFuture<ProgramController>> issueStop(ProgramId programId, @Nullable String runId) throws Exception {
authorizationEnforcer.enforce(programId, authenticationContext.getPrincipal(), Action.EXECUTE);
List<ProgramRuntimeService.RuntimeInfo> runtimeInfos = findRuntimeInfo(programId, runId);
if (runtimeInfos.isEmpty()) {
if (!store.applicationExists(programId.getParent())) {
throw new ApplicationNotFoundException(programId.getParent());
} else if (!store.programExists(programId)) {
throw new ProgramNotFoundException(programId);
} else if (runId != null) {
ProgramRunId programRunId = programId.run(runId);
// Check if the program is running and is started by the Workflow
RunRecordMeta runRecord = store.getRun(programId, runId);
if (runRecord != null && runRecord.getProperties().containsKey("workflowrunid") && runRecord.getStatus().equals(ProgramRunStatus.RUNNING)) {
String workflowRunId = runRecord.getProperties().get("workflowrunid");
throw new BadRequestException(String.format("Cannot stop the program '%s' started by the Workflow " + "run '%s'. Please stop the Workflow.", programRunId, workflowRunId));
}
throw new NotFoundException(programRunId);
}
throw new BadRequestException(String.format("Program '%s' is not running.", programId));
}
List<ListenableFuture<ProgramController>> futures = new ArrayList<>();
for (ProgramRuntimeService.RuntimeInfo runtimeInfo : runtimeInfos) {
futures.add(runtimeInfo.getController().stop());
}
return futures;
}
use of co.cask.cdap.common.NotFoundException in project cdap by caskdata.
the class ProgramLifecycleService method getScheduleStatus.
/**
* Gets the state of the given schedule
*
* @return the status of the given schedule
* @throws Exception if failed to get the state of the schedule
*/
public ProgramScheduleStatus getScheduleStatus(ScheduleId scheduleId) throws Exception {
ApplicationId applicationId = scheduleId.getParent();
ApplicationSpecification appSpec = store.getApplication(applicationId);
if (appSpec == null) {
throw new NotFoundException(applicationId);
}
ProgramSchedule schedule = scheduler.getSchedule(scheduleId);
ensureAccess(schedule.getProgramId());
return scheduler.getScheduleStatus(scheduleId);
}
Aggregations