Skip to content

Commit

Permalink
Merge pull request Azure#1251 from anuchandy/usage
Browse files Browse the repository at this point in the history
adding usage entry point for compute and network
  • Loading branch information
Martin Sawicki authored Oct 28, 2016
2 parents ece6b15 + 6b0986b commit faca7a5
Show file tree
Hide file tree
Showing 16 changed files with 500 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<UsageInner> {
/**
* @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();
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ComputeUsage> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ public final class ComputeManager extends Manager<ComputeManager, ComputeManagem
private VirtualMachineImages virtualMachineImages;
private VirtualMachineExtensionImages virtualMachineExtensionImages;
private VirtualMachineScaleSets virtualMachineScaleSets;
private ComputeUsages computeUsages;

/**
* Get a Configurable instance that can be used to create ComputeManager with optional configuration.
Expand Down Expand Up @@ -154,4 +156,14 @@ public VirtualMachineScaleSets virtualMachineScaleSets() {
}
return virtualMachineScaleSets;
}

/**
* @return the compute resource usage management API entry point
*/
public ComputeUsages usages() {
if (computeUsages == null) {
computeUsages = new ComputeUsagesImpl(super.innerManagementClient);
}
return computeUsages;
}
}
Original file line number Diff line number Diff line change
@@ -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.compute.implementation;

import com.microsoft.azure.management.compute.ComputeUsage;
import com.microsoft.azure.management.compute.ComputeUsageUnit;
import com.microsoft.azure.management.compute.UsageName;
import com.microsoft.azure.management.resources.fluentcore.model.implementation.WrapperImpl;

/**
* The implementation of {@link ComputeUsage}.
*/
class ComputeUsageImpl extends WrapperImpl<UsageInner> 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();
}
}

Original file line number Diff line number Diff line change
@@ -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<ComputeUsage, ComputeUsageImpl, UsageInner>
implements ComputeUsages {
private final ComputeManagementClientImpl client;

ComputeUsagesImpl(ComputeManagementClientImpl client) {
this.client = client;
}

@Override
public PagedList<ComputeUsage> listByRegion(Region region) {
return listByRegion(region.name());
}

@Override
public PagedList<ComputeUsage> listByRegion(String regionName) {
return wrapList(client.usages().list(regionName));
}

@Override
protected ComputeUsageImpl wrapModel(UsageInner usageInner) {
if (usageInner == null) {
return null;
}
return new ComputeUsageImpl(usageInner);
}
}
Original file line number Diff line number Diff line change
@@ -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<ComputeUsage> usages = computeManager.usages().listByRegion(Region.US_EAST);
Assert.assertTrue(usages.size() > 0);
}
}
Original file line number Diff line number Diff line change
@@ -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<UsageInner> {
/**
* @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();
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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<NetworkUsage> {
}
Loading

0 comments on commit faca7a5

Please sign in to comment.