Search in sources :

Example 6 with BundleInfo

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

the class KarServiceImpl method copyFeatureToJar.

private void copyFeatureToJar(JarOutputStream jos, Feature feature, Map<URI, Integer> locationMap) throws URISyntaxException {
    for (BundleInfo bundleInfo : feature.getBundles()) {
        URI location = new URI(bundleInfo.getLocation());
        copyResourceToJar(jos, location, locationMap);
    }
    for (ConfigFileInfo configFileInfo : feature.getConfigurationFiles()) {
        URI location = new URI(configFileInfo.getLocation());
        copyResourceToJar(jos, location, locationMap);
    }
}
Also used : BundleInfo(org.apache.karaf.features.BundleInfo) ConfigFileInfo(org.apache.karaf.features.ConfigFileInfo) URI(java.net.URI)

Example 7 with BundleInfo

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

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled.

/**
     * Test method for
     * {@link ApplicationService#getApplicationStatus(Application)}
     * <p>
     * Verifies method returns an {@link ApplicationState#FAILED } state for an
     * {@code Application} under the following conditions:
     * <p>
     * <ul>
     * <li>Main feature is installed</li>
     * <li>One dependency feature is not installed</li>
     * <li>Dependency feature that is not installed contains Bundle(s) whose
     * states and extended states are inactive</li>
     * </ul>
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled() throws Exception {
    Set<Repository> mainFeaturesRepoSet = new HashSet<Repository>();
    Set<Feature> notInstalledFeatures = new HashSet<Feature>();
    Set<BundleInfo> inactiveBundles = new HashSet<BundleInfo>();
    for (Feature feature : mainFeatureRepo2.getFeatures()) {
        if (feature.getName().equals(TEST_MAIN_FEATURES_2_MAIN_FEATURE_NAME)) {
            notInstalledFeatures.add(feature);
            inactiveBundles.addAll(feature.getBundles());
            break;
        }
    }
    assertEquals("Feature is not included in repository the expected number of times", 1, notInstalledFeatures.size());
    assertTrue("No bundles included in Feature", inactiveBundles.size() > 0);
    mainFeaturesRepoSet.add(mainFeatureRepo2);
    FeaturesService featuresService = createMockFeaturesService(mainFeaturesRepoSet, notInstalledFeatures, inactiveBundles);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : Repository(org.apache.karaf.features.Repository) BundleInfo(org.apache.karaf.features.BundleInfo) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 8 with BundleInfo

use of org.apache.karaf.features.BundleInfo 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 Repository} object.
     *
     * @param repo
     * @param notInstalledFeatureNames
     * @param inactiveBundleLocations
     * @return
     * @throws Exception
     * @see #createMockFeaturesService(Set, Set, Set) for additional details
     */
private FeaturesService createMockFeaturesService(Repository repo, Set<String> notInstalledFeatureNames, Set<String> inactiveBundleLocations) throws Exception {
    Set<Feature> notInstalledFeatures = new HashSet<Feature>();
    Set<BundleInfo> inactiveBundles = new HashSet<BundleInfo>();
    for (Feature feature : repo.getFeatures()) {
        if (null != notInstalledFeatureNames && notInstalledFeatureNames.contains(feature.getName())) {
            notInstalledFeatures.add(feature);
        }
        if (null != inactiveBundleLocations) {
            for (BundleInfo bundleInfo : feature.getBundles()) {
                if (inactiveBundleLocations.contains(bundleInfo.getLocation())) {
                    inactiveBundles.add(bundleInfo);
                }
            }
        }
    }
    Set<Repository> repoSet = new HashSet<Repository>();
    repoSet.add(repo);
    return createMockFeaturesService(repoSet, notInstalledFeatures, inactiveBundles);
}
Also used : Repository(org.apache.karaf.features.Repository) BundleInfo(org.apache.karaf.features.BundleInfo) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet)

Example 9 with BundleInfo

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

the class ApplicationServiceImplTest method getXBundlesFromFeaturesService.

/**
     * Retrieves a given number of {@code Bundle}s from the received
     * {@code FeaturesService}
     *
     * @param featuresService The {@link FeaturesService} from which to obtain a
     *                        {@code Bundle}
     * @param numBundles      The number of bundles to be retrieved from the
     *                        {@code FeaturesService}
     * @return A {@code Set} containing the requested number of {@link Bundle}s
     * from the received {@code FeaturesService} or <code>null</code> if
     * the {@code FeaturesService} does not contain the requested number
     * of {@code Bundle}s
     * @throws Exception
     */
private Set<Bundle> getXBundlesFromFeaturesService(FeaturesService featuresService, int numBundles) throws Exception {
    Set<Bundle> bundles = new HashSet<Bundle>();
    // BundleInfo bundleInfo = null;
    Bundle bundle = null;
    Feature[] features = featuresService.listFeatures();
    List<BundleInfo> bundleInfos = null;
    int ii = 0;
    while (bundles.size() < numBundles && ii < features.length) {
        bundleInfos = features[ii].getBundles();
        int jj = 0;
        while (bundles.size() < numBundles && jj < bundleInfos.size()) {
            bundle = bundleContext.getBundle(bundleInfos.get(ii).getLocation());
            if (null != bundle) {
                bundles.add(bundle);
            }
            ++jj;
        }
        ++ii;
    }
    if (bundles.size() < numBundles) {
        bundles = null;
    }
    return bundles;
}
Also used : BundleInfo(org.apache.karaf.features.BundleInfo) Bundle(org.osgi.framework.Bundle) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet)

Example 10 with BundleInfo

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

the class ApplicationServiceBean method getServices.

/**
     * {@inheritDoc}.
     */
@SuppressWarnings("unchecked")
@Override
public List<Map<String, Object>> getServices(String applicationID) {
    List<Map<String, Object>> services = configAdminExt.listServices(getDefaultFactoryLdapFilter(), getDefaultLdapFilter());
    List<Map<String, Object>> returnValues = new ArrayList<Map<String, Object>>();
    BundleContext context = getContext();
    if (!services.isEmpty()) {
        Application app = appService.getApplication(applicationID);
        MetaTypeService metatypeService = getMetaTypeService();
        if (app != null) {
            try {
                Set<BundleInfo> bundles = app.getBundles();
                Set<String> bundleLocations = new HashSet<String>();
                Set<MetaTypeInformation> metatypeInformation = new HashSet<MetaTypeInformation>();
                for (BundleInfo info : bundles) {
                    bundleLocations.add(info.getLocation());
                }
                for (Bundle bundle : context.getBundles()) {
                    for (BundleInfo info : bundles) {
                        if (info.getLocation().equals(bundle.getLocation())) {
                            metatypeInformation.add(metatypeService.getMetaTypeInformation(bundle));
                        }
                    }
                }
                for (Map<String, Object> service : services) {
                    if (service.containsKey("configurations")) {
                        List<Map<String, Object>> configurations = (List<Map<String, Object>>) service.get("configurations");
                        for (Map<String, Object> item : configurations) {
                            if (item.containsKey("bundle_location")) {
                                String bundleLocation = (String) item.get("bundle_location");
                                if (bundleLocations.contains(bundleLocation)) {
                                    returnValues.add(service);
                                    break;
                                }
                            }
                        }
                    } else {
                        if (checkForMetaTypesForService(metatypeInformation, service)) {
                            returnValues.add(service);
                        }
                    }
                }
            } catch (ApplicationServiceException e) {
                LOGGER.warn("There was an error while trying to access the application", e);
                return new ArrayList<Map<String, Object>>();
            }
        }
    }
    return returnValues;
}
Also used : MetaTypeService(org.osgi.service.metatype.MetaTypeService) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) MetaTypeInformation(org.osgi.service.metatype.MetaTypeInformation) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) BundleInfo(org.apache.karaf.features.BundleInfo) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) Application(org.codice.ddf.admin.application.service.Application) BundleContext(org.osgi.framework.BundleContext) HashSet(java.util.HashSet)

Aggregations

BundleInfo (org.apache.karaf.features.BundleInfo)19 HashSet (java.util.HashSet)11 Feature (org.apache.karaf.features.Feature)9 Bundle (org.osgi.framework.Bundle)8 HashMap (java.util.HashMap)7 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 Conditional (org.apache.karaf.features.Conditional)4 FeaturesService (org.apache.karaf.features.FeaturesService)4 Repository (org.apache.karaf.features.Repository)4 Dependency (org.apache.karaf.features.Dependency)3 Resource (org.osgi.resource.Resource)3 List (java.util.List)2 Mockito.anyString (org.mockito.Mockito.anyString)2 BundleRevision (org.osgi.framework.wiring.BundleRevision)2 MetaTypeInformation (org.osgi.service.metatype.MetaTypeInformation)2 MetaTypeService (org.osgi.service.metatype.MetaTypeService)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1