Search in sources :

Example 11 with ApplicationStatus

use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.

the class TestApplicationService method dTestAppAddRemove.

@Test
public void dTestAppAddRemove() throws ApplicationServiceException {
    systemSubject.execute(() -> {
        ApplicationService applicationService = getServiceManager().getService(ApplicationService.class);
        Application sdkApp = applicationService.getApplication(SDK_APP);
        URI sdkUri = sdkApp.getURI();
        // Remove
        try {
            applicationService.removeApplication(sdkApp);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to remove {}: {}", sdkApp.getName(), e.getMessage());
            fail();
        }
        Set<Application> apps = applicationService.getApplications();
        assertThat(apps, not(hasItem(sdkApp)));
        // Add
        try {
            applicationService.addApplication(sdkUri);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to add {}: {}", sdkUri, e.getMessage());
            fail();
        }
        sdkApp = applicationService.getApplication(SDK_APP);
        assertThat(sdkApp.getName(), is(SDK_APP));
        assertThat(sdkApp.getURI(), is(sdkUri));
        ApplicationStatus status = applicationService.getApplicationStatus(sdkApp);
        assertThat(status.getState(), is(INACTIVE));
        apps = applicationService.getApplications();
        assertThat(apps, hasItem(sdkApp));
        // Test Commands
        // Remove
        String response = console.runCommand(REMOVE_COMMAND + SDK_APP);
        assertThat("Should be empty response after " + REMOVE_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + SDK_APP);
        assertThat(SDK_APP + " should be not be found after " + REMOVE_COMMAND, response, containsString("No application found with name " + SDK_APP));
        // Add
        response = console.runCommand(ADD_COMMAND + sdkUri.toString());
        assertThat("Should be empty response after " + ADD_COMMAND, response, isEmptyString());
        response = console.runCommand(STATUS_COMMAND + SDK_APP);
        assertThat(SDK_APP + " should be INACTIVE after " + STATUS_COMMAND, response, containsString(INACTIVE_APP));
        try {
            applicationService.startApplication(SDK_APP);
        } catch (ApplicationServiceException e) {
            LOGGER.error("Failed to restart {}: {}", sdkUri, e.getMessage());
            fail();
        }
    });
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Application(org.codice.ddf.admin.application.service.Application) URI(java.net.URI) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest) Test(org.junit.Test) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest)

Example 12 with ApplicationStatus

use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.

the class StatusApplicationCommand method doExecute.

@Override
protected void doExecute(ApplicationService applicationService) throws ApplicationServiceException {
    Application application = applicationService.getApplication(appName);
    if (application != null) {
        ApplicationStatus appStatus = applicationService.getApplicationStatus(application);
        console.println(application.getName());
        console.println("\nCurrent State is: " + appStatus.getState().toString());
        console.println("\nFeatures Located within this Application:");
        for (Feature curFeature : application.getFeatures()) {
            console.println("\t" + curFeature.getName());
        }
        console.println("\nRequired Features Not Started");
        if (appStatus.getErrorFeatures().isEmpty()) {
            console.print(Ansi.ansi().fg(Ansi.Color.GREEN).toString());
            console.println("\tNONE");
            console.print(Ansi.ansi().reset().toString());
        } else {
            for (Feature curFeature : appStatus.getErrorFeatures()) {
                console.print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                console.println("\t" + curFeature.getName());
                console.print(Ansi.ansi().reset().toString());
            }
        }
        console.println("\nRequired Bundles Not Started");
        if (appStatus.getErrorBundles().isEmpty()) {
            console.print(Ansi.ansi().fg(Ansi.Color.GREEN).toString());
            console.println("\tNONE");
            console.print(Ansi.ansi().reset().toString());
        } else {
            for (Bundle curBundle : appStatus.getErrorBundles()) {
                console.print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                console.println("\t[" + curBundle.getBundleId() + "]\t" + curBundle.getSymbolicName());
                console.print(Ansi.ansi().reset().toString());
            }
        }
    } else {
        console.println("No application found with name " + appName);
    }
    return;
}
Also used : Bundle(org.osgi.framework.Bundle) ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application) Feature(org.apache.karaf.features.Feature)

Example 13 with ApplicationStatus

use of org.codice.ddf.admin.application.service.ApplicationStatus in project ddf by codice.

the class ListApplicationCommand method doExecute.

@Override
protected void doExecute(ApplicationService applicationService) throws ApplicationServiceException {
    Set<Application> applications = applicationService.getApplications();
    console.printf("%s%10s%n", "State", "Name");
    for (Application curApp : applications) {
        ApplicationStatus appStatus = applicationService.getApplicationStatus(curApp);
        // aggregator 'apps')
        if (!curApp.getFeatures().isEmpty()) {
            console.print("[");
            switch(appStatus.getState()) {
                case ACTIVE:
                    console.print(Ansi.ansi().fg(Ansi.Color.GREEN).toString());
                    break;
                case FAILED:
                    console.print(Ansi.ansi().fg(Ansi.Color.RED).toString());
                    break;
                case INACTIVE:
                    // don't set a color
                    break;
                case UNKNOWN:
                    console.print(Ansi.ansi().fg(Ansi.Color.YELLOW).toString());
                    break;
                default:
                    break;
            }
            console.print(StringUtils.rightPad(appStatus.getState().toString(), STATUS_COLUMN_LENGTH));
            console.print(Ansi.ansi().reset().toString());
            console.println("] " + curApp.getName());
        }
    }
    return;
}
Also used : ApplicationStatus(org.codice.ddf.admin.application.service.ApplicationStatus) Application(org.codice.ddf.admin.application.service.Application)

Aggregations

Application (org.codice.ddf.admin.application.service.Application)13 ApplicationStatus (org.codice.ddf.admin.application.service.ApplicationStatus)13 Test (org.junit.Test)11 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)9 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)3 FeaturesService (org.apache.karaf.features.FeaturesService)3 Repository (org.apache.karaf.features.Repository)3 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)3 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)3 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)3 URI (java.net.URI)2 Feature (org.apache.karaf.features.Feature)2 ApplicationState (org.codice.ddf.admin.application.service.ApplicationStatus.ApplicationState)2 Bundle (org.osgi.framework.Bundle)2 Logger (org.slf4j.Logger)2 Appender (ch.qos.logback.core.Appender)1 List (java.util.List)1