Share via


ResourceUtils Class

  • java.lang.Object
    • com.microsoft.azure.management.resources.fluentcore.arm.ResourceUtils

public class ResourceUtils

Utility methods for Azure resource IDs.

Method Summary

Modifier and Type Method and Description
String constructResourceId(final String subscriptionId, final String resourceGroupName, final String resourceProviderNamespace, final String resourceType, final String resourceName, final String parentResourcePath)

Creates a resource ID from information of a generic resource.

String defaultApiVersion(String id, Provider provider)

Find out the default api version to make a REST request with from the resource provider.

String extractFromResourceId(String id, String identifier)

Extract information from a resource ID string with the resource type as the identifier.

String groupFromResourceId(String id)

Extract resource group from a resource ID string.

String nameFromResourceId(String id)

Extract name of the resource from a resource ID.

String parentRelativePathFromResourceId(String id)

Extract parent resource path from a resource ID string. E.g. subscriptions/s/resourcegroups/r/foos/foo/bars/bar will return foos/foo.

String parentResourceIdFromResourceId(String id)

Extract parent resource ID from a resource ID string. E.g. subscriptions/s/resourcegroups/r/foos/foo/bars/bar will return subscriptions/s/resourcegroups/r/foos/foo.

String relativePathFromResourceId(String id)

Extract the relative path to the current resource provider. E.g. subscriptions/sub1/resourceGroups/rg1/providers/Microsoft.Foo/foos/foo1 will return foos/foo1.

String resourceProviderFromResourceId(String id)

Extract resource provider from a resource ID string.

String resourceTypeFromResourceId(String id)

Extract resource type from a resource ID string.

String subscriptionFromResourceId(String id)

Extract the subscription ID from a resource ID string.

Method Details

constructResourceId

public static String constructResourceId(final String subscriptionId, final String resourceGroupName, final String resourceProviderNamespace, final String resourceType, final String resourceName, final String parentResourcePath)

Creates a resource ID from information of a generic resource.

Parameters:

subscriptionId - the subscription UUID
resourceGroupName - the resource group name
resourceProviderNamespace - the resource provider namespace
resourceType - the type of the resource or nested resource
resourceName - name of the resource or nested resource
parentResourcePath - parent resource's relative path to the provider, if the resource is a generic resource

Returns:

the resource ID string

defaultApiVersion

public static String defaultApiVersion(String id, Provider provider)

Find out the default api version to make a REST request with from the resource provider.

Parameters:

id - the resource ID
provider - the resource provider

Returns:

the default api version to use

extractFromResourceId

public static String extractFromResourceId(String id, String identifier)

Extract information from a resource ID string with the resource type as the identifier.

Parameters:

id - the resource ID
identifier - the identifier to match, e.g. "resourceGroups", "storageAccounts"

Returns:

the information extracted from the identifier

groupFromResourceId

public static String groupFromResourceId(String id)

Extract resource group from a resource ID string.

Parameters:

id - the resource ID string

Returns:

the resource group name

nameFromResourceId

public static String nameFromResourceId(String id)

Extract name of the resource from a resource ID.

Parameters:

id - the resource ID

Returns:

the name of the resource

parentRelativePathFromResourceId

public static String parentRelativePathFromResourceId(String id)

Extract parent resource path from a resource ID string. E.g. subscriptions/s/resourcegroups/r/foos/foo/bars/bar will return foos/foo.

Parameters:

id - the resource ID string

Returns:

the parent resource ID

parentResourceIdFromResourceId

public static String parentResourceIdFromResourceId(String id)

Extract parent resource ID from a resource ID string. E.g. subscriptions/s/resourcegroups/r/foos/foo/bars/bar will return subscriptions/s/resourcegroups/r/foos/foo.

Parameters:

id - the resource ID string

Returns:

the parent resource ID

relativePathFromResourceId

public static String relativePathFromResourceId(String id)

Extract the relative path to the current resource provider. E.g. subscriptions/sub1/resourceGroups/rg1/providers/Microsoft.Foo/foos/foo1 will return foos/foo1.

Parameters:

id - the id of the resource

Returns:

the relative path

resourceProviderFromResourceId

public static String resourceProviderFromResourceId(String id)

Extract resource provider from a resource ID string.

Parameters:

id - the resource ID string

Returns:

the resource group name

resourceTypeFromResourceId

public static String resourceTypeFromResourceId(String id)

Extract resource type from a resource ID string.

Parameters:

id - the resource ID string

Returns:

the resource type

subscriptionFromResourceId

public static String subscriptionFromResourceId(String id)

Extract the subscription ID from a resource ID string.

Parameters:

id - the resource ID string

Returns:

the subscription ID

Applies to