private static GridServiceContainer[] getContainersOnMachines(
      ProcessingUnit pu, Machine[] machines) {
    if (pu.getRequiredZones().length != 1) {
      throw new IllegalStateException(
          "Processing Unit must have exactly one container zone defined.");
    }
    final List<GridServiceContainer> containers = new ArrayList<GridServiceContainer>();
    for (final Machine machine : machines) {
      for (final GridServiceContainer container : machine.getGridServiceContainers()) {
        if (container.getZones().size() == 1
            && container.getZones().containsKey(pu.getRequiredZones()[0])) {

          containers.add(container);
        }
      }
    }
    return containers.toArray(new GridServiceContainer[containers.size()]);
  }
Esempio n. 2
0
  @Override
  public void perform(String command, String arguments) {
    boolean showAll = false;
    if ("-a".equals(arguments)) {
      showAll = true;
    }
    Admin admin = gash.getWorkingLocation().getCurrentConnection().getAdmin();
    for (Machine machine : admin.getMachines()) {
      Utils.println("%s", machine.getHostName());
      GridServiceContainer[] containers = machine.getGridServiceContainers().getContainers();
      Arrays.sort(
          containers,
          new Comparator<GridServiceContainer>() {
            @Override
            public int compare(GridServiceContainer o1, GridServiceContainer o2) {
              return new Integer(o1.getAgentId()).compareTo(o2.getAgentId());
            }
          });
      int containerCount = 0;
      for (GridServiceContainer container : containers) {
        containerCount++;
        String zones = null;
        for (String zoneName : container.getZones().keySet()) {
          if (zones == null) {
            zones = zoneName;
          } else {
            zones += ", " + zoneName;
          }
        }
        if (zones == null) {
          zones = "";
        } else {
          zones = "Zones [" + zones + "]";
        }
        int i = container.getAgentId();
        String containerTree = BEGIN_VERTICAL_AND_RIGHT;
        char containerVertical = VERTICAL;
        if (containerCount == containers.length) {
          containerTree = BEGIN_ELBOW;
          containerVertical = ' ';
        }
        if (showAll) {
          Utils.println(
              "%s GSC-%s [pid %s] uid[%s] %s",
              containerTree,
              i,
              container.getVirtualMachine().getDetails().getPid(),
              container.getUid(),
              zones);
        } else {
          Utils.println(
              "%s GSC-%s [pid %s] %s",
              containerTree, i, container.getVirtualMachine().getDetails().getPid(), zones);
        }

        int processingUnitCount = 0;
        ProcessingUnitInstance[] processingUnitInstances = container.getProcessingUnitInstances();
        sortProcessingUnitInstance(processingUnitInstances);
        for (ProcessingUnitInstance processingUnitInstance : processingUnitInstances) {
          processingUnitCount++;
          String processingUnitTree = BEGIN_VERTICAL_AND_RIGHT;
          char processingUnitVertical = VERTICAL;
          if (processingUnitCount == processingUnitInstances.length) {
            processingUnitTree = BEGIN_ELBOW;
            processingUnitVertical = ' ';
          }
          String primary =
              (processingUnitInstance.getSpaceInstance() == null
                      || processingUnitInstance
                          .getSpaceInstance()
                          .getMode()
                          .equals(SpaceMode.PRIMARY)
                  ? ""
                  : "Backup");
          StringBuilder puNameAndClusterInfo =
              Utils.getPUNameAndClusterInfo(processingUnitInstance);
          if (processingUnitInstance.isJee()) {
            puNameAndClusterInfo.append(" Web");
          }

          if (showAll) {
            Utils.println(
                "%s   %s %s %s id[%s]",
                containerVertical,
                processingUnitTree,
                puNameAndClusterInfo,
                primary,
                processingUnitInstance.getUid());
          } else {
            Utils.println(
                "%s   %s %s %s",
                containerVertical, processingUnitTree, puNameAndClusterInfo, primary);
          }

          if (processingUnitInstance.isJee()) {
            JeeServiceDetails jeeDetails = processingUnitInstance.getJeeDetails();
            if (jeeDetails.getPort() > 0) {
              String jeeTree = BEGIN_ELBOW;
              if (jeeDetails.getSslPort() > 0) {
                jeeTree = BEGIN_VERTICAL_AND_RIGHT;
              }
              Utils.println(
                  "%s   %s   %s http://%s:%s%s",
                  containerVertical,
                  processingUnitVertical,
                  jeeTree,
                  jeeDetails.getHost(),
                  jeeDetails.getPort(),
                  jeeDetails.getContextPath());
            }
            if (jeeDetails.getSslPort() > 0) {
              Utils.println(
                  "%s   %s   %s https://%s:%s%s",
                  containerVertical,
                  processingUnitVertical,
                  BEGIN_ELBOW,
                  jeeDetails.getHost(),
                  jeeDetails.getSslPort(),
                  jeeDetails.getContextPath());
            }
          } else {
            for (SpaceServiceDetails details : processingUnitInstance.getSpaceDetails()) {

              if (details.getSpaceType().equals(SpaceType.REMOTE)) {
                if (showAll) {
                  Utils.println(
                      "%s   %s   %s %s [%s] %s",
                      containerVertical,
                      processingUnitVertical,
                      BEGIN_ELBOW,
                      details.getId(),
                      details.getLongDescription(),
                      "Remote");
                }
              } else {
                String instancePrimary =
                    (processingUnitInstance.getSpaceInstance().getMode().equals(SpaceMode.PRIMARY)
                        ? " "
                        : " Backup");
                if (showAll) {
                  Utils.println(
                      "%s   %s   %s %s %s serviceId[%s]",
                      containerVertical,
                      processingUnitVertical,
                      BEGIN_ELBOW,
                      details.getId(),
                      instancePrimary,
                      details.getServiceID());
                } else {
                  Utils.println(
                      "%s   %s   %s %s %s",
                      containerVertical,
                      processingUnitVertical,
                      BEGIN_ELBOW,
                      details.getId(),
                      instancePrimary);
                }
              }
            }
          }
        }
      }
    }
  }