Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License. See License.txt in the project root for
license information.
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.azure.management.resources.implementation;
import com.microsoft.azure.AzureEnvironment;
import com.microsoft.azure.AzureResponseBuilder;
import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.resources.Deployments;
import com.microsoft.azure.management.resources.Features;
import com.microsoft.azure.management.resources.GenericResources;
import com.microsoft.azure.management.resources.PolicyAssignments;
import com.microsoft.azure.management.resources.PolicyDefinitions;
import com.microsoft.azure.management.resources.Providers;
import com.microsoft.azure.management.resources.ResourceGroups;
import com.microsoft.azure.management.resources.Subscriptions;
import com.microsoft.azure.management.resources.TagOperations;
import com.microsoft.azure.management.resources.Tenants;
import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl;
import com.microsoft.azure.management.resources.fluentcore.arm.implementation.ManagerBase;
import com.microsoft.azure.management.resources.fluentcore.model.HasInner;
import com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor;
import com.microsoft.azure.management.resources.fluentcore.utils.ResourceManagerThrottlingInterceptor;
import com.microsoft.azure.serializer.AzureJacksonAdapter;
import com.microsoft.rest.RestClient;
Entry point to Azure resource management.
/**
* Entry point to Azure resource management.
*/
public final class ResourceManager extends ManagerBase implements HasInner<ResourceManagementClientImpl> {
// The sdk clients
private final ResourceManagementClientImpl resourceManagementClient;
private final FeatureClientImpl featureClient;
private final PolicyClientImpl policyClient;
private final SubscriptionClientImpl subscriptionClient;
// The collections
private ResourceGroups resourceGroups;
private GenericResources genericResources;
private Deployments deployments;
private Features features;
private Providers providers;
private PolicyDefinitions policyDefinitions;
private PolicyAssignments policyAssignments;
private Subscriptions subscriptions;
private Tenants tenants;
private TagOperations tagOperations;
Creates an instance of ResourceManager that exposes resource management API entry points.
Params: - credentials – the credentials to use
Returns: the ResourceManager instance
/**
* Creates an instance of ResourceManager that exposes resource management API entry points.
*
* @param credentials the credentials to use
* @return the ResourceManager instance
*/
public static ResourceManager.Authenticated authenticate(AzureTokenCredentials credentials) {
return new AuthenticatedImpl(new RestClient.Builder()
.withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER)
.withCredentials(credentials)
.withSerializerAdapter(new AzureJacksonAdapter())
.withResponseBuilderFactory(new AzureResponseBuilder.Factory())
.withInterceptor(new ProviderRegistrationInterceptor(credentials))
.withInterceptor(new ResourceManagerThrottlingInterceptor())
.build());
}
Creates an instance of ResourceManager that exposes resource management API entry points.
Params: - restClient – the RestClient to be used for API calls
Returns: the interface exposing resource management API entry points that work across subscriptions
/**
* Creates an instance of ResourceManager that exposes resource management API entry points.
*
* @param restClient the RestClient to be used for API calls
* @return the interface exposing resource management API entry points that work across subscriptions
*/
public static ResourceManager.Authenticated authenticate(RestClient restClient) {
return new AuthenticatedImpl(restClient);
}
Get a Configurable instance that can be used to create ResourceManager with optional configuration.
Returns: the instance allowing configurations
/**
* Get a Configurable instance that can be used to create ResourceManager with optional configuration.
*
* @return the instance allowing configurations
*/
public static Configurable configure() {
return new ResourceManager.ConfigurableImpl();
}
The interface allowing configurations to be set.
/**
* The interface allowing configurations to be set.
*/
public interface Configurable extends AzureConfigurable<Configurable> {
Creates an instance of ResourceManager that exposes resource management API entry points.
Params: - credentials – the credentials to use
Returns: the interface exposing resource management API entry points that work across subscriptions
/**
* Creates an instance of ResourceManager that exposes resource management API entry points.
*
* @param credentials the credentials to use
* @return the interface exposing resource management API entry points that work across subscriptions
*/
ResourceManager.Authenticated authenticate(AzureTokenCredentials credentials);
}
The implementation for Configurable interface.
/**
* The implementation for Configurable interface.
*/
private static class ConfigurableImpl extends AzureConfigurableImpl<Configurable> implements Configurable {
public ResourceManager.Authenticated authenticate(AzureTokenCredentials credentials) {
return ResourceManager.authenticate(buildRestClient(credentials));
}
}
The interface exposing resource management API entry points that work across subscriptions.
/**
* The interface exposing resource management API entry points that work across subscriptions.
*/
public interface Authenticated {
Returns: the entry point to tenant management API.
/**
* @return the entry point to tenant management API.
*/
Tenants tenants();
Returns: the entry point to subscription management API.
/**
* @return the entry point to subscription management API.
*/
Subscriptions subscriptions();
Specifies a subscription to expose resource management API entry points that work in a subscription.
Params: - subscriptionId – the subscription UUID
Returns: the ResourceManager instance with entry points that work in a subscription
/**
* Specifies a subscription to expose resource management API entry points that work in a subscription.
*
* @param subscriptionId the subscription UUID
* @return the ResourceManager instance with entry points that work in a subscription
*/
ResourceManager withSubscription(String subscriptionId);
}
The implementation for Authenticated interface.
/**
* The implementation for Authenticated interface.
*/
private static final class AuthenticatedImpl implements Authenticated {
private RestClient restClient;
private SubscriptionClientImpl subscriptionClient;
// The subscription less collections
private Subscriptions subscriptions;
private Tenants tenants;
AuthenticatedImpl(RestClient restClient) {
this.restClient = restClient;
this.subscriptionClient = new SubscriptionClientImpl(restClient);
}
public Subscriptions subscriptions() {
if (subscriptions == null) {
subscriptions = new SubscriptionsImpl(subscriptionClient.subscriptions());
}
return subscriptions;
}
public Tenants tenants() {
if (tenants == null) {
tenants = new TenantsImpl(subscriptionClient.tenants());
}
return tenants;
}
@Override
public ResourceManager withSubscription(String subscriptionId) {
return new ResourceManager(restClient, subscriptionId);
}
}
private ResourceManager(RestClient restClient, String subscriptionId) {
super(null, subscriptionId);
super.setResourceManager(this);
this.resourceManagementClient = new ResourceManagementClientImpl(restClient);
this.resourceManagementClient.withSubscriptionId(subscriptionId);
this.featureClient = new FeatureClientImpl(restClient);
this.featureClient.withSubscriptionId(subscriptionId);
this.policyClient = new PolicyClientImpl(restClient);
this.policyClient.withSubscriptionId(subscriptionId);
this.subscriptionClient = new SubscriptionClientImpl(restClient);
}
Returns: the resource group management API entry point
/**
* @return the resource group management API entry point
*/
public ResourceGroups resourceGroups() {
if (resourceGroups == null) {
resourceGroups = new ResourceGroupsImpl(resourceManagementClient);
}
return resourceGroups;
}
Returns: the subscription management API entry point
/**
* @return the subscription management API entry point
*/
public Subscriptions subscriptions() {
if (subscriptions == null) {
subscriptions = new SubscriptionsImpl(subscriptionClient.subscriptions());
}
return subscriptions;
}
Returns: the tenant management API entry point
/**
* @return the tenant management API entry point
*/
public Tenants tenants() {
if (tenants == null) {
tenants = new TenantsImpl(subscriptionClient.tenants());
}
return tenants;
}
Returns: the generic resource management API entry point
/**
* @return the generic resource management API entry point
*/
public GenericResources genericResources() {
if (genericResources == null) {
genericResources = new GenericResourcesImpl(this);
}
return genericResources;
}
Returns: the deployment management API entry point
/**
* @return the deployment management API entry point
*/
public Deployments deployments() {
if (deployments == null) {
deployments = new DeploymentsImpl(this);
}
return deployments;
}
Returns: the feature management API entry point
/**
* @return the feature management API entry point
*/
public Features features() {
if (features == null) {
features = new FeaturesImpl(featureClient.features());
}
return features;
}
Returns: the resource provider management API entry point
/**
* @return the resource provider management API entry point
*/
public Providers providers() {
if (providers == null) {
providers = new ProvidersImpl(resourceManagementClient.providers());
}
return providers;
}
Returns: the policy definition management API entry point
/**
* @return the policy definition management API entry point
*/
public PolicyDefinitions policyDefinitions() {
if (policyDefinitions == null) {
policyDefinitions = new PolicyDefinitionsImpl(policyClient.policyDefinitions());
}
return policyDefinitions;
}
Returns: the policy assignment management API entry point
/**
* @return the policy assignment management API entry point
*/
public PolicyAssignments policyAssignments() {
if (policyAssignments == null) {
policyAssignments = new PolicyAssignmentsImpl(policyClient.policyAssignments());
}
return policyAssignments;
}
Returns: the tag management API entry point
/**
* @return the tag management API entry point
*/
public TagOperations tagOperations() {
if (tagOperations == null) {
tagOperations = new TagOperationsImpl(this);
}
return tagOperations;
}
@Override
public ResourceManagementClientImpl inner() {
return this.resourceManagementClient;
}
}