Пример #1
0
  /**
   * Creates a new instance of application.
   *
   * @param repo Creates the application from a Karaf Feature Repository object.
   */
  public ApplicationImpl(Repository repo) {
    location = repo.getURI();
    try {
      String[] parts = repo.getName().split("-[0-9]");
      if (parts.length != 0) {
        name = parts[0];
        version = repo.getName().substring(name.length() + 1);
      } else {
        name = repo.getName();
        version = "0.0.0";
      }
      features = new HashSet<>(Arrays.asList(repo.getFeatures()));
    } catch (Exception e) {
      logger.warn(
          "Error occured while trying to parse information for application. Application created but may have missing information.");
      features = new HashSet<>();
    }
    autoInstallFeatures = new HashSet<>();
    if (features.size() == 1) {
      autoInstallFeatures.add(features.iterator().next());
    } else {
      autoInstallFeatures.addAll(
          features
              .stream()
              .filter(
                  curFeature ->
                      StringUtils.equalsIgnoreCase(
                          Feature.DEFAULT_INSTALL_MODE, curFeature.getInstall()))
              .collect(Collectors.toList()));
    }
    // Determine mainFeature
    if (autoInstallFeatures.size() == 1) {
      mainFeature = autoInstallFeatures.iterator().next();
      name = mainFeature.getName();
      version = mainFeature.getVersion();
      description = mainFeature.getDescription();
    } else {
      Optional<Feature> first =
          autoInstallFeatures.stream().filter(f -> name.equals(f.getName())).findFirst();
      if (first.isPresent()) {
        mainFeature = first.get();
        name = mainFeature.getName();
        version = mainFeature.getVersion();
        description = mainFeature.getDescription();
      }
    }

    if (mainFeature == null) {
      logger.debug(
          "Could not determine main feature in {}, using defaults. Each application "
              + "should have 1 feature with the same name as the repository or 1 auto"
              + " install feature. This Application will take no action when started"
              + " or stopped.",
          name);
    }
  }
Пример #2
0
  @Override
  public List<Map<String, Object>> getInstallationProfiles() {
    List<Feature> installationProfiles = appService.getInstallationProfiles();
    List<Map<String, Object>> profiles = new ArrayList<Map<String, Object>>();

    for (Feature profile : installationProfiles) {
      Map<String, Object> profileMap = new HashMap<String, Object>();
      profileMap.put(INSTALL_PROFILE_NAME, profile.getName());
      profileMap.put(INSTALL_PROFILE_DESCRIPTION, profile.getDescription());

      List<String> includedFeatures = new ArrayList<>();
      profile.getDependencies().forEach(dep -> includedFeatures.add(dep.getName()));
      profileMap.put(INSTALL_PROFILE_DEFAULT_APPLICATIONS, includedFeatures);

      profiles.add(profileMap);
    }

    return profiles;
  }