Class ResourceManagerUtils


  • public final class ResourceManagerUtils
    extends Object
    Defines a few utilities.
    • Method Detail

      • toPrimitiveBoolean

        public static boolean toPrimitiveBoolean​(Boolean value)
        Converts an object Boolean to a primitive boolean.
        Parameters:
        value - the Boolean value
        Returns:
        false if the given Boolean value is null or false else true
      • toPrimitiveInt

        public static int toPrimitiveInt​(Integer value)
        Converts an object Integer to a primitive int.
        Parameters:
        value - the Integer value
        Returns:
        0 if the given Integer value is null else integer value
      • toPrimitiveInt

        public static int toPrimitiveInt​(Long value)
        Converts an object Long to a primitive int.
        Parameters:
        value - the Long value
        Returns:
        0 if the given Long value is null else integer value
      • toPrimitiveLong

        public static long toPrimitiveLong​(Long value)
        Converts an object Long to a primitive long.
        Parameters:
        value - the Long value
        Returns:
        0 if the given Long value is null else long value
      • sleep

        public static void sleep​(Duration duration)
        Wrapper for thread sleep.
        Parameters:
        duration - the duration value for which thread should put on sleep.
      • createOdataFilterForTags

        public static String createOdataFilterForTags​(String tagName,
                                                      String tagValue)
        Creates an Odata filter string that can be used for filtering list results by tags.
        Parameters:
        tagName - the name of the tag. If not provided, all resources will be returned.
        tagValue - the value of the tag. If not provided, only tag name will be filtered.
        Returns:
        the Odata filter to pass into list methods
      • getDefaultSubscription

        public static String getDefaultSubscription​(com.azure.core.http.rest.PagedIterable<Subscription> subscriptions)
        Gets the only subscription as the default one in the tenant if applicable.
        Parameters:
        subscriptions - the list of subscriptions
        Returns:
        the only subscription existing in the tenant
        Throws:
        IllegalStateException - when no subscription or more than one subscription found
      • getDefaultScopeFromRequest

        public static String getDefaultScopeFromRequest​(com.azure.core.http.HttpRequest request,
                                                        com.azure.core.management.AzureEnvironment environment)
        Generates default scope for oauth2 from the specific request
        Parameters:
        request - a http request
        environment - the azure environment with current request
        Returns:
        the default scope
      • getStorageConnectionString

        public static String getStorageConnectionString​(String accountName,
                                                        String accountKey,
                                                        com.azure.core.management.AzureEnvironment environment)
        Get the Azure storage account connection string.
        Parameters:
        accountName - storage account name
        accountKey - storage account key
        environment - the Azure environment
        Returns:
        the storage account connection string.