use of org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState 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.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState 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.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState in project ddf by codice.
the class ActiveApplicationsCompleterTest method testActiveApplicationsCompleter.
/**
* Tests the {@link ActiveApplicationsCompleter#complete(String, int, List)} method,
* as well as the associated constructor
*/
@Test
public void testActiveApplicationsCompleter() {
ApplicationService testAppService = mock(ApplicationServiceImpl.class);
Application testApp = mock(ApplicationImpl.class);
Set<Application> appSet = new HashSet<>();
appSet.add(testApp);
ApplicationStatus testStatus = mock(ApplicationStatusImpl.class);
ApplicationState testState = ApplicationState.ACTIVE;
when(testAppService.getApplications()).thenReturn(appSet);
when(testAppService.getApplicationStatus(testApp)).thenReturn(testStatus);
when(testStatus.getState()).thenReturn(testState);
when(testApp.getName()).thenReturn("TestApp");
ActiveApplicationsCompleter activeApplicationsCompleter = new ActiveApplicationsCompleter();
activeApplicationsCompleter.setApplicationService(testAppService);
CommandLine commandLine = mock(CommandLine.class);
assertThat("If the return value is -1, the expected match was not found.", activeApplicationsCompleter.complete(null, commandLine, new ArrayList<>()), is(not(-1)));
}
Aggregations