use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImpl method getAllDependencyFeatures.
/**
* Retrieves all of the dependencies for a given feature.
*
* @param feature Feature to look for dependencies on.
* @return A set of all features that are dependencies
*/
private Set<Feature> getAllDependencyFeatures(Feature feature) throws Exception {
Set<Feature> tmpList = new HashSet<>();
// get accurate feature reference from service - workaround for
// KARAF-2896 'RepositoryImpl load method incorrectly populates
// "features" list'
Feature curFeature = featuresService.getFeature(feature.getName(), feature.getVersion());
if (curFeature != null) {
for (Dependency dependencyFeature : curFeature.getDependencies()) {
Feature feat = featuresService.getFeature(dependencyFeature.getName(), dependencyFeature.getVersion());
if (StringUtils.equals(curFeature.getRepositoryUrl(), feat.getRepositoryUrl())) {
tmpList.addAll(getAllDependencyFeatures(feat));
}
}
tmpList.add(curFeature);
} else {
// feature may not be installed
tmpList.add(feature);
}
return tmpList;
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImpl method traverseDependencies.
/**
* Finds a parent and children dependencies for each app. Needs to be run twice
* in order to get full dependency correlations.
*
* @param appMap Application Map containing all the application nodes.
* @param filteredApplications Set containing all the application nodes minus those in the ignored list
* @param reportDebug Boolean that allows debug statements to be output or not. Only reason
* why this exists is because this function will be called twice and only
* the second set of statements will be relevant
*/
private void traverseDependencies(Map<Application, ApplicationNodeImpl> appMap, Set<Application> filteredApplications, boolean reportDebug) {
// find dependencies in each app and add them into correct node
for (Entry<Application, ApplicationNodeImpl> curAppNode : appMap.entrySet()) {
try {
// main feature will contain dependencies
Feature mainFeature = curAppNode.getKey().getMainFeature();
if (null == mainFeature) {
if (reportDebug) {
LOGGER.debug("Application \"{}\" does not contain a main feature", curAppNode.getKey().getName());
}
continue;
}
// eliminate duplications with a set
Set<Dependency> dependencies = new HashSet<>(mainFeature.getDependencies());
// remove any features that are local to the application
dependencies.removeAll(curAppNode.getKey().getFeatures());
// loop through all of the features that are left to determine
// where they are from
Set<Application> depAppSet = new HashSet<>();
for (Dependency curDepFeature : dependencies) {
Application dependencyApp = findFeature(featuresService.getFeature(curDepFeature.getName()), filteredApplications);
if (dependencyApp != null) {
if (dependencyApp.equals(curAppNode.getKey())) {
if (reportDebug) {
LOGGER.debug("Self-dependency");
}
continue;
} else {
if (reportDebug) {
LOGGER.debug("Application {} depends on the feature {} which is located in application {}.", curAppNode.getKey().getName(), curDepFeature.getName(), dependencyApp.getName());
}
depAppSet.add(dependencyApp);
}
}
}
if (!depAppSet.isEmpty()) {
Application parentApp;
if (depAppSet.size() > 1) {
parentApp = findCommonParent(depAppSet, appMap);
if (parentApp == null) {
if (reportDebug) {
LOGGER.debug("Found more than 1 application dependency for application {}. Could not determine which one is the correct parent. Application will be sent back as root application.", curAppNode.getKey().getName());
}
continue;
}
} else {
parentApp = depAppSet.iterator().next();
}
// update the dependency app with a new child
ApplicationNode parentAppNode = appMap.get(parentApp);
parentAppNode.getChildren().add(curAppNode.getValue());
curAppNode.getValue().setParent(parentAppNode);
} else {
if (reportDebug) {
LOGGER.debug("No dependency applications found for {}. This will be sent back as a root application.", curAppNode.getKey().getName());
}
}
// ApplicationServiceException from DDF and Exception from Karaf
// (FeaturesService)
} catch (Exception e) {
if (reportDebug) {
LOGGER.warn("Encountered error while determining dependencies for \"{}\". This may cause an incomplete application hierarchy to be created.", curAppNode.getKey().getName(), e);
}
}
}
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImpl method getApplicationStatus.
@Override
public ApplicationStatus getApplicationStatus(Application application) {
Set<Feature> uninstalledFeatures = new HashSet<>();
Set<Feature> requiredFeatures = new HashSet<>();
Set<Bundle> errorBundles = new HashSet<>();
ApplicationState installState = null;
// check features
try {
// Check Main Feature
Feature mainFeature = application.getMainFeature();
boolean isMainFeatureUninstalled = true;
if (mainFeature != null) {
isMainFeatureUninstalled = !featuresService.isInstalled(mainFeature);
requiredFeatures.add(mainFeature);
} else {
Set<Feature> features = application.getFeatures();
if (features.size() == 1) {
requiredFeatures.addAll(getAllDependencyFeatures(features.iterator().next()));
} else {
for (Feature curFeature : features) {
if (StringUtils.equalsIgnoreCase(Feature.DEFAULT_INSTALL_MODE, curFeature.getInstall())) {
requiredFeatures.addAll(getAllDependencyFeatures(curFeature));
}
}
}
}
LOGGER.debug("{} has {} required features that must be started.", application.getName(), requiredFeatures.size());
BundleStateSet bundleStates = getCurrentBundleStates(requiredFeatures);
errorBundles.addAll(bundleStates.getFailedBundles());
errorBundles.addAll(bundleStates.getInactiveBundles());
if (bundleStates.getNumFailedBundles() > 0) {
// Any failed bundles, regardless of feature state, indicate a
// failed application state
installState = ApplicationState.FAILED;
} else if ((mainFeature != null && isMainFeatureUninstalled) || bundleStates.getNumInactiveBundles() > 0) {
installState = ApplicationState.INACTIVE;
} else if (bundleStates.getNumTransitionalBundles() > 0) {
installState = ApplicationState.UNKNOWN;
} else {
installState = ApplicationState.ACTIVE;
}
} catch (Exception e) {
LOGGER.warn("Encountered an error while trying to determine status of application {}. " + "Setting status as UNKNOWN.", application.getName(), e);
installState = ApplicationState.UNKNOWN;
}
return new ApplicationStatusImpl(application, installState, uninstalledFeatures, errorBundles);
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ProfileInstallCommandTest method testValidRegularProfile.
@Test
public void testValidRegularProfile() throws Exception {
profileInstallCommand.profileName = "standard";
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));
profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
verify(applicationService, times(3)).startApplication(anyString());
}
use of org.apache.karaf.features.Feature 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());
}
Aggregations