use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ControlledResourceService method getAssociatedApp.
/**
* When creating application-owned resources, we need to hold the UUID of the application in the
* ControlledResource object. On the one hand, maybe this should be done as part of the create
* flight. On the other hand, the pattern we have is to assemble the complete ControlledResource
* in the controller and have that class be immutable. So we do this lookup and error check early
* on. Throws ApplicationNotFound if there is no matching application record.
*
* @param managedBy the managed by type
* @param userRequest the user request
* @return null if not an application managed resource; application UUID otherwise
*/
@Nullable
public UUID getAssociatedApp(ManagedByType managedBy, AuthenticatedUserRequest userRequest) {
if (managedBy != ManagedByType.MANAGED_BY_APPLICATION) {
return null;
}
String applicationEmail = SamRethrow.onInterrupted(() -> samService.getUserEmailFromSam(userRequest), "get application email");
WsmApplication application = applicationDao.getApplicationByEmail(applicationEmail);
return application.getApplicationId();
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class WsmApplicationService method appFromConfig.
@VisibleForTesting
Optional<WsmApplication> appFromConfig(App config) {
try {
if (config.getIdentifier() == null || config.getServiceAccount() == null || config.getState() == null) {
logError("Invalid application configuration: missing some required fields (identifier, service-account, state)");
return Optional.empty();
}
UUID applicationId = UUID.fromString(config.getIdentifier());
WsmApplicationState state = WsmApplicationState.fromString(config.getState());
if (!EmailValidator.getInstance(false, true).isValid(config.getServiceAccount())) {
logError("Invalid application configuration: service account is not a valid email address");
return Optional.empty();
}
// We keep everything homogeneously lowercase
String serviceAccount = StringUtils.lowerCase(config.getServiceAccount());
return Optional.of(new WsmApplication().applicationId(applicationId).displayName(config.getName()).description(config.getDescription()).serviceAccount(serviceAccount).state(state));
} catch (IllegalArgumentException e) {
logError("Invalid application configuration: invalid UUID format", e);
} catch (InvalidApplicationConfigException e) {
logError("Invalid application configuration: state must be operating, deprecated, or decommissioned", e);
}
return Optional.empty();
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class WsmApplicationService method buildAppMap.
@VisibleForTesting
Map<UUID, WsmDbApplication> buildAppMap() {
List<WsmApplication> dbApps = applicationDao.listApplications();
Map<UUID, WsmDbApplication> dbAppMap = new HashMap<>();
for (WsmApplication app : dbApps) {
dbAppMap.put(app.getApplicationId(), new WsmDbApplication(app));
}
return dbAppMap;
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ApplicationUnitTest method processAppTest.
// This test writes to the database, so conflicts with the missingConfigTest
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
@Test
public void processAppTest() {
// Each "pass" in the test represents starting up with a different configuration.
// Start with an empty map == no data in the database
Map<UUID, WsmDbApplication> dbAppMap = new HashMap<>();
WsmApplication wsmApp = makeWsmApp();
// -- First Pass --
// Create a new application in the database
appService.enableTestMode();
appService.processApp(wsmApp, dbAppMap);
assertMessage(0, INFO_CREATED);
// Retrieve apps from the database and validate the data round-trip
// There can be stray applications in the database, so we use greater/equal assert
List<WsmApplication> wsmApps = appDao.listApplications();
assertThat(wsmApps.size(), greaterThanOrEqualTo(1));
assertThat(wsmApps, hasItem(wsmApp));
// Trying to create a duplicate new application. This is not caught in the map, but
// the database create fails on a PK constraint.
appService.processApp(wsmApp, dbAppMap);
assertMessage(1, ERROR_CREATE_FAILED);
// -- Second pass --
// Rebuild the db app map with wsmApp in it
dbAppMap = appService.buildAppMap();
appService.enableTestMode();
appService.processApp(wsmApp, dbAppMap);
assertMessage(0, INFO_NOCHANGE);
// Process it again with the same app map; should flag it as a duplicate
appService.processApp(wsmApp, dbAppMap);
assertMessage(1, ERROR_DUPLICATE);
// -- 3rd pass -- update name and desc
dbAppMap = appService.buildAppMap();
appService.enableTestMode();
wsmApp.displayName(GOOD_NAME);
wsmApp.description(GOOD_DESC);
appService.processApp(wsmApp, dbAppMap);
assertMessage(0, INFO_UPDATED);
// -- 4th pass -- State transition to deprecated
stateTransition(WsmApplicationState.DEPRECATED, INFO_UPDATED);
// -- 5th pass -- State transition back to operating
stateTransition(WsmApplicationState.OPERATING, INFO_UPDATED);
// -- 6th pass -- State transition to decommissioned
stateTransition(WsmApplicationState.DECOMMISSIONED, INFO_UPDATED);
// -- 7th pass -- Cannot transition from decommissioned
stateTransition(WsmApplicationState.OPERATING, ERROR_DECOMMISSIONED);
// -- 8th pass -- Cannot transition from decommissioned
stateTransition(WsmApplicationState.DEPRECATED, ERROR_DECOMMISSIONED);
}
use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.
the class ApplicationConfigurationTest method configurationTest.
@Test
public void configurationTest() {
// This test has to be in sync with the contents of application-configuration-test.yml
List<WsmApplication> wsmApps = appDao.listApplications();
assertEquals(2, wsmApps.size());
for (WsmApplication wsmApp : wsmApps) {
if (wsmApp.getApplicationId().equals(LEO_UUID)) {
checkLeo(wsmApp);
} else if (wsmApp.getApplicationId().equals(CARMEN_UUID)) {
checkCarmen(wsmApp);
} else {
fail();
}
}
}
Aggregations