use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class ApplicationClient method listAppVersions.
/**
* Lists all applications currently deployed, optionally filtering to only include applications that use one of
* the specified artifact names and the specified artifact version.
*
* @param namespace the namespace to list application versions from
* @param appName the application name to list versions for
* @return list of {@link String} application versions.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<String> listAppVersions(NamespaceId namespace, String appName) throws IOException, UnauthenticatedException, UnauthorizedException, ApplicationNotFoundException {
String path = String.format("apps/%s/versions", appName);
URL url = config.resolveNamespacedURLV3(namespace, path);
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(namespace.app(appName));
}
return ObjectResponse.fromJsonBody(response, new TypeToken<List<String>>() {
}).getResponseObject();
}
use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class ApplicationClient method addSchedule.
/**
* Add a schedule to an application.
*
* @param app the application
* @param scheduleDetail the schedule to be added
*/
public void addSchedule(ApplicationId app, ScheduleDetail scheduleDetail) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException, BadRequestException {
String path = String.format("apps/%s/versions/%s/schedules/%s", app.getApplication(), app.getVersion(), scheduleDetail.getName());
HttpResponse response = restClient.execute(HttpMethod.PUT, config.resolveNamespacedURLV3(app.getParent(), path), GSON.toJson(scheduleDetail), ImmutableMap.<String, String>of(), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST);
int responseCode = response.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(app);
} else if (responseCode == HttpURLConnection.HTTP_BAD_REQUEST) {
throw new BadRequestException(String.format("Bad Request. Reason: %s", response.getResponseBodyAsString()));
}
}
use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class ApplicationClient method listPrograms.
/**
* Lists all programs belonging to an application.
*
* @param app the application
* @return List of all {@link ProgramRecord}s
* @throws ApplicationNotFoundException if the application with the given ID was not found
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<ProgramRecord> listPrograms(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
String path = String.format("apps/%s/versions/%s", app.getApplication(), app.getVersion());
URL url = config.resolveNamespacedURLV3(app.getParent(), path);
HttpRequest request = HttpRequest.get(url).build();
HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
throw new ApplicationNotFoundException(app);
}
return ObjectResponse.fromJsonBody(response, ApplicationDetail.class).getResponseObject().getPrograms();
}
use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by caskdata.
the class WorkflowHttpHandler method getWorkflowNodeStates.
@GET
@Path("/apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/nodes/state")
public void getWorkflowNodeStates(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String applicationId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId) throws NotFoundException {
ApplicationId appId = Ids.namespace(namespaceId).app(applicationId);
ApplicationSpecification appSpec = store.getApplication(appId);
if (appSpec == null) {
throw new ApplicationNotFoundException(appId);
}
ProgramId workflowProgramId = appId.workflow(workflowId);
WorkflowSpecification workflowSpec = appSpec.getWorkflows().get(workflowProgramId.getProgram());
if (workflowSpec == null) {
throw new ProgramNotFoundException(workflowProgramId);
}
ProgramRunId workflowRunId = workflowProgramId.run(runId);
if (store.getRun(workflowRunId) == null) {
throw new NotFoundException(workflowRunId);
}
List<WorkflowNodeStateDetail> nodeStateDetails = store.getWorkflowNodeStates(workflowRunId);
Map<String, WorkflowNodeStateDetail> nodeStates = new HashMap<>();
for (WorkflowNodeStateDetail nodeStateDetail : nodeStateDetails) {
nodeStates.put(nodeStateDetail.getNodeId(), nodeStateDetail);
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(nodeStates, STRING_TO_NODESTATEDETAIL_MAP_TYPE));
}
use of io.cdap.cdap.common.ApplicationNotFoundException in project cdap by cdapio.
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.run(runId)) == null) {
throw new NotFoundException(new ProgramRunId(programId.getNamespace(), programId.getApplication(), programId.getType(), programId.getProgram(), runId));
}
return workflowSpec;
}
Aggregations