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);
}
}
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());
}
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);
}
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;
}
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;
}
Aggregations