Search in sources :

Example 11 with ApplicationNotFoundException

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);
}
Also used : ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with ApplicationNotFoundException

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();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) URL(java.net.URL)

Example 13 with ApplicationNotFoundException

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;
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) InstanceNotFoundException(co.cask.cdap.api.dataset.InstanceNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramId(co.cask.cdap.proto.id.ProgramId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException)

Example 14 with ApplicationNotFoundException

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);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException)

Example 15 with ApplicationNotFoundException

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);
    }
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) ApplicationId(co.cask.cdap.proto.id.ApplicationId) WorkflowId(co.cask.cdap.proto.id.WorkflowId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ScheduledRuntime(co.cask.cdap.proto.ScheduledRuntime)

Aggregations

ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)17 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)8 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)7 ApplicationId (co.cask.cdap.proto.id.ApplicationId)6 HttpResponse (co.cask.common.http.HttpResponse)5 NotFoundException (co.cask.cdap.common.NotFoundException)4 ProgramId (co.cask.cdap.proto.id.ProgramId)3 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)3 URL (java.net.URL)3 InstanceNotFoundException (co.cask.cdap.api.dataset.InstanceNotFoundException)2 WorkflowSpecification (co.cask.cdap.api.workflow.WorkflowSpecification)2 ProgramRuntimeService (co.cask.cdap.app.runtime.ProgramRuntimeService)2 NamespaceId (co.cask.cdap.proto.id.NamespaceId)2 HttpRequest (co.cask.common.http.HttpRequest)2 TypeToken (com.google.common.reflect.TypeToken)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ArtifactId (co.cask.cdap.api.artifact.ArtifactId)1