use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImpl method startApplication.
@Override
public synchronized void startApplication(Application application) throws ApplicationServiceException {
try {
LOGGER.debug("Starting Application {} - {}", application.getName(), application.getVersion());
Set<Feature> autoInstallFeatures = application.getAutoInstallFeatures();
if (!autoInstallFeatures.isEmpty()) {
Set<String> autoFeatureNames = autoInstallFeatures.stream().map(Feature::getName).collect(Collectors.toSet());
for (Feature feature : autoInstallFeatures) {
if (featuresService.isInstalled(feature)) {
autoFeatureNames.remove(feature.getName());
} else {
for (Dependency dependency : feature.getDependencies()) {
if (!application.getName().equals(dependency.getName()) && getApplicationNames().contains(dependency.getName())) {
if (!isApplicationStarted(getApplication(dependency.getName()))) {
startApplication(dependency.getName());
}
autoFeatureNames.remove(dependency.getName());
}
}
}
}
if (!autoFeatureNames.isEmpty()) {
featuresService.installFeatures(autoFeatureNames, EnumSet.of(Option.NoAutoRefreshBundles));
waitForApplication(application);
}
}
} catch (Exception e) {
throw new ApplicationServiceException("Could not start application " + application.getName() + " due to errors.", e);
}
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImpl method getNotInstalledFeatures.
/**
* Given a {@code Set} of {@code Feature}s, returns the subset of
* {@code Features}s that are not installed
*
* @param features The {@code Set} of {@link Feature}s from which to construct
* the subset of {@code Feature}s that are not installed
* @return A {@code Set} of {@code Feature}s that are not installed that is
* a sub-set of the <i>features</i> {@code Feature}s {@code Set}
* parameter
*/
private Set<Feature> getNotInstalledFeatures(Set<Feature> features) {
Set<Feature> notInstalledFeatures = new HashSet<Feature>();
for (Feature curFeature : features) {
if (!featuresService.isInstalled(curFeature)) {
LOGGER.debug("{} is not installed.", curFeature.getName());
notInstalledFeatures.add(curFeature);
}
}
return notInstalledFeatures;
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationStatusImplTest method testAppStatusCreation.
/**
* Tests that the app status is created properly and returns the correct
* values.
*/
@Test
public void testAppStatusCreation() {
Application testApp = mock(Application.class);
ApplicationState testState = ApplicationState.ACTIVE;
Set<Feature> testFeatures = new HashSet<Feature>();
Set<Bundle> testBundles = new HashSet<Bundle>();
Feature testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
List<Feature> testFeatureList = new ArrayList<Feature>(Arrays.asList(testFeature1, testFeature2));
testFeatures.addAll(testFeatureList);
Bundle testBundle1 = mock(Bundle.class);
Bundle testBundle2 = mock(Bundle.class);
List<Bundle> testBundleList = new ArrayList<Bundle>(Arrays.asList(testBundle1, testBundle2));
testBundles.addAll(testBundleList);
ApplicationStatus testStatus = new ApplicationStatusImpl(testApp, testState, testFeatures, testBundles);
assertEquals("Sanity check for getApplication()", testApp, testStatus.getApplication());
assertEquals("Sanity check for getState()", testState, testStatus.getState());
assertTrue("Sanity check for getErrorFeatures()", testStatus.getErrorFeatures().containsAll(testFeatureList));
assertTrue("Sanity check for getErrorBundles()", testStatus.getErrorBundles().containsAll(testBundleList));
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationGeneralASE.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where an exception is caught
*
* @throws Exception
*/
@Test(expected = ApplicationServiceException.class)
public void testStopApplicationGeneralASE() 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);
when(testApp1.getFeatures()).thenReturn(new HashSet<>(Arrays.asList(testFeature1)));
when(featuresService.isInstalled(any())).thenReturn(true);
doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any());
appService.stopApplication(testApp1);
}
use of org.apache.karaf.features.Feature in project ddf by codice.
the class ApplicationServiceImplTest method testStopApplicationNoMainFeature.
/**
* Tests the {@link ApplicationServiceImpl#stopApplication(Application)} method
* for the case where there is no main feature, but other features exist
*
* @throws Exception
*/
@Test
public void testStopApplicationNoMainFeature() 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 = createPermittedApplicationServiceImpl();
Application testApp = mock(ApplicationImpl.class);
Feature testFeature1 = mock(Feature.class);
Feature testFeature2 = mock(Feature.class);
Set<Feature> featureSet = new HashSet<Feature>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(testApp.getName()).thenReturn(TEST_APP_NAME);
when(testApp.getMainFeature()).thenReturn(null);
when(testApp.getFeatures()).thenReturn(featureSet);
when(testFeature1.getName()).thenReturn(TEST_FEATURE_1_NAME);
when(testFeature2.getName()).thenReturn(TEST_FEATURE_2_NAME);
when(testFeature1.getInstall()).thenReturn(Feature.DEFAULT_INSTALL_MODE);
when(testFeature2.getInstall()).thenReturn(Feature.DEFAULT_INSTALL_MODE);
when(featuresService.isInstalled(testFeature1)).thenReturn(true);
when(featuresService.isInstalled(testFeature2)).thenReturn(true);
appService.stopApplication(testApp);
verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_1_NAME, null, EnumSet.of(Option.NoAutoRefreshBundles));
verify(featuresService, atLeastOnce()).uninstallFeature(TEST_FEATURE_2_NAME, null, EnumSet.of(Option.NoAutoRefreshBundles));
}
Aggregations