Search in sources :

Example 76 with Feature

use of org.apache.karaf.features.Feature in project karaf by apache.

the class KarafTestSupport method assertFeatureNotInstalled.

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");
        }
    }
}
Also used : Feature(org.apache.karaf.features.Feature)

Example 77 with Feature

use of org.apache.karaf.features.Feature in project karaf by apache.

the class KarafTestSupport method assertFeaturesInstalled.

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));
}
Also used : Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet)

Example 78 with Feature

use of org.apache.karaf.features.Feature in project karaf by apache.

the class KarServiceImpl method getFeatures.

private Set<Feature> getFeatures(Map<String, Feature> featureMap, List<String> features, int depth) {
    Set<Feature> featureSet = new HashSet<>();
    if (depth > 5) {
        // Break after some recursions to avoid endless loops 
        return featureSet;
    }
    if (features == null) {
        featureSet.addAll(featureMap.values());
        return featureSet;
    }
    for (String featureName : features) {
        Feature feature = featureMap.get(featureName);
        if (feature == null) {
            System.out.println("Feature " + featureName + " not found in repository.");
        //throw new RuntimeException();
        } else {
            featureSet.add(feature);
            List<Dependency> deps = feature.getDependencies();
            List<String> depNames = new ArrayList<>();
            for (Dependency dependency : deps) {
                depNames.add(dependency.getName());
            }
            featureSet.addAll(getFeatures(featureMap, depNames, depth++));
        }
    }
    return featureSet;
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet)

Example 79 with Feature

use of org.apache.karaf.features.Feature in project karaf by apache.

the class FeaturesServiceMBeanImpl method infoFeature.

private TabularData infoFeature(Feature[] f) throws Exception {
    ArrayList<JmxFeature> features = new ArrayList<>();
    for (Feature feature : f) {
        JmxFeature jmxFeature;
        if (featuresService.isInstalled(feature)) {
            jmxFeature = new JmxFeature(feature, true);
        } else {
            jmxFeature = new JmxFeature(feature, false);
        }
        features.add(jmxFeature);
    }
    return JmxFeature.tableFrom(features);
}
Also used : JmxFeature(org.apache.karaf.features.management.codec.JmxFeature) Feature(org.apache.karaf.features.Feature) JmxFeature(org.apache.karaf.features.management.codec.JmxFeature)

Example 80 with Feature

use of org.apache.karaf.features.Feature in project ddf by codice.

the class ApplicationServiceImpl method getCurrentBundleStates.

/**
     * Evaluates the bundles contained in a set of {@link Feature}s and
     * determines if each bundle is currently in an active, inactive, or failed
     * state.
     *
     * @param features
     * @return {@link BundleStateSet} containing information on the state of
     * each bundle
     */
private final BundleStateSet getCurrentBundleStates(Set<Feature> features) {
    BundleStateSet bundleStateSet = new BundleStateSet();
    for (Feature curFeature : features) {
        for (BundleInfo curBundleInfo : curFeature.getBundles()) {
            Bundle curBundle = getContext().getBundle(curBundleInfo.getLocation());
            if (curBundle != null && curBundle.adapt(BundleRevision.class).getTypes() != BundleRevision.TYPE_FRAGMENT) {
                // check if bundle is inactive
                int bundleState = curBundle.getState();
                switch(bundleState) {
                    case Bundle.RESOLVED:
                    case Bundle.STARTING:
                    case Bundle.STOPPING:
                        bundleStateSet.addInactiveBundle(curBundle);
                        break;
                    case Bundle.INSTALLED:
                    case Bundle.UNINSTALLED:
                        bundleStateSet.addFailedBundle(curBundle);
                        break;
                    case Bundle.ACTIVE:
                        // and SpringDM) failed on start
                        for (BundleStateService curStateService : bundleStateServices) {
                            LOGGER.trace("Checking {} for bundle state of {}.", curStateService.getName(), curBundle.getSymbolicName());
                            BundleState curState = curStateService.getState(curBundle);
                            switch(curState) {
                                case Resolved:
                                case Stopping:
                                    LOGGER.trace("{} is in an inactive state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
                                    bundleStateSet.addInactiveBundle(curBundle);
                                    break;
                                case Installed:
                                case Failure:
                                    LOGGER.trace("{} is in a failed state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
                                    bundleStateSet.addFailedBundle(curBundle);
                                    break;
                                case Waiting:
                                case Starting:
                                case GracePeriod:
                                    LOGGER.trace("{} is in a transitional state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
                                    bundleStateSet.addTransitionalBundle(curBundle);
                                    break;
                                case Active:
                                    LOGGER.trace("{} is in an active state. Current State: {}", curBundle.getSymbolicName(), curState.toString());
                                    bundleStateSet.addActiveBundle(curBundle);
                                    break;
                                case Unknown:
                                default:
                                    // Ignore - BundleStateService unaware of this bundle.
                                    break;
                            }
                        }
                        // end case Bundle.Active
                        break;
                    default:
                        bundleStateSet.addActiveBundle(curBundle);
                        break;
                }
            }
        }
    }
    return bundleStateSet;
}
Also used : BundleStateService(org.apache.karaf.bundle.core.BundleStateService) BundleInfo(org.apache.karaf.features.BundleInfo) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) BundleState(org.apache.karaf.bundle.core.BundleState) Feature(org.apache.karaf.features.Feature)

Aggregations

Feature (org.apache.karaf.features.Feature)127 Test (org.junit.Test)56 FeaturesService (org.apache.karaf.features.FeaturesService)43 HashSet (java.util.HashSet)41 Repository (org.apache.karaf.features.Repository)39 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)18 Bundle (org.osgi.framework.Bundle)18 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 Map (java.util.Map)16 Dependency (org.apache.karaf.features.Dependency)15 BundleInfo (org.apache.karaf.features.BundleInfo)14 Application (org.codice.ddf.admin.application.service.Application)14 URI (java.net.URI)13 IOException (java.io.IOException)12 VersionRange (org.apache.felix.utils.version.VersionRange)12 LinkedHashSet (java.util.LinkedHashSet)11 Version (org.osgi.framework.Version)11 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 EnumSet (java.util.EnumSet)9