use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class DefaultPreviewManager method getStatus.
@Override
public PreviewStatus getStatus(@Name("applicationId") ApplicationId applicationId) throws NotFoundException, AccessException {
accessEnforcer.enforce(applicationId, authenticationContext.getPrincipal(), ApplicationPermission.PREVIEW);
PreviewStatus status = previewStore.getPreviewStatus(applicationId);
if (status == null) {
throw new NotFoundException(applicationId);
}
if (status.getStatus() == PreviewStatus.Status.WAITING) {
int position = previewRequestQueue.positionOf(applicationId);
if (position == -1) {
// status is WAITING but application is not present in in-memory queue
position = 0;
}
status = new PreviewStatus(status.getStatus(), status.getSubmitTime(), status.getThrowable(), status.getStartTime(), status.getEndTime(), position);
}
return status;
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class WorkflowStatsSLAHttpHandler method compare.
/**
* Compare the metrics of 2 runs of a workflow
*
* @param request The request
* @param responder The responder
* @param namespaceId The namespace the application is in
* @param appId The application the workflow is in
* @param workflowId The workflow that needs to have it stats shown
* @param runId The run id of the Workflow that the user wants to see
* @param otherRunId The other run id of the same workflow that the user wants to compare against
*/
@GET
@Path("apps/{app-id}/workflows/{workflow-id}/runs/{run-id}/compare")
public void compare(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("workflow-id") String workflowId, @PathParam("run-id") String runId, @QueryParam("other-run-id") String otherRunId) throws Exception {
WorkflowId workflow = new WorkflowId(namespaceId, appId, workflowId);
WorkflowRunMetrics detailedStatistics = getDetailedRecord(workflow, runId);
WorkflowRunMetrics otherDetailedStatistics = getDetailedRecord(workflow, otherRunId);
if (detailedStatistics == null) {
throw new NotFoundException("The run-id provided was not found : " + runId);
}
if (otherDetailedStatistics == null) {
throw new NotFoundException("The other run-id provided was not found : " + otherRunId);
}
List<WorkflowRunMetrics> workflowRunMetricsList = new ArrayList<>();
workflowRunMetricsList.add(detailedStatistics);
workflowRunMetricsList.add(otherDetailedStatistics);
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(format(workflowRunMetricsList)));
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class AppLifecycleHttpHandler method upgradeApplications.
/**
* Upgrades a lis of existing application to use latest version of application artifact and plugin artifacts.
*
* <pre>
* {@code
* [
* {"name":"XYZ"},
* {"name":"ABC"},
* {"name":"FOO"},
* ]
* }
* </pre>
* The response will be an array of {@link ApplicationUpdateDetail} object, which either indicates a success (200) or
* failure for each of the requested application in the same order as the request. The failure also indicates reason
* for the error. The response will be sent via ChunkResponder to continuously stream upgrade result per application.
*/
@POST
@Path("/upgrade")
@AuditPolicy(AuditDetail.REQUEST_BODY)
public void upgradeApplications(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @QueryParam("artifactScope") Set<String> artifactScopes, @QueryParam("allowSnapshot") boolean allowSnapshot) throws Exception {
// TODO: (CDAP-16910) Improve batch API performance as each application upgrade is an event independent of each
// other.
List<ApplicationId> appIds = decodeAndValidateBatchApplicationRecord(validateNamespace(namespaceId), request);
Set<ArtifactScope> allowedArtifactScopes = getArtifactScopes(artifactScopes);
try (ChunkResponder chunkResponder = responder.sendChunkStart(HttpResponseStatus.OK)) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (JsonWriter jsonWriter = new JsonWriter(new OutputStreamWriter(outputStream, StandardCharsets.UTF_8))) {
jsonWriter.beginArray();
for (ApplicationId appId : appIds) {
ApplicationUpdateDetail updateDetail;
try {
applicationLifecycleService.upgradeApplication(appId, allowedArtifactScopes, allowSnapshot);
updateDetail = new ApplicationUpdateDetail(appId);
} catch (UnsupportedOperationException e) {
String errorMessage = String.format("Application %s does not support upgrade.", appId);
updateDetail = new ApplicationUpdateDetail(appId, new NotImplementedException(errorMessage));
} catch (InvalidArtifactException | NotFoundException e) {
updateDetail = new ApplicationUpdateDetail(appId, e);
} catch (Exception e) {
updateDetail = new ApplicationUpdateDetail(appId, new ServiceException("Upgrade failed due to internal error.", e, HttpResponseStatus.INTERNAL_SERVER_ERROR));
LOG.error("Application upgrade failed with exception", e);
}
GSON.toJson(updateDetail, ApplicationUpdateDetail.class, jsonWriter);
jsonWriter.flush();
chunkResponder.sendChunk(Unpooled.wrappedBuffer(outputStream.toByteArray()));
outputStream.reset();
chunkResponder.flush();
}
jsonWriter.endArray();
}
chunkResponder.sendChunk(Unpooled.wrappedBuffer(outputStream.toByteArray()));
}
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class AppLifecycleHttpHandler method getApplicationDetails.
/**
* Gets {@link ApplicationDetail} for a set of applications. It expects a post body as a array of object, with each
* object specifying the applciation id and an optional version. E.g.
*
* <pre>
* {@code
* [
* {"appId":"XYZ", "version":"1.2.3"},
* {"appId":"ABC"},
* {"appId":"FOO", "version":"2.3.4"},
* ]
* }
* </pre>
* The response will be an array of {@link BatchApplicationDetail} object, which either indicates a success (200) or
* failure for each of the requested application in the same order as the request.
*/
@POST
@Path("/appdetail")
public void getApplicationDetails(FullHttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespace) throws Exception {
List<ApplicationId> appIds = decodeAndValidateBatchApplication(validateNamespace(namespace), request);
Map<ApplicationId, ApplicationDetail> details = applicationLifecycleService.getAppDetails(appIds);
List<BatchApplicationDetail> result = new ArrayList<>();
for (ApplicationId appId : appIds) {
ApplicationDetail detail = details.get(appId);
if (detail == null) {
result.add(new BatchApplicationDetail(new NotFoundException(appId)));
} else {
result.add(new BatchApplicationDetail(detail));
}
}
responder.sendJson(HttpResponseStatus.OK, GSON.toJson(result));
}
use of io.cdap.cdap.common.NotFoundException in project cdap by caskdata.
the class DefaultPreviewRunnerManager method stop.
@Override
public void stop(ApplicationId preview) throws Exception {
PreviewRunnerService runnerService = previewRunnerServices.stream().filter(r -> r.getPreviewApplication().filter(preview::equals).isPresent()).findFirst().orElse(null);
if (runnerService == null) {
throw new NotFoundException("Preview run cannot be stopped. Please try stopping again or start new preview run.");
}
PreviewRunnerService newRunnerService = createPreviewRunnerService();
runnerService.stopAndWait();
newRunnerService.startAndWait();
}
Aggregations