public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrEmpty(ResourceGroupName) && !string.IsNullOrEmpty(Name))
            {
                // Get for single cache
                WriteObject(new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName));
            }
            else
            {
                // List all cache in given resource group if avaliable otherwise all cache in given subscription
                RedisListResponse           response = CacheClient.ListCaches(ResourceGroupName);
                List <RedisCacheAttributes> list     = new List <RedisCacheAttributes>();
                foreach (RedisResource resource in response.Value)
                {
                    list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                }
                WriteObject(list, true);

                while (!string.IsNullOrEmpty(response.NextLink))
                {
                    // List using next link
                    response = CacheClient.ListCachesUsingNextLink(response.NextLink);
                    list     = new List <RedisCacheAttributes>();
                    foreach (RedisResource resource in response.Value)
                    {
                        list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                    }
                    WriteObject(list, true);
                }
            }
        }
        public override void ExecuteCmdlet()
        {
            string storageAccountName  = GetStorageAccountName(StorageAccountId);
            RedisCacheAttributes cache = new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName);

            CacheClient.SetDiagnostics(cache.Id, storageAccountName);
        }
Пример #3
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(null, PrimaryServerName);
            Utility.ValidateResourceGroupAndResourceName(null, SecondaryServerName);

            RedisResource primaryCache   = CacheClient.GetCache(PrimaryServerName);
            RedisResource secondaryCache = CacheClient.GetCache(SecondaryServerName);

            ConfirmAction(
                string.Format(Resources.LinkingRedisCache, SecondaryServerName, PrimaryServerName),
                PrimaryServerName,
                () =>
            {
                RedisLinkedServerWithProperties redisLinkedServer = CacheClient.SetLinkedServer(
                    resourceGroupName: Utility.GetResourceGroupNameFromRedisCacheId(primaryCache.Id),
                    cacheName: primaryCache.Name,
                    linkedCacheName: secondaryCache.Name,
                    linkedCacheId: secondaryCache.Id,
                    linkedCacheLocation: secondaryCache.Location,
                    serverRole: ReplicationRole.Secondary);

                if (redisLinkedServer == null)
                {
                    throw new CloudException(string.Format(Resources.LinkedServerCreationFailed, SecondaryServerName, PrimaryServerName));
                }
                WriteObject(new PSRedisLinkedServer(redisLinkedServer));
            }
                );
        }
Пример #4
0
        public override void ExecuteCmdlet()
        {
            RedisGetResponse response = CacheClient.GetCache(ResourceGroupName, Name);

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Resource.Properties.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Resource.Properties.Sku.Family;
                skuCapacity = response.Resource.Properties.Sku.Capacity;
            }
            else
            {
                Size      = SizeConverter.GetSizeInRedisSpecificFormat(Size);
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }


            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Resource.Location, response.Resource.Properties.RedisVersion,
                                                            skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort),
                            ResourceGroupName));
        }
        public override void ExecuteCmdlet()
        {
            RedisGetResponse response = CacheClient.GetCache(ResourceGroupName, Name);

            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Location, response.Properties.RedisVersion,
                                                            response.Properties.Sku.Family, response.Properties.Sku.Capacity, response.Properties.Sku.Name, MaxMemoryPolicy),
                            ResourceGroupName));
        }
Пример #6
0
        public override void ExecuteCmdlet()
        {
            RedisCacheAttributes cache = new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName);

            ConfirmAction(
                string.Format(Resources.RemoveRedisCacheDiagnostics, Name),
                Name,
                () => CacheClient.SetDiagnostics(cache.Id, null));
        }
Пример #7
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            RedisResource response = null;

            if (string.IsNullOrEmpty(ResourceGroupName))
            {
                response          = CacheClient.GetCache(Name);
                ResourceGroupName = Utility.GetResourceGroupNameFromRedisCacheId(response.Id);
            }
            else
            {
                response = CacheClient.GetCache(ResourceGroupName, Name);
            }

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Sku.Family;
                skuCapacity = response.Sku.Capacity;
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                SizeConverter.ValidateSize(Size.ToUpper(), SkuStrings.Premium.Equals(Sku));
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }

            if (!ShardCount.HasValue && response.ShardCount.HasValue)
            {
                ShardCount = response.ShardCount;
            }

            ConfirmAction(
                string.Format(Resources.UpdateRedisCache, Name),
                Name,
                () =>
            {
                var redisResource = CacheClient.UpdateCache(ResourceGroupName, Name, skuFamily, skuCapacity,
                                                            skuName, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, Tag);
                var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
                WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
            });
        }
Пример #8
0
        public override void ExecuteCmdlet()
        {
            string skuFamily;

            int skuCapacity = 1;

            if (string.IsNullOrEmpty(RedisVersion))
            {
                RedisVersion = redisDefaultVersion;
            }

            if (string.IsNullOrEmpty(Size))
            {
                Size = SizeConverter.C1String;
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size);
            }

            // Size to SkuFamily and SkuCapacity conversion
            skuFamily = Size.Substring(0, 1);
            int.TryParse(Size.Substring(1), out skuCapacity);

            if (string.IsNullOrEmpty(Sku))
            {
                Sku = SkuStrings.Standard;
            }

            // If Force flag is not avaliable than check if cache is already available or not
            try
            {
                RedisGetResponse availableCache = CacheClient.GetCache(ResourceGroupName, Name);
                if (availableCache != null)
                {
                    throw new CloudException(string.Format(Resources.RedisCacheExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }
            WriteObject(new RedisCacheAttributesWithAccessKeys(CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, Location, RedisVersion, skuFamily, skuCapacity, Sku, MaxMemoryPolicy, EnableNonSslPort), ResourceGroupName));
        }
Пример #9
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name);

            RedisCacheAttributes cache = new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName);

            ConfirmAction(
                string.Format(Resources.RemoveRedisCacheDiagnostics, Name),
                Name,
                () => CacheClient.SetDiagnostics(cache.Id, null));
        }
Пример #10
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            ResourceGroupName = CacheClient.GetResourceGroupNameIfNotProvided(ResourceGroupName, Name);
            string storageAccountName = GetStorageAccountName(StorageAccountId);

            RedisCacheAttributes cache = new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName);

            ConfirmAction(
                string.Format(Resources.SetRedisCacheDiagnostics, Name),
                Name,
                () =>
            {
                CacheClient.SetDiagnostics(cache.Id, storageAccountName);
            });
        }
Пример #11
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (!string.IsNullOrEmpty(MaxMemoryPolicy))
            {
                throw new ArgumentException(Resources.MaxMemoryPolicyException);
            }

            RedisResource response = CacheClient.GetCache(ResourceGroupName, Name);

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Sku.Family;
                skuCapacity = response.Sku.Capacity;
            }
            else
            {
                Size      = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }

            if (!ShardCount.HasValue && response.ShardCount.HasValue)
            {
                ShardCount = response.ShardCount;
            }


            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Location, skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort,
                                                            TenantSettings, ShardCount, response.SubnetId, response.StaticIP, response.Tags),
                            ResourceGroupName));
        }
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (!string.IsNullOrEmpty(Name))
            {
                if (!string.IsNullOrEmpty(ResourceGroupName))
                {
                    // Get single cache directly by RP call
                    WriteObject(new RedisCacheAttributes(CacheClient.GetCache(ResourceGroupName, Name), ResourceGroupName));
                }
                else
                {
                    // Get single cache from list of caches
                    RedisResource response = CacheClient.GetCache(Name);
                    WriteObject(new RedisCacheAttributes(response, Utility.GetResourceGroupNameFromRedisCacheId(response.Id)));
                }
            }
            else
            {
                // List all cache in given resource group if avaliable otherwise all cache in given subscription
                IPage <RedisResource>       response = CacheClient.ListCaches(ResourceGroupName);
                List <RedisCacheAttributes> list     = new List <RedisCacheAttributes>();
                foreach (RedisResource resource in response)
                {
                    list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                }
                WriteObject(list, true);

                while (!string.IsNullOrEmpty(response.NextPageLink))
                {
                    // List using next link
                    response = CacheClient.ListCachesUsingNextLink(ResourceGroupName, response.NextPageLink);
                    list     = new List <RedisCacheAttributes>();
                    foreach (RedisResource resource in response)
                    {
                        list.Add(new RedisCacheAttributes(resource, ResourceGroupName));
                    }
                    WriteObject(list, true);
                }
            }
        }
        protected override void ProcessRecord()
        {
            if (!string.IsNullOrEmpty(MaxMemoryPolicy))
            {
                throw new ArgumentException(Resources.MaxMemoryPolicyException);
            }

            RedisGetResponse response = CacheClient.GetCache(ResourceGroupName, Name);

            string skuName;
            string skuFamily;
            int    skuCapacity;

            if (string.IsNullOrEmpty(Sku))
            {
                skuName = response.Resource.Properties.Sku.Name;
            }
            else
            {
                skuName = Sku;
            }

            if (string.IsNullOrEmpty(Size))
            {
                skuFamily   = response.Resource.Properties.Sku.Family;
                skuCapacity = response.Resource.Properties.Sku.Capacity;
            }
            else
            {
                Size      = SizeConverter.GetSizeInRedisSpecificFormat(Size);
                skuFamily = Size.Substring(0, 1);
                int.TryParse(Size.Substring(1), out skuCapacity);
            }


            WriteObject(new RedisCacheAttributesWithAccessKeys(
                            CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Resource.Location, response.Resource.Properties.RedisVersion,
                                                            skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort),
                            ResourceGroupName));
        }
Пример #14
0
        public override void ExecuteCmdlet()
        {
            Utility.ValidateResourceGroupAndResourceName(ResourceGroupName, Name);
            if (string.IsNullOrEmpty(Sku))
            {
                Sku = SkuStrings.Standard;
            }


            if (string.IsNullOrEmpty(Size))
            {
                if (SkuStrings.Premium.Equals(Sku, StringComparison.OrdinalIgnoreCase))
                {
                    Size = SizeConverter.P1String;
                }
                else
                {
                    Size = SizeConverter.C1String;
                }
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
                SizeConverter.ValidateSize(Size.ToUpper(), SkuStrings.Premium.Equals(Sku));
            }

            int skuCapacity = 1;
            // Size to SkuFamily and SkuCapacity conversion
            string skuFamily = Size.Substring(0, 1);

            int.TryParse(Size.Substring(1), out skuCapacity);


            // If Force flag is not avaliable than check if cache is already available or not
            try
            {
                RedisResource availableCache = CacheClient.GetCache(ResourceGroupName, Name);
                if (availableCache != null)
                {
                    throw new CloudException(string.Format(Resources.RedisCacheExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }
            catch (ErrorResponseException ex)
            {
                if (ex.Body.Error.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            ConfirmAction(
                string.Format(Resources.CreateRedisCache, Name),
                Name,
                () =>
            {
                var redisResource = CacheClient.CreateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku,
                                                            RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, MinimumTlsVersion, SubnetId, StaticIP, Tag, Zone, RedisVersion, IdentityType, UserAssignedIdentity);
                var redisAccessKeys = CacheClient.GetAccessKeys(ResourceGroupName, Name);
                WriteObject(new RedisCacheAttributesWithAccessKeys(redisResource, redisAccessKeys, ResourceGroupName));
            });
        }
Пример #15
0
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrEmpty(RedisVersion))
            {
                WriteWarning("The RedisVersion parameter has been deprecated.  As such, it is no longer necessary to provide this parameter and any value specified is ignored.");
            }

            if (!string.IsNullOrEmpty(MaxMemoryPolicy))
            {
                throw new ArgumentException(Resources.MaxMemoryPolicyException);
            }

            if (string.IsNullOrEmpty(Sku))
            {
                Sku = SkuStrings.Standard;
            }


            if (string.IsNullOrEmpty(Size))
            {
                Size = SizeConverter.C1String;
            }
            else
            {
                Size = SizeConverter.GetSizeInRedisSpecificFormat(Size, SkuStrings.Premium.Equals(Sku));
            }

            int skuCapacity = 1;
            // Size to SkuFamily and SkuCapacity conversion
            string skuFamily = Size.Substring(0, 1);

            int.TryParse(Size.Substring(1), out skuCapacity);


            // If Force flag is not avaliable than check if cache is already available or not
            try
            {
                RedisResource availableCache = CacheClient.GetCache(ResourceGroupName, Name);
                if (availableCache != null)
                {
                    throw new CloudException(string.Format(Resources.RedisCacheExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Body.Code == "ResourceNotFound" || ex.Message.Contains("ResourceNotFound"))
                {
                    // cache does not exists so go ahead and create one
                }
                else if (ex.Body.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            WriteObject(
                new RedisCacheAttributesWithAccessKeys(
                    CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, Location, skuFamily, skuCapacity, Sku, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, VirtualNetwork, Subnet, StaticIP),
                    ResourceGroupName
                    )
                );
        }