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)); }
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)); }
public void Get_EmptyJSONFromCSM() { string responseString = (@"{}"); RedisManagementClient client = Utility.GetRedisManagementClient(responseString, null, HttpStatusCode.OK); RedisGetResponse response = client.Redis.Get(resourceGroupName: "resource-group", name: "cachename"); Assert.Null(response.RequestId); Assert.Null(response.Resource.Id); Assert.Null(response.Resource.Location); Assert.Null(response.Resource.Name); Assert.Null(response.Resource.Type); Assert.Null(response.Resource.Properties); }
public RedisCacheAttributes(RedisGetResponse cache, string resourceGroupName) { Id = cache.Id; Location = cache.Location; Name = cache.Name; Type = cache.Type; HostName = cache.Properties.HostName; Port = cache.Properties.Port; ProvisioningState = cache.Properties.ProvisioningState; SslPort = cache.Properties.SslPort; MaxMemoryPolicy = cache.Properties.MaxMemoryPolicy; RedisVersion = cache.Properties.RedisVersion; Size = SizeConverter.GetSizeInUserSpecificFormat(cache.Properties.Sku.Family, cache.Properties.Sku.Capacity); Sku = cache.Properties.Sku.Name; ResourceGroupName = resourceGroupName; }
public void Get_Basic() { string responseString = (@" { ""id"" : ""/subscriptions/a559b6fd-3a84-40bb-a450-b0db5ed37dfe/resourceGroups/HydraTest07152014/providers/Microsoft.Cache/Redis/hydraradiscache"", ""location"" : ""North Europe"", ""name"" : ""hydraradiscache"", ""type"" : ""Microsoft.Cache/Redis"", ""tags"" : {""update"": ""done""}, ""properties"" : { ""provisioningState"" : ""succeeded"", ""sku"": { ""name"": ""Basic"", ""family"": ""C"", ""capacity"": 1 }, ""redisVersion"" : ""2.8"", ""redisConfiguration"": {""maxmemory-policy"": ""allkeys-lru""}, ""accessKeys"" : null, ""hostName"" : ""hydraradiscache.cache.icbbvt.windows-int.net"", ""port"" : 6379, ""sslPort"" : 6380 } } "); string requestIdHeader = "0d33aff8-8a4e-4565-b893-a10e52260de0"; RedisManagementClient client = Utility.GetRedisManagementClient(responseString, requestIdHeader, HttpStatusCode.OK); RedisGetResponse response = client.Redis.Get(resourceGroupName: "resource-group", name: "cachename"); Assert.Equal(requestIdHeader, response.RequestId); Assert.Equal("/subscriptions/a559b6fd-3a84-40bb-a450-b0db5ed37dfe/resourceGroups/HydraTest07152014/providers/Microsoft.Cache/Redis/hydraradiscache", response.Resource.Id); Assert.Equal("North Europe", response.Resource.Location); Assert.Equal("hydraradiscache", response.Resource.Name); Assert.Equal("Microsoft.Cache/Redis", response.Resource.Type); Assert.Equal("succeeded", response.Resource.Properties.ProvisioningState); Assert.Equal(SkuName.Basic, response.Resource.Properties.Sku.Name); Assert.Equal(SkuFamily.C, response.Resource.Properties.Sku.Family); Assert.Equal(1, response.Resource.Properties.Sku.Capacity); Assert.Equal("2.8", response.Resource.Properties.RedisVersion); Assert.Equal("allkeys-lru", response.Resource.Properties.RedisConfiguration["maxmemory-policy"]); Assert.Equal("hydraradiscache.cache.icbbvt.windows-int.net", response.Resource.Properties.HostName); Assert.Equal(6379, response.Resource.Properties.Port); Assert.Equal(6380, response.Resource.Properties.SslPort); }
public override void ExecuteCmdlet() { 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, SkuStrings.Premium.Equals(Sku)); skuFamily = Size.Substring(0, 1); int.TryParse(Size.Substring(1), out skuCapacity); } if (!ShardCount.HasValue && response.Resource.Properties.ShardCount.HasValue) { ShardCount = response.Resource.Properties.ShardCount; } WriteObject(new RedisCacheAttributesWithAccessKeys( CacheClient.CreateOrUpdateCache(ResourceGroupName, Name, response.Resource.Location, skuFamily, skuCapacity, skuName, RedisConfiguration, EnableNonSslPort, TenantSettings, ShardCount, response.Resource.Properties.VirtualNetwork, response.Resource.Properties.Subnet, response.Resource.Properties.StaticIP), ResourceGroupName)); }
public void GetTest() { TestUtilities.StartTest(); var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this); RedisGetResponse response = _client.Redis.Get(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName); Assert.NotNull(response.RequestId); Assert.Contains(fixture.RedisCacheName, response.Resource.Id); Assert.Equal(fixture.RedisCacheName, response.Resource.Name); Assert.True("succeeded".Equals(response.Resource.Properties.ProvisioningState, StringComparison.InvariantCultureIgnoreCase)); Assert.Equal(SkuName.Basic, response.Resource.Properties.Sku.Name); Assert.Equal(SkuFamily.C, response.Resource.Properties.Sku.Family); Assert.Equal(0, response.Resource.Properties.Sku.Capacity); Assert.Contains(fixture.RedisCacheName, response.Resource.Properties.HostName); Assert.Equal(6379, response.Resource.Properties.Port); Assert.Equal(6380, response.Resource.Properties.SslPort); TestUtilities.EndTest(); }
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)); }
public void UpdateEnableNonSslPortBugTest() { TestUtilities.StartTest(); var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this); RedisGetResponse responseGet = _client.Redis.Get(resourceGroupName: "SunnySDK25", name: "sunnysdk25-centralus"); Assert.True(responseGet.Resource.Properties.EnableNonSslPort.Value); Dictionary <string, string> redisConfiguration = new Dictionary <string, string>(); redisConfiguration.Add("maxmemory-policy", "allkeys-lru"); RedisCreateOrUpdateResponse responseCreate = _client.Redis.CreateOrUpdate(resourceGroupName: "SunnySDK25", name: "sunnysdk25-centralus", parameters: new RedisCreateOrUpdateParameters { Location = "Central US", Properties = new RedisProperties { RedisVersion = "2.8", Sku = new Sku() { Name = SkuName.Standard, Family = SkuFamily.C, Capacity = 2 }, RedisConfiguration = redisConfiguration } }); Assert.Equal(6379, responseCreate.Resource.Properties.Port); Assert.Equal(6380, responseCreate.Resource.Properties.SslPort); Assert.True(responseCreate.Resource.Properties.EnableNonSslPort.Value); TestUtilities.EndTest(); }
public void TryCreatingCache(string resourceGroupName, string cacheName, string location) { var redisClient = RedisCacheManagementTestUtilities.GetRedisManagementClient(_testBase); RedisCreateOrUpdateResponse createResponse = redisClient.Redis.CreateOrUpdate(resourceGroupName: resourceGroupName, name: cacheName, parameters: new RedisCreateOrUpdateParameters { Location = location, Properties = new RedisProperties { RedisVersion = "2.8", Sku = new Sku() { Name = SkuName.Basic, Family = SkuFamily.C, Capacity = 0 } } }); RedisGetResponse response = redisClient.Redis.Get(resourceGroupName: resourceGroupName, name: cacheName); ThrowIfTrue(!response.Resource.Id.Contains(cacheName), "Cache name not found inside Id."); ThrowIfTrue(!response.Resource.Name.Equals(cacheName), string.Format("Cache name is not equal to {0}", cacheName)); ThrowIfTrue(!response.Resource.Properties.HostName.Contains(cacheName), "Cache name not found inside host name."); // wait for maximum 30 minutes for cache to create for (int i = 0; i < 60; i++) { TestUtilities.Wait(new TimeSpan(0, 0, 30)); RedisGetResponse responseGet = redisClient.Redis.Get(resourceGroupName: resourceGroupName, name: cacheName); if ("succeeded".Equals(responseGet.Resource.Properties.ProvisioningState, StringComparison.InvariantCultureIgnoreCase)) { break; } ThrowIfTrue(i == 60, "Cache is not in succeeded state even after 30 min."); } }
public void CreateUpdateDeleteTest() { TestUtilities.StartTest(); var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this); RedisCreateOrUpdateResponse responseCreate = _client.Redis.CreateOrUpdate(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName, parameters: new RedisCreateOrUpdateParameters { Location = fixture.Location, Properties = new RedisProperties { RedisVersion = "2.8", Sku = new Sku() { Name = SkuName.Basic, Family = SkuFamily.C, Capacity = 0 } } }); Assert.NotNull(responseCreate.RequestId); Assert.Contains(fixture.RedisCacheName, responseCreate.Resource.Id); Assert.Equal(fixture.Location, responseCreate.Resource.Location); Assert.Equal(fixture.RedisCacheName, responseCreate.Resource.Name); Assert.Equal("Microsoft.Cache/Redis", responseCreate.Resource.Type); Assert.True("creating".Equals(responseCreate.Resource.Properties.ProvisioningState, StringComparison.InvariantCultureIgnoreCase)); Assert.Equal(SkuName.Basic, responseCreate.Resource.Properties.Sku.Name); Assert.Equal(SkuFamily.C, responseCreate.Resource.Properties.Sku.Family); Assert.Equal(0, responseCreate.Resource.Properties.Sku.Capacity); Assert.Contains("2.8", responseCreate.Resource.Properties.RedisVersion); Assert.Contains(fixture.RedisCacheName, responseCreate.Resource.Properties.HostName); Assert.Equal(6379, responseCreate.Resource.Properties.Port); Assert.Equal(6380, responseCreate.Resource.Properties.SslPort); Assert.False(responseCreate.Resource.Properties.EnableNonSslPort); // wait for maximum 30 minutes for cache to create for (int i = 0; i < 60; i++) { TestUtilities.Wait(new TimeSpan(0, 0, 30)); RedisGetResponse responseGet = _client.Redis.Get(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName); if ("succeeded".Equals(responseGet.Resource.Properties.ProvisioningState, StringComparison.InvariantCultureIgnoreCase)) { break; } Assert.False(i == 60, "Cache is not in succeeded state even after 30 min."); } RedisCreateOrUpdateResponse responseUpdate = _client.Redis.CreateOrUpdate(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName, parameters: new RedisCreateOrUpdateParameters { Location = fixture.Location, Properties = new RedisProperties { RedisVersion = "2.8", Sku = new Sku() { Name = SkuName.Basic, Family = SkuFamily.C, Capacity = 0 }, RedisConfiguration = new Dictionary <string, string>() { { "maxmemory-policy", "allkeys-lru" } }, EnableNonSslPort = true } }); Assert.NotNull(responseUpdate.RequestId); Assert.Contains(fixture.RedisCacheName, responseUpdate.Resource.Id); Assert.Equal(fixture.Location, responseUpdate.Resource.Location); Assert.Equal(fixture.RedisCacheName, responseUpdate.Resource.Name); Assert.Equal("Microsoft.Cache/Redis", responseUpdate.Resource.Type); Assert.Equal(SkuName.Basic, responseUpdate.Resource.Properties.Sku.Name); Assert.Equal(SkuFamily.C, responseUpdate.Resource.Properties.Sku.Family); Assert.Equal(0, responseUpdate.Resource.Properties.Sku.Capacity); Assert.Contains("2.8", responseUpdate.Resource.Properties.RedisVersion); Assert.Equal("allkeys-lru", responseUpdate.Resource.Properties.RedisConfiguration["maxmemory-policy"]); Assert.Contains(fixture.RedisCacheName, responseUpdate.Resource.Properties.HostName); Assert.Equal(6379, responseUpdate.Resource.Properties.Port); Assert.Equal(6380, responseUpdate.Resource.Properties.SslPort); Assert.True(responseUpdate.Resource.Properties.EnableNonSslPort); AzureOperationResponse responseDelete = _client.Redis.Delete(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisCacheName); List <HttpStatusCode> acceptedStatusCodes = new List <HttpStatusCode>(); acceptedStatusCodes.Add(HttpStatusCode.OK); acceptedStatusCodes.Add(HttpStatusCode.Accepted); acceptedStatusCodes.Add(HttpStatusCode.NotFound); Assert.Contains <HttpStatusCode>(responseDelete.StatusCode, acceptedStatusCodes); Assert.NotNull(responseDelete.RequestId); TestUtilities.EndTest(); }
public void CreateUpdateDeleteClusterCacheTest() { TestUtilities.StartTest(); var _client = RedisCacheManagementTestUtilities.GetRedisManagementClient(this); RedisCreateOrUpdateResponse responseCreate = _client.Redis.CreateOrUpdate(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisClusterCacheName, parameters: new RedisCreateOrUpdateParameters { Location = fixture.ClusterCacheLocation, Properties = new RedisProperties { RedisVersion = "3.0", Sku = new Sku() { Name = SkuName.Premium, Family = SkuFamily.P, Capacity = 1 }, ShardCount = 2, TenantSettings = new Dictionary <string, string>() { { "some-key", "some-value" } } } }); Assert.Contains(fixture.RedisClusterCacheName, responseCreate.Resource.Id); Assert.Equal(fixture.ClusterCacheLocation, responseCreate.Resource.Location); Assert.Equal(fixture.RedisClusterCacheName, responseCreate.Resource.Name); Assert.True("creating".Equals(responseCreate.Resource.Properties.ProvisioningState, StringComparison.InvariantCultureIgnoreCase)); Assert.Equal(SkuName.Premium, responseCreate.Resource.Properties.Sku.Name); Assert.Equal(SkuFamily.P, responseCreate.Resource.Properties.Sku.Family); Assert.Equal(1, responseCreate.Resource.Properties.Sku.Capacity); Assert.Contains(fixture.RedisClusterCacheName, responseCreate.Resource.Properties.HostName); Assert.Equal(6379, responseCreate.Resource.Properties.Port); Assert.Equal(6380, responseCreate.Resource.Properties.SslPort); Assert.False(responseCreate.Resource.Properties.EnableNonSslPort.Value); Assert.Equal(2, responseCreate.Resource.Properties.ShardCount.Value); Assert.Equal("some-value", responseCreate.Resource.Properties.TenantSettings["some-key"]); // wait for maximum 30 minutes for cache to create for (int i = 0; i < 60; i++) { TestUtilities.Wait(new TimeSpan(0, 0, 30)); RedisGetResponse responseGet = _client.Redis.Get(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisClusterCacheName); if ("succeeded".Equals(responseGet.Resource.Properties.ProvisioningState, StringComparison.InvariantCultureIgnoreCase)) { break; } Assert.False(i == 60, "Cache is not in succeeded state even after 30 min."); } RedisCreateOrUpdateResponse responseUpdate = _client.Redis.CreateOrUpdate(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisClusterCacheName, parameters: new RedisCreateOrUpdateParameters { Location = fixture.ClusterCacheLocation, Properties = new RedisProperties { Sku = new Sku() { Name = SkuName.Premium, Family = SkuFamily.P, Capacity = 1 }, TenantSettings = new Dictionary <string, string>() { { "some-key-1", "some-value-1" } } } }); Assert.Equal("some-value-1", responseUpdate.Resource.Properties.TenantSettings["some-key-1"]); AzureOperationResponse responseDelete = _client.Redis.Delete(resourceGroupName: fixture.ResourceGroupName, name: fixture.RedisClusterCacheName); List <HttpStatusCode> acceptedStatusCodes = new List <HttpStatusCode>(); acceptedStatusCodes.Add(HttpStatusCode.OK); acceptedStatusCodes.Add(HttpStatusCode.Accepted); acceptedStatusCodes.Add(HttpStatusCode.NotFound); Assert.Contains <HttpStatusCode>(responseDelete.StatusCode, acceptedStatusCodes); Assert.NotNull(responseDelete.RequestId); TestUtilities.EndTest(); }
protected override void ProcessRecord() { 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); } string skuFamily; int skuCapacity = 1; 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, redisDefaultVersion, skuFamily, skuCapacity, Sku, RedisConfiguration, EnableNonSslPort), ResourceGroupName)); }
public RedisCacheAttributes(RedisGetResponse cache, string resourceGroupName) : this(cache.Resource, resourceGroupName) { }