Skip to content

Commit

Permalink
changing .region() on all resources to return the enum and adding .re…
Browse files Browse the repository at this point in the history
…gionName() to return the String

this way, .region() will return the more intuitive/discoverable strongly types enum constant, but in case someone cares about handling a future region that's not currently in the constant, they can fall back on .regionName().
With the latter point in mind, this change does NOT change the internal use of region, i.e. I first renamed previously existing .region() to .regionName() and did not change the automatically refactored existing impls to refer to teh new .region(), but kept them as referring to .regionName().
  • Loading branch information
unknown authored and unknown committed Jun 25, 2016
1 parent 21d7469 commit 06638ea
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public VirtualMachineImpl withNewStorageAccount(String name) {
StorageAccount.DefinitionWithGroup definitionWithGroup = this.storageManager
.storageAccounts()
.define(name)
.withRegion(this.region());
.withRegion(this.regionName());
StorageAccount.DefinitionCreatable definitionAfterGroup;
if (this.newGroup != null) {
definitionAfterGroup = definitionWithGroup.withNewGroup(this.newGroup);
Expand Down Expand Up @@ -608,7 +608,7 @@ public VirtualMachineImpl withNewAvailabilitySet(AvailabilitySet.DefinitionCreat
@Override
public VirtualMachineImpl withNewAvailabilitySet(String name) {
return withNewAvailabilitySet(super.myManager.availabilitySets().define(name)
.withRegion(region())
.withRegion(regionName())
.withExistingGroup(this.resourceGroupName())
);
}
Expand Down Expand Up @@ -963,7 +963,7 @@ private void handleStorageSettings() throws Exception {
|| dataDisksRequiresImplicitStorageAccountCreation()) {
storageAccount = this.storageManager.storageAccounts()
.define(this.namer.randomName("stg", 24))
.withRegion(this.region())
.withRegion(this.regionName())
.withExistingGroup(this.resourceGroupName())
.create();
}
Expand Down Expand Up @@ -1024,7 +1024,7 @@ public void success(ServiceResponse<StorageAccount> result) {
|| dataDisksRequiresImplicitStorageAccountCreation()) {
this.storageManager.storageAccounts()
.define(this.namer.randomName("stg", 24))
.withRegion(this.region())
.withRegion(this.regionName())
.withExistingGroup(this.resourceGroupName())
.createAsync(new ServiceCallback<StorageAccount>() {
@Override
Expand Down Expand Up @@ -1158,7 +1158,7 @@ private NetworkInterface.DefinitionWithPublicIpAddress prepareNetworkInterface(S
NetworkInterface.DefinitionWithGroup definitionWithGroup = this.networkManager
.networkInterfaces()
.define(name)
.withRegion(this.region());
.withRegion(this.regionName());
NetworkInterface.DefinitionWithNetwork definitionWithNetwork;
if (this.newGroup != null) {
definitionWithNetwork = definitionWithGroup.withNewGroup(this.newGroup);
Expand All @@ -1185,7 +1185,7 @@ private void initializeDataDisks() {
private NetworkInterface.DefinitionWithNetwork preparePrimaryNetworkInterface(String name) {
NetworkInterface.DefinitionWithGroup definitionWithGroup = this.networkManager.networkInterfaces()
.define(name)
.withRegion(this.region());
.withRegion(this.regionName());
NetworkInterface.DefinitionWithNetwork definitionAfterGroup;
if (this.newGroup != null) {
definitionAfterGroup = definitionWithGroup.withNewGroup(this.newGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public void canCreateVirtualMachine() throws Exception {
}
}
Assert.assertNotNull(foundedVM);
Assert.assertEquals(LOCATION, foundedVM.region());
Assert.assertEquals(LOCATION, foundedVM.regionName());
// Get
foundedVM = computeManager.virtualMachines().getByGroup(RG_NAME, VMNAME);
Assert.assertNotNull(foundedVM);
Assert.assertEquals(LOCATION, foundedVM.region());
Assert.assertEquals(LOCATION, foundedVM.regionName());

// Fetch instance view
PowerState powerState = foundedVM.powerState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public NicIpConfigurationImpl withNewNetwork(Network.DefinitionStages.WithCreate
public NicIpConfigurationImpl withNewNetwork(String name, String addressSpaceCidr) {
Network.DefinitionStages.WithGroup definitionWithGroup = this.networkManager.networks()
.define(name)
.withRegion(this.parent().region());
.withRegion(this.parent().regionName());

Network.DefinitionStages.WithCreate definitionAfterGroup;
if (this.parent().newGroup() != null) {
Expand Down Expand Up @@ -215,7 +215,7 @@ protected static void ensureConfigurations(List<NicIpConfiguration> nicIpConfigu
private PublicIpAddress.DefinitionCreatable prepareCreatablePublicIp(String name, String leafDnsLabel) {
PublicIpAddress.DefinitionWithGroup definitionWithGroup = this.networkManager.publicIpAddresses()
.define(name)
.withRegion(this.parent().region());
.withRegion(this.parent().regionName());

PublicIpAddress.DefinitionCreatable definitionAfterGroup;
if (this.parent().newGroup() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public interface ResourceGroup extends
*/
String provisioningState();

/**
* @return the region of the resource group
*/
String region();

/**
* @return the tags attached to the resource group
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ public interface Resource extends Indexable {
String type();

/**
* @return the name of the reosurce
* @return the name of the resource
*/
String name();

/**
* @return the name of the region the resource is in
*/
String regionName();

/**
* @return the region the resource is in
*/
String region();
Region region();

/**
* @return the tags for the resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String resourceGroupName() {
*/
public final FluentModelImplT withNewGroup(String groupName) {
return this.withNewGroup(
this.myManager.resourceManager().resourceGroups().define(groupName).withRegion(this.region()));
this.myManager.resourceManager().resourceGroups().define(groupName).withRegion(this.regionName()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ protected ResourceImpl(String key, InnerModelT innerObject) {
*******************************************/

@Override
public String region() {
public String regionName() {
return this.inner().location();
}

@Override
public Region region() {
return Region.fromName(this.regionName());
}

@Override
public Map<String, String> tags() {
Map<String, String> tags = this.inner().getTags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ public String provisioningState() {
}

@Override
public String region() {
public String regionName() {
return this.inner().location();
}

@Override
public Region region() {
return Region.fromName(this.regionName());
}

@Override
public String id() {
return this.inner().id();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.microsoft.azure.CloudException;
import com.microsoft.azure.Page;
import com.microsoft.azure.PagedList;
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
import com.microsoft.azure.management.resources.fluentcore.arm.models.implementation.GroupPagedList;
import com.microsoft.azure.management.resources.implementation.api.PageImpl;
import com.microsoft.azure.management.resources.implementation.api.ResourceGroupInner;
Expand Down Expand Up @@ -123,7 +124,12 @@ public String provisioningState() {
}

@Override
public String region() {
public String regionName() {
return null;
}

@Override
public Region region() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void canCreateResourceGroup() throws Exception {
Assert.assertNotNull(groupResult);
Assert.assertEquals("finance", groupResult.tags().get("department"));
Assert.assertEquals("tagvalue", groupResult.tags().get("tagname"));
Assert.assertEquals(location, groupResult.region());
Assert.assertEquals(location, groupResult.regionName());
// Get
ResourceGroup getGroup = resourceGroups.getByName(rgName);
Assert.assertNotNull(getGroup);
Expand All @@ -45,7 +45,7 @@ public void canCreateResourceGroup() throws Exception {
.withTag("tag1", "value1")
.apply();
Assert.assertEquals("value1", updatedGroup.tags().get("tag1"));
Assert.assertEquals(location, getGroup.region());
Assert.assertEquals(location, getGroup.regionName());
// Delete
resourceGroups.delete(rgName);
Assert.assertFalse(resourceGroups.checkExistence(rgName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void clearWrapperProperties() {

@Override
protected void createResource() throws Exception {
createParameters.withLocation(this.region());
createParameters.withLocation(this.regionName());
createParameters.withTags(this.inner().getTags());
this.client.create(this.resourceGroupName(), this.name(), createParameters);
// create response does not seems including the endpoints so fetching it again.
Expand All @@ -213,7 +213,7 @@ protected void createResource() throws Exception {

@Override
protected ServiceCall createResourceAsync(final ServiceCallback<Void> callback) {
createParameters.withLocation(this.region());
createParameters.withLocation(this.regionName());
createParameters.withTags(this.inner().getTags());
final StorageAccountImpl self = this;
return this.client.createAsync(this.resourceGroupName(), this.name(), createParameters,
Expand Down
2 changes: 1 addition & 1 deletion azure/src/test/java/com/microsoft/azure/TestNSG.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public NetworkSecurityGroup createResource(NetworkSecurityGroups nsgs) throws Ex
.create();

// Verify
Assert.assertTrue(nsg.region().equalsIgnoreCase(region.toString()));
Assert.assertTrue(nsg.region().equals(region));
Assert.assertTrue(nsg.securityRules().size() == 2);

return nsg;
Expand Down

0 comments on commit 06638ea

Please sign in to comment.