Search in sources :

Example 6 with Instances

use of co.cask.cdap.proto.Instances in project cdap by caskdata.

the class MonitorClient method setSystemServiceInstances.

/**
   * Sets the number of instances the system service is running on.
   *
   * @param serviceName name of the system service
   * @param instances 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 UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public void setSystemServiceInstances(String serviceName, int instances) throws IOException, NotFoundException, BadRequestException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveURL(String.format("system/services/%s/instances", serviceName));
    HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build();
    HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST);
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NotFoundException(new SystemServiceId(serviceName));
    } else if (response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST) {
        throw new BadRequestException(new String(response.getResponseBody()));
    }
}
Also used : HttpRequest(co.cask.common.http.HttpRequest) Instances(co.cask.cdap.proto.Instances) SystemServiceId(co.cask.cdap.proto.id.SystemServiceId) HttpResponse(co.cask.common.http.HttpResponse) NotFoundException(co.cask.cdap.common.NotFoundException) BadRequestException(co.cask.cdap.common.BadRequestException) URL(java.net.URL)

Example 7 with Instances

use of co.cask.cdap.proto.Instances in project cdap by caskdata.

the class ProgramClient method setWorkerInstances.

/**
   * Sets the number of instances that a worker will run on.
   *
   * @param instances number of instances for the worker to run on
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application or worker could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public void setWorkerInstances(ProgramId worker, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(worker.getNamespaceId(), String.format("apps/%s/workers/%s/instances", worker.getApplication(), worker.getProgram()));
    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(worker);
    }
}
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)

Aggregations

Instances (co.cask.cdap.proto.Instances)7 NotFoundException (co.cask.cdap.common.NotFoundException)4 HttpRequest (co.cask.common.http.HttpRequest)4 HttpResponse (co.cask.common.http.HttpResponse)4 URL (java.net.URL)4 ApplicationNotFoundException (co.cask.cdap.common.ApplicationNotFoundException)3 ProgramNotFoundException (co.cask.cdap.common.ProgramNotFoundException)3 ServiceInstances (co.cask.cdap.proto.ServiceInstances)3 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)2 BatchRunnableInstances (co.cask.cdap.proto.BatchRunnableInstances)2 ProtoConstraint (co.cask.cdap.proto.ProtoConstraint)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 BadRequestException (co.cask.cdap.common.BadRequestException)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 SystemServiceId (co.cask.cdap.proto.id.SystemServiceId)1