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);
}
}));
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}));
}
Aggregations