use of co.cask.cdap.proto.SystemServiceMeta in project cdap by caskdata.
the class GenerateClientUsageExample method monitorClient.
public void monitorClient() throws Exception {
// Construct the client used to interact with CDAP
MonitorClient monitorClient = new MonitorClient(clientConfig);
// Fetch the list of system services
List<SystemServiceMeta> services = monitorClient.listSystemServices();
// Fetch status of system transaction service
String serviceStatus = monitorClient.getSystemServiceStatus("transaction");
// Fetch the number of instances of the system transaction service
int systemServiceInstances = monitorClient.getSystemServiceInstances("transaction");
// Set the number of instances of the system transaction service
monitorClient.setSystemServiceInstances("transaction", 1);
}
use of co.cask.cdap.proto.SystemServiceMeta in project cdap by caskdata.
the class MonitorHandler method getServiceSpec.
@Path("/system/services")
@GET
public void getServiceSpec(HttpRequest request, HttpResponder responder) throws Exception {
List<SystemServiceMeta> response = Lists.newArrayList();
SortedSet<String> services = new TreeSet<>(serviceManagementMap.keySet());
List<String> serviceList = new ArrayList<>(services);
for (String service : serviceList) {
MasterServiceManager serviceManager = serviceManagementMap.get(service);
if (serviceManager.isServiceEnabled()) {
String logs = serviceManager.isLogAvailable() ? Constants.Monitor.STATUS_OK : Constants.Monitor.STATUS_NOTOK;
String canCheck = serviceManager.canCheckStatus() ? (serviceManager.isServiceAvailable() ? STATUSOK : STATUSNOTOK) : NOTAPPLICABLE;
//TODO: Add metric name for Event Rate monitoring
response.add(new SystemServiceMeta(service, serviceManager.getDescription(), canCheck, logs, serviceManager.getMinInstances(), serviceManager.getMaxInstances(), getSystemServiceInstanceCount(service), serviceManager.getInstances()));
}
}
responder.sendJson(HttpResponseStatus.OK, response);
}
use of co.cask.cdap.proto.SystemServiceMeta in project cdap by caskdata.
the class MonitorClient method listSystemServices.
/**
* Lists all system services.
*
* @return list of {@link SystemServiceMeta}s.
* @throws IOException if a network error occurred
* @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
*/
public List<SystemServiceMeta> listSystemServices() throws IOException, UnauthenticatedException, UnauthorizedException {
URL url = config.resolveURL("system/services");
HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken());
return ObjectResponse.fromJsonBody(response, new TypeToken<List<SystemServiceMeta>>() {
}).getResponseObject();
}
use of co.cask.cdap.proto.SystemServiceMeta in project cdap by caskdata.
the class MonitorHandlerTest method testSystemServices.
@Test
public void testSystemServices() throws Exception {
Type token = new TypeToken<List<SystemServiceMeta>>() {
}.getType();
HttpURLConnection urlConn = openURL("system/services", HttpMethod.GET);
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
List<SystemServiceMeta> actual = GSON.fromJson(new String(ByteStreams.toByteArray(urlConn.getInputStream()), Charsets.UTF_8), token);
Assert.assertEquals(9, actual.size());
urlConn.disconnect();
}
Aggregations