use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ServiceManagerImpl method waitForFeature.
@Override
public void waitForFeature(String featureName, Predicate<FeatureState> predicate) throws Exception {
boolean ready = false;
long timeoutLimit = System.currentTimeMillis() + FEATURES_AND_BUNDLES_TIMEOUT;
FeaturesService featuresService = getFeaturesService();
while (!ready) {
FeatureState state = null;
if (featuresService != null) {
Feature feature = featuresService.getFeature(featureName);
state = featuresService.getState(feature.getName() + "/" + feature.getVersion());
if (state == null) {
LOGGER.debug("No Feature found for featureName: {}", featureName);
return;
} else if (predicate.test(state)) {
ready = true;
}
}
if (!ready) {
if (System.currentTimeMillis() > timeoutLimit) {
printInactiveBundles();
fail(String.format("Feature did not change to State [" + predicate + "] within %d minutes.", TimeUnit.MILLISECONDS.toMinutes(FEATURES_AND_BUNDLES_TIMEOUT)));
}
LOGGER.info("Still waiting on feature [{}], current state [{}]...", featureName, state);
Thread.sleep(1000);
}
}
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ProfileInstallCommandTest method testUninstallInstallerFailure.
@Test(expected = Exception.class)
public void testUninstallInstallerFailure() throws Exception {
Feature installerFeature = createMockFeature("admin-modules-installer");
this.featuresService = mock(FeaturesService.class);
when(featuresService.getFeature(anyString())).thenReturn(installerFeature);
when(featuresService.isInstalled(installerFeature)).thenReturn(true);
doThrow(Exception.class).when(featuresService).uninstallFeature("admin-modules-installer", NO_AUTO_REFRESH);
profileInstallCommand.profileName = "invalidStopBundles";
profileInstallCommand.doExecute(applicationService, featuresService, bundleService);
}
use of org.apache.karaf.features.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testIsApplicationStartedReturnsFalseForFailedApplicationState.
/**
* Test method for
* {@link ApplicationServiceImpl#isApplicationStarted(Application)}
* <p>
* Verifies that method returns false when application state is
* {@link ApplicationState#FAILED}
*
* @throws Exception
*/
@Test
public void testIsApplicationStartedReturnsFalseForFailedApplicationState() throws Exception {
Set<String> inactiveBundles = new HashSet<String>();
inactiveBundles.add(TEST_MAIN_FEATURES_2_UNIQUE_BUNDLE_LOCATION);
FeaturesService featuresService = createMockFeaturesService(mainFeatureRepo2, null, inactiveBundles);
when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
when(featuresService.isInstalled(mainFeatureRepo2.getFeatures()[0])).thenReturn(false);
ApplicationService appService = createPermittedApplicationServiceImpl();
assertFalse(appService.isApplicationStarted(appService.getApplication(TEST_MAIN_FEATURES_2_MAIN_FEATURE_NAME)));
}
use of org.apache.karaf.features.FeaturesService 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.FeaturesService in project ddf by codice.
the class ApplicationServiceImplTest method testRemoveApplicationUninstallAllFeaturesException.
/**
* Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
* for the case where an exception is thrown within uninstallAllFeatures(Application)
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationUninstallAllFeaturesException() throws Exception {
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
final Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MOCK");
root.addAppender(mockAppender);
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<>();
featureSet.add(testFeature1);
featureSet.add(testFeature2);
when(featuresService.isInstalled(any(Feature.class))).thenReturn(true);
when(testApp.getFeatures()).thenReturn(featureSet);
doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any(EnumSet.class));
appService.removeApplication(testApp);
verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {
@Override
public boolean matches(final Object argument) {
return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_FAIL);
}
}));
}
Aggregations