Пример #1
0
  public void waitForFeature(String featureName, Predicate<FeatureState> predicate)
      throws Exception {
    boolean ready = false;

    long timeoutLimit = System.currentTimeMillis() + REQUIRED_BUNDLES_TIMEOUT;
    while (!ready) {
      FeaturesService featuresService = getFeaturesService();
      if (featuresService != null) {
        Feature feature = featuresService.getFeature(featureName);
        FeatureState state =
            featuresService.getState(feature.getName() + "/" + feature.getVersion());
        if (state == null) {
          LOGGER.warn("No Feature found for featureName: {}", featureName);
          return;
        } else if (predicate.test(state)) {
          ready = true;
        }
      }

      if (!ready) {
        if (System.currentTimeMillis() > timeoutLimit) {
          printInactiveBundles();
          fail(
              String.format(
                  "Feature did not change to State ["
                      + predicate.toString()
                      + "] within %d minutes.",
                  TimeUnit.MILLISECONDS.toMinutes(REQUIRED_BUNDLES_TIMEOUT)));
        }
        LOGGER.info("Feature [{}] not [{}], sleeping...", featureName, predicate.toString());
        Thread.sleep(1000);
      }
    }
  }
Пример #2
0
 /** Uninstalls a feature and checks that feature is properly uninstalled. */
 public void unInstallAndCheckFeature(String feature) throws Exception {
   System.err.println(executeCommand("features:uninstall " + feature));
   FeaturesService featuresService = ServiceLocator.getOsgiService(FeaturesService.class);
   System.err.println(executeCommand("osgi:list -t 0"));
   Assert.assertFalse(
       "Expected " + feature + " feature to be installed.",
       featuresService.isInstalled(featuresService.getFeature(feature)));
 }
Пример #3
0
 private void refreshAll() {
   Repository[] repos = featuresService.listRepositories();
   for (Repository repo : repos) {
     try {
       System.out.println("Refreshing feature url " + repo.getURI());
       featuresService.refreshRepository(repo.getURI());
     } catch (Exception e) {
       System.err.println("Error refreshing " + repo.getURI().toString() + ": " + e.getMessage());
     }
   }
 }
Пример #4
0
    @Override
    public boolean matches(DependencyTree dependencyTree) {
      boolean result = false;

      if (!getDependencyTreeFilter().matches(dependencyTree)) {
        try {
          Feature feature = Features.getFeatureForBundle(service.listFeatures(), dependencyTree);
          if (feature != null) {
            String replacement = String.format("%s/%s", feature.getName(), feature.getVersion());
            features.add(replacement);
            LOG.info(
                String.format(
                    "Installing feature %s for maven dependency %s/%s/%s",
                    replacement,
                    dependencyTree.getGroupId(),
                    dependencyTree.getArtifactId(),
                    dependencyTree.getVersion()));
            result = true;
          }
        } catch (Exception e) {
          LOG.debug(
              String.format(
                  "Unable to retrieve features information while processing dependency %s",
                  dependencyTree.getArtifactId()),
              e);
        }
      }

      return result;
    }
Пример #5
0
 private void installFeature(String name) {
   try {
     featuresService.installFeature(name);
     logger.info("Installed '{}'", name);
   } catch (Exception e) {
     logger.error("Failed installing '{}': {}", name, e.getMessage());
   }
 }
Пример #6
0
 public void assertFeatureInstalled(String featureName) {
   Feature[] features = featuresService.listInstalledFeatures();
   for (Feature feature : features) {
     if (featureName.equals(feature.getName())) {
       return;
     }
   }
   fail("Feature " + featureName + " should be installed but is not");
 }
 boolean repoRemove(URL repoUrl) {
   try {
     featuresService.removeRepository(repoUrl.toURI());
     return true;
   } catch (Exception e) {
     logger.error("Unable to remove repository: " + repoUrl, e);
     return false;
   }
 }
 @Override
 public ICapability getCapabilityById(String id) {
   try {
     return new KarafCapability(featuresService, featuresService.getFeature(id), this);
   } catch (Exception e) {
     logger.error("Unknown error retrieving feature: " + id, e);
   }
   return null;
 }
 boolean featureUninstall(Feature feature) {
   String name = feature.getName();
   String version = feature.getVersion();
   try {
     featuresService.uninstallFeature(name, version);
     return true;
   } catch (Exception e) {
     logger.error("Unable to uninstall feature: " + name, e);
     return false;
   }
 }
 boolean featureInstall(Feature feature) {
   String name = feature.getName();
   String version = feature.getVersion();
   EnumSet<Option> options = EnumSet.of(Option.Verbose);
   try {
     featuresService.installFeature(name, version, options);
     return true;
   } catch (Exception e) {
     logger.error("Unable to uninstall feature: " + name, e);
     return false;
   }
 }
Пример #11
0
 private Set<String> getFeatureLocations() throws Exception {
   Set<String> bundleLocations = new LinkedHashSet<String>();
   for (Feature feature : featuresService.listFeatures()) {
     try {
       for (BundleInfo info : feature.getBundles()) {
         bundleLocations.add(info.getLocation());
       }
     } catch (Exception e) {
       // Ignore
     }
   }
   return bundleLocations;
 }
Пример #12
0
  private void installPackage(final Map<String, Object> config) {
    Object packageName = config.get("package");
    String name = PREFIX + PREFIX_PACKAGE + ((String) packageName).trim();
    installFeature(name);

    // uninstall all other packages
    try {
      for (Feature feature : featuresService.listFeatures()) {
        if (feature.getName().startsWith(PREFIX + PREFIX_PACKAGE)
            && !feature.getName().equals(name)
            && featuresService.isInstalled(feature)) {
          try {
            featuresService.uninstallFeature(feature.getName());
          } catch (Exception e) {
            logger.error("Failed uninstalling '{}': {}", feature.getName(), e.getMessage());
          }
        }
      }
    } catch (Exception e) {
      logger.error("Failed retrieving features: {}", e.getMessage());
    }
  }
 void repoRemove(Properties props, Bundle bundle) throws Exception {
   for (int index = 0; index < propCountValue(props, bundle); index++) {
     URL repoUrl = propUrlValue(props, bundle, index);
     for (Repository repo : featuresService.listRepositories()) {
       if (repo.getURI().equals(repoUrl.toURI())) {
         for (Feature feature : repo.getFeatures()) {
           featureUninstall(feature);
         }
       }
     }
     repoRemove(repoUrl);
   }
 }
 @Override
 public Set<String> listCapabilities() {
   Set<String> ids = new HashSet<>();
   try {
     for (Feature feature : featuresService.listFeatures()) {
       ids.add(feature.getName());
     }
   } catch (Exception e) {
     logger.error("Unknown error trying to retrieve available Karaf features", e);
     return ids;
   }
   return ids;
 }
Пример #15
0
 protected Object doExecute() throws Exception {
   if (nameOrUrl != null) {
     String effectiveVersion = (version == null) ? "LATEST" : version;
     URI uri = featureFinder.getUriFor(nameOrUrl, effectiveVersion);
     if (uri == null) {
       uri = new URI(nameOrUrl);
     }
     System.out.println("Refreshing feature url " + uri);
     featuresService.refreshRepository(uri);
   } else {
     refreshAll();
   }
   return null;
 }
 /**
  * Check if a features repository is already registered locally.
  *
  * @param uri the features repository URI.
  * @return true if the features repository is already registered locally, false else.
  */
 public Boolean isRepositoryRegisteredLocally(String uri) {
   try {
     Repository[] localRepositories = featuresService.listRepositories();
     for (Repository localRepository : localRepositories) {
       if (localRepository.getURI().toString().equals(uri)) {
         return true;
       }
     }
   } catch (Exception e) {
     LOGGER.warn(
         "CELLAR FEATURES: can't check if the feature repository {} is registered locally",
         uri,
         e);
   }
   return false;
 }
 @Override
 public Set<ICapability> getAllCapabilities() {
   Set<ICapability> capabilities = new HashSet<ICapability>();
   try {
     for (Feature feature : featuresService.listFeatures()) {
       ICapability capabilityById = this.getCapabilityById(feature.getName());
       if (capabilityById != null) {
         capabilities.add(capabilityById);
       }
     }
   } catch (Exception e) {
     logger.error("Unknown error trying to retrieve available Karaf features", e);
     return capabilities;
   }
   return capabilities;
 }
Пример #18
0
 /**
  * Get the list of features where the bundle is belonging.
  *
  * @param bundleLocation the bundle location.
  * @return the list of feature where the bundle is present.
  * @throws Exception in case of retrieval failure.
  */
 protected List<Feature> retrieveFeature(String bundleLocation) throws Exception {
   Feature[] features = featuresService.listFeatures();
   List<Feature> matchingFeatures = new ArrayList<Feature>();
   for (Feature feature : features) {
     List<BundleInfo> bundles = feature.getBundles();
     for (BundleInfo bundleInfo : bundles) {
       String location = bundleInfo.getLocation();
       if (location.equalsIgnoreCase(bundleLocation)) {
         matchingFeatures.add(feature);
         LOGGER.debug(
             "CELLAR BUNDLE: found a feature {} containing bundle {}",
             feature.getName(),
             bundleLocation);
       }
     }
   }
   return matchingFeatures;
 }
  /**
   * Check if a feature is already installed locally.
   *
   * @param name the feature name.
   * @param version the feature version.
   * @return true if the feature is already installed locally, false else.
   */
  public Boolean isFeatureInstalledLocally(String name, String version) {
    if (featuresService != null) {
      try {
        Feature[] localFeatures = featuresService.listInstalledFeatures();

        if (localFeatures != null && localFeatures.length > 0) {
          for (Feature localFeature : localFeatures) {
            if (localFeature.getName().equals(name)
                && (localFeature.getVersion().equals(version) || version == null)) return true;
          }
        }
      } catch (Exception e) {
        LOGGER.warn(
            "CELLAR FEATURES: can't check if the feature {}/{} is installed locally",
            name,
            version,
            e);
      }
    }
    return false;
  }
Пример #20
0
  @Test
  public void testInstallation() throws Exception {

    assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-core")));
    assertTrue(featuresService.isInstalled(featuresService.getFeature("fcrepo-camel")));
    assertTrue(featuresService.isInstalled(featuresService.getFeature("activemq-camel")));
    assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-blueprint")));
    assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-http4")));
    assertTrue(featuresService.isInstalled(featuresService.getFeature("camel-jetty9")));
    assertNotNull(bundleContext);

    assertEquals(
        ACTIVE,
        bundleContext.getBundle(System.getProperty("o.f.c.serialization-bundle")).getState());
    assertEquals(
        ACTIVE, bundleContext.getBundle(System.getProperty("o.f.c.fixity-bundle")).getState());
    assertEquals(
        ACTIVE, bundleContext.getBundle(System.getProperty("o.f.c.reindexing-bundle")).getState());
    assertEquals(
        ACTIVE, bundleContext.getBundle(System.getProperty("o.f.c.i.solr-bundle")).getState());
    assertEquals(
        ACTIVE,
        bundleContext.getBundle(System.getProperty("o.f.c.i.triplestore-bundle")).getState());
    assertEquals(
        ACTIVE, bundleContext.getBundle(System.getProperty("o.f.c.s.activemq-bundle")).getState());
    assertEquals(
        ACTIVE, bundleContext.getBundle(System.getProperty("o.f.c.s.camel-bundle")).getState());
  }
Пример #21
0
 @Test
 public void testFeatureInstallation() throws Exception {
   assertTrue(featuresService.isInstalled(featuresService.getFeature("hibernate-orm")));
 }
 @Test
 public void test() throws Exception {
   assertTrue(featuresService.isInstalled(featuresService.getFeature("scheduler")));
   assertTrue(featuresService.isInstalled(featuresService.getFeature("wrapper")));
 }
Пример #23
0
  @Test
  public void testUrlHandler() throws Exception {
    if (isBlobStoreLiveConfigured()) {
      createManagedBlobStoreService("aws-s3");
      BlobStore blobStoreService = getOsgiService(BlobStore.class);
      Thread.sleep(DEFAULT_TIMEOUT);

      FeaturesService featuresService = getOsgiService(FeaturesService.class);
      featuresService.installFeature("jclouds-url-handler");

      // Let's add a bundle to S3
      String groupId = "org.jclouds.api";
      String artifactId = "byon";
      String version = System.getProperty("jclouds.version");

      System.err.println(executeCommand("jclouds:blobstore-list"));
      System.err.println(executeCommand("jclouds:blobstore-container-create itest-container"));

      URL artifactUrl = new URL("mvn:" + groupId + "/" + artifactId + "/" + version);
      URL blobUrl =
          new URL(
              "blob:aws-s3/itest-container/maven2/org/jclouds/api/byon/"
                  + version
                  + "/"
                  + artifactId
                  + "-"
                  + version
                  + ".jar");
      InputStream is = artifactUrl.openConnection().getInputStream();
      OutputStream os = blobUrl.openConnection().getOutputStream();
      try {
        ByteStreams.copy(is, os);
        os.flush();
      } finally {
        Closeables2.closeQuietly(is);
        Closeables2.closeQuietly(os);
      }
      // Make sure that only S3 is available as a repo.
      System.err.println(
          executeCommands(
              "config:edit org.ops4j.pax.url.mvn",
              "config:propset org.ops4j.pax.url.mvn.localRepository "
                  + System.getProperty("karaf.base")
                  + File.separatorChar
                  + "none",
              "config:propset org.ops4j.pax.url.mvn.repositories blob:aws-s3/itest-container/maven2@snapshots ",
              "config:update"));
      Thread.sleep(DEFAULT_TIMEOUT);

      final Set<String> installedSymbolicNames = new LinkedHashSet<String>();

      // Add a Bundle Listener
      bundleContext.addBundleListener(
          new BundleListener() {
            @Override
            public void bundleChanged(BundleEvent event) {
              if (event.getType() == BundleEvent.INSTALLED) {
                installedSymbolicNames.add(event.getBundle().getSymbolicName());
              }
            }
          });

      // Install the bundle the from S3.
      System.err.println(executeCommand("osgi:install mvn:org.jclouds.api/byon/" + version));

      // Verify that no other bundle can be installed.
      System.err.println(executeCommand("osgi:install mvn:org.jclouds.api/nova/" + version));
      assertTrue(installedSymbolicNames.contains("byon"));
      assertFalse(installedSymbolicNames.contains("nova"));
    }
  }