use of io.cdap.cdap.proto.SystemServiceMeta in project cdap by caskdata.
the class MonitorClientTestRun method testAll.
@Test
public void testAll() throws Exception {
List<SystemServiceMeta> services = monitorClient.listSystemServices();
Assert.assertTrue(services.size() > 0);
// check that all the system services can have their status individually retrieved
for (SystemServiceMeta service : services) {
Assert.assertEquals("OK", monitorClient.getSystemServiceStatus(service.getName()));
}
String someService = services.get(0).getName();
List<Containers.ContainerInfo> containers = monitorClient.getSystemServiceLiveInfo(someService).getContainers();
Assert.assertNotNull(containers);
Assert.assertTrue(containers.isEmpty());
Assert.assertEquals(0, monitorClient.getSystemServiceInstances(someService));
monitorClient.setSystemServiceInstances(someService, 1);
monitorClient.getSystemServiceInstances(someService);
Assert.assertTrue(monitorClient.allSystemServicesOk());
}
use of io.cdap.cdap.proto.SystemServiceMeta in project cdap by caskdata.
the class MonitorHandler method getServiceSpec.
@Path("/system/services")
@GET
public void getServiceSpec(HttpRequest request, HttpResponder responder) {
contextAccessEnforcer.enforceOnParent(EntityType.SYSTEM_SERVICE, InstanceId.SELF, StandardPermission.LIST);
List<SystemServiceMeta> response = new ArrayList<>();
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.isServiceAvailable() ? STATUSOK : STATUSNOTOK;
// 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, GSON.toJson(response));
}
use of io.cdap.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 io.cdap.cdap.proto.SystemServiceMeta in project cdap by caskdata.
the class RemoteMonitorServicesFetcher 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 Iterable<SystemServiceMeta> listSystemServices() throws NotFoundException, IOException {
HttpRequest.Builder requestBuilder = remoteClient.requestBuilder(HttpMethod.GET, Constants.Monitor.SYSTEM_LOG_SERVICE_URL);
HttpResponse response;
response = execute(requestBuilder.build());
return ObjectResponse.fromJsonBody(response, new TypeToken<List<SystemServiceMeta>>() {
}).getResponseObject();
}
use of io.cdap.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();
}
Aggregations