cloudera

Cloudera Manager API to fetch the list of Flume agents


I am trying to fetch the number of Flume agents are running on My CDH5.8 cluster using Cloudera Manager API .

https://cloudera.github.io/cm_api/

Till now i could not figure out which RESTful Model I should consider or the related Java class. If any one can help or to inform the the referenced Java class to look into that will be great


Solution

  • If you use the following API:

    https://cloudera.github.io/cm_api/apidocs/v13/path__clusters_-clusterName-services-serviceName-_roles.html

    The size of the items array in the JSON object returned will be the number of Flume agents. To find the number of running agents, for each item, check that roleState equals STARTED.

    The Java class ApiRole is probably what you need. This code snippet from the whirr-cm example is close to what you want.

    https://github.com/cloudera/whirr-cm/blob/edb38ca7faa3e4bb2c23450ff0183c2dd631dcf4/src/main/java/com/cloudera/whirr/cm/server/impl/CmServerImpl.java#L486

            for (ApiService apiService : apiResourceRootV3.getClustersResource().getServicesResource(getName(cluster))
                .readServices(DataView.SUMMARY)) {
              for (ApiRole apiRole : apiResourceRootV3.getClustersResource().getServicesResource(getName(cluster))
                  .getRolesResource(apiService.getName()).readRoles()) {
                if (apiRole.getRoleState().equals(ApiRoleState.STARTED)) {
                  servicesNotStarted.remove(apiRole.getName());
                }
              }
            }
    

    You would just need to limit this to the Flume service.

    https://cloudera.github.io/cm_api/javadoc/5.11.0/index.html