diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsage.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsage.java new file mode 100644 index 0000000000000..c917c028b3325 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsage.java @@ -0,0 +1,37 @@ +/** + * 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.compute; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.compute.implementation.UsageInner; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +/** + * An immutable client-side representation of an Azure compute resource usage info object. + */ +@Fluent +public interface ComputeUsage extends Wrapper { + /** + * @return the unit of measurement. + */ + ComputeUsageUnit unit(); + + /** + * @return the current count of the allocated resources in the subscription + */ + int currentValue(); + + /** + * @return the maximum count of the resources that can be allocated in the + * subscription + */ + int limit(); + + /** + * @return the name of the type of usage + */ + UsageName name(); +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsageUnit.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsageUnit.java new file mode 100644 index 0000000000000..4c0dfb658fccc --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsageUnit.java @@ -0,0 +1,69 @@ +/** + * 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.compute; + +/** + * Compute usage units. + */ +public class ComputeUsageUnit { + /** Static value Count for ComputeUsageUnit. */ + public static final ComputeUsageUnit COUNT = new ComputeUsageUnit("Count"); + + /** Static value Bytes for ComputeUsageUnit. */ + public static final ComputeUsageUnit BYTES = new ComputeUsageUnit("Bytes"); + + /** Static value Seconds for ComputeUsageUnit. */ + public static final ComputeUsageUnit SECONDS = new ComputeUsageUnit("Seconds"); + + /** Static value Percent for ComputeUsageUnit. */ + public static final ComputeUsageUnit PERCENT = new ComputeUsageUnit("Percent"); + + /** Static value CountsPerSecond for ComputeUsageUnit. */ + public static final ComputeUsageUnit COUNTS_PER_SECOND = new ComputeUsageUnit("CountsPerSecond"); + + /** Static value BytesPerSecond for ComputeUsageUnit. */ + public static final ComputeUsageUnit BYTES_PER_SECOND = new ComputeUsageUnit("BytesPerSecond"); + + /** + * The string value of the compute usage unit. + */ + private final String value; + + /** + * Creates a custom value for ComputeUsageUnit. + * @param value the custom value + */ + public ComputeUsageUnit(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.value; + } + + @Override + public int hashCode() { + return this.value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + String value = this.toString(); + if (!(obj instanceof ComputeUsageUnit)) { + return false; + } + if (obj == this) { + return true; + } + ComputeUsageUnit rhs = (ComputeUsageUnit) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsages.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsages.java new file mode 100644 index 0000000000000..bf55ec1c6decf --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/ComputeUsages.java @@ -0,0 +1,16 @@ +/** + * 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.compute; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListingByRegion; + +/** + * Entry point for compute resource usage management API. + */ +@Fluent +public interface ComputeUsages extends SupportsListingByRegion { +} 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 index ed7e18586ff34..a0de186b43f44 100644 --- 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 @@ -3,6 +3,7 @@ import com.microsoft.azure.RestClient; import com.microsoft.azure.credentials.AzureTokenCredentials; import com.microsoft.azure.management.compute.AvailabilitySets; +import com.microsoft.azure.management.compute.ComputeUsages; import com.microsoft.azure.management.compute.VirtualMachineExtensionImages; import com.microsoft.azure.management.compute.VirtualMachineImages; import com.microsoft.azure.management.compute.VirtualMachineScaleSets; @@ -26,6 +27,7 @@ public final class ComputeManager extends Manager implements ComputeUsage { + ComputeUsageImpl(UsageInner innerObject) { + super(innerObject); + } + + @Override + public ComputeUsageUnit unit() { + return new ComputeUsageUnit(inner().unit()); + } + + @Override + public int currentValue() { + return inner().currentValue(); + } + + @Override + public int limit() { + return (int) inner().limit(); + } + + @Override + public UsageName name() { + return inner().name(); + } +} + diff --git a/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeUsagesImpl.java b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeUsagesImpl.java new file mode 100644 index 0000000000000..85132a0419c40 --- /dev/null +++ b/azure-mgmt-compute/src/main/java/com/microsoft/azure/management/compute/implementation/ComputeUsagesImpl.java @@ -0,0 +1,42 @@ +/** + * 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.compute.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.compute.ComputeUsage; +import com.microsoft.azure.management.compute.ComputeUsages; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * The implementation of {@link ComputeUsages}. + */ +class ComputeUsagesImpl extends ReadableWrappersImpl + implements ComputeUsages { + private final ComputeManagementClientImpl client; + + ComputeUsagesImpl(ComputeManagementClientImpl client) { + this.client = client; + } + + @Override + public PagedList listByRegion(Region region) { + return listByRegion(region.name()); + } + + @Override + public PagedList listByRegion(String regionName) { + return wrapList(client.usages().list(regionName)); + } + + @Override + protected ComputeUsageImpl wrapModel(UsageInner usageInner) { + if (usageInner == null) { + return null; + } + return new ComputeUsageImpl(usageInner); + } +} \ No newline at end of file diff --git a/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeUsageOperationsTests.java b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeUsageOperationsTests.java new file mode 100644 index 0000000000000..f7997998d3f45 --- /dev/null +++ b/azure-mgmt-compute/src/test/java/com/microsoft/azure/management/compute/ComputeUsageOperationsTests.java @@ -0,0 +1,26 @@ +package com.microsoft.azure.management.compute; + +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +public class ComputeUsageOperationsTests extends ComputeManagementTestBase { + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + } + + @Test + public void canListComputeUsages() throws Exception { + List usages = computeManager.usages().listByRegion(Region.US_EAST); + Assert.assertTrue(usages.size() > 0); + } +} diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsage.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsage.java new file mode 100644 index 0000000000000..987b0cb6735ca --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsage.java @@ -0,0 +1,37 @@ +/** + * 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.network; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.network.implementation.UsageInner; +import com.microsoft.azure.management.resources.fluentcore.model.Wrapper; + +/** + * An immutable client-side representation of an Azure compute resource usage info object. + */ +@Fluent +public interface NetworkUsage extends Wrapper { + /** + * @return the unit of measurement. + */ + NetworkUsageUnit unit(); + + /** + * @return the current count of the allocated resources in the subscription + */ + int currentValue(); + + /** + * @return the maximum count of the resources that can be allocated in the + * subscription + */ + int limit(); + + /** + * @return the name of the type of usage + */ + UsageName name(); +} diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsageUnit.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsageUnit.java new file mode 100644 index 0000000000000..2f3c39d379771 --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsageUnit.java @@ -0,0 +1,69 @@ +/** + * 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.network; + +/** + * Netowrk usage units. + */ +public class NetworkUsageUnit { + /** Static value Count for NetworkUsageUnit. */ + public static final NetworkUsageUnit COUNT = new NetworkUsageUnit("Count"); + + /** Static value Bytes for NetworkUsageUnit. */ + public static final NetworkUsageUnit BYTES = new NetworkUsageUnit("Bytes"); + + /** Static value Seconds for NetworkUsageUnit. */ + public static final NetworkUsageUnit SECONDS = new NetworkUsageUnit("Seconds"); + + /** Static value Percent for NetworkUsageUnit. */ + public static final NetworkUsageUnit PERCENT = new NetworkUsageUnit("Percent"); + + /** Static value CountsPerSecond for NetworkUsageUnit. */ + public static final NetworkUsageUnit COUNTS_PER_SECOND = new NetworkUsageUnit("CountsPerSecond"); + + /** Static value BytesPerSecond for ComputeUsageUnit. */ + public static final NetworkUsageUnit BYTES_PER_SECOND = new NetworkUsageUnit("BytesPerSecond"); + + /** + * The string value of the network usage unit. + */ + private final String value; + + /** + * Creates a custom value for NetworkUsageUnit. + * @param value the custom value + */ + public NetworkUsageUnit(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.value; + } + + @Override + public int hashCode() { + return this.value.hashCode(); + } + + @Override + public boolean equals(Object obj) { + String value = this.toString(); + if (!(obj instanceof NetworkUsageUnit)) { + return false; + } + if (obj == this) { + return true; + } + NetworkUsageUnit rhs = (NetworkUsageUnit) obj; + if (value == null) { + return rhs.value == null; + } else { + return value.equals(rhs.value); + } + } +} diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsages.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsages.java new file mode 100644 index 0000000000000..82ca53b541f64 --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/NetworkUsages.java @@ -0,0 +1,11 @@ +package com.microsoft.azure.management.network; + +import com.microsoft.azure.management.apigeneration.Fluent; +import com.microsoft.azure.management.resources.fluentcore.collection.SupportsListingByRegion; + +/** + * Entry point for network resource usage management API. + */ +@Fluent +public interface NetworkUsages extends SupportsListingByRegion { +} diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java index e9a218f52b4da..516e9249b7c56 100644 --- a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkManager.java @@ -17,6 +17,7 @@ import com.microsoft.azure.management.network.Network; import com.microsoft.azure.management.network.NetworkInterfaces; import com.microsoft.azure.management.network.NetworkSecurityGroups; +import com.microsoft.azure.management.network.NetworkUsages; import com.microsoft.azure.management.network.Networks; import com.microsoft.azure.management.network.PublicIpAddresses; import com.microsoft.azure.management.network.RouteTables; @@ -38,6 +39,7 @@ public final class NetworkManager extends Manager listAssociatedSubnets(List subnetRefs) { final Map networks = new HashMap<>(); diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkUsageImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkUsageImpl.java new file mode 100644 index 0000000000000..27fc0bdf7a337 --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkUsageImpl.java @@ -0,0 +1,41 @@ +/** + * 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.network.implementation; + +import com.microsoft.azure.management.network.NetworkUsage; +import com.microsoft.azure.management.network.NetworkUsageUnit; +import com.microsoft.azure.management.network.UsageName; +import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl; + +/** + * The implementation of {@link NetworkUsage}. + */ +class NetworkUsageImpl extends WrapperImpl implements NetworkUsage { + NetworkUsageImpl(UsageInner innerObject) { + super(innerObject); + } + + @Override + public NetworkUsageUnit unit() { + return new NetworkUsageUnit(inner().unit()); + } + + @Override + public int currentValue() { + return (int) inner().currentValue(); + } + + @Override + public int limit() { + return (int) inner().limit(); + } + + @Override + public UsageName name() { + return inner().name(); + } +} + diff --git a/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkUsagesImpl.java b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkUsagesImpl.java new file mode 100644 index 0000000000000..d16b37e35f799 --- /dev/null +++ b/azure-mgmt-network/src/main/java/com/microsoft/azure/management/network/implementation/NetworkUsagesImpl.java @@ -0,0 +1,42 @@ +/** + * 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.network.implementation; + +import com.microsoft.azure.PagedList; +import com.microsoft.azure.management.network.NetworkUsage; +import com.microsoft.azure.management.network.NetworkUsages; +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl; + +/** + * The implementation of {@link NetworkUsages}. + */ +class NetworkUsagesImpl extends ReadableWrappersImpl + implements NetworkUsages { + private final NetworkManagementClientImpl client; + + NetworkUsagesImpl(NetworkManagementClientImpl client) { + this.client = client; + } + + @Override + public PagedList listByRegion(Region region) { + return listByRegion(region.name()); + } + + @Override + public PagedList listByRegion(String regionName) { + return wrapList(client.usages().list(regionName)); + } + + @Override + protected NetworkUsageImpl wrapModel(UsageInner usageInner) { + if (usageInner == null) { + return null; + } + return new NetworkUsageImpl(usageInner); + } +} \ No newline at end of file diff --git a/azure-mgmt-network/src/test/java/com/microsoft/azure/management/network/NetworkManagementTestBase.java b/azure-mgmt-network/src/test/java/com/microsoft/azure/management/network/NetworkManagementTestBase.java index 23863382f6bb3..8fcda6c2a7978 100644 --- a/azure-mgmt-network/src/test/java/com/microsoft/azure/management/network/NetworkManagementTestBase.java +++ b/azure-mgmt-network/src/test/java/com/microsoft/azure/management/network/NetworkManagementTestBase.java @@ -5,6 +5,7 @@ import com.microsoft.azure.credentials.ApplicationTokenCredentials; import com.microsoft.azure.management.network.implementation.NetworkManager; import com.microsoft.azure.management.resources.implementation.ResourceManager; +import okhttp3.logging.HttpLoggingInterceptor; public abstract class NetworkManagementTestBase { protected static ResourceManager resourceManager; @@ -15,12 +16,12 @@ public static void createClients() { System.getenv("client-id"), System.getenv("domain"), System.getenv("secret"), - null); + AzureEnvironment.AZURE); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials) - //.withLogLevel(HttpLoggingInterceptor.Level.BASIC) + .withLogLevel(HttpLoggingInterceptor.Level.BODY) .build(); resourceManager = ResourceManager diff --git a/azure-mgmt-network/src/test/java/com/microsoft/azure/management/network/NetworkUsageOperationsTests.java b/azure-mgmt-network/src/test/java/com/microsoft/azure/management/network/NetworkUsageOperationsTests.java new file mode 100644 index 0000000000000..afbb363fdbe4a --- /dev/null +++ b/azure-mgmt-network/src/test/java/com/microsoft/azure/management/network/NetworkUsageOperationsTests.java @@ -0,0 +1,26 @@ +package com.microsoft.azure.management.network; + +import com.microsoft.azure.management.resources.fluentcore.arm.Region; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +public class NetworkUsageOperationsTests extends NetworkManagementTestBase { + @BeforeClass + public static void setup() throws Exception { + createClients(); + } + + @AfterClass + public static void cleanup() throws Exception { + } + + @Test + public void canListNetworkUsages() throws Exception { + List usages = networkManager.usages().listByRegion(Region.US_EAST); + Assert.assertTrue(usages.size() > 0); + } +} diff --git a/azure/src/main/java/com/microsoft/azure/management/Azure.java b/azure/src/main/java/com/microsoft/azure/management/Azure.java index 0bf89a750fc52..4c563bad3d12a 100644 --- a/azure/src/main/java/com/microsoft/azure/management/Azure.java +++ b/azure/src/main/java/com/microsoft/azure/management/Azure.java @@ -14,6 +14,7 @@ import com.microsoft.azure.management.batch.BatchAccounts; import com.microsoft.azure.management.batch.implementation.BatchManager; import com.microsoft.azure.management.compute.AvailabilitySets; +import com.microsoft.azure.management.compute.ComputeUsages; import com.microsoft.azure.management.compute.VirtualMachineImages; import com.microsoft.azure.management.compute.VirtualMachineScaleSets; import com.microsoft.azure.management.compute.VirtualMachines; @@ -23,6 +24,7 @@ import com.microsoft.azure.management.network.LoadBalancers; import com.microsoft.azure.management.network.NetworkInterfaces; import com.microsoft.azure.management.network.NetworkSecurityGroups; +import com.microsoft.azure.management.network.NetworkUsages; import com.microsoft.azure.management.network.Networks; import com.microsoft.azure.management.network.PublicIpAddresses; import com.microsoft.azure.management.network.RouteTables; @@ -376,6 +378,13 @@ public NetworkSecurityGroups networkSecurityGroups() { return networkManager.networkSecurityGroups(); } + /** + * @return entry point to managing network resource usages + */ + public NetworkUsages networkUsages() { + return networkManager.usages(); + } + /** * @return entry point to managing virtual machines */ @@ -411,6 +420,13 @@ public NetworkInterfaces networkInterfaces() { return this.networkManager.networkInterfaces(); } + /** + * @return entry point to managing compute resource usages + */ + public ComputeUsages computeUsages() { + return computeManager.usages(); + } + /** * @return entry point to managing key vaults */