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