示例#1
0
        // Deprovision Redshift Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string        connectionData    = request.ConnectionData;
            var           deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest          = request.Manifest;

            string devOptions = request.DeveloperOptions;

            try
            {
                AmazonRedshiftClient client;
                var conInfo          = ConnectionInfo.Parse(connectionData);
                var developerOptions = RedshiftDeveloperOptions.Parse(devOptions);

                var establishClientResult = EstablishClient(manifest, developerOptions, out client);
                if (!establishClientResult.IsSuccess)
                {
                    deprovisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return(deprovisionResult);
                }

                var response =
                    client.DeleteCluster(new DeleteClusterRequest()
                {
                    ClusterIdentifier = conInfo.ClusterIdentifier,
                    //SkipFinalSnapshot = true
                });
                // modified 5/22/14 to fix deprecation in Amazon AWS SDK
                if (response.Cluster != null)
                {
                    do
                    {
                        var verificationResponse = client.DescribeClusters(new DescribeClustersRequest()
                        {
                            ClusterIdentifier = conInfo.ClusterIdentifier
                        });
                        // modified 5/22/14 to fix deprecation in Amazon AWS SDK
                        if (!verificationResponse.Clusters.Any())
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (ClusterNotFoundException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return(deprovisionResult);
        }
示例#2
0
        private OperationResult ParseDevOptions(string developerOptions, out RedshiftDeveloperOptions devOptions)
        {
            devOptions = null;
            var result = new OperationResult()
            {
                IsSuccess = false
            };
            var progress = "";

            try
            {
                progress  += "Parsing developer options...\n";
                devOptions = RedshiftDeveloperOptions.Parse(developerOptions);
            }
            catch (ArgumentException e)
            {
                result.EndUserMessage = e.Message;
                return(result);
            }

            result.IsSuccess      = true;
            result.EndUserMessage = progress;
            return(result);
        }
示例#3
0
        // Provision Redshift Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("")
            {
                IsSuccess = false
            };
            AddonManifest manifest         = request.Manifest;
            string        developerOptions = request.DeveloperOptions;

            try
            {
                AmazonRedshiftClient     client;
                RedshiftDeveloperOptions devOptions;

                var parseOptionsResult = ParseDevOptions(developerOptions, out devOptions);
                if (!parseOptionsResult.IsSuccess)
                {
                    provisionResult.EndUserMessage = parseOptionsResult.EndUserMessage;
                    return(provisionResult);
                }

                var establishClientResult = EstablishClient(manifest, RedshiftDeveloperOptions.Parse(developerOptions), out client);
                if (!establishClientResult.IsSuccess)
                {
                    provisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return(provisionResult);
                }

                var response = client.CreateCluster(CreateClusterRequest(devOptions));
                // modified 5/22/14 to fix amazon aws deprecation
                if (response.Cluster != null)
                {
                    //var conInfo = new ConnectionInfo()
                    //{
                    //    DbInstanceIdentifier = devOptions.DbInstanceIndentifier
                    //};
                    //provisionResult.IsSuccess = true;
                    //provisionResult.ConnectionData = conInfo.ToString();
                    //Thread.Sleep(TimeSpan.FromMinutes(6));

                    do
                    {
                        var verificationResponse = client.DescribeClusters(new DescribeClustersRequest()
                        {
                            ClusterIdentifier = devOptions.ClusterIdentifier
                        });
                        // next few lines fixed 5/22/14 to resolve amazon aws deprecation
                        if (verificationResponse.Clusters.Any() && verificationResponse.Clusters[0].ClusterStatus == "available")
                        {
                            var dbInstance = verificationResponse.Clusters[0];
                            var conInfo    = new ConnectionInfo()
                            {
                                ClusterIdentifier = devOptions.ClusterIdentifier,
                                EndpointAddress   = dbInstance.Endpoint.Address,
                                EndpointPort      = dbInstance.Endpoint.Port
                            };
                            provisionResult.IsSuccess      = true;
                            provisionResult.ConnectionData = conInfo.ToString();
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return(provisionResult);
        }