Search in sources :

Example 1 with Instances

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

the class ProgramLifecycleHttpHandler method getFlowletInstances.

/* ********************* Flow/Flowlet APIs ***********************************************************/
/**
   * Returns number of instances for a flowlet within a flow.
   */
@GET
@Path("/apps/{app-id}/flows/{flow-id}/flowlets/{flowlet-id}/instances")
public void getFlowletInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("flow-id") String flowId, @PathParam("flowlet-id") String flowletId) {
    try {
        int count = store.getFlowletInstances(new ProgramId(namespaceId, appId, ProgramType.FLOW, flowId), flowletId);
        responder.sendJson(HttpResponseStatus.OK, new Instances(count));
    } catch (SecurityException e) {
        responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (Throwable e) {
        if (respondIfElementNotFound(e, responder)) {
            return;
        }
        throw e;
    }
}
Also used : BatchRunnableInstances(co.cask.cdap.proto.BatchRunnableInstances) Instances(co.cask.cdap.proto.Instances) ServiceInstances(co.cask.cdap.proto.ServiceInstances) ProgramId(co.cask.cdap.proto.id.ProgramId) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ProtoConstraint(co.cask.cdap.proto.ProtoConstraint) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with Instances

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

the class ProgramLifecycleHttpHandlerTest method setServiceInstances.

private int setServiceInstances(Id.Service serviceId, int instances) throws Exception {
    String instanceUrl = String.format("apps/%s/services/%s/instances", serviceId.getApplicationId(), serviceId.getId());
    String versionedInstanceUrl = getVersionedAPIPath(instanceUrl, Constants.Gateway.API_VERSION_3_TOKEN, serviceId.getNamespaceId());
    String instancesBody = GSON.toJson(new Instances(instances));
    return doPut(versionedInstanceUrl, instancesBody).getStatusLine().getStatusCode();
}
Also used : ServiceInstances(co.cask.cdap.proto.ServiceInstances) Instances(co.cask.cdap.proto.Instances)

Example 3 with Instances

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

the class ProgramClient method setServiceInstances.

/**
   * Sets the number of instances of a service.
   *
   * @param service the service
   * @param instances number of instances for the service
   * @throws IOException if a network error occurred
   * @throws NotFoundException if the application or service could not be found
   * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
   */
public void setServiceInstances(ServiceId service, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/services/%s/instances", service.getApplication(), service.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(service);
    }
}
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 4 with Instances

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

the class ProgramLifecycleHttpHandler method getWorkerInstances.

/**
   * Returns number of instances of a worker.
   */
@GET
@Path("/apps/{app-id}/workers/{worker-id}/instances")
public void getWorkerInstances(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("worker-id") String workerId) throws Exception {
    try {
        int count = store.getWorkerInstances(validateAndGetNamespace(namespaceId).app(appId).worker(workerId));
        responder.sendJson(HttpResponseStatus.OK, new Instances(count));
    } catch (SecurityException e) {
        responder.sendStatus(HttpResponseStatus.UNAUTHORIZED);
    } catch (Throwable e) {
        if (respondIfElementNotFound(e, responder)) {
            return;
        }
        throw e;
    }
}
Also used : BatchRunnableInstances(co.cask.cdap.proto.BatchRunnableInstances) Instances(co.cask.cdap.proto.Instances) ServiceInstances(co.cask.cdap.proto.ServiceInstances) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ProtoConstraint(co.cask.cdap.proto.ProtoConstraint) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with Instances

use of co.cask.cdap.proto.Instances 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)

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