internal static void UpdateTopologySet(DateTime captureTime, string accountId, string region, string entityIdentifier, string entityId, string memberKey, string changeType) { var latestDataKey = Common.GetDataKey("latest", accountId, region); var newDataKey = Common.GetDataKey(captureTime, accountId, region); var latestEntitySetKey = string.Format("{0}-{1}set", latestDataKey, entityIdentifier); var newEntitySetKey = string.Format("{0}-{1}set", newDataKey, entityIdentifier); var entityTimelineSetKey = string.Format("timeline-{0}-{1}-{2}", accountId, region, entityIdentifier); //var dataKey = Common.GetDataKey(accountId, region); var entityKey = string.Format("{0}-{1}-{2}", newDataKey, entityIdentifier, entityId); var db = RedisManager.GetRedisDatabase(); RedisManager.AddSetWithExpiry(entityKey, memberKey, db); //if (RedisManager.GetSet(latestEntitySetKey, db).Length > 0) { if (string.IsNullOrEmpty(changeType)) { RedisManager.AddSetWithExpiry(latestEntitySetKey, entityKey, db); } else { switch (changeType) { case "CREATE": RedisManager.AddSetWithExpiry(latestEntitySetKey, entityKey, db); break; case "UPDATE": RedisManager.RemoveSetMember(latestEntitySetKey, entityId, db); RedisManager.AddSetWithExpiry(latestEntitySetKey, entityKey, db); break; case "DELETE": RedisManager.RemoveSetMember(latestEntitySetKey, entityKey, db); break; } } } RedisManager.CopySetAndStore(newEntitySetKey, latestEntitySetKey, db); RedisManager.AddSortedSet(entityTimelineSetKey, newEntitySetKey, db); }
internal static void WriteAsgs(DateTime captureTime, string accountId, RegionEndpoint regionEndPoint) { var asc = new AmazonAutoScalingClient(regionEndPoint); DescribeAutoScalingGroupsResponse asgResponse = asc.DescribeAutoScalingGroups(); DescribeAutoScalingInstancesResponse asgInstanceResponse = asc.DescribeAutoScalingInstances(); var db = RedisManager.GetRedisDatabase(); foreach (var asGroup in asgResponse.AutoScalingGroups) { //to do: may not be required. //RedisManager.AddSetWithExpiry(string.Format("{0}-asgs", dataKey), string.Format("asg-{0}", asGroup.AutoScalingGroupName), db); var asgJson = JsonConvert.SerializeObject(asGroup); //RedisManager.AddWithExpiry(string.Format("{0}-asg-{1}", dataKey, asGroup.AutoScalingGroupName), asgJson, db); var newDataKey = Common.GetDataKey(captureTime, accountId, regionEndPoint.SystemName); var entityKey = string.Format("{0}-{1}-{2}", newDataKey, "asg", asGroup.AutoScalingGroupName); Common.UpdateTopology(captureTime, accountId, regionEndPoint.SystemName, "asg", asGroup.AutoScalingGroupName, asgJson, "UPDATE"); //code to add asg name to the instance details var latestDataKey = Common.GetDataKey("latest", accountId, regionEndPoint.SystemName); var latestEntitySetKey = string.Format("{0}-{1}set", latestDataKey, "ins"); foreach (var instance in asGroup.Instances) { //load instance data from redis var latestInstanceKey = RedisManager.GetSetMember(latestEntitySetKey, instance.InstanceId, db); var instanceJson = db.StringGet(latestInstanceKey.ToString()); if (instanceJson.HasValue) { var dataInstance = JsonConvert.DeserializeObject <Data.Instance>(instanceJson); //add elb name to instance dataInstance.AsgKeyName = entityKey; //add the instance data with asg name back to redis instanceJson = JsonConvert.SerializeObject(dataInstance); RedisManager.AddWithExpiry(latestInstanceKey, instanceJson, db); } } } }
internal static void WriteElbs(DateTime captureTime, string accountId, RegionEndpoint regionEndPoint) { var elbc = new AmazonElasticLoadBalancingClient(regionEndPoint); var elbResponse = elbc.DescribeLoadBalancers(); var db = RedisManager.GetRedisDatabase(); foreach (var elb in elbResponse.LoadBalancerDescriptions) { //to do: may not be required. //RedisManager.AddSetWithExpiry(string.Format("{0}-lbs", dataKey), string.Format("lbg-{0}", elb.LoadBalancerName), db); var elbJson = JsonConvert.SerializeObject(elb); //RedisManager.AddWithExpiry(string.Format("{0}-lb-{1}", dataKey, elb.LoadBalancerName), elbJson, db); var newDataKey = Common.GetDataKey(captureTime, accountId, regionEndPoint.SystemName); var entityKey = string.Format("{0}-{1}-{2}", newDataKey, "lb", elb.LoadBalancerName); Common.UpdateTopology(captureTime, accountId, regionEndPoint.SystemName, "lb", elb.LoadBalancerName, elbJson, "UPDATE"); //code to add elb name to the instance details var latestDataKey = Common.GetDataKey("latest", accountId, regionEndPoint.SystemName); var latestEntitySetKey = string.Format("{0}-{1}set", latestDataKey, "ins"); foreach (var instance in elb.Instances) { //load instance data from redis var latestInstanceKey = RedisManager.GetSetMember(latestEntitySetKey, instance.InstanceId, db); var instanceJson = db.StringGet(latestInstanceKey.ToString()); if (instanceJson.HasValue) { var dataInstance = JsonConvert.DeserializeObject <Data.Instance>(instanceJson); //add elb name to instance dataInstance.ElbKeyName = entityKey; //add the instance data with asg name back to redis instanceJson = JsonConvert.SerializeObject(dataInstance); RedisManager.AddWithExpiry(latestInstanceKey, instanceJson, db); } } } }