Search in sources :

Example 66 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)

Example 67 with Feature

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

the class ProfileInstallCommand method uninstallFeatures.

private void uninstallFeatures(FeaturesService featuresService, List<String> uninstallFeatures) throws Exception {
    if (uninstallFeatures != null) {
        printSectionHeading("Uninstalling Features");
        Set<String> uniqueValues = new HashSet<>();
        for (String feature : uninstallFeatures) {
            if (uniqueValues.add(feature)) {
                printItemStatusPending("Uninstalling: ", feature);
                Feature featureObject = null;
                try {
                    featureObject = featuresService.getFeature(feature);
                } catch (Exception e) {
                    printError(String.format(FEATURE_FAILURE_MESSAGE, feature));
                    throw e;
                }
                if (featureObject == null) {
                    printItemStatusFailure("Uninstall Failed: ", feature);
                    printError(String.format(FEATURE_FAILURE_MESSAGE, feature));
                    throw new IllegalArgumentException(String.format(FEATURE_FAILURE_MESSAGE, feature));
                }
                uninstallFeature(featuresService, featureObject);
                printItemStatusSuccess("Uninstalled: ", feature);
            }
        }
    }
}
Also used : Feature(org.apache.karaf.features.Feature) BundleException(org.osgi.framework.BundleException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) FileNotFoundException(java.io.FileNotFoundException) ResolutionException(org.osgi.service.resolver.ResolutionException) HashSet(java.util.HashSet)

Example 68 with Feature

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

the class ApplicationServiceBeanTest method testGetInstallationProfiles.

/**
 * Tests the {@link ApplicationServiceBean#getInstallationProfiles()} method
 *
 * @throws Exception
 */
@Test
public void testGetInstallationProfiles() throws Exception {
    Feature testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    Dependency testDependency1 = mock(Dependency.class);
    Dependency testDependency2 = mock(Dependency.class);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testFeature2.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testDependency1.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testDependency2.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testFeature1.getDescription()).thenReturn(TEST_FEATURE_DESCRIPTION);
    when(testFeature2.getDescription()).thenReturn(TEST_FEATURE_DESCRIPTION);
    List<Dependency> dependencies1 = new ArrayList<>();
    dependencies1.add(testDependency1);
    List<Dependency> dependencies2 = new ArrayList<>();
    dependencies2.add(testDependency2);
    when(testFeature1.getDependencies()).thenReturn(dependencies1);
    when(testFeature2.getDependencies()).thenReturn(dependencies2);
    List<Feature> featureList = new ArrayList<>();
    featureList.add(testFeature1);
    featureList.add(testFeature2);
    when(testAppService.getInstallationProfiles()).thenReturn(featureList);
    ApplicationServiceBean serviceBean = newApplicationServiceBean();
    List<Map<String, Object>> result = serviceBean.getInstallationProfiles();
    assertThat("Should contain the nodes set up previously.", (String) result.get(0).get("name"), is(TEST_FEATURE_NAME));
    assertThat("Should have two entries.", result.size(), is(2));
}
Also used : ArrayList(java.util.ArrayList) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 69 with Feature

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

the class FeatureDetailsTest method testFeatureDetails.

/**
 * Tests the {@link FeatureDetails#FeatureDetails(Feature, String, String)} constructor, and all
 * associated getters
 */
@Test
public void testFeatureDetails() {
    Feature testFeature = mock(Feature.class);
    when(testFeature.getName()).thenReturn(TEST_FEATURE_NAME);
    when(testFeature.getId()).thenReturn(TEST_FEATURE_ID);
    when(testFeature.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    when(testFeature.getInstall()).thenReturn(TEST_FEATURE_INSTALL);
    when(testFeature.getDescription()).thenReturn(TEST_FEATURE_DESCRIP);
    when(testFeature.getDetails()).thenReturn(TEST_FEATURE_DETAILS);
    when(testFeature.getResolver()).thenReturn(TEST_FEATURE_RESOLVER);
    FeatureDetails testDetails = new FeatureDetails(testFeature, TEST_FEATURE_STATUS, TEST_FEATURE_REPO);
    assertEquals(TEST_FEATURE_NAME, testDetails.getName());
    assertEquals(TEST_FEATURE_ID, testDetails.getId());
    assertEquals(TEST_FEATURE_VERSION, testDetails.getVersion());
    assertEquals(TEST_FEATURE_INSTALL, testDetails.getInstall());
    assertEquals(TEST_FEATURE_DESCRIP, testDetails.getDescription());
    assertEquals(TEST_FEATURE_DETAILS, testDetails.getDetails());
    assertEquals(TEST_FEATURE_RESOLVER, testDetails.getResolver());
    assertEquals(TEST_FEATURE_REPO, testDetails.getRepository());
    assertEquals(TEST_FEATURE_STATUS, testDetails.getStatus());
}
Also used : Feature(org.apache.karaf.features.Feature) Test(org.junit.Test)

Example 70 with Feature

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

the class ProfileListCommandTest 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)

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