use of com.azure.resourcemanager.relay.RelayManager in project terra-workspace-manager by DataBiosphere.
the class CrlService method buildRelayManager.
private RelayManager buildRelayManager(AzureCloudContext azureCloudContext, AzureConfiguration azureConfig) {
TokenCredential azureCreds = getManagedAppCredentials(azureConfig);
AzureProfile azureProfile = new AzureProfile(azureCloudContext.getAzureTenantId(), azureCloudContext.getAzureSubscriptionId(), AzureEnvironment.AZURE);
// We must use FQDN because there are two `Defaults` symbols imported otherwise.
RelayManager manager = bio.terra.cloudres.azure.resourcemanager.relay.Defaults.crlConfigure(clientConfig, RelayManager.configure()).authenticate(azureCreds, azureProfile);
return manager;
}
use of com.azure.resourcemanager.relay.RelayManager in project terra-workspace-manager by DataBiosphere.
the class DeleteAzureRelayNamespaceStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
RelayManager manager = crlService.getRelayManager(azureCloudContext, azureConfig);
var azureResourceId = String.format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Relay/namespaces/%s", azureCloudContext.getAzureSubscriptionId(), azureCloudContext.getAzureResourceGroupId(), resource.getNamespaceName());
try {
logger.info("Attempting to delete Relay Namespace " + azureResourceId);
manager.namespaces().deleteById(azureResourceId);
return StepResult.getStepResultSuccess();
} catch (Exception ex) {
logger.info("Attempt to delete Azure Relay Namespace failed on this try: " + azureResourceId, ex);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
}
}
use of com.azure.resourcemanager.relay.RelayManager in project terra-workspace-manager by DataBiosphere.
the class CreateAzureRelayNamespaceStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
RelayManager manager = crlService.getRelayManager(azureCloudContext, azureConfig);
try {
manager.namespaces().define(resource.getNamespaceName()).withRegion(resource.getRegion()).withExistingResourceGroup(azureCloudContext.getAzureResourceGroupId()).create(Defaults.buildContext(CreateRelayRequestData.builder().setName(resource.getNamespaceName()).setRegion(Region.fromName(resource.getRegion())).setResourceGroupName(azureCloudContext.getAzureResourceGroupId()).setTenantId(azureCloudContext.getAzureTenantId()).setSubscriptionId(azureCloudContext.getAzureSubscriptionId()).build()));
} catch (ManagementException e) {
// https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/common-deployment-errors
if (StringUtils.equals(e.getValue().getCode(), "Conflict")) {
logger.info("Azure Relay Namepace {} in managed resource group {} already exists", resource.getNamespaceName(), azureCloudContext.getAzureResourceGroupId());
return StepResult.getStepResultSuccess();
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of com.azure.resourcemanager.relay.RelayManager in project terra-workspace-manager by DataBiosphere.
the class CreateAzureRelayNamespaceStep method undoStep.
@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
RelayManager manager = crlService.getRelayManager(azureCloudContext, azureConfig);
try {
manager.namespaces().deleteByResourceGroup(azureCloudContext.getAzureResourceGroupId(), resource.getNamespaceName());
} catch (ManagementException e) {
// Stairway steps may run multiple times, so we may already have deleted this resource.
if (StringUtils.equals(e.getValue().getCode(), "ResourceNotFound")) {
logger.info("Azure Relay Namespace {} in managed resource group {} already deleted", resource.getNamespaceName(), azureCloudContext.getAzureResourceGroupId());
return StepResult.getStepResultSuccess();
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
use of com.azure.resourcemanager.relay.RelayManager in project terra-workspace-manager by DataBiosphere.
the class GetAzureRelayNamespaceStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
final AzureCloudContext azureCloudContext = context.getWorkingMap().get(ControlledResourceKeys.AZURE_CLOUD_CONTEXT, AzureCloudContext.class);
RelayManager manager = crlService.getRelayManager(azureCloudContext, azureConfig);
try {
manager.namespaces().getByResourceGroup(azureCloudContext.getAzureResourceGroupId(), resource.getNamespaceName());
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, new DuplicateResourceException(String.format("An Azure Relay Namespace with name %s already exists in resource group %s", azureCloudContext.getAzureResourceGroupId(), resource.getName())));
} catch (ManagementException e) {
// https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/common-deployment-errors
if (StringUtils.contains(e.getValue().getCode(), "ResourceNotFound")) {
return StepResult.getStepResultSuccess();
}
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
}
Aggregations