1

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

Regards

D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38
Rana
  • 115
  • 1
  • 6

1 Answers1

1

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

tk421
  • 5,775
  • 6
  • 23
  • 34
  • Thank you for your reply, I shall go through the code. I found a workaround using RESTful model [ curl -u admin:admin "localhost:7180/api/v13/clusters/Cloudera%20QuickSart/servic‌​es/{servicename}/roles" ] Now I am trying to stop the role(flume agent) but failed. I tried with [ curl -X POST -u admin:admin "localhost:7180/api/v13/clusters/Cloudera%20QuickS tart/services/flume/roles/agent11/roleCommands/stop" ] – Rana Jul 03 '17 at 05:50
  • 1
    If you're trying to stop a Flume agent, you'll need to do something like this: curl -X POST -u admin:admin -H "Content-Type:application/json" -d '{ "items": ["agent11"] }' 'localhost:7180/api/v13/clusters/Cloudera%20QuickS tart/services/flume/roleCommands/stop'. See https://github.com/cloudera/cm_api/wiki/Start-Stop-Restart-JobTracker-Role and https://stackoverflow.com/questions/25004746/restart-jobtracker-through-cloudera-manager-api for more examples. – tk421 Jul 03 '17 at 08:53