code: private int listSessions() throws IOException {
      try {
        ClusterManagerService.Client client = getCMSClient();
        List<RunningSession> sessions;
        try {
          sessions = client.getSessions();
        } catch (SafeModeException e) {
          throw new IOException(
            "Cannot list sessions, ClusterManager is in Safe Mode");
        }
        System.out.printf("%d sessions currently running:\n",
            sessions.size());
        System.out.printf("SessionID\t" +
            "Session Name\t" +
            "Session User\t" +
            "Session Poolgroup\t" +
            "Session Pool\t" +
            "Session Priority\t" +
            "Running Mappers\t" +
            "Running Reducers\t" +
            "Running Jobtrackers\n");
        for (RunningSession session : sessions) {
          SessionPriority priority = session.getPriority();
          if (priority == null) {
            priority = SessionPriority.NORMAL;
          }
          System.out.printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",
              session.getHandle(),
              session.getName().replace("\t", "\\t").replace("\n", "\\n"),
              session.getUserId(),
              session.getPoolInfo().getPoolGroupName(),
              session.getPoolInfo().getPoolName(),
              priority,
              session.getRunningResources().get(ResourceType.MAP),
              session.getRunningResources().get(ResourceType.REDUCE),
              session.getRunningResources().get(ResourceType.JOBTRACKER));
        }
      } catch (TException e) {
        throw new IOException(e);
      }
  
      return 0;
    }
docs: Gets a list of the sessions from the cluster manager
  and outputs them on the console
  @return 0 in case of success, non zero value on error
  @throws IOException