Exemplo n.º 1
0
  @Override
  protected void doExecute(ApplicationService applicationService)
      throws ApplicationServiceException {

    Set<Application> applications = applicationService.getApplications();
    console.printf("%s%10s%n", "State", "Name");
    for (Application curApp : applications) {
      ApplicationStatus appStatus = applicationService.getApplicationStatus(curApp);
      // only show applications that have features (gets rid of repo
      // aggregator 'apps')
      if (!curApp.getFeatures().isEmpty()) {
        console.print("[");
        switch (appStatus.getState()) {
          case ACTIVE:
            console.print(Ansi.ansi().fg(Ansi.Color.GREEN).toString());
            break;
          case FAILED:
            console.print(Ansi.ansi().fg(Ansi.Color.RED).toString());
            break;
          case INACTIVE:
            // don't set a color
            break;
          case UNKNOWN:
            console.print(Ansi.ansi().fg(Ansi.Color.YELLOW).toString());
            break;
          default:
            break;
        }
        console.print(StringUtils.rightPad(appStatus.getState().toString(), STATUS_COLUMN_LENGTH));
        console.print(Ansi.ansi().reset().toString());
        console.println("] " + curApp.getName());
      }
    }
    return;
  }
Exemplo n.º 2
0
  /** {@inheritDoc}. */
  @SuppressWarnings("unchecked")
  @Override
  public List<Map<String, Object>> getServices(String applicationID) {
    List<Map<String, Object>> services =
        configAdminExt.listServices(getDefaultFactoryLdapFilter(), getDefaultLdapFilter());
    List<Map<String, Object>> returnValues = new ArrayList<Map<String, Object>>();
    BundleContext context = getContext();

    if (!services.isEmpty()) {
      Application app = appService.getApplication(applicationID);
      MetaTypeService metatypeService = getMetaTypeService();

      if (app != null) {
        try {
          Set<BundleInfo> bundles = app.getBundles();

          Set<String> bundleLocations = new HashSet<String>();
          Set<MetaTypeInformation> metatypeInformation = new HashSet<MetaTypeInformation>();
          for (BundleInfo info : bundles) {
            bundleLocations.add(info.getLocation());
          }

          for (Bundle bundle : context.getBundles()) {
            for (BundleInfo info : bundles) {
              if (info.getLocation().equals(bundle.getLocation())) {
                metatypeInformation.add(metatypeService.getMetaTypeInformation(bundle));
              }
            }
          }

          for (Map<String, Object> service : services) {
            if (service.containsKey("configurations")) {
              List<Map<String, Object>> configurations =
                  (List<Map<String, Object>>) service.get("configurations");
              for (Map<String, Object> item : configurations) {
                if (item.containsKey("bundle_location")) {
                  String bundleLocation = (String) item.get("bundle_location");
                  if (bundleLocations.contains(bundleLocation)) {
                    returnValues.add(service);
                    break;
                  }
                }
              }
            } else {
              if (checkForMetaTypesForService(metatypeInformation, service)) {
                returnValues.add(service);
              }
            }
          }

        } catch (ApplicationServiceException e) {
          LOGGER.warn("There was an error while trying to access the application", e);
          return new ArrayList<Map<String, Object>>();
        }
      }
    }

    return returnValues;
  }
Exemplo n.º 3
0
 private void makeDependencyList(List<String> childrenList, ApplicationNode application) {
   LOGGER.debug("Getting Dependency List", application.getApplication().getName());
   for (ApplicationNode curNode : application.getChildren()) {
     Application node = curNode.getApplication();
     childrenList.add(node.getName());
     makeDependencyList(childrenList, curNode);
   }
 }
Exemplo n.º 4
0
 @Override
 public int compareTo(Application otherApp) {
   int nameCompare = name.compareTo(otherApp.getName());
   if (nameCompare == 0) {
     return version.compareTo(otherApp.getVersion());
   } else {
     return nameCompare;
   }
 }
Exemplo n.º 5
0
  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    } else if (obj == this) {
      return true;
    } else if (!(obj instanceof Application)) {
      return false;
    }

    Application otherApp = (Application) obj;
    return name.equals(otherApp.getName()) && version.equals(otherApp.getVersion());
  }
Exemplo n.º 6
0
 private Map<String, Object> convertApplicationNode(ApplicationNode application) {
   LOGGER.debug("Converting {} to a map", application.getApplication().getName());
   Map<String, Object> appMap = new HashMap<String, Object>();
   Application internalApplication = application.getApplication();
   appMap.put(MAP_NAME, internalApplication.getName());
   appMap.put(MAP_VERSION, internalApplication.getVersion());
   appMap.put(MAP_DESCRIPTION, internalApplication.getDescription());
   appMap.put(MAP_STATE, application.getStatus().getState().toString());
   appMap.put(MAP_URI, internalApplication.getURI().toString());
   List<Map<String, Object>> children = new ArrayList<Map<String, Object>>();
   for (ApplicationNode curNode : application.getChildren()) {
     children.add(convertApplicationNode(curNode));
   }
   appMap.put(MAP_CHILDREN, children);
   return appMap;
 }
Exemplo n.º 7
0
  private Map<String, Object> convertApplicationEntries(
      ApplicationNode application,
      List<String> parentList,
      List<Map<String, Object>> applicationsArray) {
    LOGGER.debug("Converting {} to a map", application.getApplication().getName());
    Map<String, Object> appMap = new HashMap<String, Object>();
    Application internalApplication = application.getApplication();
    appMap.put(MAP_NAME, internalApplication.getName());
    appMap.put(MAP_VERSION, internalApplication.getVersion());
    appMap.put(MAP_DESCRIPTION, internalApplication.getDescription());
    appMap.put(MAP_STATE, application.getStatus().getState().toString());
    appMap.put(MAP_URI, internalApplication.getURI().toString());
    List<String> childrenList = new ArrayList<String>();
    parentList.add(internalApplication.getName());
    List<String> transferParentList = new ArrayList<String>();
    appMap.put(MAP_PARENTS, parentList);

    for (ApplicationNode curNode : application.getChildren()) {
      Application node = curNode.getApplication();
      childrenList.add(node.getName());
      makeDependencyList(childrenList, curNode);

      convertApplicationEntries(curNode, parentList, applicationsArray);
    }
    appMap.put(MAP_DEPENDENCIES, childrenList);

    if (parentList.size() == 1) {
      transferParentList.clear();
      appMap.put(MAP_PARENTS, transferParentList);
    } else {
      int index = parentList.indexOf(internalApplication.getName());
      for (int i = 0; i < index; i++) {
        transferParentList.add(parentList.get(i));
      }
      appMap.put(MAP_PARENTS, transferParentList);
      parentList.clear();
      parentList.addAll(transferParentList);
    }
    applicationsArray.add(appMap);
    return appMap;
  }