use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class AppLifecycleHttpHandler method listAppVersions.
/**
* Returns the list of versions of the application.
*/
@GET
@Path("/apps/{app-id}/versions")
public void listAppVersions(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") final String namespaceId, @PathParam("app-id") final String appId) throws Exception {
ApplicationId applicationId = validateApplicationId(namespaceId, appId);
Collection<String> versions = applicationLifecycleService.getAppVersions(namespaceId, appId);
if (versions.isEmpty()) {
throw new ApplicationNotFoundException(applicationId);
}
responder.sendJson(HttpResponseStatus.OK, versions);
}
use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class PreferencesClient method getApplicationPreferences.
/**
* Returns the Preferences stored at the Application Level.
*
* @param application Application Id
* @param resolved Set to True if collapsed/resolved properties are desired
* @return map of key-value pairs
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
* @throws ApplicationNotFoundException if the requested application is not found
*/
public Map<String, String> getApplicationPreferences(ApplicationId application, boolean resolved) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
String res = Boolean.toString(resolved);
URL url = config.resolveNamespacedURLV3(application.getParent(), String.format("/apps/%s/preferences?resolved=%s", application.getApplication(), res));
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new NotFoundException(application);
}
return ObjectResponse.fromJsonBody(response, new TypeToken<Map<String, String>>() {
}).getResponseObject();
}
use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowSpecForValidRun.
/**
* Get the {@link WorkflowSpecification} if valid application id, workflow id, and runid are provided.
* @param namespaceId the namespace id
* @param applicationId the application id
* @param workflowId the workflow id
* @param runId the runid of the workflow
* @return the specifications for the Workflow
* @throws NotFoundException is thrown when the application, workflow, or runid is not found
*/
private WorkflowSpecification getWorkflowSpecForValidRun(String namespaceId, String applicationId, String workflowId, String runId) throws NotFoundException {
ApplicationId appId = new ApplicationId(namespaceId, applicationId);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowId);
ProgramId programId = new ProgramId(namespaceId, applicationId, ProgramType.WORKFLOW, workflowId);
if (workflowSpec == null) {
throw new ProgramNotFoundException(programId);
}
if (store.getRun(programId, runId) == null) {
throw new NotFoundException(new ProgramRunId(programId.getNamespace(), programId.getApplication(), programId.getType(), programId.getProgram(), runId));
}
return workflowSpec;
}
use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class ApplicationLifecycleService method getAppDetail.
/**
* Get detail about the specified application
*
* @param appId the id of the application to get
* @return detail about the specified application
* @throws ApplicationNotFoundException if the specified application does not exist
*/
public ApplicationDetail getAppDetail(ApplicationId appId) throws Exception {
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
ensureAccess(appId);
String ownerPrincipal = ownerAdmin.getOwnerPrincipal(appId);
return ApplicationDetail.fromSpec(appSpec, ownerPrincipal);
}
use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class WorkflowHttpHandler method getScheduledRuntime.
private void getScheduledRuntime(HttpResponder responder, String namespaceId, String appName, String workflowName, boolean previousRuntimeRequested) throws SchedulerException, NotFoundException {
try {
ApplicationId appId = new ApplicationId(namespaceId, appName);
WorkflowId workflowId = new WorkflowId(appId, workflowName);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
if (appSpec.getWorkflows().get(workflowName) == null) {
throw new ProgramNotFoundException(workflowId);
}
List<ScheduledRuntime> runtimes;
if (previousRuntimeRequested) {
runtimes = scheduler.previousScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
} else {
runtimes = scheduler.nextScheduledRuntime(workflowId, SchedulableProgramType.WORKFLOW);
}
responder.sendJson(HttpResponseStatus.OK, runtimes);
} catch (SecurityException e) {
responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
}
}
Aggregations