Search in sources :

Example 1 with ApplicationState

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);
}
Also used : Bundle(org.osgi.framework.Bundle) ApplicationState(org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState) Feature(org.apache.karaf.features.Feature) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityServiceException(ddf.security.service.SecurityServiceException) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) HashSet(java.util.HashSet)

Example 2 with ApplicationState

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));
}
Also used : Bundle(org.osgi.framework.Bundle) ApplicationState(org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ArrayList(java.util.ArrayList) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with ApplicationState

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)));
}
Also used : CommandLine(org.apache.karaf.shell.api.console.CommandLine) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) ApplicationState(org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState) ArrayList(java.util.ArrayList) Application(org.codice.ddf.admin.application.service.Application) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

HashSet (java.util.HashSet)3 ApplicationState (org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState)3 ArrayList (java.util.ArrayList)2 Feature (org.apache.karaf.features.Feature)2 Application (org.codice.ddf.admin.application.service.Application)2 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)2 Test (org.junit.Test)2 Bundle (org.osgi.framework.Bundle)2 SecurityServiceException (ddf.security.service.SecurityServiceException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CommandLine (org.apache.karaf.shell.api.console.CommandLine)1 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)1 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1