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