Search in sources :

Example 1 with ResourceManager

use of com.azure.resourcemanager.resources.ResourceManager in project terra-workspace-manager by DataBiosphere.

the class ValidateMRGStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException {
    AzureCloudContext azureCloudContext = flightContext.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), AzureCloudContext.class);
    try {
        ResourceManager resourceManager = crlService.getResourceManager(azureCloudContext, azureConfig);
        resourceManager.resourceGroups().getByName(azureCloudContext.getAzureResourceGroupId());
    } catch (Exception azureError) {
        throw new CloudContextRequiredException("Invalid Azure cloud context", azureError);
    }
    return StepResult.getStepResultSuccess();
}
Also used : CloudContextRequiredException(bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) ResourceManager(com.azure.resourcemanager.resources.ResourceManager) CloudContextRequiredException(bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException)

Example 2 with ResourceManager

use of com.azure.resourcemanager.resources.ResourceManager in project terra-workspace-manager by DataBiosphere.

the class CrlService method buildResourceManager.

/**
 * Get a resource manager pointed at the MRG subscription
 *
 * @param azureCloudContext target cloud context
 * @return azure resource manager
 */
public ResourceManager buildResourceManager(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.
    ResourceManager manager = bio.terra.cloudres.azure.resourcemanager.common.Defaults.crlConfigure(clientConfig, ResourceManager.configure()).authenticate(azureCreds, azureProfile).withSubscription(azureCloudContext.getAzureSubscriptionId());
    return manager;
}
Also used : AzureProfile(com.azure.core.management.profile.AzureProfile) ResourceManager(com.azure.resourcemanager.resources.ResourceManager) TokenCredential(com.azure.core.credential.TokenCredential)

Example 3 with ResourceManager

use of com.azure.resourcemanager.resources.ResourceManager in project azure-maven-plugins by microsoft.

the class AzureService method listSupportedRegions.

default List<Region> listSupportedRegions(String subscriptionId) {
    String[] names = StringUtils.split(name(), "/");
    if (names.length != 2) {
        throw new AzureToolkitRuntimeException(String.format("It is illegal to list regions for service '%s'.", name()));
    }
    final String provider = names[0];
    final String resourceType = names[1];
    List<Region> allRegionList = az(IAzureAccount.class).listRegions(subscriptionId);
    List<Region> result = new ArrayList<>();
    final ResourceManager resourceManager = getResourceManager(subscriptionId);
    resourceManager.providers().getByName(provider).resourceTypes().stream().filter(type -> StringUtils.equalsIgnoreCase(type.resourceType(), resourceType)).findAny().map(ProviderResourceType::locations).ifPresent(list -> result.addAll(list.stream().map(Region::fromName).filter(allRegionList::contains).collect(Collectors.toList())));
    return result.isEmpty() ? allRegionList : result;
}
Also used : IAzureBaseResource(com.microsoft.azure.toolkit.lib.common.entity.IAzureBaseResource) NettyAsyncHttpClientBuilder(com.azure.core.http.netty.NettyAsyncHttpClientBuilder) ProviderResourceType(com.azure.resourcemanager.resources.models.ProviderResourceType) IAzureAccount(com.microsoft.azure.toolkit.lib.account.IAzureAccount) StringUtils(org.apache.commons.lang3.StringUtils) HttpPipelinePolicy(com.azure.core.http.policy.HttpPipelinePolicy) ArrayList(java.util.ArrayList) Region(com.microsoft.azure.toolkit.lib.common.model.Region) NoopAddressResolverGroup(io.netty.resolver.NoopAddressResolverGroup) ProxyOptions(com.azure.core.http.ProxyOptions) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) Subscription(com.microsoft.azure.toolkit.lib.common.model.Subscription) ResourceManager(com.azure.resourcemanager.resources.ResourceManager) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) AzureProfile(com.azure.core.management.profile.AzureProfile) IAccount(com.microsoft.azure.toolkit.lib.account.IAccount) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) Azure.az(com.microsoft.azure.toolkit.lib.Azure.az) AddressResolverGroup(io.netty.resolver.AddressResolverGroup) List(java.util.List) HttpClient(com.azure.core.http.HttpClient) ProviderRegistrationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy) Optional(java.util.Optional) DefaultAddressResolverGroup(io.netty.resolver.DefaultAddressResolverGroup) Providers(com.azure.resourcemanager.resources.models.Providers) IAzureModule(com.microsoft.azure.toolkit.lib.common.entity.IAzureModule) IAzureAccount(com.microsoft.azure.toolkit.lib.account.IAzureAccount) ArrayList(java.util.ArrayList) Region(com.microsoft.azure.toolkit.lib.common.model.Region) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) ResourceManager(com.azure.resourcemanager.resources.ResourceManager)

Aggregations

ResourceManager (com.azure.resourcemanager.resources.ResourceManager)3 AzureProfile (com.azure.core.management.profile.AzureProfile)2 CloudContextRequiredException (bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException)1 AzureCloudContext (bio.terra.workspace.service.workspace.model.AzureCloudContext)1 TokenCredential (com.azure.core.credential.TokenCredential)1 HttpClient (com.azure.core.http.HttpClient)1 ProxyOptions (com.azure.core.http.ProxyOptions)1 NettyAsyncHttpClientBuilder (com.azure.core.http.netty.NettyAsyncHttpClientBuilder)1 HttpLogDetailLevel (com.azure.core.http.policy.HttpLogDetailLevel)1 HttpPipelinePolicy (com.azure.core.http.policy.HttpPipelinePolicy)1 ProviderRegistrationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy)1 ProviderResourceType (com.azure.resourcemanager.resources.models.ProviderResourceType)1 Providers (com.azure.resourcemanager.resources.models.Providers)1 Azure.az (com.microsoft.azure.toolkit.lib.Azure.az)1 IAccount (com.microsoft.azure.toolkit.lib.account.IAccount)1 IAzureAccount (com.microsoft.azure.toolkit.lib.account.IAzureAccount)1 Cacheable (com.microsoft.azure.toolkit.lib.common.cache.Cacheable)1 IAzureBaseResource (com.microsoft.azure.toolkit.lib.common.entity.IAzureBaseResource)1 IAzureModule (com.microsoft.azure.toolkit.lib.common.entity.IAzureModule)1 AzureToolkitRuntimeException (com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException)1