Search in sources :

Example 51 with NotFoundException

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

the class ProgramClient method getWorkflowCurrent.

/**
   * Get the current run information for the Workflow based on the runid
   *
   * @param workflowId ID of the workflow
   * @param runId ID of the run for which the details are to be returned
   * @return list of {@link WorkflowActionNode} currently running for the given runid
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application, workflow, or runid could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<WorkflowActionNode> getWorkflowCurrent(WorkflowId workflowId, String runId) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    String path = String.format("/apps/%s/workflows/%s/runs/%s/current", workflowId.getApplication(), workflowId.getProgram(), runId);
    URL url = config.resolveNamespacedURLV3(workflowId.getNamespaceId(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(workflowId.run(runId));
    }
    ObjectResponse<List<WorkflowActionNode>> objectResponse = ObjectResponse.fromJsonBody(response, new TypeToken<List<WorkflowActionNode>>() {
    }.getType(), GSON);
    return objectResponse.getResponseObject();
}
Also used : TypeToken(com.google.common.reflect.TypeToken) WorkflowActionNode(co.cask.cdap.api.workflow.WorkflowActionNode) HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) List(java.util.List) URL(java.net.URL)

Example 52 with NotFoundException

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

the class MonitorClient method getSystemServiceInstances.

/**
   * Gets the number of instances the system service is running on.
   *
   * @param serviceName name of the system service
   * @return number of instances the system service is running on
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the system service with the specified name was not found
   * @throws ServiceNotEnabledException if the system service is not currently enabled
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public int getSystemServiceInstances(String serviceName) throws IOException, NotFoundException, ServiceNotEnabledException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_FORBIDDEN);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(new SystemServiceId(serviceName));
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN) {
        throw new ServiceNotEnabledException(serviceName);
    }
    return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances();
}
Also used : SystemServiceId(co.cask.cdap.proto.id.SystemServiceId) ServiceNotEnabledException(co.cask.cdap.common.ServiceNotEnabledException) HttpResponse(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Example 53 with NotFoundException

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

the class ScheduleClient method getStatus.

public String getStatus(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s/schedules/%s/status", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
    URL url = config.resolveNamespacedURLV3(scheduleId.getParent().getParent(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
        throw new NotFoundException(scheduleId);
    }
    Map<String, String> responseObject = ObjectResponse.<Map<String, String>>fromJsonBody(response, MAP_STRING_STRING_TYPE, GSON).getResponseObject();
    return responseObject.get("status");
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Example 54 with NotFoundException

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

the class ScheduleClient method resume.

public void resume(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s/schedules/%s/resume", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
    URL url = config.resolveNamespacedURLV3(scheduleId.toId().getNamespace(), path);
    HttpResponse response = restClient.execute(HttpMethod.POST, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
        throw new NotFoundException(scheduleId);
    }
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Example 55 with NotFoundException

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

the class AbstractMetadataClient method makeRequest.

// makes a request and throws BadRequestException or NotFoundException, as appropriate
private HttpResponse makeRequest(Id.NamespacedId namespacedId, String path, HttpMethod httpMethod, @Nullable String body) throws IOException, UnauthenticatedException, NotFoundException, BadRequestException, UnauthorizedException {
    URL url = resolve(namespacedId.getNamespace(), path);
    HttpRequest.Builder builder = HttpRequest.builder(httpMethod, url);
    if (body != null) {
        builder.withBody(body);
    }
    HttpResponse response = execute(builder.build(), HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
        throw new BadRequestException(response.getResponseBodyAsString());
    }
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(namespacedId.toEntityId());
    }
    return response;
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) HttpResponse(co.cask.common.http.HttpResponse) BadRequestException(co.cask.cdap.common.BadRequestException) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Aggregations

NotFoundException (co.cask.cdap.common.NotFoundException)122 URL (java.net.URL)42 HttpResponse (co.cask.common.http.HttpResponse)41 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)28 NamespaceNotFoundException (co.cask.cdap.common.NamespaceNotFoundException)26 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)25 Path (javax.ws.rs.Path)25 BadRequestException (co.cask.cdap.common.BadRequestException)22 ProgramId (co.cask.cdap.proto.id.ProgramId)19 ApplicationId (co.cask.cdap.proto.id.ApplicationId)17 NamespaceId (co.cask.cdap.proto.id.NamespaceId)14 Test (org.junit.Test)14 POST (javax.ws.rs.POST)12 HttpRequest (co.cask.common.http.HttpRequest)10 IOException (java.io.IOException)10 GET (javax.ws.rs.GET)10 ApplicationSpecification (co.cask.cdap.api.app.ApplicationSpecification)9 ArtifactNotFoundException (co.cask.cdap.common.ArtifactNotFoundException)8 DatasetTypeNotFoundException (co.cask.cdap.common.DatasetTypeNotFoundException)8 TypeToken (com.google.common.reflect.TypeToken)8