Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Azure/azure-sdk-for-java into vm-…
Browse files Browse the repository at this point in the history
…miscellaneous
  • Loading branch information
anuchandy committed Oct 27, 2016
2 parents 6e9ef72 + 845d4d8 commit afb0cb0
Show file tree
Hide file tree
Showing 42 changed files with 1,187 additions and 1,218 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,9 @@ public void canCRUDBatchAccount() throws Exception {
.parent()
.apply();
batchManager.batchAccounts().deleteByGroup(batchAccount.resourceGroupName(), batchAccount.name());
try {
batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertTrue(false);
}
catch (CloudException exception) {
Assert.assertEquals(exception.getResponse().code(), 404);
}

batchAccount = batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertNull(batchAccount);
}

@Test
Expand Down Expand Up @@ -217,12 +213,7 @@ public void canCreateBatchAccountWithApplication() throws Exception {
Assert.assertEquals(application.updatesAllowed(), allowUpdates);

batchManager.batchAccounts().deleteByGroup(batchAccount.resourceGroupName(), batchAccount.name());
try {
batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertTrue(false);
}
catch (CloudException exception) {
Assert.assertEquals(exception.getResponse().code(), 404);
}
batchAccount = batchManager.batchAccounts().getById(batchAccount.id());
Assert.assertNull(batchAccount);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public final class ResourceId {
private String resourceGroupName;
private String name;
private ResourceId parent;
private String providerNamespace;
private String resourceType;
private String id;

/**
* Returns parsed ResourceId object for a given resource id.
Expand All @@ -28,13 +31,21 @@ public static ResourceId parseResourceId(String id) {
// Example of id is id=/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/ans/providers/Microsoft.Network/applicationGateways/something
// Remove the first '/' and then split using '/'
String[] splits = id.substring(1).split("/");

if (splits.length % 2 == 1) {
throw new InvalidParameterException();
}
ResourceId resourceId = new ResourceId();

resourceId.id = id;
resourceId.subscriptionId = splits[1];
resourceId.resourceGroupName = splits[3];
resourceId.providerNamespace = splits[5];


resourceId.name = splits[splits.length - 1];
resourceId.resourceType = splits[splits.length - 2];

int numberOfParents = splits.length / 2 - 4;
if (numberOfParents == 0) {
return resourceId;
Expand Down Expand Up @@ -73,4 +84,35 @@ public String name() {
public ResourceId parent() {
return this.parent;
}

/**
* @return name of the provider.
*/
public String providerNamespace() {
return this.providerNamespace;
}

/**
* @return type of the resource.
*/
public String resourceType() {
return this.resourceType;
}

/**
* @return full type of the resource.
*/
public String fullResourceType() {
if (this.parent == null) {
return this.providerNamespace + "/" + this.resourceType;
}
return this.parent.fullResourceType() + "/" + this.resourceType;
}

/**
* @return the id of the resource.
*/
public String id() {
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private ResourceUtils() { }
* @return the resource group name
*/
public static String groupFromResourceId(String id) {
return extractFromResourceId(id, "resource[gG]roups");
return ResourceId.parseResourceId(id).resourceGroupName();
}

/**
Expand All @@ -33,7 +33,7 @@ public static String groupFromResourceId(String id) {
* @return the resource group name
*/
public static String resourceProviderFromResourceId(String id) {
return extractFromResourceId(id, "providers");
return ResourceId.parseResourceId(id).providerNamespace();
}

/**
Expand All @@ -45,8 +45,7 @@ public static String resourceTypeFromResourceId(String id) {
if (id == null) {
return null;
}
String[] splits = id.split("/");
return splits[splits.length - 2];
return ResourceId.parseResourceId(id).resourceType();
}

/**
Expand All @@ -61,14 +60,12 @@ public static String parentResourceIdFromResourceId(String id) {
if (id == null) {
return null;
}
String parentId = id.replace("/" + resourceTypeFromResourceId(id) + "/" + nameFromResourceId(id), "");
Pattern pattern = Pattern.compile("[-\\w._/]+/providers/Microsoft.[\\w]+$");
Matcher matcher = pattern.matcher(id);
if (matcher.find()) {
return null;
} else {
return parentId;
ResourceId resourceId = ResourceId.parseResourceId(id);
if (resourceId != null && resourceId.parent() != null) {
return ResourceId.parseResourceId(id).parent().id();
}

return null;
}

/**
Expand All @@ -82,14 +79,13 @@ public static String parentRelativePathFromResourceId(String id) {
if (id == null) {
return null;
}
String parentId = id.replace("/" + resourceTypeFromResourceId(id) + "/" + nameFromResourceId(id), "");
Pattern pattern = Pattern.compile("[-\\w._/]+/providers/Microsoft.[\\w]+$");
Matcher matcher = pattern.matcher(id);
if (matcher.find()) {
return "";
} else {
return relativePathFromResourceId(parentId);

ResourceId parent = ResourceId.parseResourceId(id).parent();
if (parent != null) {
return parent.resourceType() + "/" + parent.name();
}

return "";
}

/**
Expand Down Expand Up @@ -141,8 +137,7 @@ public static String nameFromResourceId(String id) {
if (id == null) {
return null;
}
String[] splits = id.split("/");
return splits[splits.length - 1];
return ResourceId.parseResourceId(id).name();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

/**
* Provides access to getting a specific Azure resource based on its resource group and parent.
*
* @param <T> the type of the resource collection
*/
@LangDefinition(ContainerName = "CollectionActions", CreateAsyncMethods = true, MethodConversionType = LangDefinition.MethodConversion.OnlyMethod)
public interface SupportsDeletingByParent<T> {
public interface SupportsDeletingByParent {
/**
* Deletes a resource from Azure, identifying it by its name and its resource group.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class IndependentChildResourcesImpl<
SupportsGettingById<T>,
SupportsGettingByParent<T>,
SupportsListingByParent<T>,
SupportsDeletingByParent<T> {
SupportsDeletingByParent {
protected final InnerCollectionT innerCollection;
protected final ManagerT manager;

Expand All @@ -67,8 +67,6 @@ public PagedList<T> listByParent(GroupableResource parentResource) {
return listByParent(parentResource.resourceGroupName(), parentResource.name());
}



@Override
public void deleteByParent(String groupName, String parentName, String name) {
deleteByParentAsync(groupName, parentName, name).toBlocking().subscribe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public abstract class IndependentChildrenImpl<
SupportsGettingByParent<T>,
SupportsListingByParent<T>,
SupportsDeletingById,
SupportsDeletingByParent<T> {
SupportsDeletingByParent {
protected final InnerCollectionT innerCollection;
protected final ManagerT manager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class GenericResourceImpl
GenericResource.Definition,
GenericResource.UpdateStages.WithApiVersion,
GenericResource.Update {
private final ResourceManagementClientImpl serviceCleint;
private final ResourceManagementClientImpl serviceClient;
private final ResourcesInner resourceClient;
private final Providers providersClient;
private String resourceProviderNamespace;
Expand All @@ -48,7 +48,7 @@ final class GenericResourceImpl
resourceProviderNamespace = ResourceUtils.resourceProviderFromResourceId(innerModel.id());
resourceType = ResourceUtils.resourceTypeFromResourceId(innerModel.id());
parentResourcePath = ResourceUtils.parentRelativePathFromResourceId(innerModel.id());
this.serviceCleint = serviceClient;
this.serviceClient = serviceClient;
this.resourceClient = innerCollection;
this.providersClient = providerClient;
}
Expand Down Expand Up @@ -148,7 +148,7 @@ public String call(Provider provider) {
id = inner().id();
} else {
id = ResourceUtils.constructResourceId(
serviceCleint.subscriptionId(),
serviceClient.subscriptionId(),
resourceGroupName(),
resourceProviderNamespace(),
resourceType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,34 @@ public class ResourceIdTests {
@Test
public void ResourceIdForTopLevelResourceWorksFine() {
ResourceId resourceId = ResourceId.parseResourceId("/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/resourceGroupName/providers/Microsoft.Network/applicationGateways/something");

Assert.assertEquals(resourceId.name(), "something");
Assert.assertEquals(resourceId.subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef");
Assert.assertEquals(resourceId.resourceGroupName(), "resourceGroupName");
Assert.assertEquals(resourceId.providerNamespace(), "Microsoft.Network");
Assert.assertEquals(resourceId.resourceType(), "applicationGateways");
Assert.assertEquals(resourceId.fullResourceType(), "Microsoft.Network/applicationGateways");
Assert.assertNull(resourceId.parent());
}

@Test
public void ResourceIdForChildLevelResourceWorksFine() {
ResourceId resourceId = ResourceId.parseResourceId("/subscriptions/9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef/resourceGroups/resourceGroupName/providers/Microsoft.Network/applicationGateways/something/someChildType/childName");

Assert.assertEquals(resourceId.name(), "childName");
Assert.assertEquals(resourceId.subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef");
Assert.assertEquals(resourceId.resourceGroupName(), "resourceGroupName");
Assert.assertEquals(resourceId.providerNamespace(), "Microsoft.Network");
Assert.assertEquals(resourceId.resourceType(), "someChildType");
Assert.assertEquals(resourceId.fullResourceType(), "Microsoft.Network/applicationGateways/someChildType");
Assert.assertNotNull(resourceId.parent());
Assert.assertEquals(resourceId.parent().name(), "something");
Assert.assertEquals(resourceId.parent().subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef");
Assert.assertEquals(resourceId.parent().resourceGroupName(), "resourceGroupName");
Assert.assertEquals(resourceId.parent().name(), "something");
Assert.assertEquals(resourceId.parent().providerNamespace(), "Microsoft.Network");
Assert.assertEquals(resourceId.parent().resourceType(), "applicationGateways");
Assert.assertEquals(resourceId.parent().fullResourceType(), "Microsoft.Network/applicationGateways");
}

@Test
Expand All @@ -45,14 +56,23 @@ public void ResourceIdForGrandChildLevelResourceWorksFine() {
Assert.assertEquals(resourceId.name(), "grandChild");
Assert.assertEquals(resourceId.subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef");
Assert.assertEquals(resourceId.resourceGroupName(), "resourceGroupName");
Assert.assertEquals(resourceId.providerNamespace(), "Microsoft.Network");
Assert.assertEquals(resourceId.resourceType(), "grandChildType");
Assert.assertEquals(resourceId.fullResourceType(), "Microsoft.Network/applicationGateways/someChildType/grandChildType");
Assert.assertNotNull(resourceId.parent());
Assert.assertEquals(resourceId.parent().name(), "childName");
Assert.assertEquals(resourceId.parent().subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef");
Assert.assertEquals(resourceId.parent().resourceGroupName(), "resourceGroupName");
Assert.assertEquals(resourceId.parent().providerNamespace(), "Microsoft.Network");
Assert.assertEquals(resourceId.parent().resourceType(), "someChildType");
Assert.assertEquals(resourceId.parent().fullResourceType(), "Microsoft.Network/applicationGateways/someChildType");
Assert.assertNotNull(resourceId.parent().parent());
Assert.assertEquals(resourceId.parent().parent().name(), "something");
Assert.assertEquals(resourceId.parent().parent().subscriptionId(), "9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef");
Assert.assertEquals(resourceId.parent().parent().resourceGroupName(), "resourceGroupName");
Assert.assertEquals(resourceId.parent().parent().name(), "something");
Assert.assertEquals(resourceId.parent().parent().providerNamespace(), "Microsoft.Network");
Assert.assertEquals(resourceId.parent().parent().resourceType(), "applicationGateways");
Assert.assertEquals(resourceId.parent().parent().fullResourceType(), "Microsoft.Network/applicationGateways");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void canExtractGroupFromId() throws Exception {
@Test
public void canExtractParentPathFromId() throws Exception {
Assert.assertEquals("subscriptions/123/resourceGroups/foo/providers/Microsoft.Bar/bars/bar1", ResourceUtils.parentResourceIdFromResourceId("subscriptions/123/resourceGroups/foo/providers/Microsoft.Bar/bars/bar1/bazs/baz1"));
Assert.assertEquals("subscriptions/123/resourceGroups/foo/providers/Microsoft.Bar", ResourceUtils.parentResourceIdFromResourceId("subscriptions/123/resourceGroups/foo/providers/Microsoft.Bar/bars/bar1"));
Assert.assertNull(ResourceUtils.parentResourceIdFromResourceId("subscriptions/123/resourceGroups/foo/providers/Microsoft.Bar/bars/bar1"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
*/

package com.microsoft.azure.management.sql;

import com.fasterxml.jackson.annotation.JsonValue;

/**
* Defines values for ElasticPoolState.
*/
public final class ElasticPoolState {
/** Static value Creating for ElasticPoolState. */
public static final ElasticPoolState CREATING = new ElasticPoolState("Creating");

/** Static value Ready for ElasticPoolState. */
public static final ElasticPoolState READY = new ElasticPoolState("Ready");

/** Static value Disabled for ElasticPoolState. */
public static final ElasticPoolState DISABLED = new ElasticPoolState("Disabled");

private String value;

/**
* Creates a custom value for ElasticPoolState.
* @param value the custom value
*/
public ElasticPoolState(String value) {
this.value = value;
}

@JsonValue
@Override
public String toString() {
return value;
}

@Override
public int hashCode() {
return value.hashCode();
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof ElasticPoolState)) {
return false;
}
if (obj == this) {
return true;
}
ElasticPoolState rhs = (ElasticPoolState) obj;
if (value == null) {
return rhs.value == null;
} else {
return value.equals(rhs.value);
}
}
}
Loading

0 comments on commit afb0cb0

Please sign in to comment.