Search in sources :

Example 36 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 37 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 38 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 39 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)

Example 40 with Feature

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

the class SystemStateManager method captureSystemState.

private void captureSystemState() {
    LOGGER.info("Capturing system state");
    try {
        baseFeatures = Arrays.stream(features.listInstalledFeatures()).map(Feature::getName).collect(Collectors.toList());
        Configuration[] configs = adminConfig.listConfigurations(CONFIGURATION_FILTER);
        for (Configuration config : configs) {
            baseConfigurations.put(config.getPid(), config);
        }
        console.runCommand("catalog:export --provider --force --skip-signature-verification --delete=false --output \"./itest-catalog-entries.zip\" --cql \"\\\"metacard-tags\\\" not like 'geonames'\"");
        LOGGER.info("Feature Count: {}", baseFeatures.size());
        LOGGER.info("Configuration Count: {}", baseConfigurations.size());
    } catch (Exception e) {
        LOGGER.error("Error capturing system configuration.", e);
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) Feature(org.apache.karaf.features.Feature)

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