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;
}
}
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();
}
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);
}
}
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;
}
}
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);
}
}
Aggregations