Search in sources :

Example 21 with NotFoundException

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;
}
Also used : PreviewStatus(io.cdap.cdap.app.preview.PreviewStatus) NotFoundException(io.cdap.cdap.common.NotFoundException)

Example 22 with NotFoundException

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)));
}
Also used : ArrayList(java.util.ArrayList) NotFoundException(io.cdap.cdap.common.NotFoundException) WorkflowId(io.cdap.cdap.proto.id.WorkflowId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 23 with NotFoundException

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()));
    }
}
Also used : NotImplementedException(io.cdap.cdap.common.NotImplementedException) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonWriter(com.google.gson.stream.JsonWriter) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) UnauthorizedException(io.cdap.cdap.security.spi.authorization.UnauthorizedException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) WriteConflictException(io.cdap.cdap.internal.app.runtime.artifact.WriteConflictException) DatasetManagementException(io.cdap.cdap.api.dataset.DatasetManagementException) IOException(java.io.IOException) ConflictException(io.cdap.cdap.common.ConflictException) NotImplementedException(io.cdap.cdap.common.NotImplementedException) ExecutionException(java.util.concurrent.ExecutionException) AccessException(io.cdap.cdap.api.security.AccessException) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) ArtifactAlreadyExistsException(io.cdap.cdap.common.ArtifactAlreadyExistsException) NotFoundException(io.cdap.cdap.common.NotFoundException) ServiceException(io.cdap.cdap.common.ServiceException) JsonSyntaxException(com.google.gson.JsonSyntaxException) BadRequestException(io.cdap.cdap.common.BadRequestException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) ArtifactScope(io.cdap.cdap.api.artifact.ArtifactScope) ApplicationUpdateDetail(io.cdap.cdap.proto.ApplicationUpdateDetail) ServiceException(io.cdap.cdap.common.ServiceException) OutputStreamWriter(java.io.OutputStreamWriter) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) ChunkResponder(io.cdap.http.ChunkResponder) InvalidArtifactException(io.cdap.cdap.common.InvalidArtifactException) Path(javax.ws.rs.Path) AuditPolicy(io.cdap.cdap.common.security.AuditPolicy) POST(javax.ws.rs.POST)

Example 24 with NotFoundException

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));
}
Also used : ApplicationDetail(io.cdap.cdap.proto.ApplicationDetail) BatchApplicationDetail(io.cdap.cdap.proto.BatchApplicationDetail) ArrayList(java.util.ArrayList) ApplicationNotFoundException(io.cdap.cdap.common.ApplicationNotFoundException) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException) NotFoundException(io.cdap.cdap.common.NotFoundException) ArtifactNotFoundException(io.cdap.cdap.common.ArtifactNotFoundException) BatchApplicationDetail(io.cdap.cdap.proto.BatchApplicationDetail) ApplicationId(io.cdap.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 25 with NotFoundException

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();
}
Also used : PreviewRunnerService(io.cdap.cdap.internal.app.preview.PreviewRunnerService) NotFoundException(io.cdap.cdap.common.NotFoundException)

Aggregations

NotFoundException (io.cdap.cdap.common.NotFoundException)266 HttpResponse (io.cdap.common.http.HttpResponse)86 URL (java.net.URL)76 ApplicationNotFoundException (io.cdap.cdap.common.ApplicationNotFoundException)54 ProgramId (io.cdap.cdap.proto.id.ProgramId)52 NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)50 ApplicationId (io.cdap.cdap.proto.id.ApplicationId)50 Path (javax.ws.rs.Path)50 BadRequestException (io.cdap.cdap.common.BadRequestException)42 ProgramNotFoundException (io.cdap.cdap.common.ProgramNotFoundException)42 ApplicationSpecification (io.cdap.cdap.api.app.ApplicationSpecification)36 NamespaceId (io.cdap.cdap.proto.id.NamespaceId)36 IOException (java.io.IOException)36 GET (javax.ws.rs.GET)36 Test (org.junit.Test)30 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)28 HashMap (java.util.HashMap)28 ProgramSpecification (io.cdap.cdap.api.ProgramSpecification)26 ConflictException (io.cdap.cdap.common.ConflictException)26 ArrayList (java.util.ArrayList)26