Search in sources :

Example 1 with SystemServiceMeta

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());
}
Also used : SystemServiceMeta(io.cdap.cdap.proto.SystemServiceMeta) Test(org.junit.Test)

Example 2 with SystemServiceMeta

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));
}
Also used : SystemServiceMeta(io.cdap.cdap.proto.SystemServiceMeta) MasterServiceManager(io.cdap.cdap.common.twill.MasterServiceManager) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with SystemServiceMeta

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);
}
Also used : MonitorClient(io.cdap.cdap.client.MonitorClient) SystemServiceMeta(io.cdap.cdap.proto.SystemServiceMeta)

Example 4 with SystemServiceMeta

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();
}
Also used : HttpRequest(io.cdap.common.http.HttpRequest) SystemServiceMeta(io.cdap.cdap.proto.SystemServiceMeta) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(io.cdap.common.http.HttpResponse)

Example 5 with SystemServiceMeta

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();
}
Also used : SystemServiceMeta(io.cdap.cdap.proto.SystemServiceMeta) TypeToken(com.google.common.reflect.TypeToken) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL)

Aggregations

SystemServiceMeta (io.cdap.cdap.proto.SystemServiceMeta)7 TypeToken (com.google.common.reflect.TypeToken)2 HttpResponse (io.cdap.common.http.HttpResponse)2 Test (org.junit.Test)2 MonitorClient (io.cdap.cdap.client.MonitorClient)1 MasterServiceManager (io.cdap.cdap.common.twill.MasterServiceManager)1 HttpRequest (io.cdap.common.http.HttpRequest)1 File (java.io.File)1 Type (java.lang.reflect.Type)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1