Search in sources :

Example 6 with ApplicationNotFoundException

use of co.cask.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();
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) HttpResponse(co.cask.common.http.HttpResponse) URL(java.net.URL)

Example 7 with ApplicationNotFoundException

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

Example 8 with ApplicationNotFoundException

use of co.cask.cdap.common.ApplicationNotFoundException in project cdap by caskdata.

the class ApplicationClient method delete.

/**
   * Deletes an application.
   *
   * @param app the application to delete
   * @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 void delete(ApplicationId app) throws ApplicationNotFoundException, IOException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s", app.getApplication(), app.getVersion());
    HttpResponse response = restClient.execute(HttpMethod.DELETE, config.resolveNamespacedURLV3(app.getParent(), path), config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new ApplicationNotFoundException(app);
    }
}
Also used : ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) HttpResponse(co.cask.common.http.HttpResponse)

Example 9 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)

Example 10 with ApplicationNotFoundException

use of co.cask.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(workflowProgramId, runId) == 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, nodeStates, STRING_TO_NODESTATEDETAIL_MAP_TYPE);
}
Also used : ApplicationSpecification(co.cask.cdap.api.app.ApplicationSpecification) HashMap(java.util.HashMap) 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) ProgramId(co.cask.cdap.proto.id.ProgramId) WorkflowNodeStateDetail(co.cask.cdap.proto.WorkflowNodeStateDetail) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) WorkflowSpecification(co.cask.cdap.api.workflow.WorkflowSpecification) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) ApplicationId(co.cask.cdap.proto.id.ApplicationId) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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