Search in sources :

Example 1 with InvalidApplicationStateException

use of bio.terra.workspace.db.exception.InvalidApplicationStateException in project terra-workspace-manager by DataBiosphere.

the class ApplicationAblePrecheckStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    WsmApplication application = applicationDao.getApplication(applicationId);
    // For enable, we require that the application be in the operating state
    if (ableEnum == AbleEnum.ENABLE) {
        if (application.getState() != WsmApplicationState.OPERATING) {
            throw new InvalidApplicationStateException("Applications is " + application.getState().toApi() + " and cannot be enabled");
        }
    }
    FlightMap workingMap = context.getWorkingMap();
    workingMap.put(WsmApplicationKeys.WSM_APPLICATION, application);
    // See if the application is enabled
    WsmWorkspaceApplication workspaceApp;
    try {
        workspaceApp = applicationDao.getWorkspaceApplication(workspaceId, applicationId);
        workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_DAO, computeCorrectState(ableEnum, workspaceApp.isEnabled()));
    } catch (ApplicationNotFoundException e) {
        workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_DAO, computeCorrectState(ableEnum, false));
    }
    // See if the application already has APPLICATION role for the workspace
    boolean enabledSam = samService.isApplicationEnabledInSam(workspaceId, application.getServiceAccount(), userRequest);
    workingMap.put(WsmApplicationKeys.APPLICATION_ABLE_SAM, computeCorrectState(ableEnum, enabledSam));
    return StepResult.getStepResultSuccess();
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) ApplicationNotFoundException(bio.terra.workspace.db.exception.ApplicationNotFoundException) FlightMap(bio.terra.stairway.FlightMap) InvalidApplicationStateException(bio.terra.workspace.db.exception.InvalidApplicationStateException) WsmWorkspaceApplication(bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)

Aggregations

FlightMap (bio.terra.stairway.FlightMap)1 ApplicationNotFoundException (bio.terra.workspace.db.exception.ApplicationNotFoundException)1 InvalidApplicationStateException (bio.terra.workspace.db.exception.InvalidApplicationStateException)1 WsmApplication (bio.terra.workspace.service.workspace.model.WsmApplication)1 WsmWorkspaceApplication (bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)1