From cd79c1464e12746faaf4ee9f2a8e6052791a4c7b Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 21 Oct 2016 15:46:24 -0700 Subject: [PATCH 1/2] Make region expandable and fix gov region name --- .../resources/fluentcore/arm/Region.java | 132 +++++++++++++----- 1 file changed, 98 insertions(+), 34 deletions(-) diff --git a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java index 405a0bc196e2..f461d0cd90bf 100644 --- a/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java +++ b/azure-mgmt-resources/src/main/java/com/microsoft/azure/management/resources/fluentcore/arm/Region.java @@ -6,73 +6,120 @@ package com.microsoft.azure.management.resources.fluentcore.arm; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + /** * Enumeration of the Azure datacenter regions. See https://azure.microsoft.com/regions/ */ -public enum Region { +public class Region { // CHECKSTYLE IGNORE Javadoc FOR NEXT 48 LINES /************************************************** * Azure Cloud - Americas **************************************************/ - US_WEST("westus", "West US"), - US_WEST2("westus2", "West US 2"), - US_CENTRAL("centralus", "Central US"), - US_EAST("eastus", "East US"), - US_EAST2("eastus2", "East US 2"), - US_NORTH_CENTRAL("northcentralus", "North Central US"), - US_SOUTH_CENTRAL("southcentralus", "South Central US"), - US_WEST_CENTRAL("westcentralus", "West Central US"), - CANADA_CENTRAL("canadacentral", "Canada Central"), - CANADA_EAST("canadaeast", "Canada East"), - BRAZIL_SOUTH("brazilsouth", "Brazil South"), + public static final Region US_WEST = new Region("westus", "West US"); + public static final Region US_WEST2 = new Region("westus2", "West US 2"); + public static final Region US_CENTRAL = new Region("centralus", "Central US"); + public static final Region US_EAST = new Region("eastus", "East US"); + public static final Region US_EAST2 = new Region("eastus2", "East US 2"); + public static final Region US_NORTH_CENTRAL = new Region("northcentralus", "North Central US"); + public static final Region US_SOUTH_CENTRAL = new Region("southcentralus", "South Central US"); + public static final Region US_WEST_CENTRAL = new Region("westcentralus", "West Central US"); + public static final Region CANADA_CENTRAL = new Region("canadacentral", "Canada Central"); + public static final Region CANADA_EAST = new Region("canadaeast", "Canada East"); + public static final Region BRAZIL_SOUTH = new Region("brazilsouth", "Brazil South"); /************************************************** * Azure Cloud - Europe **************************************************/ - EUROPE_NORTH("northeurope", "North Europe"), - EUROPE_WEST("westeurope", "West Europe"), - UK_SOUTH("uksouth", "UK South"), - UK_WEST("ukwest", "UK West"), + public static final Region EUROPE_NORTH = new Region("northeurope", "North Europe"); + public static final Region EUROPE_WEST = new Region("westeurope", "West Europe"); + public static final Region UK_SOUTH = new Region("uksouth", "UK South"); + public static final Region UK_WEST = new Region("ukwest", "UK West"); /************************************************** * Azure Cloud - Asia **************************************************/ - ASIA_EAST("eastasia", "East Asia"), - ASIA_SOUTHEAST("southeastasia", "South East Asia"), - JAPAN_EAST("japaneast", "Japan East"), - JAPAN_WEST("japanwest", "Japan West"), - AUSTRALIA_EAST("australiaeast", "Australia East"), - AUSTRALIA_SOUTHEAST("australiasoutheast", "Australia Southeast"), - INDIA_CENTRAL("centralindia", "Central India"), - INDIA_SOUTH("southindia", "South India"), - INDIA_WEST("westindia", "West India"), + public static final Region ASIA_EAST = new Region("eastasia", "East Asia"); + public static final Region ASIA_SOUTHEAST = new Region("southeastasia", "South East Asia"); + public static final Region JAPAN_EAST = new Region("japaneast", "Japan East"); + public static final Region JAPAN_WEST = new Region("japanwest", "Japan West"); + public static final Region AUSTRALIA_EAST = new Region("australiaeast", "Australia East"); + public static final Region AUSTRALIA_SOUTHEAST = new Region("australiasoutheast", "Australia Southeast"); + public static final Region INDIA_CENTRAL = new Region("centralindia", "Central India"); + public static final Region INDIA_SOUTH = new Region("southindia", "South India"); + public static final Region INDIA_WEST = new Region("westindia", "West India"); /************************************************** * Azure China Cloud **************************************************/ - CHINA_NORTH("chinanorth", "China North"), - CHINA_EAST("chinaeast", "China East"), + public static final Region CHINA_NORTH = new Region("chinanorth", "China North"); + public static final Region CHINA_EAST = new Region("chinaeast", "China East"); /************************************************** * Azure German Cloud **************************************************/ - GERMANY_CENTRAL("germanycentral", "Germany Central"), - GERMANY_NORTHEAST("germanynortheast", "Germany Northeast"), + public static final Region GERMANY_CENTRAL = new Region("germanycentral", "Germany Central"); + public static final Region GERMANY_NORTHEAST = new Region("germanynortheast", "Germany Northeast"); /************************************************** * Azure Government Cloud **************************************************/ - GOV_US_VIRGINIA("usgoveast", "US Gov Virginia"), - GOV_US_IOWA("usgovcentral", "US Gov Iowa"); + public static final Region GOV_US_VIRGINIA = new Region("usgovvirginia", "US Gov Virginia"); + public static final Region GOV_US_IOWA = new Region("usgoviowa", "US Gov Iowa"); + + private static final List VALUES; private final String name; private final String label; - Region(String name, String label) { + static { + Field[] declaredFields = Region.class.getDeclaredFields(); + List values = new ArrayList<>(); + for (Field field : declaredFields) { + if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { + field.setAccessible(true); + try { + values.add((Region) field.get(null)); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + } + VALUES = Collections.unmodifiableList(values); + } + + /** + * Create a region from a name and a label. + * + * @param name the uniquely identifiable name of the region + * @param label the label of the region + */ + public Region(String name, String label) { this.name = name; this.label = label; } + @JsonValue @Override public String toString() { + return name(); + } + + /** + * @return the name of the region + */ + public String name() { return this.name; } + /** + * @return the label of the region + */ + public String label() { + return this.label; + } + /** * Parses a label into a Region object. * @@ -80,7 +127,7 @@ public String toString() { * @return the parsed region or null if there's no such region */ public static Region fromLabel(String label) { - for (Region region : Region.values()) { + for (Region region : Region.VALUES) { if (region.label.equalsIgnoreCase(label)) { return region; } @@ -95,11 +142,28 @@ public static Region fromLabel(String label) { * @return the parsed region or null if there's no such region */ public static Region fromName(String name) { - for (Region region : Region.values()) { + for (Region region : Region.VALUES) { if (region.name.equalsIgnoreCase(name)) { return region; } } return null; } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Region)) { + return false; + } + if (obj == this) { + return true; + } + Region rhs = (Region) obj; + return name.equalsIgnoreCase(rhs.name); + } } From ebf1311282fbc7997b0976ea39e606799cbd9bf5 Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Fri, 21 Oct 2016 14:41:08 -0700 Subject: [PATCH 2/2] Fix redis snapshot version --- azure-mgmt-redis/pom.xml | 3 +-- azure/pom.xml | 10 +++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/azure-mgmt-redis/pom.xml b/azure-mgmt-redis/pom.xml index cec7bec26e89..f03cfa690bc4 100644 --- a/azure-mgmt-redis/pom.xml +++ b/azure-mgmt-redis/pom.xml @@ -12,7 +12,6 @@ azure-mgmt-redis jar - 1.0.0-SNAPSHOT Microsoft Azure SDK for Redis Cache Management This package contains Microsoft Azure Redis Cache SDK. @@ -132,4 +131,4 @@ - \ No newline at end of file + diff --git a/azure/pom.xml b/azure/pom.xml index 1bc623749f6e..6ca6f54b193c 100644 --- a/azure/pom.xml +++ b/azure/pom.xml @@ -99,6 +99,11 @@ azure-mgmt-dns 1.0.0-beta4-SNAPSHOT + + com.microsoft.azure + azure-mgmt-redis + 1.0.0-beta4-SNAPSHOT + junit junit @@ -121,11 +126,6 @@ api-annotations 0.0.1 - - com.microsoft.azure - azure-mgmt-redis - 1.0.0-SNAPSHOT -