Exemplo n.º 1
0
 /**
  * Gets the UIDs of all GSCs.
  *
  * @return a set of UIDs
  * @throws CLIException Reporting a failure to locate the requested GSCs or get the UIDs.
  */
 public Set<String> getGridServiceContainerUids() throws CLIException {
   Map<String, Object> container;
   try {
     container = client.getAdmin("GridServiceContainers");
   } catch (final ErrorStatusException e) {
     throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
   } catch (final RestException e) {
     throw new CLIException(e);
   }
   @SuppressWarnings("unchecked")
   final List<String> containerUris = (List<String>) container.get("Uids-Elements");
   final Set<String> containerUids = new HashSet<String>();
   for (final String containerUri : containerUris) {
     final String uid = containerUri.substring(containerUri.lastIndexOf('/') + 1);
     containerUids.add(uid);
   }
   return containerUids;
 }
Exemplo n.º 2
0
  /**
   * Returns all the UIDs of the GSCs that run the given service, in the context of the given
   * application.
   *
   * @param applicationName The name of the application deployed in the requested GSCs
   * @param serviceName The name of the service deployed in the requested GSCs
   * @return a set of UIDs of the GSCs that run the given service in the context of the given
   *     application
   * @throws CLIException Reporting a failure to locate the requested GSCs or get the UIDs.
   */
  public Set<String> getGridServiceContainerUidsForService(
      final String applicationName, final String serviceName) throws CLIException {

    final Set<String> containerUids = new HashSet<String>();

    final int numberOfInstances = this.getInstanceList(applicationName, serviceName).size();

    final String absolutePUName = ServiceUtils.getAbsolutePUName(applicationName, serviceName);
    for (int i = 0; i < numberOfInstances; i++) {

      final String containerUrl =
          "applications/Names/"
              + applicationName
              + "/ProcessingUnits/Names/"
              + absolutePUName
              + "/Instances/"
              + i
              + "/GridServiceContainer/Uid";
      try {
        final Map<String, Object> container = client.getAdmin(containerUrl);

        if (container == null) {
          throw new IllegalStateException("Could not find container " + containerUrl);
        }
        if (!container.containsKey("Uid")) {
          throw new IllegalStateException("Could not find AgentUid of container " + containerUrl);
        }

        containerUids.add((String) container.get("Uid"));
      } catch (final ErrorStatusException e) {
        throw new CLIStatusException(e, e.getReasonCode(), e.getArgs());
      } catch (final RestException e) {
        throw new CLIStatusException("cant_find_service_for_app", serviceName, applicationName);
      }
    }
    return containerUids;
  }