Search in sources :

Example 1 with CheckNameAvailabilityParameters

use of com.azure.resourcemanager.redis.models.CheckNameAvailabilityParameters in project azure-maven-plugins by microsoft.

the class AzureRedis method checkNameAvailability.

@AzureOperation(name = "redis.check_name", params = "name", type = AzureOperation.Type.SERVICE)
public CheckNameAvailabilityResultEntity checkNameAvailability(String subscriptionId, String name) {
    final RedisManager redisManager = RedisManagerFactory.create(subscriptionId);
    RedisClient redis = redisManager.redisCaches().manager().serviceClient().getRedis();
    try {
        redis.checkNameAvailability(new CheckNameAvailabilityParameters().withName(name).withType("Microsoft.Cache/redis"));
        return new CheckNameAvailabilityResultEntity(true, null);
    } catch (ManagementException ex) {
        ManagementError value = ex.getValue();
        if (value != null && "NameNotAvailable".equals(value.getCode())) {
            return new CheckNameAvailabilityResultEntity(false, String.format("The name '%s' for Redis Cache is not available", name), value.getMessage());
        }
        throw ex;
    }
}
Also used : RedisClient(com.azure.resourcemanager.redis.fluent.RedisClient) ManagementException(com.azure.core.management.exception.ManagementException) ManagementError(com.azure.core.management.exception.ManagementError) CheckNameAvailabilityResultEntity(com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity) RedisManager(com.azure.resourcemanager.redis.RedisManager) CheckNameAvailabilityParameters(com.azure.resourcemanager.redis.models.CheckNameAvailabilityParameters) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Aggregations

ManagementError (com.azure.core.management.exception.ManagementError)1 ManagementException (com.azure.core.management.exception.ManagementException)1 RedisManager (com.azure.resourcemanager.redis.RedisManager)1 RedisClient (com.azure.resourcemanager.redis.fluent.RedisClient)1 CheckNameAvailabilityParameters (com.azure.resourcemanager.redis.models.CheckNameAvailabilityParameters)1 CheckNameAvailabilityResultEntity (com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity)1 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)1