The Stack data type.
Esempio n. 1
0
        private static List<ResourceRecord> GetResourceRecords(IAwsClient awsClient, IEnumerable<StackResource> stackResources, AwsStack awsStack, string hostedZoneName)
        {
            var resourceRecords = new List<ResourceRecord>();
            if (stackResources.Any(x => x.ResourceType == ResourceTypeConstants.RecordSet))
            {
                string zoneName = hostedZoneName.Trim(new[] {'.'});
                HostedZone hostedZone = awsClient.DnsService.GetHostedZoneByName(zoneName);

                IEnumerable<ResourceRecordSet> resourceRecordSets = awsClient.DnsService.GetResourceRecordSets(hostedZone);
                string nameFilter = string.Format("{0}.{1}", awsStack.StackName, zoneName);

                resourceRecords = resourceRecordSets
                    .Where(x => x.Name.ToLower().Contains(nameFilter.ToLower()))
                    .Select(x => new ResourceRecord
                    {
                        FullyQualifiedDomainName = x.Name,
                        TimeToLive = (int) x.TTL,
                        Type = x.Type,
                        Values = x.ResourceRecords.Select(rr => rr.Value).ToList(),
                        ResourceId = x.Name // resource records don't have an ID in AWS, but this is unique so it's good enough for now
                    }).ToList();
            }

            return resourceRecords;
        }
Esempio n. 2
0
 private static void Map(AwsStack src, Stack dest)
 {
     dest.Description     = src.Description;
     dest.Name            = src.StackName;
     dest.CreateTime      = src.CreationTime;
     dest.ResourceId      = src.StackId;
     dest.Status          = src.StackStatus;
     dest.NeedsRefreshing = false;
 }
Esempio n. 3
0
        private static List <StackEvent> GetStackEvents(IAwsClient awsClient, AwsStack awsStack)
        {
            IEnumerable <AwsStackEvent> awsEvents = awsClient.StackService.GetStackEvents(awsStack);
            List <StackEvent>           events    = awsEvents.Select(x => new StackEvent
            {
                LogicalId = x.LogicalResourceId,
                Reason    = x.ResourceStatusReason,
                Status    = x.ResourceStatus,
                TimeStamp = x.Timestamp,
                Type      = x.ResourceType
            }).ToList();

            return(events);
        }
 public IEnumerable<StackResource> GetResources(Stack stack)
 {
     var request = new DescribeStackResourcesRequest {StackName = stack.StackName};
     DescribeStackResourcesResponse response;
     try
     {
         response = _cloudFormationClient.DescribeStackResources(request);
     }
     catch (AmazonCloudFormationException exception)
     {
         if (exception.Message.Contains(_nonExistenceMarker))
         {
             return Enumerable.Empty<StackResource>();
         }
         throw;
     }
     return response.StackResources;
 }
Esempio n. 5
0
        public void LoadStack(IAwsClient awsClient, AwsStack stack, string hostedZone, Guid profileId)
        {
            Stack dbStack = _stackRepository.FindAll().FirstOrDefault(x => x.Name == stack.StackName);

            IEnumerable <StackResource> stackResources  = awsClient.StackService.GetResources(stack).ToList();
            List <ResourceRecord>       resourceRecords = GetResourceRecords(awsClient, stackResources, stack, hostedZone);
            List <Guid> instanceIds = GetInstanceIds(stackResources).ToList();

            Stack        stackToPersist = dbStack ?? new Stack();
            SaveMechanic saveMechanic   = dbStack == null ? SaveMechanic.Add : SaveMechanic.Update;

            Map(stack, stackToPersist);
            stackToPersist.ResourceRecords = resourceRecords;
            if (!stackToPersist.CreatedByApplication)
            {
                stackToPersist.InstanceIds = instanceIds;
            }
            stackToPersist.StackEvents    = GetStackEvents(awsClient, stack);
            stackToPersist.OwnerProfileId = profileId;
            Persist(stackToPersist, saveMechanic);
        }
Esempio n. 6
0
        public void LoadStack(IAwsClient awsClient, AwsStack stack, string hostedZone, Guid profileId)
        {
            Stack dbStack = _stackRepository.FindAll().FirstOrDefault(x => x.Name == stack.StackName);

            IEnumerable<StackResource> stackResources = awsClient.StackService.GetResources(stack).ToList();
            List<ResourceRecord> resourceRecords = GetResourceRecords(awsClient, stackResources, stack, hostedZone);
            List<Guid> instanceIds = GetInstanceIds(stackResources).ToList();

            Stack stackToPersist = dbStack ?? new Stack();
            SaveMechanic saveMechanic = dbStack == null ? SaveMechanic.Add : SaveMechanic.Update;

            Map(stack, stackToPersist);
            stackToPersist.ResourceRecords = resourceRecords;
            if (!stackToPersist.CreatedByApplication)
            {
                stackToPersist.InstanceIds = instanceIds;
            }
            stackToPersist.StackEvents = GetStackEvents(awsClient, stack);
            stackToPersist.OwnerProfileId = profileId;
            Persist(stackToPersist, saveMechanic);
        }
Esempio n. 7
0
        private static List <ResourceRecord> GetResourceRecords(IAwsClient awsClient, IEnumerable <StackResource> stackResources, AwsStack awsStack, string hostedZoneName)
        {
            var resourceRecords = new List <ResourceRecord>();

            if (stackResources.Any(x => x.ResourceType == ResourceTypeConstants.RecordSet))
            {
                string     zoneName   = hostedZoneName.Trim(new[] { '.' });
                HostedZone hostedZone = awsClient.DnsService.GetHostedZoneByName(zoneName);

                IEnumerable <ResourceRecordSet> resourceRecordSets = awsClient.DnsService.GetResourceRecordSets(hostedZone);
                string nameFilter = string.Format("{0}.{1}", awsStack.StackName, zoneName);

                resourceRecords = resourceRecordSets
                                  .Where(x => x.Name.ToLower().Contains(nameFilter.ToLower()))
                                  .Select(x => new ResourceRecord
                {
                    FullyQualifiedDomainName = x.Name,
                    TimeToLive = (int)x.TTL,
                    Type       = x.Type,
                    Values     = x.ResourceRecords.Select(rr => rr.Value).ToList(),
                    ResourceId = x.Name                             // resource records don't have an ID in AWS, but this is unique so it's good enough for now
                }).ToList();
            }

            return(resourceRecords);
        }
Esempio n. 8
0
 private static List<StackEvent> GetStackEvents(IAwsClient awsClient, AwsStack awsStack)
 {
     IEnumerable<AwsStackEvent> awsEvents = awsClient.StackService.GetStackEvents(awsStack);
     List<StackEvent> events = awsEvents.Select(x => new StackEvent
     {
         LogicalId = x.LogicalResourceId,
         Reason = x.ResourceStatusReason,
         Status = x.ResourceStatus,
         TimeStamp = x.Timestamp,
         Type = x.ResourceType
     }).ToList();
     return events;
 }
Esempio n. 9
0
 private static void Map(AwsStack src, Stack dest)
 {
     dest.Description = src.Description;
     dest.Name = src.StackName;
     dest.CreateTime = src.CreationTime;
     dest.ResourceId = src.StackId;
     dest.Status = src.StackStatus;
     dest.NeedsRefreshing = false;
 }