Search in sources :

Example 31 with Feature

use of org.apache.karaf.features.Feature in project admin-console-beta by connexta.

the class CreateFeatureDependencyGraph method createFeatureDependenciesGraph.

private DirectedGraph<Field, DependencyEdge> createFeatureDependenciesGraph(List<FeatureField> features) {
    DirectedGraph<Field, DependencyEdge> graph = new DirectedPseudograph<>(DependencyEdge.class);
    FEATURE_BUNDLE_VERTEX_PROV.getAttributes().forEach(attri -> exporter.registerAttribute(attri.getAttriName(), attri.getCategory(), attri.getType()));
    features.forEach(graph::addVertex);
    Map<String, FeatureField> featuresById = features.stream().collect(Collectors.toMap(FeatureField::id, f -> f));
    for (FeatureField feature : features) {
        for (String featId : feature.featDeps()) {
            try {
                Feature feat = featureUtils.getFeature(featId);
                if (feat != null && featuresById.containsKey(feat.getId())) {
                    graph.addEdge(feature, featuresById.get(feat.getId()), DependencyEdge.create(null));
                } else {
                    LOGGER.error("Failed to find feature {} while creating feature dependency graph.", featId);
                }
            } catch (Exception e) {
                LOGGER.error("Failed to find feature {} while creating feature dependency graph.", featId, e);
            }
        }
        feature.bundleDeps().forEach(dep -> {
            graph.addVertex(dep);
            graph.addEdge(feature, dep, DependencyEdge.create(null));
        });
    }
    return graph;
}
Also used : DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) LoggerFactory(org.slf4j.LoggerFactory) DIRECTORY_DOES_NOT_EXIST(org.codice.ddf.admin.common.report.message.DefaultMessages.DIRECTORY_DOES_NOT_EXIST) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField) DefaultMessages.failedPersistError(org.codice.ddf.admin.common.report.message.DefaultMessages.failedPersistError) ImmutableList(com.google.common.collect.ImmutableList) FAILED_PERSIST(org.codice.ddf.admin.common.report.message.DefaultMessages.FAILED_PERSIST) Map(java.util.Map) BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) Field(org.codice.ddf.admin.api.Field) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) BaseFunctionField(org.codice.ddf.admin.common.fields.base.BaseFunctionField) Feature(org.apache.karaf.features.Feature) Set(java.util.Set) GraphMLExporter(org.jgrapht.ext.GraphMLExporter) Collectors(java.util.stream.Collectors) FeatureUtils(org.codice.ddf.admin.query.dev.system.dependency.FeatureUtils) List(java.util.List) Paths(java.nio.file.Paths) DependencyEdge(org.codice.ddf.admin.query.dev.system.graph.DependencyEdge) DirectedGraph(org.jgrapht.DirectedGraph) FeatureGraphProvider(org.codice.ddf.admin.query.dev.system.graph.FeatureGraphProvider) DirectoryField(org.codice.ddf.admin.common.fields.common.DirectoryField) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField) BooleanField(org.codice.ddf.admin.common.fields.base.scalar.BooleanField) FunctionField(org.codice.ddf.admin.api.fields.FunctionField) Field(org.codice.ddf.admin.api.Field) BaseFunctionField(org.codice.ddf.admin.common.fields.base.BaseFunctionField) DirectoryField(org.codice.ddf.admin.common.fields.common.DirectoryField) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField) DependencyEdge(org.codice.ddf.admin.query.dev.system.graph.DependencyEdge) Feature(org.apache.karaf.features.Feature) DirectedPseudograph(org.jgrapht.graph.DirectedPseudograph)

Example 32 with Feature

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

the class IgniteKarafFeaturesInstallationTest method testAllBundlesActiveAndFeaturesInstalled.

/**
 * @throws Exception
 */
@Test
public void testAllBundlesActiveAndFeaturesInstalled() throws Exception {
    // Asssert all bundles except fragments are ACTIVE.
    for (Bundle b : bundleCtx.getBundles()) {
        System.out.println(String.format("Checking state of bundle [symbolicName=%s, state=%s]", b.getSymbolicName(), b.getState()));
        if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null)
            assertTrue(b.getState() == Bundle.ACTIVE);
    }
    // Check that according to the FeaturesService, all Ignite features except ignite-log4j are installed.
    Feature[] features = featuresSvc.getFeatures(IGNITE_FEATURES_NAME_REGEX);
    assertNotNull(features);
    assertEquals(EXPECTED_FEATURES, features.length);
    for (Feature f : features) {
        if (IGNORED_FEATURES.contains(f.getName()))
            continue;
        boolean installed = featuresSvc.isInstalled(f);
        System.out.println(String.format("Checking if feature is installed [featureName=%s, installed=%s]", f.getName(), installed));
        assertTrue(installed);
        assertEquals(PROJECT_VERSION.replaceAll("-", "."), f.getVersion().replaceAll("-", "."));
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 33 with Feature

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

the class ProfileInstallCommandTest method createMockFeature.

private Feature createMockFeature(String name) {
    Feature feature = mock(Feature.class);
    when(feature.getName()).thenReturn(name);
    when(feature.getVersion()).thenReturn("0.0.0");
    return feature;
}
Also used : Feature(org.apache.karaf.features.Feature)

Example 34 with Feature

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

the class ProfileInstallCommandTest method testUninstallInstallerFailure.

@Test(expected = Exception.class)
public void testUninstallInstallerFailure() throws Exception {
    Feature installerFeature = createMockFeature("admin-modules-installer");
    this.featuresService = mock(FeaturesService.class);
    when(featuresService.getFeature(anyString())).thenReturn(installerFeature);
    when(featuresService.isInstalled(installerFeature)).thenReturn(true);
    doThrow(Exception.class).when(featuresService).uninstallFeature("admin-modules-installer", "0.0.0", NO_AUTO_REFRESH);
    profileInstallCommand.profileName = "invalidStopBundles";
    profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
}
Also used : FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 35 with Feature

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

the class ApplicationServiceBean method getInstallationProfiles.

@Override
public List<Map<String, Object>> getInstallationProfiles() {
    try {
        List<Feature> installationProfiles = appService.getInstallationProfiles();
        List<Map<String, Object>> profiles = new ArrayList<>();
        for (Feature profile : installationProfiles) {
            Map<String, Object> profileMap = new HashMap<>();
            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;
    } catch (VirtualMachineError e) {
        throw e;
    } catch (Throwable e) {
        LOGGER.info("Could not retrieve installation profiles", e);
        throw new ApplicationServiceBeanException("Could not retrieve installation profiles");
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Feature(org.apache.karaf.features.Feature) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

Feature (org.apache.karaf.features.Feature)130 Test (org.junit.Test)57 FeaturesService (org.apache.karaf.features.FeaturesService)44 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 VersionRange (org.apache.felix.utils.version.VersionRange)12 IOException (java.io.IOException)11 LinkedHashSet (java.util.LinkedHashSet)11 Version (org.osgi.framework.Version)11 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 EnumSet (java.util.EnumSet)9