Search in sources :

Example 6 with RetryException

use of bio.terra.stairway.exception.RetryException in project terra-workspace-manager by DataBiosphere.

the class DeleteControlledAzureResourcesStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException, RetryException {
    List<ControlledResource> controlledResourceList = resourceDao.listControlledResources(workspaceUuid, CloudPlatform.AZURE);
    // Delete VMs first because they use other resources like disks, networks, etc.
    Map<Boolean, List<ControlledResource>> vmsAndOtherControlledResources = controlledResourceList.stream().collect(Collectors.partitioningBy(cr -> cr.getResourceType() == WsmResourceType.CONTROLLED_AZURE_VM));
    for (ControlledResource vm : vmsAndOtherControlledResources.get(true)) {
        controlledResourceService.deleteControlledResourceSync(workspaceUuid, vm.getResourceId(), userRequest, false);
    }
    /**
     * TODO: https://broadworkbench.atlassian.net/browse/WOR-92 delete Azure storage containers
     * first before deleting storage account to ensure Sam and WSM DBs are cleaned up
     */
    for (ControlledResource resource : vmsAndOtherControlledResources.get(false)) {
        controlledResourceService.deleteControlledResourceSync(workspaceUuid, resource.getResourceId(), userRequest, false);
    }
    return StepResult.getStepResultSuccess();
}
Also used : Logger(org.slf4j.Logger) ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) LoggerFactory(org.slf4j.LoggerFactory) ResourceDao(bio.terra.workspace.db.ResourceDao) WsmResourceType(bio.terra.workspace.service.resource.model.WsmResourceType) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ControlledResourceService(bio.terra.workspace.service.resource.controlled.ControlledResourceService) StepResult(bio.terra.stairway.StepResult) List(java.util.List) Step(bio.terra.stairway.Step) RetryException(bio.terra.stairway.exception.RetryException) Map(java.util.Map) CloudPlatform(bio.terra.workspace.service.workspace.model.CloudPlatform) FlightContext(bio.terra.stairway.FlightContext) ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) List(java.util.List)

Example 7 with RetryException

use of bio.terra.stairway.exception.RetryException in project terra-resource-buffer by DataBiosphere.

the class SetIamPolicyStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws RetryException {
    // Skip if IAM binding is not set.
    if (gcpProjectConfig.getIamBindings() == null || gcpProjectConfig.getIamBindings().isEmpty()) {
        return StepResult.getStepResultSuccess();
    }
    String projectId = flightContext.getWorkingMap().get(GOOGLE_PROJECT_ID, String.class);
    try {
        Policy policy = rmCow.projects().getIamPolicy(projectId, new GetIamPolicyRequest()).execute();
        gcpProjectConfig.getIamBindings().stream().map(iamBinding -> new Binding().setRole(iamBinding.getRole()).setMembers(iamBinding.getMembers())).forEach(policy.getBindings()::add);
        rmCow.projects().setIamPolicy(projectId, new SetIamPolicyRequest().setPolicy(policy)).execute();
    } catch (IOException e) {
        logger.info("Error when setting IAM policy", e);
        return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : StepResult(bio.terra.stairway.StepResult) Logger(org.slf4j.Logger) Step(bio.terra.stairway.Step) RetryException(bio.terra.stairway.exception.RetryException) com.google.api.services.cloudresourcemanager.v3.model(com.google.api.services.cloudresourcemanager.v3.model) GcpProjectConfig(bio.terra.buffer.generated.model.GcpProjectConfig) LoggerFactory(org.slf4j.LoggerFactory) CloudResourceManagerCow(bio.terra.cloudres.google.cloudresourcemanager.CloudResourceManagerCow) IOException(java.io.IOException) StepStatus(bio.terra.stairway.StepStatus) GOOGLE_PROJECT_ID(bio.terra.buffer.service.resource.FlightMapKeys.GOOGLE_PROJECT_ID) FlightContext(bio.terra.stairway.FlightContext) IOException(java.io.IOException) StepResult(bio.terra.stairway.StepResult)

Aggregations

RetryException (bio.terra.stairway.exception.RetryException)7 IOException (java.io.IOException)6 StepResult (bio.terra.stairway.StepResult)5 FlightContext (bio.terra.stairway.FlightContext)3 Step (bio.terra.stairway.Step)3 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)3 Logger (org.slf4j.Logger)3 StepStatus (bio.terra.stairway.StepStatus)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 LoggerFactory (org.slf4j.LoggerFactory)2 GcpProjectConfig (bio.terra.buffer.generated.model.GcpProjectConfig)1 GOOGLE_PROJECT_ID (bio.terra.buffer.service.resource.FlightMapKeys.GOOGLE_PROJECT_ID)1 BigQueryCow (bio.terra.cloudres.google.bigquery.BigQueryCow)1 CloudResourceManagerCow (bio.terra.cloudres.google.cloudresourcemanager.CloudResourceManagerCow)1 AIPlatformNotebooksCow (bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow)1 InstanceName (bio.terra.cloudres.google.notebooks.InstanceName)1 FlightMap (bio.terra.stairway.FlightMap)1 ResourceDao (bio.terra.workspace.db.ResourceDao)1