public void assertFeaturesInstalled(String ... expectedFeatures) throws Exception { Set<String> expectedFeaturesSet = new HashSet<>(Arrays.asList(expectedFeatures)); Feature[] features = featureService.listInstalledFeatures(); Set<String> installedFeatures = new HashSet<>(); for (Feature feature : features) { installedFeatures.add(feature.getName()); } String msg = "Expecting the following features to be installed : " + expectedFeaturesSet + " but found " + installedFeatures; Assert.assertTrue(msg, installedFeatures.containsAll(expectedFeaturesSet)); }
/** * Scans the system to make sure that all bundles and their components * are fully started. * * @return true if all bundles and their components are active */ private boolean isFullyStarted() { try { for (Feature feature : featuresService.listInstalledFeatures()) { if (!isFullyStarted(feature)) { return false; } } return true; } catch (Exception ex) { return false; } }
public void assertFeatureInstalled(String featureName, String featureVersion) throws Exception { Feature featureToAssert = featureService.getFeatures(featureName, featureVersion)[0]; Feature[] features = featureService.listInstalledFeatures(); for (Feature feature : features) { if (featureToAssert.equals(feature)) { return; } } Assert.fail("Feature " + featureName + (featureVersion != null ? "/" + featureVersion : "") + " should be installed but is not"); }
public void assertFeatureNotInstalled(String featureName, String featureVersion) throws Exception { Feature featureToAssert = featureService.getFeatures(featureName, featureVersion)[0]; Feature[] features = featureService.listInstalledFeatures(); for (Feature feature : features) { if (featureToAssert.equals(feature)) { Assert.fail("Feature " + featureName + (featureVersion != null ? "/" + featureVersion : "") + " is installed whereas it should not be"); } } }
/** * The feature service does not uninstall feature dependencies when uninstalling a single feature. * So we need to make sure we uninstall all features that were newly installed. * * @param featuresBefore * @throws Exception */ public void uninstallNewFeatures(Set<Feature> featuresBefore) throws Exception { Feature[] features = featureService.listInstalledFeatures(); Set<String> uninstall = new HashSet<>(); for (Feature curFeature : features) { if (!featuresBefore.contains(curFeature)) { uninstall.add(curFeature.getId()); } } try { System.out.println("Uninstalling " + uninstall); featureService.uninstallFeatures(uninstall, NO_AUTO_REFRESH); } catch (Exception e) { LOG.error(e.getMessage(), e); } }
protected void installAssertAndUninstallFeatures(String... feature) throws Exception { Set<Feature> featuresBefore = new HashSet<>(Arrays.asList(featuresService.listInstalledFeatures())); try { for (String curFeature : feature) { featuresService.installFeature(curFeature); assertFeatureInstalled(curFeature); } } finally { uninstallNewFeatures(featuresBefore); } }
private synchronized boolean installFeature(FeaturesService featuresService, String name) { try { Feature[] features = featuresService.listInstalledFeatures(); if (!isInstalled(features, name)) { featuresService.installFeature(name); features = featuresService.listInstalledFeatures(); if (isInstalled(features, name)) { logger.debug("Installed '{}'", name); postInstalledEvent(name); return true; } } } catch (Exception e) { logger.error("Failed installing '{}': {}", name, e.getMessage()); } return false; }
protected void installAssertAndUninstallFeature(String feature, String version) throws Exception { Set<Feature> featuresBefore = new HashSet<>(Arrays.asList(featuresService.listInstalledFeatures())); try { featuresService.installFeature(feature, version); assertFeatureInstalled(feature, version); } finally { uninstallNewFeatures(featuresBefore); } }
protected void installAssertAndUninstallFeature(String feature) throws Exception { Set<Feature> featuresBefore = new HashSet<>(Arrays.asList(featuresService.listInstalledFeatures())); try { featuresService.installFeature(feature); assertFeatureInstalled(feature); } finally { uninstallNewFeatures(featuresBefore); } }
private synchronized boolean uninstallFeature(FeaturesService featuresService, String name) { try { Feature[] features = featuresService.listInstalledFeatures(); if (isInstalled(features, name)) { featuresService.uninstallFeature(name); logger.info("Uninstalled '{}'", name); postUninstalledEvent(name); return true; } } catch (Exception e) { logger.debug("Failed uninstalling '{}': {}", name, e.getMessage()); } return false; }
private Collection<String> getInstalledOsgiPluginIds() { Collection<String> potentialOsgiPluginIds = new HashSet<>(); try { for( String installedKar : this.getKarService().list() ) { potentialOsgiPluginIds.add( installedKar ); } } catch ( Exception e ) { } for( Feature feature : this.getFeaturesService().listInstalledFeatures() ) { potentialOsgiPluginIds.add( feature.getName() ); } return potentialOsgiPluginIds; }
/** * 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; }
/** * 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; }
EnumSet.of(FeaturesService.Option.Upgrade, FeaturesService.Option.NoFailOnFeatureNotFound)); try { Feature[] features = featuresService.listInstalledFeatures(); Set<String> installed = new HashSet<>(); Set<String> failed = new HashSet<>();
/** * {@inheritDoc} */ public TabularData getFeatures() throws Exception { try { List<Feature> allFeatures = Arrays.asList(featuresService.listFeatures()); List<Feature> insFeatures = Arrays.asList(featuresService.listInstalledFeatures()); ArrayList<JmxFeature> features = new ArrayList<>(); for (Feature feature : allFeatures) { try { features.add(new JmxFeature(feature, insFeatures.contains(feature), featuresService.isRequired(feature))); } catch (Throwable t) { t.printStackTrace(); } } return JmxFeature.tableFrom(features); } catch (Throwable t) { t.printStackTrace(); return null; } }
public void assertFeatureInstalled(String featureName) { try { Feature[] features = featuresService.listInstalledFeatures(); for (Feature feature : features) { if (featureName.equals(feature.getName())) { return; } } fail("Feature " + featureName + " should be installed but is not"); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
@Override public FeaturesService addingService(ServiceReference<FeaturesService> reference) { BundleContext bc = reference.getBundle().getBundleContext(); final FeaturesService featureService = bc.getService(reference); final Optional<XmlFileStorageAdapter> currentPersister = XmlFileStorageAdapter.getInstance(); if(XmlFileStorageAdapter.getInstance().isPresent()) { final Set<String> installedFeatureIds = Sets.newHashSet(); for (final Feature installedFeature : featureService.listInstalledFeatures()) { installedFeatureIds.add(installedFeature.getId()); } currentPersister.get().setFeaturesService(new FeatureListProvider() { @Override public Set<String> listFeatures() { return installedFeatureIds; } }); } configFeaturesListener = new ConfigFeaturesListener(configPusher,featureService); registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null); return featureService; }
private boolean isInstalled(final Feature feature) { for(int retries=0;retries<MAX_RETRIES;retries++) { try { List<Feature> installedFeatures = Arrays.asList(featuresService.listInstalledFeatures()); if(installedFeatures.contains(feature)) { return true; } else { LOG.warn("Karaf featuresService.listInstalledFeatures() has not yet finished installing feature (retry {}) {} {}",retries,feature.getName(),feature.getVersion()); } } catch (Exception e) { if(retries < MAX_RETRIES) { LOG.warn("Karaf featuresService.listInstalledFeatures() has thrown an exception, retry {}", retries, e); } else { LOG.error("Giving up on Karaf featuresService.listInstalledFeatures() which has thrown an exception, retry {}", retries, e); throw e; } } try { Thread.sleep(RETRY_PAUSE_MILLIS); } catch (InterruptedException e1) { throw new IllegalStateException(e1); } } LOG.error("Giving up (after {} retries) on Karaf featuresService.listInstalledFeatures() which has not yet finished installing feature {} {}",MAX_RETRIES,feature.getName(),feature.getVersion()); return false; }
public void assertFeatureInstalled(String featureName, String featureVersion) { try { Feature[] features = featuresService.listInstalledFeatures(); for (Feature feature : features) { if (featureName.equals(feature.getName()) && featureVersion.equals(feature.getVersion())) { return; } } fail("Feature " + featureName + "/" + featureVersion + " should be installed but is not"); } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }
/** * The feature service does not uninstall feature dependencies when uninstalling a single feature. * So we need to make sure we uninstall all features that were newly installed. */ protected void uninstallNewFeatures(Set<Feature> featuresBefore) { try { Feature[] features = featuresService.listInstalledFeatures(); for (Feature curFeature : features) { if (!featuresBefore.contains(curFeature)) { try { System.out.println("Uninstalling " + curFeature.getName()); featuresService.uninstallFeature(curFeature.getName(), curFeature.getVersion()); } catch (Exception e) { // ignore } } } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } }