Search in sources :

Example 1 with SystemServiceMeta

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

Example 2 with SystemServiceMeta

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

Example 4 with SystemServiceMeta

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();
}
Also used : Type(java.lang.reflect.Type) HttpURLConnection(java.net.HttpURLConnection) SystemServiceMeta(co.cask.cdap.proto.SystemServiceMeta) List(java.util.List) Test(org.junit.Test)

Aggregations

SystemServiceMeta (co.cask.cdap.proto.SystemServiceMeta)4 MonitorClient (co.cask.cdap.client.MonitorClient)1 MasterServiceManager (co.cask.cdap.common.twill.MasterServiceManager)1 HttpResponse (co.cask.common.http.HttpResponse)1 TypeToken (com.google.common.reflect.TypeToken)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 Test (org.junit.Test)1