Search in sources :

Example 96 with NotFoundException

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

the class ProgramClient method getProgramRuns.

/**
   * Gets the run records of a program.
   *
   * @param program the program
   * @param state - filter by status of the program
   * @return the run records of the program
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application or program could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public List<RunRecord> getProgramRuns(ProgramId program, String state, long startTime, long endTime, int limit) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    String queryParams = String.format("%s=%s&%s=%d&%s=%d&%s=%d", Constants.AppFabric.QUERY_PARAM_STATUS, state, Constants.AppFabric.QUERY_PARAM_START_TIME, startTime, Constants.AppFabric.QUERY_PARAM_END_TIME, endTime, Constants.AppFabric.QUERY_PARAM_LIMIT, limit);
    String path = String.format("apps/%s/versions/%s/%s/%s/runs?%s", program.getApplication(), program.getVersion(), program.getType().getCategoryName(), program.getProgram(), queryParams);
    URL url = config.resolveNamespacedURLV3(program.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(program);
    }
    return ObjectResponse.fromJsonBody(response, new TypeToken<List<RunRecord>>() {
    }).getResponseObject();
}
Also used : RunRecord(co.cask.cdap.proto.RunRecord) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Example 97 with NotFoundException

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

the class ProgramClient method setFlowletInstances.

/**
   * Sets the number of instances that a flowlet will run on.
   *
   * @param flowlet the flowlet
   * @param instances number of instances for the flowlet to run on
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application, flow, or flowlet could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public void setFlowletInstances(FlowletId flowlet, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(flowlet.getParent().getNamespaceId(), String.format("apps/%s/flows/%s/flowlets/%s/instances", flowlet.getApplication(), flowlet.getFlow(), flowlet.getFlowlet()));
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(flowlet);
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) Instances(co.cask.cdap.proto.Instances) HttpResponse(co.cask.common.http.HttpResponse) ProgramNotFoundException(co.cask.cdap.common.ProgramNotFoundException) ApplicationNotFoundException(co.cask.cdap.common.ApplicationNotFoundException) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Example 98 with NotFoundException

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

the class ScheduleClient method delete.

/**
   * Delete an existing schedule.
   *
   * @param scheduleId the ID of the schedule to be deleted
   */
public void delete(ScheduleId scheduleId) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String path = String.format("apps/%s/versions/%s/schedules/%s", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
    URL url = config.resolveNamespacedURLV3(scheduleId.toId().getNamespace(), path);
    HttpResponse response = restClient.execute(HttpMethod.DELETE, 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 99 with NotFoundException

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

the class ScheduleClient method doUpdate.

private void doUpdate(ScheduleId scheduleId, String json) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException, AlreadyExistsException {
    String path = String.format("apps/%s/versions/%s/schedules/%s/update", scheduleId.getApplication(), scheduleId.getVersion(), scheduleId.getSchedule());
    URL url = config.resolveNamespacedURLV3(scheduleId.getNamespaceId(), path);
    HttpRequest request = HttpRequest.post(url).withBody(json).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
        throw new NotFoundException(scheduleId);
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) HttpResponse(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) URL(java.net.URL)

Example 100 with NotFoundException

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

the class ScheduleClient method doList.

private List<ScheduleDetail> doList(WorkflowId workflow) throws IOException, UnauthenticatedException, NotFoundException, UnauthorizedException {
    String path = String.format("apps/%s/workflows/%s/schedules", workflow.getApplication(), workflow.getProgram());
    URL url = config.resolveNamespacedURLV3(workflow.getNamespaceId(), path);
    HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND);
    if (HttpURLConnection.HTTP_NOT_FOUND == response.getResponseCode()) {
        throw new NotFoundException(workflow);
    }
    ObjectResponse<List<ScheduleDetail>> objectResponse = ObjectResponse.fromJsonBody(response, LIST_SCHEDULE_DETAIL_TYPE, GSON);
    return objectResponse.getResponseObject();
}
Also used : HttpResponse(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) List(java.util.List) 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