Search in sources :

Example 16 with ApplicationServiceException

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

the class ApplicationConfigInstallerTest method testRunASE.

/**
     * Tests the {@link ApplicationConfigInstaller#run()} method for the case
     * where an ApplicationServiceException is thrown by appService.addApplication(..)
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRunASE() 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);
    FeaturesService featuresService = mock(FeaturesService.class);
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    doThrow(new ApplicationServiceException()).when(testAppService).startApplication(anyString());
    URL fileURL = this.getClass().getResource("/" + GOOD_FILE);
    ApplicationConfigInstaller configInstaller = getApplicationConfigInstaller(fileURL.getFile(), testAppService, featuresService, START_FEATURE, STOP_FEATURE);
    configInstaller.run();
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(RUN_ASE_EX);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) URL(java.net.URL) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 17 with ApplicationServiceException

use of org.codice.ddf.admin.application.service.ApplicationServiceException 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);
    }
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Dependency(org.apache.karaf.features.Dependency) 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)

Example 18 with ApplicationServiceException

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

the class ApplicationServiceImpl method removeApplication.

@Override
public void removeApplication(URI applicationURL) throws ApplicationServiceException {
    try {
        //This is a workaround for the Karaf FeaturesService
        //To remove the repository, it attempts to uninstall all features
        //whether they are uninstalled or not.
        uninstallAllFeatures(applicationURL);
        featuresService.removeRepository(applicationURL, false);
    } catch (Exception e) {
        LOGGER.warn("Could not remove application due to error.", e);
        throw new ApplicationServiceException(e);
    }
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityServiceException(ddf.security.service.SecurityServiceException) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException)

Example 19 with ApplicationServiceException

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

the class ApplicationServiceImpl method removeApplication.

@Override
public void removeApplication(Application application) throws ApplicationServiceException {
    try {
        if (application != null && isPermittedToViewFeature(application.getName())) {
            uninstallAllFeatures(application);
            featuresService.removeRepository(application.getURI(), false);
        }
    } catch (Exception e) {
        LOGGER.warn("Could not remove application due to error.", e);
        throw new ApplicationServiceException(e);
    }
}
Also used : ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SecurityServiceException(ddf.security.service.SecurityServiceException) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException)

Example 20 with ApplicationServiceException

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

the class AddApplicationCommandTest method testAddApplicationCommandASE.

/**
     * Tests the {@link AddApplicationCommand} class and its contained methods
     * for the case where the ApplicationService throws an ApplicationServiceException
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testAddApplicationCommandASE() 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);
    root.setLevel(Level.ALL);
    ApplicationService testAppService = mock(ApplicationServiceImpl.class);
    AddApplicationCommand addApplicationCommand = new AddApplicationCommand();
    addApplicationCommand.appName = "TestApp";
    addApplicationCommand.setApplicationService(testAppService);
    doThrow(new ApplicationServiceException()).when(testAppService).addApplication(any(URI.class));
    addApplicationCommand.execute();
    verify(mockAppender).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(CMD_ERROR_STRING);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) URI(java.net.URI) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) ArgumentMatcher(org.mockito.ArgumentMatcher) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)27 Test (org.junit.Test)14 Application (org.codice.ddf.admin.application.service.Application)9 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)7 Logger (org.slf4j.Logger)7 Appender (ch.qos.logback.core.Appender)6 SecurityServiceException (ddf.security.service.SecurityServiceException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 URI (java.net.URI)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)6 File (java.io.File)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Response (javax.ws.rs.core.Response)3 Feature (org.apache.karaf.features.Feature)3 Repository (org.apache.karaf.features.Repository)3