Search in sources :

Example 16 with Dependency

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

the class ApplicationServiceImplTest method testStopApplicationMainFeature.

/**
     * Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
     * for the case where a main feature exists
     *
     * @throws Exception
     */
@Test
public void testStopApplicationMainFeature() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = new ApplicationServiceImpl(bundleStateServices) {

        @Override
        protected BundleContext getContext() {
            return bundleContext;
        }
    };
    Application testApp1 = mock(ApplicationImpl.class);
    Feature testFeature1 = mock(Feature.class);
    Dependency testDependency1 = mock(Dependency.class);
    List<Dependency> dependencyList1 = new ArrayList<>();
    Set<Feature> featureSet1 = new HashSet<>();
    dependencyList1.add(testDependency1);
    featureSet1.add(testFeature1);
    when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
    when(testApp1.getMainFeature()).thenReturn(testFeature1);
    when(testApp1.getFeatures()).thenReturn(featureSet1);
    when(featuresService.isInstalled(testFeature1)).thenReturn(true);
    when(testFeature1.getDependencies()).thenReturn(dependencyList1);
    when(testDependency1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    when(testFeature1.getVersion()).thenReturn(TEST_FEATURE_VERSION);
    appService.stopApplication(testApp1);
    verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, TEST_FEATURE_VERSION, EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) ArrayList(java.util.ArrayList) FeaturesService(org.apache.karaf.features.FeaturesService) Dependency(org.apache.karaf.features.Dependency) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 17 with Dependency

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

the class FeatureUtils method featureToField.

private FeatureField featureToField(Feature feat, Map<String, BundleField> bundlesByLocation) {
    List<String> featDeps = feat.getDependencies().stream().map(Dependency::getName).collect(Collectors.toList());
    List<BundleField> bundleDepLocations = feat.getBundles().stream().map(BundleInfo::getLocation).map(loc -> createBundleFromLocation(loc, bundlesByLocation)).collect(Collectors.toList());
    return new FeatureField().name(feat.getName()).featDescription(feat.getDescription()).state(feat.getInstall()).id(feat.getId()).repoUrl(feat.getRepositoryUrl()).addFeatureDeps(featDeps).addBundleDeps(bundleDepLocations);
}
Also used : Dependency(org.apache.karaf.features.Dependency) Arrays(java.util.Arrays) BundleInfo(org.apache.karaf.features.BundleInfo) Logger(org.slf4j.Logger) Feature(org.apache.karaf.features.Feature) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) FeaturesService(org.apache.karaf.features.FeaturesService) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField) List(java.util.List) Map(java.util.Map) Collections(java.util.Collections) BundleField(org.codice.ddf.admin.query.dev.system.fields.BundleField) BundleField(org.codice.ddf.admin.query.dev.system.fields.BundleField) BundleInfo(org.apache.karaf.features.BundleInfo) FeatureField(org.codice.ddf.admin.query.dev.system.fields.FeatureField)

Example 18 with Dependency

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

the class ProfileListCommandTest method setup.

@Before
public void setup() throws IOException {
    ddfHome.newFolder("etc", "profiles");
    profilePath = Paths.get(ddfHome.getRoot().toString(), "etc", "profiles");
    Files.copy(this.getClass().getResourceAsStream("/profiles/devProfile.json"), Paths.get(profilePath.toAbsolutePath().toString(), "devProfile.json"));
    Files.copy(this.getClass().getResourceAsStream("/profiles/profileWithDuplicates.json"), Paths.get(profilePath.toAbsolutePath().toString(), "profileWithDuplicates.json"));
    this.applicationService = mock(ApplicationServiceImpl.class);
    this.featuresService = mock(FeaturesServiceImpl.class);
    this.bundleService = mock(BundleServiceImpl.class);
    out = new ByteArrayOutputStream();
    console = new PrintStream(out);
    profileListCommand = getProfileListCommand(profilePath, console);
    Feature feature = createMockFeature("standard");
    List<Dependency> deps = Arrays.asList(createMockDependency("app1"), createMockDependency("app2"), createMockDependency("app3"));
    when(feature.getDependencies()).thenReturn(deps);
    when(applicationService.getInstallationProfiles()).thenReturn(Collections.singletonList(feature));
}
Also used : FeaturesServiceImpl(org.apache.karaf.features.internal.service.FeaturesServiceImpl) PrintStream(java.io.PrintStream) ApplicationServiceImpl(org.codice.ddf.admin.application.service.impl.ApplicationServiceImpl) BundleServiceImpl(org.apache.karaf.bundle.core.internal.BundleServiceImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) Before(org.junit.Before)

Example 19 with Dependency

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

the class ApplicationServiceImplTest method createMockFeaturesService.

/**
 * Creates a mock {@code FeaturesService} object consisting of all of the features contained in a
 * {@code Set} of {@code Repository} objects. Each {@code Feature} will be in the <i>installed</i>
 * state unless it is contained in the received set of features that are not to be installed. Each
 * {@code Bundle} will be in the {@code Bundle#ACTIVE} state and the {@code BundleState#Active}
 * extended bundle state (as reported by a dependency injection framework) unless it is contained
 * in the received set of {@code Bundle}s that are not to be active, in which case the {@code
 * Bundle} will be in the {@code Bundle#INSTALLED} state and the {@code BundleState#Installed}
 * extended bundle state.
 *
 * <p>Note that not all of the state and {@code Bundle} information is contained in the {@code
 * FeaturesService}. As such, this method stores some of the required information in the class's
 * {@code #bundleContext} and {@code bundleStateServices}. As such, these objects must be
 * re-instantiated for each test (i.e., they must be instantiated in the {@link #setUp()} method).
 *
 * @param repos A {@code Set} of {@link Repository} objects from which to obtain the {@link
 *     Feature}s that are to be included in the mock {@code FeaturesService}
 * @param notInstalledFeatures A {@code Set} of {@code Feature}s that the {@code FeaturesService}
 *     should report as not installed
 * @param inactiveBundles A {@code Set} of {@link BundleInfo}s containing the locations of {@code
 *     Bundle}s that should be set to inactive and for which the {@link BundleStateService}
 *     contained in index 0 of {@link #bundleStateServices} should report a {@link
 *     BundleState#Installed} state.
 * @return A mock {@link FeaturesService} with {@link Feature}s and {@link Bundle}s in the
 *     requested states.
 * @throws Exception
 */
private FeaturesService createMockFeaturesService(Set<Repository> repos, Set<Feature> notInstalledFeatures, Set<BundleInfo> inactiveBundles) throws Exception {
    if (LOGGER.isTraceEnabled()) {
        for (Repository repo : repos) {
            for (Feature feature : repo.getFeatures()) {
                LOGGER.trace("Repo Feature: {}", feature);
                LOGGER.trace("Repo Feature name/version: {}/{}", feature.getName(), feature.getVersion());
                LOGGER.trace("Dependencies: ");
                for (Dependency depFeature : feature.getDependencies()) {
                    LOGGER.trace("Dependency Feature: {}", depFeature);
                    LOGGER.trace("Dependency Feature name/version: {}/{}", depFeature.getName(), depFeature.getVersion());
                }
            }
        }
    }
    if (null == notInstalledFeatures) {
        notInstalledFeatures = new HashSet<>();
    }
    if (null == inactiveBundles) {
        inactiveBundles = new HashSet<>();
    }
    Set<String> installedBundleLocations = new HashSet<>();
    for (BundleInfo bundleInfo : inactiveBundles) {
        installedBundleLocations.add(bundleInfo.getLocation());
    }
    FeaturesService featuresService = mock(FeaturesService.class);
    Set<Feature> featuresSet = new HashSet<>();
    BundleRevision mockBundleRevision = mock(BundleRevision.class);
    when(mockBundleRevision.getTypes()).thenReturn(0);
    for (Repository curRepo : repos) {
        for (Feature curFeature : curRepo.getFeatures()) {
            featuresSet.add(curFeature);
            when(featuresService.getFeature(curFeature.getName())).thenReturn(curFeature);
            when(featuresService.getFeature(curFeature.getName(), curFeature.getVersion())).thenReturn(curFeature);
            // TODO: File Karaf bug that necessitates this, then reference
            // it here.
            when(featuresService.getFeature(curFeature.getName(), "0.0.0")).thenReturn(curFeature);
            when(featuresService.isInstalled(curFeature)).thenReturn(!notInstalledFeatures.contains(curFeature));
            // of that bundle, this logic will need to be modified.
            for (BundleInfo bundleInfo : curFeature.getBundles()) {
                if (installedBundleLocations.contains(bundleInfo.getLocation())) {
                    Bundle mockInstalledBundle = mock(Bundle.class);
                    when(mockInstalledBundle.getState()).thenReturn(Bundle.INSTALLED);
                    when(mockInstalledBundle.adapt(BundleRevision.class)).thenReturn(mockBundleRevision);
                    when(bundleContext.getBundle(bundleInfo.getLocation())).thenReturn(mockInstalledBundle);
                    when(bundleStateServices.get(0).getState(mockInstalledBundle)).thenReturn(BundleState.Installed);
                } else {
                    Bundle mockActiveBundle = mock(Bundle.class);
                    when(mockActiveBundle.getState()).thenReturn(Bundle.ACTIVE);
                    when(mockActiveBundle.adapt(BundleRevision.class)).thenReturn(mockBundleRevision);
                    when(bundleContext.getBundle(bundleInfo.getLocation())).thenReturn(mockActiveBundle);
                    when(bundleStateServices.get(0).getState(mockActiveBundle)).thenReturn(BundleState.Active);
                }
            }
        }
    }
    when(featuresService.listRepositories()).thenReturn(repos.toArray(new Repository[repos.size()]));
    when(featuresService.listFeatures()).thenReturn(featuresSet.toArray(new Feature[] {}));
    return featuresService;
}
Also used : Repository(org.apache.karaf.features.Repository) BundleInfo(org.apache.karaf.features.BundleInfo) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) FeaturesService(org.apache.karaf.features.FeaturesService) Dependency(org.apache.karaf.features.Dependency) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet)

Aggregations

Dependency (org.apache.karaf.features.Dependency)19 Feature (org.apache.karaf.features.Feature)14 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)5 BundleInfo (org.apache.karaf.features.BundleInfo)4 Conditional (org.apache.karaf.features.Conditional)3 FeaturesService (org.apache.karaf.features.FeaturesService)3 Test (org.junit.Test)3 SecurityServiceException (ddf.security.service.SecurityServiceException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Map (java.util.Map)2 VersionRange (org.apache.felix.utils.version.VersionRange)2 Repository (org.apache.karaf.features.Repository)2 ResourceUtils.addIdentityRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement)2 ResourceUtils.toFeatureRequirement (org.apache.karaf.features.internal.resolver.ResourceUtils.toFeatureRequirement)2 Application (org.codice.ddf.admin.application.service.Application)2 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)2 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)2 Requirement (org.osgi.resource.Requirement)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1