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