diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java index aa559fd13748..ce2a6556c6bb 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetImpl.java @@ -32,12 +32,13 @@ public class AvailabilitySetImpl // The client to make AvailabilitySet Management API calls private final AvailabilitySetsInner client; - public AvailabilitySetImpl(String name, AvailabilitySetInner inner, AvailabilitySetsInner innerCollection, - ResourceGroups resourceGroups, - VirtualMachines virtualMachines) { - super(inner.id(), inner, resourceGroups); + public AvailabilitySetImpl(String name, AvailabilitySetInner innerModel, + final AvailabilitySetsInner client, + final ResourceGroups resourceGroups, + final VirtualMachines virtualMachines) { + super(innerModel.id(), innerModel, resourceGroups); this.name = name; - this.client = innerCollection; + this.client = client; this.virtualMachines = virtualMachines; } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java index fc98e75016f6..30e93d6e14e4 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsImpl.java @@ -25,7 +25,9 @@ public class AvailabilitySetsImpl implements AvailabilitySets { private final VirtualMachines virtualMachines; private final PagedListConverter converter; - public AvailabilitySetsImpl(AvailabilitySetsInner client, ResourceGroups resourceGroups, VirtualMachines virtualMachines) { + public AvailabilitySetsImpl(final AvailabilitySetsInner client, + final ResourceGroups resourceGroups, + final VirtualMachines virtualMachines) { this.client = client; this.resourceGroups = resourceGroups; this.virtualMachines = virtualMachines; @@ -38,14 +40,21 @@ public AvailabilitySet typeConvert(AvailabilitySetInner availabilitySetInner) { } @Override - public void delete(String groupName, String name) throws Exception { - this.client.delete(groupName, name); - } - - @Override - public AvailabilitySet get(String groupName, String name) throws Exception { - ServiceResponse response = this.client.get(groupName, name); - return createFluentModel(response.getBody()); + public PagedList list() throws CloudException, IOException { + return new GroupPagedList(resourceGroups.list()) { + @Override + public List listNextGroup(String resourceGroupName) throws RestException, IOException { + PageImpl page = new PageImpl<>(); + page.setItems(client.list(resourceGroupName).getBody()); + page.setNextPageLink(null); + return converter.convert(new PagedList(page) { + @Override + public Page nextPage(String nextPageLink) throws RestException, IOException { + return null; + } + }); + } + }; } @Override @@ -61,6 +70,12 @@ public Page nextPage(String nextPageLink) throws RestExcep }); } + @Override + public AvailabilitySet get(String groupName, String name) throws CloudException, IOException { + ServiceResponse response = this.client.get(groupName, name); + return createFluentModel(response.getBody()); + } + @Override public AvailabilitySet.DefinitionBlank define(String name) throws Exception { return createFluentModel(name); @@ -72,21 +87,8 @@ public void delete(String id) throws Exception { } @Override - public PagedList list() throws CloudException, IOException { - return new GroupPagedList(resourceGroups.list()) { - @Override - public List listNextGroup(String resourceGroupName) throws RestException, IOException { - PageImpl page = new PageImpl<>(); - page.setItems(client.list(resourceGroupName).getBody()); - page.setNextPageLink(null); - return converter.convert(new PagedList(page) { - @Override - public Page nextPage(String nextPageLink) throws RestException, IOException { - return null; - } - }); - } - }; + public void delete(String groupName, String name) throws Exception { + this.client.delete(groupName, name); } /** Fluent model create helpers **/ diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsInGroup.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsInGroup.java index 340052a57c91..d7327aa9f660 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsInGroup.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/AvailabilitySetsInGroup.java @@ -7,20 +7,19 @@ import com.microsoft.azure.management.resources.ResourceGroup; import java.io.IOException; -import java.util.List; public class AvailabilitySetsInGroup implements AvailabilitySets.InGroup { private final ResourceGroup resourceGroup; - private final AvailabilitySets availabilitySetsCore; + private final AvailabilitySets availabilitySets; - public AvailabilitySetsInGroup(AvailabilitySets availabilitySetsCore, ResourceGroup resourceGroup) { + public AvailabilitySetsInGroup(AvailabilitySets availabilitySets, ResourceGroup resourceGroup) { this.resourceGroup = resourceGroup; - this.availabilitySetsCore = availabilitySetsCore; + this.availabilitySets = availabilitySets; } @Override public AvailabilitySet.DefinitionProvisionable define(String name) throws Exception { - return this.availabilitySetsCore + return this.availabilitySets .define(name) .withRegion(this.resourceGroup.location()) .withExistingGroup(this.resourceGroup.name()); @@ -28,11 +27,11 @@ public AvailabilitySet.DefinitionProvisionable define(String name) throws Except @Override public void delete(String name) throws Exception { - this.availabilitySetsCore.delete(this.resourceGroup.name(), name); + this.availabilitySets.delete(this.resourceGroup.name(), name); } @Override public PagedList list() throws CloudException, IOException { - return this.availabilitySetsCore.list(resourceGroup.name()); + return this.availabilitySets.list(resourceGroup.name()); } } diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java new file mode 100644 index 000000000000..15254eb24375 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeManager.java @@ -0,0 +1,90 @@ +package com.microsoft.azure.management.compute.implementation; + +import com.microsoft.azure.management.compute.AvailabilitySets; +import com.microsoft.azure.management.compute.VirtualMachines; +import com.microsoft.azure.management.compute.implementation.api.ComputeManagementClientImpl; +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.implementation.ResourceManager; +import com.microsoft.rest.RestClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +public final class ComputeManager { + private RestClient restClient; + private String subscriptionId; + // The service managers + private ResourceManager resourceClient; + // The sdk clients + private ComputeManagementClientImpl computeManagementClient; + // The collections + private AvailabilitySets availabilitySets; + private VirtualMachines virtualMachines; + + public static Configurable configurable() { + return new ComputeManager().new ConfigurableImpl(); + } + + public static ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + return new ComputeManager(credentials, subscriptionId); + } + + public static ComputeManager authenticate(RestClient restClient, String subscriptionId) { + return new ComputeManager(restClient, subscriptionId); + } + + public interface Configurable extends AzureConfigurable { + ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + } + + final class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { + public ComputeManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + buildRestClient(credentials); + return ComputeManager.authenticate(restClient, subscriptionId); + } + } + + private ComputeManager(ServiceClientCredentials credentials, String subscriptionId) { + this.restClient = new RestClient + .Builder("https://management.azure.com") + .withCredentials(credentials) + .build(); + this.subscriptionId = subscriptionId; + } + + private ComputeManager(RestClient restClient, String subscriptionId) { + this.restClient = restClient; + this.subscriptionId = subscriptionId; + } + + private ComputeManager() {} + + public AvailabilitySets availabilitySets() { + if (availabilitySets == null) { + availabilitySets = new AvailabilitySetsImpl(computeManagementClient().availabilitySets(), + resourceClient().resourceGroups(), virtualMachines()); + } + return availabilitySets; + } + + public VirtualMachines virtualMachines() { + virtualMachines = null; + return virtualMachines; + } + + private ComputeManagementClientImpl computeManagementClient() { + if (computeManagementClient == null) { + computeManagementClient = new ComputeManagementClientImpl(restClient); + computeManagementClient.setSubscriptionId(subscriptionId); + } + return computeManagementClient; + } + + private ResourceManager resourceClient() { + if (restClient == null) { + resourceClient = ResourceManager + .authenticate(restClient) + .useSubscription(subscriptionId); + } + return resourceClient; + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeResourceConnector.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeResourceConnector.java index aa1cead37b18..c633fc2c6e50 100644 --- a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeResourceConnector.java +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeResourceConnector.java @@ -2,50 +2,47 @@ import com.microsoft.azure.management.compute.AvailabilitySets; import com.microsoft.azure.management.compute.VirtualMachines; -import com.microsoft.azure.management.compute.implementation.api.ComputeManagementClientImpl; import com.microsoft.azure.management.resources.ResourceConnector; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.implementation.ResourceConnectorBase; -import com.microsoft.rest.credentials.ServiceClientCredentials; +import com.microsoft.rest.RestClient; public class ComputeResourceConnector extends ResourceConnectorBase { - private ComputeManagementClientImpl client; + private ComputeManager computeClient; private AvailabilitySets.InGroup availabilitySets; + private VirtualMachines.InGroup virtualMachines; - private ComputeResourceConnector(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - super(credentials, subscriptionId, resourceGroup); - constructClient(); + private ComputeResourceConnector(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + super(restClient, subscriptionId, resourceGroup); } - private static ComputeResourceConnector create(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - return new ComputeResourceConnector(credentials, subscriptionId, resourceGroup); - } - - private void constructClient() { - client = new ComputeManagementClientImpl(credentials); - client.setSubscriptionId(subscriptionId); + private static ComputeResourceConnector create(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + return new ComputeResourceConnector(restClient, subscriptionId, resourceGroup); } public static class Builder implements ResourceConnector.Builder { - public ComputeResourceConnector create(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - return ComputeResourceConnector.create(credentials, subscriptionId, resourceGroup); + public ComputeResourceConnector create(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + return ComputeResourceConnector.create(restClient, subscriptionId, resourceGroup); } } public AvailabilitySets.InGroup availabilitySets() { if (availabilitySets == null) { - availabilitySets = new AvailabilitySetsInGroup(availabilitySetsCore(), resourceGroup); + availabilitySets = new AvailabilitySetsInGroup(computeClient().availabilitySets(), resourceGroup); } return availabilitySets; } - public VirtualMachines VirtualMachines() { + public VirtualMachines.InGroup VirtualMachines() { // TODO return null; } - private AvailabilitySets availabilitySetsCore() { - AvailabilitySets availabilitySetsCore = new AvailabilitySetsImpl(client.availabilitySets(), resourceGroups(), VirtualMachines()); - return availabilitySetsCore; + private ComputeManager computeClient() { + if (computeClient == null) { + computeClient = ComputeManager + .authenticate(restClient, subscriptionId); + } + return computeClient; } } diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIP.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIP.java new file mode 100644 index 000000000000..669f22fdfb86 --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/PublicIP.java @@ -0,0 +1,5 @@ +package com.microsoft.azure.management.network; + + +public interface PublicIP { +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java index 9ea0f38d4e8b..e9461c4a1cd5 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/DeploymentOperations.java @@ -1,12 +1,16 @@ package com.microsoft.azure.management.resources; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsGetting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; public interface DeploymentOperations extends SupportsListing, - SupportsGetting { - InGroup resourceGroup(String resourceGroupName); + SupportsListingByGroup, + SupportsGetting, + SupportsGettingByGroup { + InGroup resourceGroup(ResourceGroup resourceGroup); interface InGroup extends SupportsListing, diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java index af3368848615..edcd7aa6b080 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/Deployments.java @@ -1,6 +1,9 @@ package com.microsoft.azure.management.resources; import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsGetting; @@ -9,13 +12,17 @@ import java.io.IOException; public interface Deployments extends + SupportsCreating, SupportsListing, + SupportsListingByGroup, SupportsGetting, - SupportsCreating, - SupportsDeleting { + SupportsGettingByGroup, + SupportsDeleting, + SupportsDeletingByGroup { boolean checkExistence(String deploymentName) throws IOException, CloudException; + boolean checkExistence(String groupName, String deploymentName) throws IOException, CloudException; - InGroup resourceGroup(String resourceGroupName); + InGroup resourceGroup(ResourceGroup resourceGroup); interface InGroup extends SupportsListing, diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java index a8d3597c783c..e4427fea95e8 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/GenericResources.java @@ -1,6 +1,9 @@ package com.microsoft.azure.management.resources; import com.microsoft.azure.CloudException; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsDeletingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsGettingByGroup; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsGetting; @@ -10,8 +13,16 @@ public interface GenericResources extends SupportsListing, + SupportsListingByGroup, SupportsGetting, + SupportsGettingByGroup, SupportsCreating, - SupportsDeleting { + SupportsDeleting, + SupportsDeletingByGroup { boolean checkExistence(String resourceGroupName, String resourceProviderNamespace, String parentResourcePath, String resourceType, String resourceName, String apiVersion) throws IOException, CloudException; + + interface InGroup extends + SupportsListing, + SupportsGetting { + } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceConnector.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceConnector.java index 5bdbcb372d6c..77e3bb7cb04f 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceConnector.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/ResourceConnector.java @@ -1,9 +1,9 @@ package com.microsoft.azure.management.resources; -import com.microsoft.rest.credentials.ServiceClientCredentials; +import com.microsoft.rest.RestClient; public interface ResourceConnector { interface Builder { - T create(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup); + T create(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/AzureConfigureBase.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/AzureConfigurable.java similarity index 80% rename from azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/AzureConfigureBase.java rename to azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/AzureConfigurable.java index a19c1b6620eb..d1cc59658897 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/AzureConfigureBase.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/AzureConfigurable.java @@ -3,7 +3,7 @@ import okhttp3.Interceptor; import okhttp3.logging.HttpLoggingInterceptor; -public interface AzureConfigureBase> { +public interface AzureConfigurable> { T withLogLevel(HttpLoggingInterceptor.Level level); T withInterceptor(Interceptor interceptor); T withUserAgent(String userAgent); diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java index d0ac12cb6340..6b92f205244b 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsGettingByGroup.java @@ -20,7 +20,11 @@ package com.microsoft.azure.management.resources.fluentcore.arm.collection; +import com.microsoft.azure.CloudException; + +import java.io.IOException; + // Requires class to support reading entities with a supplied group name public interface SupportsGettingByGroup { - T get(String groupName, String name) throws Exception; + T get(String groupName, String name) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java index 96fc24dd78ee..6acda3c4d0ee 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/collection/SupportsListingByGroup.java @@ -33,5 +33,5 @@ public interface SupportsListingByGroup { * @return * @throws Exception */ - PagedList list(String groupName) throws CloudException, IOException;; + PagedList list(String groupName) throws CloudException, IOException; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigureBaseImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java similarity index 71% rename from azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigureBaseImpl.java rename to azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java index 32293932a1d3..166250a88c95 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigureBaseImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/implementation/AzureConfigurableImpl.java @@ -1,16 +1,17 @@ package com.microsoft.azure.management.resources.fluentcore.arm.implementation; -import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigureBase; +import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.rest.RestClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; import okhttp3.Interceptor; import okhttp3.logging.HttpLoggingInterceptor; -public class AzureConfigureBaseImpl> - implements AzureConfigureBase { +public class AzureConfigurableImpl> + implements AzureConfigurable { protected RestClient.Builder restClientBuilder; protected RestClient restClient; - protected AzureConfigureBaseImpl() { + protected AzureConfigurableImpl() { this.restClientBuilder = new RestClient.Builder("https://management.azure.com"); } @@ -31,4 +32,8 @@ public T withUserAgent(String userAgent) { this.restClientBuilder = this.restClientBuilder.withUserAgent(userAgent); return (T) this; } + + protected void buildRestClient(ServiceClientCredentials credentials) { + restClient = restClientBuilder.withCredentials(credentials).build(); + } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ARMResourceConnector.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ARMResourceConnector.java index 99776e172853..98b082f34272 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ARMResourceConnector.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ARMResourceConnector.java @@ -1,36 +1,50 @@ package com.microsoft.azure.management.resources.implementation; -import com.microsoft.azure.management.resources.Deployments.InGroup; +import com.microsoft.azure.management.resources.Deployments; import com.microsoft.azure.management.resources.GenericResources; import com.microsoft.azure.management.resources.ResourceConnector; import com.microsoft.azure.management.resources.ResourceGroup; -import com.microsoft.rest.credentials.ServiceClientCredentials; +import com.microsoft.rest.RestClient; public class ARMResourceConnector extends ResourceConnectorBase { - private GenericResources genericResources; - private InGroup deployments; + private ResourceManager resourceClient; + private GenericResources.InGroup genericResources; + private Deployments.InGroup deployments; - private ARMResourceConnector(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - super(credentials, subscriptionId, resourceGroup); - this.genericResources = new GenericResourcesImpl(resourceManagementClient(), resourceGroup.name()); - this.deployments = new DeploymentsInGroupImpl(resourceManagementClient(), resourceGroup.name()); + private ARMResourceConnector(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + super(restClient, subscriptionId, resourceGroup); } - private static ARMResourceConnector create(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - return new ARMResourceConnector(credentials, subscriptionId, resourceGroup); + private static ARMResourceConnector create(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + return new ARMResourceConnector(restClient, subscriptionId, resourceGroup); } public static class Builder implements ResourceConnector.Builder { - public ARMResourceConnector create(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - return ARMResourceConnector.create(credentials, subscriptionId, resourceGroup); + public ARMResourceConnector create(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + return ARMResourceConnector.create(restClient, subscriptionId, resourceGroup); } } - public GenericResources genericResources() { + public GenericResources.InGroup genericResources() { + if (genericResources == null) { + genericResources = new GenericResourcesInGroupImpl(resourceClient().genericResources(), resourceGroup); + } return genericResources; } - public InGroup deployments() { + public Deployments.InGroup deployments() { + if (deployments == null) { + deployments = new DeploymentsInGroupImpl(resourceClient().deployments(), resourceGroup); + } return deployments; } + + private ResourceManager resourceClient() { + if (resourceClient == null) { + resourceClient = ResourceManager + .authenticate(restClient) + .useSubscription(subscriptionId); + } + return resourceClient; + } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureAuthenticatedImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureAuthenticatedImpl.java deleted file mode 100644 index a5491f300612..000000000000 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureAuthenticatedImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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.management.resources.Subscriptions; -import com.microsoft.azure.management.resources.Tenants; -import com.microsoft.azure.management.resources.implementation.api.SubscriptionClientImpl; -import com.microsoft.rest.RestClient; -import com.microsoft.rest.credentials.ServiceClientCredentials; - -final class AzureAuthenticatedImpl - implements AzureResourceManager.Authenticated { - private final RestClient restClient; - private SubscriptionClientImpl subscriptionClient; - - AzureAuthenticatedImpl(ServiceClientCredentials credentials) { - this.restClient = new RestClient - .Builder("https://management.azure.com") - .withCredentials(credentials) - .build(); - } - - AzureAuthenticatedImpl(RestClient restClient) { - this.restClient = restClient; - } - - @Override - public Subscriptions subscriptions() { - if (subscriptionClient == null) { - subscriptionClient = new SubscriptionClientImpl(restClient); - } - return new SubscriptionsImpl(subscriptionClient); - } - - @Override - public Tenants tenants() { - if (subscriptionClient == null) { - subscriptionClient = new SubscriptionClientImpl(restClient); - } - return new TenantsImpl(subscriptionClient); - } - - @Override - public AzureResourceManager.Subscription withSubscription(String subscriptionId) { - return new AzureSubscriptionImpl(restClient, subscriptionId); - } -} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureConfigureImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureConfigureImpl.java deleted file mode 100644 index afeceebd4c51..000000000000 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureConfigureImpl.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.microsoft.azure.management.resources.implementation; - -import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigureBaseImpl; -import com.microsoft.rest.credentials.ServiceClientCredentials; - -final class AzureConfigureImpl extends AzureConfigureBaseImpl - implements AzureResourceManager.Configure { - @Override - public AzureResourceManager.Authenticated authenticate(ServiceClientCredentials credentials) { - this.restClient = this.restClientBuilder.withCredentials(credentials).build(); - return new AzureAuthenticatedImpl(this.restClient); - } -} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureResourceManager.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureResourceManager.java deleted file mode 100644 index b0758e04402c..000000000000 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureResourceManager.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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.management.resources.*; -import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigureBase; -import com.microsoft.rest.credentials.ServiceClientCredentials; - -public final class AzureResourceManager { - public static Configure configure() { - return new AzureConfigureImpl(); - } - - public static Authenticated authenticate(ServiceClientCredentials credentials) { - return new AzureAuthenticatedImpl(credentials); - } - - public interface Configure extends AzureConfigureBase { - Authenticated authenticate(ServiceClientCredentials credentials); - } - - public interface Authenticated { - Subscriptions subscriptions(); - Tenants tenants(); - Subscription withSubscription(String subscriptionId); - } - - public interface Subscription { - ResourceGroups resourceGroups(); - GenericResources genericResources(); - Deployments deployments(); - Deployments.InGroup deployments(String resourceGroupName); - } -} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureSubscriptionImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureSubscriptionImpl.java deleted file mode 100644 index 6dd9d47600e8..000000000000 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/AzureSubscriptionImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * 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.management.resources.Deployments; -import com.microsoft.azure.management.resources.GenericResources; -import com.microsoft.azure.management.resources.ResourceGroups; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; -import com.microsoft.rest.RestClient; - -final class AzureSubscriptionImpl implements AzureResourceManager.Subscription { - private final RestClient restClient; - private String subscriptionId; - - private ResourceManagementClientImpl resourceManagementClient; - - AzureSubscriptionImpl(RestClient restClient, String subscriptionId) { - this.restClient = restClient; - this.subscriptionId = subscriptionId; - } - - @Override - public ResourceGroups resourceGroups() { - if (resourceManagementClient == null) { - resourceManagementClient = new ResourceManagementClientImpl(restClient); - resourceManagementClient.setSubscriptionId(subscriptionId); - } - return new ResourceGroupsImpl(resourceManagementClient); - } - - @Override - public GenericResources genericResources() { - if (resourceManagementClient == null) { - resourceManagementClient = new ResourceManagementClientImpl(restClient); - resourceManagementClient.setSubscriptionId(subscriptionId); - } - return new GenericResourcesImpl(resourceManagementClient); - } - - @Override - public Deployments deployments() { - if (resourceManagementClient == null) { - resourceManagementClient = new ResourceManagementClientImpl(restClient); - resourceManagementClient.setSubscriptionId(subscriptionId); - } - return new DeploymentsImpl(resourceManagementClient); - } - - @Override - public Deployments.InGroup deployments(String resourceGroupName) { - if (resourceManagementClient == null) { - resourceManagementClient = new ResourceManagementClientImpl(restClient); - resourceManagementClient.setSubscriptionId(subscriptionId); - } - return new DeploymentsInGroupImpl(resourceManagementClient, resourceGroupName); - } -} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java index fc55cbb7a738..eeecae2fe8c5 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentImpl.java @@ -7,7 +7,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableRefreshableWrapperImpl; import com.microsoft.azure.management.resources.implementation.api.DeploymentsInner; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; import com.microsoft.azure.management.resources.Deployment; import com.microsoft.azure.management.resources.Provider; import com.microsoft.azure.management.resources.ResourceGroup; @@ -27,23 +26,22 @@ public class DeploymentImpl extends Deployment.DefinitionWithParameters, Deployment.DefinitionProvisionable { - private final DeploymentsInner deployments; - private final ResourceManagementClientImpl serviceClient; + private final DeploymentsInner client; + private final DeploymentOperationsInner deploymentOperationsClient; private final ResourceGroups resourceGroups; private String resourceGroupName; - public DeploymentImpl(DeploymentExtendedInner deployment, DeploymentsInner deployments, ResourceGroups resourceGroups, ResourceManagementClientImpl serviceClient) { - super (deployment.name(), deployment); - this.deployments = deployments; - this.resourceGroupName = ResourceUtils.groupFromResourceId(deployment.id()); + public DeploymentImpl(DeploymentExtendedInner innerModel, + final DeploymentsInner client, + final DeploymentOperationsInner deploymentOperationsClient, + final ResourceGroups resourceGroups) { + super (innerModel.name(), innerModel); + this.client = client; + this.deploymentOperationsClient = deploymentOperationsClient; + this.resourceGroupName = ResourceUtils.groupFromResourceId(innerModel.id()); this.resourceGroups = resourceGroups; - this.serviceClient = serviceClient; } - /*********************************************************** - * Getters - ***********************************************************/ - @Override public String resourceGroupName() { return this.resourceGroupName; @@ -148,7 +146,7 @@ public DeploymentMode mode() { @Override public DeploymentOperations deploymentOperations() { - return new DeploymentOperationsImpl(serviceClient, this); + return new DeploymentOperationsImpl(deploymentOperationsClient, this, resourceGroups); } /************************************************************** @@ -231,10 +229,6 @@ public DefinitionWithParameters withParametersLink(String uri, String contentVer return this; } - /************************************************************ - * Verbs - ************************************************************/ - @Override public Deployment provision() throws Exception { // FLUENT: implementation of ResourceGroup.DefinitionProvisionable.Provisionable DeploymentInner inner = new DeploymentInner() @@ -244,7 +238,7 @@ public Deployment provision() throws Exception { // FLUENT: implementat inner.properties().setTemplateLink(templateLink()); inner.properties().setParameters(parameters()); inner.properties().setParametersLink(parametersLink()); - deployments.createOrUpdate(resourceGroupName(), name(), inner); + client.createOrUpdate(resourceGroupName(), name(), inner); return this; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationImpl.java index a34bbfc875e6..6e5d0428c193 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationImpl.java @@ -1,6 +1,5 @@ package com.microsoft.azure.management.resources.implementation; -import com.microsoft.azure.management.resources.ResourceGroups; import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.model.implementation.IndexableRefreshableWrapperImpl; import com.microsoft.azure.management.resources.implementation.api.DeploymentOperationsInner; @@ -13,18 +12,16 @@ public class DeploymentOperationImpl extends IndexableRefreshableWrapperImpl implements DeploymentOperation { - - private final DeploymentOperationsInner deploymentOperations; - private final ResourceGroups resourceGroups; private String resourceGroupName; - private String deployementName; + private String deploymentName; + + private final DeploymentOperationsInner client; - public DeploymentOperationImpl(DeploymentOperationInner deploymentOperation, DeploymentOperationsInner deploymentOperations, ResourceGroups resourceGroups) { - super (deploymentOperation.id(), deploymentOperation); - this.deploymentOperations = deploymentOperations; - this.resourceGroupName = ResourceUtils.groupFromResourceId(deploymentOperation.id()); - this.deployementName = ResourceUtils.extractFromResourceId(deploymentOperation.id(), "deployments"); - this.resourceGroups = resourceGroups; + public DeploymentOperationImpl(DeploymentOperationInner innerModel, final DeploymentOperationsInner client) { + super (innerModel.id(), innerModel); + this.client = client; + this.resourceGroupName = ResourceUtils.groupFromResourceId(innerModel.id()); + this.deploymentName = ResourceUtils.extractFromResourceId(innerModel.id(), "deployments"); } /*********************************************************** @@ -78,7 +75,7 @@ public TargetResource targetResource() { @Override public DeploymentOperation refresh() throws Exception { - this.setInner(deploymentOperations.get(resourceGroupName, deployementName, operationId()).getBody()); + this.setInner(client.get(resourceGroupName, deploymentName, operationId()).getBody()); return this; } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java index d1e403053bbe..b0731020825c 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsImpl.java @@ -7,7 +7,6 @@ import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupPagedList; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; import com.microsoft.azure.management.resources.implementation.api.DeploymentOperationsInner; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; import com.microsoft.azure.management.resources.Deployment; import com.microsoft.azure.management.resources.DeploymentOperation; import com.microsoft.azure.management.resources.ResourceGroup; @@ -19,29 +18,28 @@ public class DeploymentOperationsImpl implements DeploymentOperations { + private final DeploymentOperationsInner client; + private final Deployment deployment; + private final ResourceGroups resourceGroups; + private final PagedListConverter converter; - private ResourceManagementClientImpl serviceClient; - private Deployment deployment; - private DeploymentOperationsInner deploymentOperations; - private ResourceGroups resourceGroups; - private PagedListConverter converter; - - public DeploymentOperationsImpl(ResourceManagementClientImpl serviceClient, Deployment deployment) { - this.serviceClient = serviceClient; - this.deploymentOperations = serviceClient.deploymentOperations(); - this.resourceGroups = new ResourceGroupsImpl(serviceClient); + public DeploymentOperationsImpl(final DeploymentOperationsInner client, + final Deployment deployment, + final ResourceGroups resourceGroups) { + this.client = client; this.deployment = deployment; + this.resourceGroups = resourceGroups; converter = new PagedListConverter() { @Override public DeploymentOperation typeConvert(DeploymentOperationInner deploymentInner) { - return new DeploymentOperationImpl(deploymentInner, deploymentOperations, resourceGroups); + return createFluentModel(deploymentInner); } }; } @Override - public InGroup resourceGroup(String resourceGroupName) { - return new DeploymentOperationsInGroupImpl(serviceClient, deployment, resourceGroupName); + public InGroup resourceGroup(ResourceGroup resourceGroup) { + return new DeploymentOperationsInGroupImpl(this, resourceGroup); } @Override @@ -49,22 +47,39 @@ public PagedList list() throws CloudException, IOException return new GroupPagedList(resourceGroups.list()) { @Override public List listNextGroup(String resourceGroupName) throws RestException, IOException { - return converter.convert(deploymentOperations.list(resourceGroupName, deployment.name()).getBody()); + return converter.convert(client.list(resourceGroupName, deployment.name()).getBody()); } }; } + @Override + public PagedList list(String groupName) throws CloudException, IOException { + return converter.convert(client.list(groupName, deployment.name()).getBody()); + } + @Override public DeploymentOperation get(String operationId) throws IOException, CloudException { for (ResourceGroup group : resourceGroups.list()) { try { - DeploymentOperationInner inner = deploymentOperations.get(group.name(), deployment.name(), operationId).getBody(); + DeploymentOperationInner inner = client.get(group.name(), deployment.name(), operationId).getBody(); if (inner != null) { - return new DeploymentOperationImpl(inner, deploymentOperations, resourceGroups); + return createFluentModel(inner); } } catch (CloudException ex) { } } return null; } + + @Override + public DeploymentOperation get(String groupName, String operationId) throws IOException, CloudException { + return createFluentModel(client.get(groupName, deployment.name(), operationId).getBody()); + } + + + /** Fluent model create helpers **/ + + private DeploymentOperationImpl createFluentModel(DeploymentOperationInner deploymentOperationInner) { + return new DeploymentOperationImpl(deploymentOperationInner, this.client); + } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsInGroupImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsInGroupImpl.java index 9ab141ca78a6..d50037ddf028 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsInGroupImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentOperationsInGroupImpl.java @@ -2,51 +2,28 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; -import com.microsoft.azure.management.resources.DeploymentOperations; -import com.microsoft.azure.management.resources.ResourceGroups; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; -import com.microsoft.azure.management.resources.implementation.api.DeploymentOperationsInner; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; -import com.microsoft.azure.management.resources.Deployment; -import com.microsoft.azure.management.resources.DeploymentOperation; -import com.microsoft.azure.management.resources.implementation.api.DeploymentOperationInner; - +import com.microsoft.azure.management.resources.*; import java.io.IOException; -import java.util.List; public class DeploymentOperationsInGroupImpl implements DeploymentOperations.InGroup { + private final DeploymentOperations deploymentOperations; + private final ResourceGroup resourceGroup; - private ResourceManagementClientImpl serviceClient; - private DeploymentOperationsInner deploymentOperations; - private ResourceGroups resourceGroups; - private Deployment deployment; - private PagedListConverter converter; - private String resourceGroupName; - - - public DeploymentOperationsInGroupImpl(ResourceManagementClientImpl serviceClient, Deployment deployment, String resourceGroupName) { - this.serviceClient = serviceClient; - this.deploymentOperations = serviceClient.deploymentOperations(); - this.resourceGroups = new ResourceGroupsImpl(serviceClient); - this.deployment = deployment; - converter = new PagedListConverter() { - @Override - public DeploymentOperation typeConvert(DeploymentOperationInner deploymentInner) { - return new DeploymentOperationImpl(deploymentInner, deploymentOperations, resourceGroups); - } - }; - this.resourceGroupName = resourceGroupName; + public DeploymentOperationsInGroupImpl(final DeploymentOperations deploymentOperations, final ResourceGroup resourceGroup) { + this.deploymentOperations = deploymentOperations; + this.resourceGroup = resourceGroup; } @Override public PagedList list() throws CloudException, IOException { - return converter.convert(deploymentOperations.list(resourceGroupName, deployment.name()).getBody()); + return deploymentOperations.list(this.resourceGroup.name()); } @Override public DeploymentOperation get(String operationId) throws IOException, CloudException { - return new DeploymentOperationImpl(deploymentOperations.get(resourceGroupName, deployment.name(), operationId).getBody(), deploymentOperations, resourceGroups); + return deploymentOperations.get(this.resourceGroup.name(), operationId); + } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java index da563227bdb8..4d6ca4059bfc 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsImpl.java @@ -4,10 +4,11 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.Deployments; import com.microsoft.azure.management.resources.ResourceGroups; +import com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils; import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupPagedList; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; +import com.microsoft.azure.management.resources.implementation.api.DeploymentOperationsInner; import com.microsoft.azure.management.resources.implementation.api.DeploymentsInner; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; import com.microsoft.azure.management.resources.Deployment; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.implementation.api.DeploymentExtendedInner; @@ -19,26 +20,28 @@ public class DeploymentsImpl implements Deployments { - protected ResourceManagementClientImpl serviceClient; - protected DeploymentsInner deployments; - protected ResourceGroups resourceGroups; - protected PagedListConverter converter; + private final DeploymentsInner client; + private final DeploymentOperationsInner deploymentOperationsClient; + private final ResourceGroups resourceGroups; + private PagedListConverter converter; - public DeploymentsImpl(final ResourceManagementClientImpl serviceClient) { - this.serviceClient = serviceClient; - this.deployments = serviceClient.deployments(); - this.resourceGroups = new ResourceGroupsImpl(serviceClient); + public DeploymentsImpl(final DeploymentsInner client, + final DeploymentOperationsInner deploymentOperationsClient, + final ResourceGroups resourceGroups) { + this.client = client; + this.deploymentOperationsClient = deploymentOperationsClient; + this.resourceGroups = resourceGroups; converter = new PagedListConverter() { @Override public Deployment typeConvert(DeploymentExtendedInner deploymentInner) { - return new DeploymentImpl(deploymentInner, deployments, resourceGroups, serviceClient); + return createFluentModel(deploymentInner); } }; } @Override - public InGroup resourceGroup(String resourceGroupName) { - return new DeploymentsInGroupImpl(serviceClient, resourceGroupName); + public InGroup resourceGroup(ResourceGroup resourceGroup) { + return new DeploymentsInGroupImpl(this, resourceGroup); } @Override @@ -46,35 +49,23 @@ public PagedList list() throws CloudException, IOException { return new GroupPagedList(resourceGroups.list()) { @Override public List listNextGroup(String resourceGroupName) throws RestException, IOException { - return converter.convert(deployments.list(resourceGroupName).getBody()); + return converter.convert(client.list(resourceGroupName).getBody()); } }; } @Override - public boolean checkExistence(String deploymentName) throws IOException, CloudException { - for (ResourceGroup group : resourceGroups.list()) { - if (deployments.checkExistence(group.name(), deploymentName).getBody()) { - return true; - } - } - return false; - } - - @Override - public Deployment.DefinitionBlank define(String name) throws Exception { - DeploymentExtendedInner deployment = new DeploymentExtendedInner(); - deployment.setName(name); - return new DeploymentImpl(deployment, deployments, resourceGroups, serviceClient); + public PagedList list(String groupName) throws CloudException, IOException { + return converter.convert(client.list(groupName).getBody()); } @Override public Deployment get(String name) throws IOException, CloudException { for (ResourceGroup group : resourceGroups.list()) { try { - DeploymentExtendedInner inner = deployments.get(group.name(), name).getBody(); + DeploymentExtendedInner inner = client.get(group.name(), name).getBody(); if (inner != null) { - return new DeploymentImpl(inner, deployments, resourceGroups, serviceClient); + return createFluentModel(inner); } } catch (CloudException ex) { } @@ -82,8 +73,54 @@ public Deployment get(String name) throws IOException, CloudException { return null; } + @Override + public Deployment get(String groupName, String name) throws IOException, CloudException { + DeploymentExtendedInner inner = client.get(groupName, name).getBody(); + return createFluentModel(inner); + } + @Override public void delete(String id) throws Exception { + this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); + } + + @Override + public void delete(String groupName, String name) throws Exception { + client.delete(groupName, name); + } + + @Override + public Deployment.DefinitionBlank define(String name) throws Exception { + return createFluentModel(name); + } + + @Override + public boolean checkExistence(String deploymentName) throws IOException, CloudException { + for (ResourceGroup group : resourceGroups.list()) { + if (client.checkExistence(group.name(), deploymentName).getBody()) { + return true; + } + } + return false; + } + + @Override + public boolean checkExistence(String groupName, String deploymentName) throws IOException, CloudException { + if (client.checkExistence(groupName, deploymentName).getBody()) { + return true; + } + return false; + } + + /** Fluent model create helpers **/ + + private DeploymentImpl createFluentModel(String name) { + DeploymentExtendedInner deploymentExtendedInner = new DeploymentExtendedInner(); + deploymentExtendedInner.setName(name); + return new DeploymentImpl(deploymentExtendedInner, client, deploymentOperationsClient, resourceGroups); + } + private DeploymentImpl createFluentModel(DeploymentExtendedInner deploymentExtendedInner) { + return new DeploymentImpl(deploymentExtendedInner, client, deploymentOperationsClient, resourceGroups); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsInGroupImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsInGroupImpl.java index 1b924ee48809..5236d6b13c6c 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsInGroupImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/DeploymentsInGroupImpl.java @@ -3,65 +3,44 @@ import com.microsoft.azure.CloudException; import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.Deployments; -import com.microsoft.azure.management.resources.ResourceGroups; -import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; -import com.microsoft.azure.management.resources.implementation.api.DeploymentsInner; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; +import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.resources.Deployment; -import com.microsoft.azure.management.resources.implementation.api.DeploymentExtendedInner; import java.io.IOException; -import java.util.List; public class DeploymentsInGroupImpl implements Deployments.InGroup { + private final Deployments deployments; + private final ResourceGroup resourceGroup; - private ResourceManagementClientImpl serviceClient; - private DeploymentsInner deployments; - private ResourceGroups resourceGroups; - private PagedListConverter converter; - private String resourceGroupName; - - - public DeploymentsInGroupImpl(final ResourceManagementClientImpl serviceClient, String resourceGroupName) { - this.serviceClient = serviceClient; - this.deployments = serviceClient.deployments(); - this.resourceGroups = new ResourceGroupsImpl(serviceClient); - converter = new PagedListConverter() { - @Override - public Deployment typeConvert(DeploymentExtendedInner deploymentInner) { - return new DeploymentImpl(deploymentInner, deployments, resourceGroups, serviceClient); - } - }; - this.resourceGroupName = resourceGroupName; + public DeploymentsInGroupImpl(Deployments deployments, ResourceGroup resourceGroup) { + this.deployments = deployments; + this.resourceGroup = resourceGroup; } @Override public PagedList list() throws CloudException, IOException { - return converter.convert(deployments.list(resourceGroupName).getBody()); + return this.deployments.list(this.resourceGroup.name()); } @Override public boolean checkExistence(String deploymentName) throws IOException, CloudException { - return deployments.checkExistence(resourceGroupName, deploymentName).getBody(); + return this.deployments.checkExistence(this.resourceGroup.name(), deploymentName); } @Override public Deployment get(String name) throws IOException, CloudException { - return new DeploymentImpl(deployments.get(resourceGroupName, name).getBody(), deployments, resourceGroups, serviceClient); + return this.deployments.get(this.resourceGroup.name(), name); } @Override public Deployment.DefinitionWithGroup define(String name) throws Exception { - DeploymentExtendedInner deployment = new DeploymentExtendedInner(); - deployment.setName(name); - return new DeploymentImpl(deployment, deployments, resourceGroups, serviceClient) - .withExistingResourceGroup(resourceGroupName); + return this.deployments.define(name).withExistingResourceGroup(resourceGroup.name()); } @Override - public void delete(String id) throws Exception { - + public void delete(String name) throws Exception { + this.deployments.delete(this.resourceGroup.name(), name); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeatureImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeatureImpl.java index 77d362ccd681..2499b26c4ba3 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeatureImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeatureImpl.java @@ -9,8 +9,8 @@ public class FeatureImpl extends implements Feature { - public FeatureImpl(FeatureResultInner feature) { - super(feature.id(), feature); + public FeatureImpl(FeatureResultInner innerModel) { + super(innerModel.id(), innerModel); } /*********************************************************** diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java index 8e2397560c5f..8f0465af646e 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesImpl.java @@ -4,22 +4,17 @@ import com.microsoft.azure.PagedList; import com.microsoft.azure.management.resources.Features; import com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter; -import com.microsoft.azure.management.resources.implementation.api.FeatureClientImpl; import com.microsoft.azure.management.resources.implementation.api.FeaturesInner; import com.microsoft.azure.management.resources.Feature; import com.microsoft.azure.management.resources.implementation.api.FeatureResultInner; - import java.io.IOException; -import java.util.List; public final class FeaturesImpl implements Features { - private FeaturesInner features; - private FeatureClientImpl serviceClient; + private final FeaturesInner client; - public FeaturesImpl(FeatureClientImpl serviceClient) { - this.serviceClient = serviceClient; - this.features = serviceClient.features(); + public FeaturesImpl(final FeaturesInner client) { + this.client = client; } @Override @@ -30,7 +25,7 @@ public Feature typeConvert(FeatureResultInner tenantInner) { return new FeatureImpl(tenantInner); } }; - return converter.convert(features.listAll().getBody()); + return converter.convert(client.listAll().getBody()); } @Override diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java index fea5938cfc61..9ecb2118ffd9 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/FeaturesInResourceProviderImpl.java @@ -14,13 +14,11 @@ public final class FeaturesInResourceProviderImpl implements Features.InResourceProvider { - private FeaturesInner features; - private FeatureClientImpl serviceClient; + private final FeaturesInner client; private String resourceProviderNamespace; - public FeaturesInResourceProviderImpl(FeatureClientImpl serviceClient, String resourceProviderNamespace) { - this.serviceClient = serviceClient; - this.features = serviceClient.features(); + public FeaturesInResourceProviderImpl(FeaturesInner client, String resourceProviderNamespace) { + this.client = client; this.resourceProviderNamespace = resourceProviderNamespace; } @@ -32,16 +30,16 @@ public Feature typeConvert(FeatureResultInner tenantInner) { return new FeatureImpl(tenantInner); } }; - return converter.convert(features.list(resourceProviderNamespace).getBody()); + return converter.convert(client.list(resourceProviderNamespace).getBody()); } @Override public Feature register(String featureName) throws IOException, CloudException { - return new FeatureImpl(features.register(resourceProviderNamespace, featureName).getBody()); + return new FeatureImpl(client.register(resourceProviderNamespace, featureName).getBody()); } @Override public Feature get(String name) throws CloudException, IOException { - return new FeatureImpl(features.get(resourceProviderNamespace, name).getBody()); + return new FeatureImpl(client.get(resourceProviderNamespace, name).getBody()); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java index 1717a1f98987..9e7c8458cf60 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourceImpl.java @@ -9,8 +9,8 @@ public class GenericResourceImpl extends GroupableResourceImpl implements GenericResource { - public GenericResourceImpl(String id, GenericResourceInner innerObject, ResourceManagementClientImpl serviceClient) { - super(id, innerObject, new ResourceGroupsImpl(serviceClient)); + public GenericResourceImpl(String id, GenericResourceInner innerModel, final ResourceManagementClientImpl serviceClient) { + super(id, innerModel, new ResourceGroupsImpl(serviceClient)); } @Override diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java index c0a52c18c405..abc80aadbe91 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesImpl.java @@ -16,42 +16,44 @@ public final class GenericResourcesImpl implements GenericResources { - final ResourceManagementClientImpl serviceClient; - final ResourcesInner resources; - final ResourceGroupsInner resourceGroups; - final String resourceGroupName; + private final ResourceManagementClientImpl serviceClient; + private final ResourcesInner resources; + private final ResourceGroupsInner resourceGroups; public GenericResourcesImpl(ResourceManagementClientImpl serviceClient) { this.serviceClient = serviceClient; this.resources = serviceClient.resources(); this.resourceGroups = serviceClient.resourceGroups(); - resourceGroupName = null; } - public GenericResourcesImpl(ResourceManagementClientImpl serviceClient, String resourceGroupName) { - this.serviceClient = serviceClient; - this.resources = serviceClient.resources(); - this.resourceGroups = serviceClient.resourceGroups(); - this.resourceGroupName = resourceGroupName; + @Override + public PagedList list() throws CloudException, IOException { + return listIntern(null); } @Override - public PagedList list() throws CloudException, IOException { - PagedListConverter converter = new PagedListConverter() { - @Override - public GenericResource typeConvert(GenericResourceInner genericResourceInner) { - return new GenericResourceImpl(genericResourceInner.id(), genericResourceInner, serviceClient); - } - }; - if (resourceGroupName == null) { + public PagedList list(String groupName) throws CloudException, IOException { + return listIntern(groupName); + } - } - return converter.convert(resourceGroups.listResources(resourceGroupName).getBody()); + @Override + public GenericResource get(String name) throws IOException, CloudException { + return getIntern(null, name); } @Override - public boolean checkExistence(String resourceGroupName, String resourceProviderNamespace, String parentResourcePath, String resourceType, String resourceName, String apiVersion) throws IOException, CloudException { - return resources.checkExistence(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion).getBody(); + public GenericResource get(String groupName, String name) throws IOException, CloudException { + return getIntern(groupName, name); + } + + @Override + public void delete(String id) throws Exception { + // TODO + } + + @Override + public void delete(String groupName, String name) throws Exception { + // TODO } @Override @@ -60,16 +62,25 @@ public GenericResource.DefinitionBlank define(String name) throws Exception { } @Override - public void delete(String id) throws Exception { + public boolean checkExistence(String resourceGroupName, String resourceProviderNamespace, String parentResourcePath, String resourceType, String resourceName, String apiVersion) throws IOException, CloudException { + return resources.checkExistence(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, apiVersion).getBody(); + } + private PagedList listIntern(String groupName) throws IOException, CloudException { + PagedListConverter converter = new PagedListConverter() { + @Override + public GenericResource typeConvert(GenericResourceInner genericResourceInner) { + return new GenericResourceImpl(genericResourceInner.id(), genericResourceInner, serviceClient); + } + }; + return converter.convert(resourceGroups.listResources(groupName).getBody()); } - @Override - public GenericResource get(String name) throws IOException, CloudException { + private GenericResource getIntern(String groupName, String name) throws IOException, CloudException { if (name == null) { return null; } - List innerList = resourceGroups.listResources(resourceGroupName).getBody(); + List innerList = resourceGroups.listResources(groupName).getBody(); for (GenericResourceInner inner : innerList) { if (name.equals(inner.name())) { return new GenericResourceImpl(inner.id(), inner, serviceClient); diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesInGroupImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesInGroupImpl.java new file mode 100644 index 000000000000..b7b995a36177 --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/GenericResourcesInGroupImpl.java @@ -0,0 +1,29 @@ +package com.microsoft.azure.management.resources.implementation; + +import com.microsoft.azure.CloudException; +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.resources.GenericResource; +import com.microsoft.azure.management.resources.GenericResources; +import com.microsoft.azure.management.resources.ResourceGroup; + +import java.io.IOException; + +public final class GenericResourcesInGroupImpl implements GenericResources.InGroup { + private final GenericResources genericResources; + private final ResourceGroup resourceGroup; + + public GenericResourcesInGroupImpl(GenericResources genericResources, ResourceGroup resourceGroup) { + this.genericResources = genericResources; + this.resourceGroup = resourceGroup; + } + + @Override + public GenericResource get(String name) throws CloudException, IOException { + return this.genericResources.get(this.resourceGroup.name(), name); + } + + @Override + public PagedList list() throws CloudException, IOException { + return this.genericResources.list(resourceGroup.name()); + } +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/LocationImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/LocationImpl.java index 03322e8e0a0c..51419ebc0ea1 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/LocationImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/LocationImpl.java @@ -12,8 +12,8 @@ public class LocationImpl extends private final SubscriptionsInner client; - public LocationImpl(LocationInner location, SubscriptionsInner client) { - super(location.id(), location); + public LocationImpl(LocationInner innerModel, final SubscriptionsInner client) { + super(innerModel.id(), innerModel); this.client = client; } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceConnectorBase.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceConnectorBase.java index c3c421e0af1f..d28ed6fe2b38 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceConnectorBase.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceConnectorBase.java @@ -2,35 +2,16 @@ import com.microsoft.azure.management.resources.ResourceConnector; import com.microsoft.azure.management.resources.ResourceGroup; -import com.microsoft.azure.management.resources.ResourceGroups; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; -import com.microsoft.rest.credentials.ServiceClientCredentials; +import com.microsoft.rest.RestClient; public class ResourceConnectorBase implements ResourceConnector { - protected final ServiceClientCredentials credentials; + protected final RestClient restClient; protected final String subscriptionId; protected final ResourceGroup resourceGroup; - private ResourceGroups resourceGroups; - private ResourceManagementClientImpl client; - protected ResourceConnectorBase(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - this.credentials = credentials; + protected ResourceConnectorBase(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + this.restClient = restClient; this.subscriptionId = subscriptionId; this.resourceGroup = resourceGroup; } - - protected ResourceGroups resourceGroups() { - if (resourceGroups == null) { - resourceGroups = new ResourceGroupsImpl(resourceManagementClient()); - } - return resourceGroups; - } - - protected ResourceManagementClientImpl resourceManagementClient() { - if (client == null) { - client = new ResourceManagementClientImpl(credentials); - client.setSubscriptionId(subscriptionId); - } - return client; - } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupImpl.java index 7a24050ff4ea..eb7510f35d41 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupImpl.java @@ -23,8 +23,8 @@ public class ResourceGroupImpl extends private final ResourceGroupsInner client; private final ResourceManagementClientImpl serviceClient; - public ResourceGroupImpl(ResourceGroupInner azureGroup, ResourceManagementClientImpl serviceClient) { - super(azureGroup.name(), azureGroup); + public ResourceGroupImpl(final ResourceGroupInner innerModel, final ResourceManagementClientImpl serviceClient) { + super(innerModel.name(), innerModel); this.client = serviceClient.resourceGroups(); this.serviceClient = serviceClient; } @@ -59,7 +59,7 @@ public Map tags() { @Override public ResourceGroupImpl withLocation(String regionName) { // FLUENT: implementation of ResourceGroup.DefinitionBlank - this.inner().setLocation(regionName); // + this.inner().setLocation(regionName); // return this; } @@ -69,14 +69,14 @@ public ResourceGroupImpl withLocation(Region region) { // FLUENT: im } @Override - public ResourceGroupImpl withTags(Map tags) { // FLUENT: implementation of ResourceGroup.DefinitionProvisionable - this.inner().setTags(new HashMap<>(tags)); // ResourceGroup.Update.UpdateBlank.Taggable + public ResourceGroupImpl withTags(Map tags) { // FLUENT: implementation of ResourceGroup.DefinitionProvisionable + this.inner().setTags(new HashMap<>(tags)); // ResourceGroup.Update.UpdateBlank.Taggable return this; } @Override - public ResourceGroupImpl withTag(String key, String value) { // FLUENT: implementation of ResourceGroup.DefinitionProvisionable - if(this.inner().tags() == null) { // ResourceGroup.Update.UpdateBlank.Taggable + public ResourceGroupImpl withTag(String key, String value) { // FLUENT: implementation of ResourceGroup.DefinitionProvisionable + if(this.inner().tags() == null) { // ResourceGroup.Update.UpdateBlank.Taggable this.inner().setTags(new HashMap()); } this.inner().tags().put(key, value); @@ -84,8 +84,8 @@ public ResourceGroupImpl withTag(String key, String value) { // FLUENT: impl } @Override - public ResourceGroupImpl withoutTag(String key) { // FLUENT: implementation of ResourceGroup.Update.UpdateBlank.Taggable - this.inner().tags().remove(key); // + public ResourceGroupImpl withoutTag(String key) { // FLUENT: implementation of ResourceGroup.Update.UpdateBlank.Taggable + this.inner().tags().remove(key); // return this; } @@ -114,7 +114,7 @@ public ResourceGroupImpl apply() throws Exception { // FLUENT: impl } @Override - public ResourceGroupImpl provision() throws Exception { // FLUENT: implementation of ResourceGroup.DefinitionProvisionable.Provisionable + public ResourceGroupImpl provision() throws Exception { // FLUENT: implementation of ResourceGroup.DefinitionProvisionable.Provisionable ResourceGroupInner params = new ResourceGroupInner(); params.setLocation(this.inner().location()); params.setTags(this.inner().tags()); @@ -123,13 +123,13 @@ public ResourceGroupImpl provision() throws Exception { // FLUENT: impl } @Override - public ResourceGroupImpl refresh() throws Exception { // FLUENT: implementation of ResourceGroup.Refreshable + public ResourceGroupImpl refresh() throws Exception { // FLUENT: implementation of ResourceGroup.Refreshable this.setInner(client.get(this.id).getBody()); return this; } @Override public T connectToResource(T.Builder adapterBuilder) { - return adapterBuilder.create(this.serviceClient.credentials(), this.serviceClient.subscriptionId(), this); + return adapterBuilder.create(this.serviceClient.restClient(), this.serviceClient.subscriptionId(), this); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java index 3aec1926fc50..cc2e914c85ef 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceGroupsImpl.java @@ -10,14 +10,13 @@ import com.microsoft.azure.management.resources.implementation.api.ResourceGroupInner; import java.io.IOException; -import java.util.List; public class ResourceGroupsImpl implements ResourceGroups { - private ResourceGroupsInner client; - private ResourceManagementClientImpl serviceClient; + private final ResourceGroupsInner client; + private final ResourceManagementClientImpl serviceClient; - public ResourceGroupsImpl(ResourceManagementClientImpl serviceClient) { + public ResourceGroupsImpl(final ResourceManagementClientImpl serviceClient) { this.serviceClient = serviceClient; this.client = serviceClient.resourceGroups(); } @@ -27,17 +26,16 @@ public PagedList list() throws CloudException, IOException { PagedListConverter converter = new PagedListConverter() { @Override public ResourceGroup typeConvert(ResourceGroupInner resourceGroupInner) { - return new ResourceGroupImpl(resourceGroupInner, serviceClient); + return createFluentModel(resourceGroupInner); } }; return converter.convert(client.list().getBody()); } @Override - // Gets a specific resource group public ResourceGroupImpl get(String name) throws CloudException, IOException { - ResourceGroupInner group = client.get(name).getBody(); - return new ResourceGroupImpl(group, serviceClient); + ResourceGroupInner resourceGroupInner = client.get(name).getBody(); + return createFluentModel(resourceGroupInner); } @Override @@ -47,12 +45,12 @@ public void delete(String name) throws Exception { @Override public ResourceGroupImpl update(String name) { - return createFluentWrapper(name); + return createFluentModel(name); } @Override public ResourceGroupImpl define(String name) { - return createFluentWrapper(name); + return createFluentModel(name); } @Override @@ -60,14 +58,15 @@ public boolean checkExistence(String name) throws CloudException, IOException { return client.checkExistence(name).getBody(); } - /*************************************************** - * Helpers - ***************************************************/ + /** Fluent model create helpers **/ - // Wraps native Azure resource group - private ResourceGroupImpl createFluentWrapper(String name) { - ResourceGroupInner azureGroup = new ResourceGroupInner(); - azureGroup.setName(name); - return new ResourceGroupImpl(azureGroup, serviceClient); + private ResourceGroupImpl createFluentModel(String name) { + ResourceGroupInner resourceGroupInner = new ResourceGroupInner(); + resourceGroupInner.setName(name); + return new ResourceGroupImpl(resourceGroupInner, serviceClient); + } + + private ResourceGroupImpl createFluentModel(ResourceGroupInner resourceGroupInner) { + return new ResourceGroupImpl(resourceGroupInner, serviceClient); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceManager.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceManager.java new file mode 100644 index 000000000000..d2a132aa6a91 --- /dev/null +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/ResourceManager.java @@ -0,0 +1,141 @@ +/** + * 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.management.resources.*; +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.implementation.api.ResourceManagementClientImpl; +import com.microsoft.azure.management.resources.implementation.api.SubscriptionClientImpl; +import com.microsoft.rest.RestClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +public final class ResourceManager { + private RestClient restClient; + private String subscriptionId; + // The sdk clients + private ResourceManagementClientImpl resourceManagementClient; + // The collections + ResourceGroups resourceGroups; + GenericResources genericResources; + Deployments deployments; + Deployments.InGroup deploymentsInGroup; + + public static Configure configure() { + return new ResourceManager().new ConfigurableImpl(); + } + + public static ResourceManager.Authenticated authenticate(ServiceClientCredentials credentials) { + return (new ResourceManager(credentials)).new AuthenticatedImpl(); + } + + public static ResourceManager.Authenticated authenticate(RestClient restClient) { + return (new ResourceManager(restClient)).new AuthenticatedImpl(); + } + + public interface Configure extends AzureConfigurable { + ResourceManager.Authenticated authenticate(ServiceClientCredentials credentials); + } + + class ConfigurableImpl extends AzureConfigurableImpl implements Configure { + public ResourceManager.Authenticated authenticate(ServiceClientCredentials credentials) { + buildRestClient(credentials); + return ResourceManager.authenticate(restClient); + } + } + + public interface Authenticated { + Tenants tenants(); + Subscriptions subscriptions(); + ResourceManager useSubscription(String subscriptionId); + } + + class AuthenticatedImpl implements Authenticated { + private SubscriptionClientImpl subscriptionClient; + // The subscription less collections + private Subscriptions subscriptions; + private Tenants tenants; + + public AuthenticatedImpl() {} + + 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; + } + + public ResourceManager useSubscription(String subscriptionId) { + ResourceManager.this.subscriptionId = subscriptionId; + return ResourceManager.this; + } + + private SubscriptionClientImpl subscriptionClient() { + if (subscriptionClient == null) { + subscriptionClient = new SubscriptionClientImpl(restClient); + } + return subscriptionClient; + } + } + + private ResourceManager(ServiceClientCredentials credentials) { + this.restClient = new RestClient + .Builder("https://management.azure.com") + .withCredentials(credentials) + .build(); + } + + private ResourceManager(RestClient restClient) { + this.restClient = restClient; + } + + private ResourceManager() {} + + public ResourceGroups resourceGroups() { + if (resourceGroups == null) { + resourceGroups = new ResourceGroupsImpl(resourceManagementClient()); + } + return resourceGroups; + } + + public GenericResources genericResources() { + if (genericResources == null) { + genericResources = new GenericResourcesImpl(resourceManagementClient()); + } + return genericResources; + } + + public Deployments deployments() { + if (deployments == null) { + ResourceManagementClientImpl client = resourceManagementClient(); + deployments = new DeploymentsImpl(client.deployments(), client.deploymentOperations(), resourceGroups()); + } + return deployments; + } + + public Deployments.InGroup deployments(ResourceGroup resourceGroup) { + if (deploymentsInGroup == null) { + deploymentsInGroup = new DeploymentsInGroupImpl(deployments(), resourceGroup); + } + return deploymentsInGroup; + } + + private ResourceManagementClientImpl resourceManagementClient() { + if (resourceManagementClient == null) { + resourceManagementClient = new ResourceManagementClientImpl(restClient); + resourceManagementClient.setSubscriptionId(subscriptionId); + } + return resourceManagementClient; + } +} diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java index 3af9fdb2666a..02d793e13d0c 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionImpl.java @@ -19,12 +19,10 @@ public class SubscriptionImpl extends implements Subscription { - private final SubscriptionsInner subscriptions; - private final SubscriptionClientImpl client; + private final SubscriptionsInner client; - public SubscriptionImpl(SubscriptionInner subscription, SubscriptionClientImpl client) { - super(subscription.id(), subscription); - this.subscriptions = client.subscriptions(); + public SubscriptionImpl(SubscriptionInner innerModel, final SubscriptionsInner client) { + super(innerModel.id(), innerModel); this.client = client; } @@ -61,9 +59,9 @@ public PagedList listLocations() throws IOException, CloudException { PagedListConverter converter = new PagedListConverter() { @Override public Location typeConvert(LocationInner locationInner) { - return new LocationImpl(locationInner, subscriptions); + return new LocationImpl(locationInner, client); } }; - return converter.convert(subscriptions.listLocations(this.subscriptionId()).getBody()); + return converter.convert(client.listLocations(this.subscriptionId()).getBody()); } } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java index dc6c9baa17c8..0a8d1e4f890d 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/SubscriptionsImpl.java @@ -14,12 +14,10 @@ public final class SubscriptionsImpl implements Subscriptions { - private SubscriptionsInner subscriptions; - private SubscriptionClientImpl client; + private final SubscriptionsInner client; - public SubscriptionsImpl(SubscriptionClientImpl client) { + public SubscriptionsImpl(final SubscriptionsInner client) { this.client = client; - this.subscriptions = client.subscriptions(); } @Override @@ -30,13 +28,13 @@ public Subscription typeConvert(SubscriptionInner subscriptionInner) { return new SubscriptionImpl(subscriptionInner, client); } }; - return converter.convert(subscriptions.list().getBody()); + return converter.convert(client.list().getBody()); } @Override // Gets a specific resource group public SubscriptionImpl get(String name) throws CloudException, IOException { - SubscriptionInner subscription = subscriptions.get(name).getBody(); + SubscriptionInner subscription = client.get(name).getBody(); return new SubscriptionImpl(subscription, client); } diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantImpl.java index a89222abaa6d..2bcb6276ec8a 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantImpl.java @@ -9,8 +9,8 @@ public class TenantImpl extends implements Tenant { - public TenantImpl(TenantIdDescriptionInner tenant) { - super(tenant.id(), tenant); + public TenantImpl(TenantIdDescriptionInner innerModel) { + super(innerModel.id(), innerModel); } /*********************************************************** diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java index fb4e4a751a39..2c34d91779d6 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/implementation/TenantsImpl.java @@ -14,12 +14,10 @@ public final class TenantsImpl implements Tenants { - private TenantsInner tenants; - private SubscriptionClientImpl client; + private final TenantsInner client; - public TenantsImpl(SubscriptionClientImpl client) { + public TenantsImpl(final TenantsInner client) { this.client = client; - this.tenants = client.tenants(); } @Override @@ -30,6 +28,6 @@ public Tenant typeConvert(TenantIdDescriptionInner tenantInner) { return new TenantImpl(tenantInner); } }; - return converter.convert(tenants.list().getBody()); + return converter.convert(client.list().getBody()); } } diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java index 4c7fbd6231b3..3f505935ded1 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/DeploymentsTests.java @@ -21,7 +21,7 @@ public class DeploymentsTests extends ResourceManagerTestBase { @BeforeClass public static void setup() throws Exception { createClient(); - resourceGroups = subscription.resourceGroups(); + resourceGroups = resourceClient.resourceGroups(); resourceGroup = resourceGroups.define(rgName) .withLocation(Region.US_SOUTH_CENTRAL) .provision(); @@ -41,7 +41,7 @@ public void canDeployVirtualNetwork() throws Exception { .withParametersLink(parametersUri, contentVersion) .withMode(DeploymentMode.COMPLETE) .provision(); - Deployment deployment = subscription.deployments(rgName).get(deploymentName); + Deployment deployment = resourceClient.deployments().get(rgName, deploymentName); Assert.assertNotNull(deployment); Assert.assertEquals("Succeeded", deployment.provisioningState()); GenericResource generic = connector.genericResources().get("VNet1"); diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java index ae368e8ee468..2c2e9649a27a 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceGroupsTests.java @@ -8,7 +8,7 @@ public class ResourceGroupsTests extends ResourceManagerTestBase { private ResourceGroups resourceGroups; public ResourceGroupsTests() throws Exception { - resourceGroups = subscription.resourceGroups(); + resourceGroups = resourceClient.resourceGroups(); } @Test diff --git a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java index d3cf1bbc0d92..a9256f6abd8e 100644 --- a/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java +++ b/azure-mgmt-resources/src/test/java/com/microsoft/azure/management/resources/ResourceManagerTestBase.java @@ -1,20 +1,18 @@ package com.microsoft.azure.management.resources; import com.microsoft.azure.credentials.ApplicationTokenCredentials; -import com.microsoft.azure.management.resources.implementation.AzureResourceManager; +import com.microsoft.azure.management.resources.implementation.ResourceManager; public abstract class ResourceManagerTestBase { - protected static AzureResourceManager.Authenticated resourceClient; - protected static AzureResourceManager.Subscription subscription; + protected static ResourceManager resourceClient; public static void createClient() throws Exception { - resourceClient = AzureResourceManager.authenticate( + resourceClient = ResourceManager.authenticate( new ApplicationTokenCredentials( System.getenv("arm.clientid"), System.getenv("arm.domain"), System.getenv("arm.secret"), null) - ); - subscription = resourceClient.withSubscription(System.getenv("arm.subscriptionid")); + ).useSubscription(System.getenv("arm.subscriptionid")); } } diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java index 77e88fcc4524..75354e2f0f22 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/StorageAccounts.java @@ -5,13 +5,15 @@ import com.microsoft.azure.management.resources.fluentcore.arm.collection.SupportsListingByGroup; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsCreating; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsDeleting; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsGetting; import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListing; public interface StorageAccounts extends + SupportsCreating, SupportsListing, SupportsListingByGroup, + SupportsGetting, SupportsGettingByGroup, - SupportsCreating, SupportsDeleting, SupportsDeletingByGroup { diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureAuthenticatedImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureAuthenticatedImpl.java deleted file mode 100644 index 954e29ceb376..000000000000 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureAuthenticatedImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.microsoft.azure.management.storage.implementation; - -import com.microsoft.azure.management.resources.ResourceGroups; -import com.microsoft.azure.management.resources.implementation.ResourceGroupsImpl; -import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; -import com.microsoft.azure.management.storage.StorageAccounts; -import com.microsoft.azure.management.storage.Usages; -import com.microsoft.azure.management.storage.implementation.api.StorageManagementClientImpl; -import com.microsoft.rest.RestClient; -import com.microsoft.rest.credentials.ServiceClientCredentials; - -class AzureAuthenticatedImpl - implements AzureStorageManager.Authenticated { - private final RestClient restClient; - private final String subscriptionId; - // The sdk clients - private ResourceManagementClientImpl resourceManagementClient; - private StorageManagementClientImpl storageManagementClient; - // The collections - private StorageAccounts storageAccounts; - private Usages storageUsages; - - AzureAuthenticatedImpl(ServiceClientCredentials credentials, String subscriptionId) { - this.restClient = new RestClient - .Builder("https://management.azure.com") - .withCredentials(credentials) - .build(); - this.subscriptionId = subscriptionId; - } - - AzureAuthenticatedImpl(RestClient restClient, String subscriptionId) { - this.restClient = restClient; - this.subscriptionId = subscriptionId; - } - - @Override - public StorageAccounts storageAccounts() { - if (storageAccounts == null) { - storageAccounts = new StorageAccountsImpl(storageManagementClient().storageAccounts(), resourceGroupsCore()); - } - return storageAccounts; - } - - @Override - public Usages usages() { - if (storageUsages == null) { - storageUsages = new UsagesImpl(storageManagementClient()); - } - return storageUsages; - } - - private ResourceManagementClientImpl resourceManagementClient() { - if (resourceManagementClient == null) { - resourceManagementClient = new ResourceManagementClientImpl(restClient); - resourceManagementClient.setSubscriptionId(subscriptionId); - } - return resourceManagementClient; - } - - private StorageManagementClientImpl storageManagementClient() { - if (storageManagementClient == null) { - storageManagementClient = new StorageManagementClientImpl(restClient); - storageManagementClient.setSubscriptionId(subscriptionId); - } - return storageManagementClient; - } - - private ResourceGroups resourceGroupsCore() { - return new ResourceGroupsImpl(resourceManagementClient()); - } -} diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureConfigureImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureConfigureImpl.java deleted file mode 100644 index 3cff223c3c75..000000000000 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureConfigureImpl.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.microsoft.azure.management.storage.implementation; - -import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigureBaseImpl; -import com.microsoft.rest.credentials.ServiceClientCredentials; - -final class AzureConfigureImpl extends AzureConfigureBaseImpl - implements AzureStorageManager.Configure { - @Override - public AzureStorageManager.Authenticated authenticate(ServiceClientCredentials credentials, String subscriptionId) { - this.restClient = this.restClientBuilder.withCredentials(credentials).build(); - return new AzureAuthenticatedImpl(this.restClient, subscriptionId); - } -} diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureStorageManager.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureStorageManager.java deleted file mode 100644 index 3a8a4f8f3e08..000000000000 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/AzureStorageManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.microsoft.azure.management.storage.implementation; - -import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigureBase; -import com.microsoft.azure.management.storage.StorageAccounts; -import com.microsoft.azure.management.storage.Usages; -import com.microsoft.rest.credentials.ServiceClientCredentials; - -public final class AzureStorageManager { - public static Configure configure() { - return new AzureConfigureImpl(); - } - - public static Authenticated authenticate(ServiceClientCredentials credentials, String subscriptionId) { - return new AzureAuthenticatedImpl(credentials, subscriptionId); - } - - public interface Configure extends AzureConfigureBase { - Authenticated authenticate(ServiceClientCredentials credentials, String subscriptionId); - } - - public interface Authenticated { - StorageAccounts storageAccounts(); - Usages usages(); - } -} diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java index c0b99f68e326..d4ece7cce705 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountImpl.java @@ -28,10 +28,13 @@ public class StorageAccountImpl private final StorageAccountsInner client; - public StorageAccountImpl(String name, StorageAccountInner inner, StorageAccountsInner innerCollection, ResourceGroups resourceGroups) { - super(inner.id(), inner, resourceGroups); + public StorageAccountImpl(String name, + StorageAccountInner innerModel, + final StorageAccountsInner client, + final ResourceGroups resourceGroups) { + super(innerModel.id(), innerModel, resourceGroups); this.name = name; - this.client = innerCollection; + this.client = client; } @Override diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java index 0ba891635e88..ef276e270540 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsImpl.java @@ -23,7 +23,7 @@ public class StorageAccountsImpl private final ResourceGroups resourceGroups; private final PagedListConverter converter; - public StorageAccountsImpl(StorageAccountsInner client, ResourceGroups resourceGroups) { + public StorageAccountsImpl(final StorageAccountsInner client, final ResourceGroups resourceGroups) { this.client = client; this.resourceGroups = resourceGroups; this.converter = new PagedListConverter() { @@ -34,29 +34,46 @@ public StorageAccount typeConvert(StorageAccountInner storageAccountInner) { }; } + @Override public PagedList list() throws CloudException, IOException { ServiceResponse> response = client.list(); return converter.convert(toPagedList(response.getBody())); } + @Override public PagedList list(String groupName) throws CloudException, IOException { ServiceResponse> response = client.listByResourceGroup(groupName); return converter.convert(toPagedList(response.getBody())); } - public StorageAccount get(String groupName, String name) throws Exception { + @Override + public StorageAccount get(String name) throws CloudException, IOException { + ServiceResponse> response = client.list(); + for (StorageAccountInner storageAccountInner : response.getBody()) { + if (storageAccountInner.name() == name) { + return createFluentModel(storageAccountInner); + } + } + return null; + } + + @Override + public StorageAccount get(String groupName, String name) throws CloudException, IOException { ServiceResponse serviceResponse = this.client.getProperties(groupName, name); return createFluentModel(serviceResponse.getBody()); } + @Override public void delete(String id) throws Exception { this.delete(ResourceUtils.groupFromResourceId(id), ResourceUtils.nameFromResourceId(id)); } + @Override public void delete(String groupName, String name) throws Exception { this.client.delete(groupName, name); } + @Override public StorageAccount.DefinitionBlank define(String name) throws Exception { return createFluentModel(name); } diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsInGroupImpl.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsInGroupImpl.java index bd1dde103fcf..83ecab43f41e 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsInGroupImpl.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageAccountsInGroupImpl.java @@ -6,31 +6,30 @@ import com.microsoft.azure.management.storage.StorageAccounts; import com.microsoft.azure.management.storage.StorageAccount; import java.io.IOException; -import java.util.List; // Implementation of storage account collection with a resource group context. // public class StorageAccountsInGroupImpl implements StorageAccounts.InGroup { - private ResourceGroup resourceGroup; - private StorageAccounts storageAccountsCore; + private final StorageAccounts storageAccounts; + private final ResourceGroup resourceGroup; - public StorageAccountsInGroupImpl(StorageAccounts storageAccountsCore, ResourceGroup resourceGroup) { - this.storageAccountsCore = storageAccountsCore; + public StorageAccountsInGroupImpl(final StorageAccounts storageAccounts, final ResourceGroup resourceGroup) { + this.storageAccounts = storageAccounts; this.resourceGroup = resourceGroup; } public StorageAccount.DefinitionProvisionable define(String name) throws Exception { - return storageAccountsCore.define(name) + return storageAccounts.define(name) .withRegion(resourceGroup.location()) .withExistingGroup(resourceGroup.name()); } public void delete(String name) throws Exception { - storageAccountsCore.delete(resourceGroup.name(), name); + storageAccounts.delete(resourceGroup.name(), name); } public PagedList list() throws CloudException, IOException { - return storageAccountsCore.list(resourceGroup.name()); + return storageAccounts.list(resourceGroup.name()); } } diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java new file mode 100644 index 000000000000..9ea772891dd3 --- /dev/null +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageManager.java @@ -0,0 +1,91 @@ +package com.microsoft.azure.management.storage.implementation; + +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.implementation.ResourceManager; +import com.microsoft.azure.management.storage.StorageAccounts; +import com.microsoft.azure.management.storage.Usages; +import com.microsoft.azure.management.storage.implementation.api.StorageManagementClientImpl; +import com.microsoft.rest.RestClient; +import com.microsoft.rest.credentials.ServiceClientCredentials; + +public final class StorageManager { + private RestClient restClient; + private String subscriptionId; + // The service managers + private ResourceManager resourceClient; + // The sdk clients + private StorageManagementClientImpl storageManagementClient; + // The collections + private StorageAccounts storageAccounts; + private Usages storageUsages; + + public static Configurable configurable() { + return new StorageManager().new ConfigurableImpl(); + } + + public static StorageManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + return new StorageManager(credentials, subscriptionId); + } + + public static StorageManager authenticate(RestClient restClient, String subscriptionId) { + return new StorageManager(restClient, subscriptionId); + } + + public interface Configurable extends AzureConfigurable { + StorageManager authenticate(ServiceClientCredentials credentials, String subscriptionId); + } + + class ConfigurableImpl extends AzureConfigurableImpl implements Configurable { + public StorageManager authenticate(ServiceClientCredentials credentials, String subscriptionId) { + buildRestClient(credentials); + return StorageManager.authenticate(restClient, subscriptionId); + } + } + + private StorageManager(ServiceClientCredentials credentials, String subscriptionId) { + this.restClient = new RestClient + .Builder("https://management.azure.com") + .withCredentials(credentials) + .build(); + this.subscriptionId = subscriptionId; + } + + private StorageManager(RestClient restClient, String subscriptionId) { + this.restClient = restClient; + this.subscriptionId = subscriptionId; + } + + private StorageManager() {} + + public StorageAccounts storageAccounts() { + if (storageAccounts == null) { + storageAccounts = new StorageAccountsImpl(storageManagementClient().storageAccounts(), resourceClient().resourceGroups()); + } + return storageAccounts; + } + + public Usages usages() { + if (storageUsages == null) { + storageUsages = new UsagesImpl(storageManagementClient()); + } + return storageUsages; + } + + private StorageManagementClientImpl storageManagementClient() { + if (storageManagementClient == null) { + storageManagementClient = new StorageManagementClientImpl(restClient); + storageManagementClient.setSubscriptionId(subscriptionId); + } + return storageManagementClient; + } + + private ResourceManager resourceClient() { + if (restClient == null) { + resourceClient = ResourceManager + .authenticate(restClient) + .useSubscription(subscriptionId); + } + return resourceClient; + } +} diff --git a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageResourceConnector.java b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageResourceConnector.java index 07b171c10a20..b52a55faf608 100644 --- a/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageResourceConnector.java +++ b/azure-mgmt-storage/src/main/java/com/microsoft/azure/management/storage/implementation/StorageResourceConnector.java @@ -4,51 +4,38 @@ import com.microsoft.azure.management.resources.implementation.ResourceConnectorBase; import com.microsoft.azure.management.resources.ResourceGroup; import com.microsoft.azure.management.storage.StorageAccounts; -import com.microsoft.azure.management.storage.Usages; -import com.microsoft.azure.management.storage.implementation.api.StorageManagementClientImpl; -import com.microsoft.rest.credentials.ServiceClientCredentials; +import com.microsoft.rest.RestClient; public class StorageResourceConnector extends ResourceConnectorBase { - private StorageManagementClientImpl client; + private StorageManager storageClient; private StorageAccounts.InGroup storageAccounts; - private Usages usages; - private StorageResourceConnector(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - super(credentials, subscriptionId, resourceGroup); - constructClient(); + private StorageResourceConnector(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + super(restClient, subscriptionId, resourceGroup); } - private static StorageResourceConnector create(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - return new StorageResourceConnector(credentials, subscriptionId, resourceGroup); - } - - private void constructClient() { - client = new StorageManagementClientImpl(credentials); - client.setSubscriptionId(subscriptionId); + private static StorageResourceConnector create(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + return new StorageResourceConnector(restClient, subscriptionId, resourceGroup); } public static class Builder implements ResourceConnector.Builder { - public StorageResourceConnector create(ServiceClientCredentials credentials, String subscriptionId, ResourceGroup resourceGroup) { - return StorageResourceConnector.create(credentials, subscriptionId, resourceGroup); + public StorageResourceConnector create(RestClient restClient, String subscriptionId, ResourceGroup resourceGroup) { + return StorageResourceConnector.create(restClient, subscriptionId, resourceGroup); } } public StorageAccounts.InGroup storageAccounts() { if (storageAccounts == null) { - this.storageAccounts = new StorageAccountsInGroupImpl(storageAccountsCore(), resourceGroup); + this.storageAccounts = new StorageAccountsInGroupImpl(storageClient().storageAccounts(), resourceGroup); } return storageAccounts; } - public Usages usages() { - if (usages == null) { - this.usages = new UsagesImpl(client); + private StorageManager storageClient() { + if (storageClient == null) { + storageClient = StorageManager + .authenticate(restClient, subscriptionId); } - return usages; - } - - private StorageAccounts storageAccountsCore() { - StorageAccounts storageAccountsCore = new StorageAccountsImpl(this.client.storageAccounts(), resourceGroups()); - return storageAccountsCore; + return storageClient; } } diff --git a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java index c7b2e180cc37..8ed0b23c796f 100644 --- a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java +++ b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageAccountOperationsTests.java @@ -41,10 +41,10 @@ public void getStorageAccountFromResource() throws Exception { .withAccountType(AccountType.PREMIUM_LRS) .provision(); - Usages usages = resourceClient.resourceGroups() + StorageAccounts.InGroup storageAccountsInGroup = resourceClient.resourceGroups() .get("my-rg") .connectToResource(new StorageResourceConnector.Builder()) - .usages(); + .storageAccounts(); } @Test diff --git a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java index 7d506ff8ff8c..b1835be7fe5f 100644 --- a/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java +++ b/azure-mgmt-storage/src/test/java/com/microsoft/azure/management/storage/StorageManagementTestBase.java @@ -1,13 +1,13 @@ package com.microsoft.azure.management.storage; import com.microsoft.azure.credentials.ApplicationTokenCredentials; -import com.microsoft.azure.management.resources.implementation.AzureResourceManager; -import com.microsoft.azure.management.storage.implementation.AzureStorageManager; +import com.microsoft.azure.management.resources.implementation.ResourceManager; +import com.microsoft.azure.management.storage.implementation.StorageManager; +import okhttp3.logging.HttpLoggingInterceptor; public abstract class StorageManagementTestBase { - protected static AzureResourceManager.Authenticated subscriptionClient; - protected static AzureResourceManager.Subscription resourceClient; - protected static AzureStorageManager.Authenticated storageClient; + protected static ResourceManager resourceClient; + protected static StorageManager storageClient; public static void createClients() { ApplicationTokenCredentials credentials = new ApplicationTokenCredentials( @@ -16,9 +16,13 @@ public static void createClients() { System.getenv("arm.secret"), null); - subscriptionClient = AzureResourceManager.authenticate(credentials); - resourceClient = subscriptionClient.withSubscription(System.getenv("arm.subscriptionid")); - storageClient = AzureStorageManager.authenticate(credentials, System.getenv("arm.subscriptionid")); + resourceClient = ResourceManager + .authenticate(credentials) + .useSubscription(System.getenv("arm.subscriptionid")); + + storageClient = StorageManager. + authenticate(credentials, System.getenv("arm.subscriptionid")); + // resourceManagementClient.setLogLevel(HttpLoggingInterceptor.Level.BODY); // storageManagementClient.setLogLevel(HttpLoggingInterceptor.Level.BODY); } diff --git a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java index b37d30a64248..c34f7e0318cb 100644 --- a/azure/src/main/java/com/microsoft/azure/implementation/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/implementation/Azure.java @@ -7,32 +7,37 @@ package com.microsoft.azure.implementation; import com.microsoft.azure.management.compute.AvailabilitySets; +import com.microsoft.azure.management.compute.VirtualMachines; import com.microsoft.azure.management.resources.GenericResources; import com.microsoft.azure.management.resources.Subscriptions; import com.microsoft.azure.management.resources.Tenants; -import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigureBase; +import com.microsoft.azure.management.resources.fluentcore.arm.AzureConfigurable; import com.microsoft.azure.management.resources.fluentcore.collection.*; +import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.management.storage.StorageAccounts; import com.microsoft.azure.management.storage.Usages; +import com.microsoft.rest.RestClient; import com.microsoft.rest.credentials.ServiceClientCredentials; public final class Azure { + private final RestClient restClient; + // The service specific managers + ResourceManager.Authenticated resourceManager; + public static Configure configure() { return new AzureConfigureImpl(); } - public static Authenticated authenticate(ServiceClientCredentials credentials) { - return new AzureAuthenticatedImpl(credentials); + public static Azure authenticate(ServiceClientCredentials credentials) { + return new Azure(credentials); } - public interface Configure extends AzureConfigureBase { - Authenticated authenticate(ServiceClientCredentials credentials); + public static Azure authenticate(RestClient restClient) { + return new Azure(restClient); } - public interface Authenticated { - Subscriptions subscriptions(); - Tenants tenants(); - Subscription withSubscription(String subscriptionId); + public interface Configure extends AzureConfigurable { + Azure authenticate(ServiceClientCredentials credentials); } public interface Subscription { @@ -41,6 +46,7 @@ public interface Subscription { StorageAccounts storageAccounts(); Usages storageUsages(); AvailabilitySets availabilitySets(); + VirtualMachines virtualMachines(); } public interface ResourceGroups extends SupportsListing, @@ -56,4 +62,34 @@ public interface ResourceGroup extends com.microsoft.azure.management.resources. // AvailabilitySetsInGroup availabilitySets(); // VirtualNetworksInGroup virtualNetworks(); } + + private Azure(ServiceClientCredentials credentials) { + this.restClient = new RestClient + .Builder("https://management.azure.com") + .withCredentials(credentials) + .build(); + } + + private Azure(RestClient restClient) { + this.restClient = restClient; + } + + public Subscriptions subscriptions() { + return resourceManager().subscriptions(); + } + + public Tenants tenants() { + return resourceManager().tenants(); + } + + public Azure.Subscription withSubscription(String subscriptionId) { + return new AzureSubscriptionImpl(restClient, subscriptionId); + } + + private ResourceManager.Authenticated resourceManager() { + if (resourceManager == null) { + resourceManager = ResourceManager.authenticate(this.restClient); + } + return resourceManager; + } } diff --git a/azure/src/main/java/com/microsoft/azure/implementation/AzureAuthenticatedImpl.java b/azure/src/main/java/com/microsoft/azure/implementation/AzureAuthenticatedImpl.java deleted file mode 100644 index cf4cf45ed237..000000000000 --- a/azure/src/main/java/com/microsoft/azure/implementation/AzureAuthenticatedImpl.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.implementation; - -import com.microsoft.azure.management.resources.Subscriptions; -import com.microsoft.azure.management.resources.Tenants; -import com.microsoft.azure.management.resources.implementation.api.SubscriptionClientImpl; -import com.microsoft.azure.management.resources.implementation.SubscriptionsImpl; -import com.microsoft.azure.management.resources.implementation.TenantsImpl; -import com.microsoft.rest.RestClient; -import com.microsoft.rest.credentials.ServiceClientCredentials; - -final class AzureAuthenticatedImpl - implements Azure.Authenticated { - private final RestClient restClient; - private SubscriptionClientImpl subscriptionClient; - - AzureAuthenticatedImpl(ServiceClientCredentials credentials) { - this.restClient = new RestClient - .Builder("https://management.azure.com") - .withCredentials(credentials) - .build(); - } - - AzureAuthenticatedImpl(RestClient restClient) { - this.restClient = restClient; - } - - @Override - public Subscriptions subscriptions() { - if (subscriptionClient == null) { - subscriptionClient = new SubscriptionClientImpl(restClient); - } - return new SubscriptionsImpl(subscriptionClient); - } - - @Override - public Tenants tenants() { - if (subscriptionClient == null) { - subscriptionClient = new SubscriptionClientImpl(restClient); - } - return new TenantsImpl(subscriptionClient); - } - - @Override - public Azure.Subscription withSubscription(String subscriptionId) { - return new AzureSubscriptionImpl(restClient, subscriptionId); - } -} diff --git a/azure/src/main/java/com/microsoft/azure/implementation/AzureConfigureImpl.java b/azure/src/main/java/com/microsoft/azure/implementation/AzureConfigureImpl.java index f1bcb877bc14..ec7fce3f1e96 100644 --- a/azure/src/main/java/com/microsoft/azure/implementation/AzureConfigureImpl.java +++ b/azure/src/main/java/com/microsoft/azure/implementation/AzureConfigureImpl.java @@ -1,15 +1,15 @@ package com.microsoft.azure.implementation; -import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigureBaseImpl; +import com.microsoft.azure.management.resources.fluentcore.arm.implementation.AzureConfigurableImpl; import com.microsoft.rest.credentials.ServiceClientCredentials; -final class AzureConfigureImpl extends AzureConfigureBaseImpl +final class AzureConfigureImpl extends AzureConfigurableImpl implements Azure.Configure { AzureConfigureImpl() {} @Override - public Azure.Authenticated authenticate(ServiceClientCredentials credentials) { + public Azure authenticate(ServiceClientCredentials credentials) { this.restClient = this.restClientBuilder.withCredentials(credentials).build(); - return new AzureAuthenticatedImpl(this.restClient); + return Azure.authenticate(this.restClient); } } diff --git a/azure/src/main/java/com/microsoft/azure/implementation/AzureSubscriptionImpl.java b/azure/src/main/java/com/microsoft/azure/implementation/AzureSubscriptionImpl.java index 74328c440e7e..10e08c482f2e 100644 --- a/azure/src/main/java/com/microsoft/azure/implementation/AzureSubscriptionImpl.java +++ b/azure/src/main/java/com/microsoft/azure/implementation/AzureSubscriptionImpl.java @@ -8,33 +8,28 @@ import com.microsoft.azure.management.compute.AvailabilitySets; import com.microsoft.azure.management.compute.VirtualMachines; -import com.microsoft.azure.management.compute.implementation.AvailabilitySetsImpl; -import com.microsoft.azure.management.compute.implementation.api.ComputeManagementClientImpl; +import com.microsoft.azure.management.compute.implementation.ComputeManager; import com.microsoft.azure.management.resources.GenericResources; -import com.microsoft.azure.management.resources.ResourceGroups; +import com.microsoft.azure.management.resources.implementation.ResourceManager; import com.microsoft.azure.management.resources.implementation.api.ResourceManagementClientImpl; -import com.microsoft.azure.management.resources.implementation.GenericResourcesImpl; -import com.microsoft.azure.management.resources.implementation.ResourceGroupsImpl; import com.microsoft.azure.management.storage.StorageAccounts; import com.microsoft.azure.management.storage.Usages; -import com.microsoft.azure.management.storage.implementation.StorageAccountsImpl; -import com.microsoft.azure.management.storage.implementation.UsagesImpl; -import com.microsoft.azure.management.storage.implementation.api.StorageManagementClientImpl; +import com.microsoft.azure.management.storage.implementation.StorageManager; import com.microsoft.rest.RestClient; final class AzureSubscriptionImpl implements Azure.Subscription { private final String subscriptionId; private final RestClient restClient; + // service specific managers in subscription level. + private ResourceManager resourceClient; + private StorageManager storageClient; + private ComputeManager computeClient; // SDK Clients + // TODO: Get rid of these private ResourceManagementClientImpl resourceManagementClient; - private StorageManagementClientImpl storageManagementClient; - private ComputeManagementClientImpl computeManagementClient; // Fluent Collections private Azure.ResourceGroups azureResourceGroups; - private GenericResources genericResources; - private StorageAccounts storageAccounts; - private Usages storageUsages; private AvailabilitySets availabilitySets; AzureSubscriptionImpl(RestClient restClient, String subscriptionId) { @@ -52,66 +47,59 @@ public Azure.ResourceGroups resourceGroups() { @Override public GenericResources genericResources() { - if (genericResources == null) { - genericResources = new GenericResourcesImpl(resourceManagementClient()); - } - return genericResources; + return resourceClient().genericResources(); } @Override public StorageAccounts storageAccounts() { - if (storageAccounts == null) { - storageAccounts = new StorageAccountsImpl(storageManagementClient().storageAccounts(), resourceGroupsCore()); - } - return storageAccounts; + return storageClient().storageAccounts(); } @Override public Usages storageUsages() { - if (storageUsages == null) { - storageUsages = new UsagesImpl(storageManagementClient()); - } - return storageUsages; + return storageClient().usages(); } @Override public AvailabilitySets availabilitySets() { - if (availabilitySets == null) { - availabilitySets = new AvailabilitySetsImpl(computeManagementClient().availabilitySets(), resourceGroupsCore(), virtualMachines()); - } - return availabilitySets; + return computeClient().availabilitySets(); } + @Override public VirtualMachines virtualMachines() { - // TODO - return null; + return computeClient().virtualMachines(); } - private ResourceManagementClientImpl resourceManagementClient() { - if (resourceManagementClient == null) { - resourceManagementClient = new ResourceManagementClientImpl(restClient); - resourceManagementClient.setSubscriptionId(subscriptionId); + private ResourceManager resourceClient() { + if (resourceClient == null) { + resourceClient = ResourceManager + .authenticate(restClient) + .useSubscription(subscriptionId); } - return resourceManagementClient; + return resourceClient; } - private StorageManagementClientImpl storageManagementClient() { - if (storageManagementClient == null) { - storageManagementClient = new StorageManagementClientImpl(restClient); - storageManagementClient.setSubscriptionId(subscriptionId); + private StorageManager storageClient() { + if (storageClient == null) { + storageClient = StorageManager + .authenticate(restClient, subscriptionId); } - return storageManagementClient; + return storageClient; } - private ComputeManagementClientImpl computeManagementClient() { - if (computeManagementClient == null) { - computeManagementClient = new ComputeManagementClientImpl(restClient); - computeManagementClient.setSubscriptionId(subscriptionId); + private ComputeManager computeClient() { + if (computeClient == null) { + computeClient = ComputeManager + .authenticate(restClient, subscriptionId); } - return computeManagementClient; + return computeClient; } - private ResourceGroups resourceGroupsCore() { - return new ResourceGroupsImpl(resourceManagementClient()); + private ResourceManagementClientImpl resourceManagementClient() { + if (resourceManagementClient == null) { + resourceManagementClient = new ResourceManagementClientImpl(restClient); + resourceManagementClient.setSubscriptionId(subscriptionId); + } + return resourceManagementClient; } } diff --git a/azure/src/test/java/com/microsoft/azure/AzureTests.java b/azure/src/test/java/com/microsoft/azure/AzureTests.java index 11cc6e6fea11..212a3920e276 100644 --- a/azure/src/test/java/com/microsoft/azure/AzureTests.java +++ b/azure/src/test/java/com/microsoft/azure/AzureTests.java @@ -20,7 +20,7 @@ public class AzureTests { System.getenv("domain"), System.getenv("secret"), AzureEnvironment.AZURE); - private static final String subscriptionId = System.getenv("subscription-id"); + private static final String subscriptionId = System.getenv("resourceClient-id"); private Subscriptions subscriptions; private Azure.ResourceGroups resourceGroups; @@ -28,7 +28,7 @@ public class AzureTests { @Before public void setup() throws Exception { - Azure.Authenticated azure = Azure.configure() + Azure azure = Azure.configure() .withLogLevel(HttpLoggingInterceptor.Level.BASIC) .withUserAgent("AzureTests") .authenticate(credentials);