Esempio n. 1
0
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string        connectionData      = request.ConnectionData;
            var           deprovisionResult   = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest            = request.Manifest;
            var           developerParameters = request.DeveloperParameters;
            var           developerOptions    = GoogleCloudDeveloperOptions.Parse(developerParameters);

            try
            {
                var conInfo = ConnectionInfo.Parse(connectionData);
                developerOptions.InstanceName = conInfo.InstanceName;
                developerOptions.Zone         = conInfo.Zone;
                var op = new InstanceOperations(manifest, developerOptions);
                op.RemoveInstance();
                deprovisionResult.IsSuccess      = true;
                deprovisionResult.EndUserMessage = "Successfully deleted instance: " + conInfo.InstanceName;
            }

            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
                deprovisionResult.IsSuccess      = false;
            }
            return(deprovisionResult);
        }
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var deprovisionResult = new ProvisionAddOnResult("") { IsSuccess = true };
            deprovisionResult.ConnectionData = "deprovision";
            AddonManifest manifest = request.Manifest;
            string connectionData = request.ConnectionData;
            string devOptions = request.DeveloperOptions;
            //string jobid = null;

            try
            {
                IAmazonElasticMapReduce client;
                //var conInfo = ConnectionInfo.Parse(connectionData);
                var developerOptions = EMRDeveloperOptions.Parse(devOptions);

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

                var result = client.TerminateJobFlows(new TerminateJobFlowsRequest() { JobFlowIds = { connectionData } });

                deprovisionResult.IsSuccess = true;
                deprovisionResult.EndUserMessage = "EMR Cluster Termination Request Successfully Invoked.";
            }
            catch (Exception)
            {
                deprovisionResult.EndUserMessage = "An error occurred during deprovisioning, please check the SOC logs for further assistance.";
            }

            return deprovisionResult;
        }
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var connectionData = request.ConnectionData;
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            var devOptions = DeveloperParameters.Parse(request.DeveloperParameters, request.Manifest.GetProperties());
            // set up the credentials for azure
            SubscriptionCloudCredentials creds = CertificateAuthenticationHelper.GetCredentials(devOptions.AzureManagementSubscriptionId, devOptions.AzureAuthenticationKey);
            // set up the storage management client
            var client = new StorageManagementClient(creds);

            // AI-121 & AI-122
            // we're going to have to implement some additional handling here, including parsing of the connection data
            // i strongly recommend we look at putting this in json

            // then if requested, delete the storage account name
            client.StorageAccounts.Delete(devOptions.StorageAccountName);

            do
            {
                var verificationResponse = client.StorageAccounts.Get(devOptions.StorageAccountName);

                if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Deleting))
                {
                    deprovisionResult.IsSuccess = true;
                    deprovisionResult.EndUserMessage = "Deprovision Request Complete, please allow a few minutes for resources to be fully deleted.";
                    break;
                }
                Thread.Sleep(TimeSpan.FromSeconds(10d));
            }
            while (true);
            return deprovisionResult;
        }
Esempio n. 4
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("")
            {
                IsSuccess = false
            };
            var manifest            = request.Manifest;
            var developerParameters = request.DeveloperParameters;
            var developerOptions    = GoogleCloudDeveloperOptions.Parse(developerParameters);

            try
            {
                //add instance
                var op = new InstanceOperations(manifest, developerOptions);
                op.AddInstance();
                provisionResult.IsSuccess      = true;
                provisionResult.ConnectionData = "InstanceName=" + developerOptions.InstanceName + "&Zone=" + developerOptions.Zone;
                provisionResult.EndUserMessage = "Successfully added instance " + developerOptions.InstanceName + "\n";
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
                provisionResult.IsSuccess      = false;
            }
            return(provisionResult);
        }
Esempio n. 5
0
        // Deprovision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var           deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest          = request.Manifest;
            string        devOptions        = request.DeveloperOptions;

            try
            {
                AmazonGlacierClient client;
                var conInfo          = ConnectionInfo.Parse(connectionData);
                var developerOptions = DeveloperOptions.Parse(devOptions);

                var establishClientResult = EstablishClient(manifest, developerOptions, out client);
                if (!establishClientResult.IsSuccess)
                {
                    deprovisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return(deprovisionResult);
                }
                var getArchivesInVault = client.DescribeVault(new DescribeVaultRequest()
                {
                    AccountId = conInfo.AccountId, VaultName = conInfo.VaultName
                });
                var response =
                    client.DeleteVault(new DeleteVaultRequest()
                {
                    AccountId = conInfo.AccountId,
                    VaultName = conInfo.VaultName
                });
                // 5/22/14 fixing amazon aws deprecation
                if (response.HttpStatusCode != null)
                {
                    do
                    {
                        var verificationResponse = client.DescribeVault(new DescribeVaultRequest()
                        {
                        });
                        // 5/22/14 fixing amazaon aws deprecration
                        if (verificationResponse == null)
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (ResourceNotFoundException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return(deprovisionResult);
        }
        // Provision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("") { IsSuccess = false };
            var manifest = request.Manifest;
            var developerOptions = request.DeveloperOptions;

            try
            {
                AmazonS3Client client;
                S3DeveloperOptions devOptions;

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

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

                var response = client.PutBucket(new PutBucketRequest
                {
                    BucketName = devOptions.BucketName,
                    BucketRegion = S3Region.US
                });

                if (response.HttpStatusCode != HttpStatusCode.OK)
                {
                    provisionResult.EndUserMessage = response.HttpStatusCode.ToString();
                    return provisionResult;
                }

                var verificationResponse = client.ListBuckets(new ListBucketsRequest());

                var bucket = verificationResponse.Buckets.Find(m => m.BucketName.Equals(devOptions.BucketName));

                if (bucket == null)
                {
                    provisionResult.EndUserMessage = "We aren't getting the bucket filtered here correctly.";
                    return provisionResult;
                }

                provisionResult.ConnectionData = "BucketName=" + devOptions.BucketName;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
                Log.Error(e.Message + "\n" + e.StackTrace);
                provisionResult.EndUserMessage = e.Message + "\n" + e.StackTrace;
            }

            provisionResult.IsSuccess = true;
            return provisionResult;
        }
Esempio n. 7
0
        // Deprovision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var           deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest          = request.Manifest;
            string        devOptions        = request.DeveloperOptions;

            try
            {
                AmazonSQSClient client;
                var             conInfo          = ConnectionInfo.Parse(connectionData);
                var             developerOptions = DeveloperOptions.Parse(devOptions);

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

                var response =
                    client.DeleteQueue(new DeleteQueueRequest()
                {
                    QueueUrl = conInfo.queueURL
                });

                do
                {
                    var verificationResponse = client.GetQueueUrl(new GetQueueUrlRequest()
                    {
                        QueueName = conInfo.queueName,
                        QueueOwnerAWSAccountId = developerOptions.AccessKey,
                    });
                    // 5/22/14 fixing amazaon aws deprecration
                    if (verificationResponse.QueueUrl == null)
                    {
                        deprovisionResult.IsSuccess = true;
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(10d));
                } while (true);
            }

            catch (QueueDoesNotExistException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (QueueDeletedRecentlyException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return(deprovisionResult);
        }
        // Deprovision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest = request.Manifest;
            string devOptions = request.DeveloperOptions;

            try
            {
                AmazonSQSClient client;
                var conInfo = ConnectionInfo.Parse(connectionData);
                var developerOptions = DeveloperOptions.Parse(devOptions);

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

                var response =
                    client.DeleteQueue(new DeleteQueueRequest()
                    {
                        QueueUrl = conInfo.queueURL
                    });

                do  {
                        var verificationResponse = client.GetQueueUrl(new GetQueueUrlRequest()
                        {
                            QueueName = conInfo.queueName,
                            QueueOwnerAWSAccountId = developerOptions.AccessKey,
                        });
                        // 5/22/14 fixing amazaon aws deprecration
                        if (verificationResponse.QueueUrl == null)
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));

                    } while (true);
                }

            catch (QueueDoesNotExistException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (QueueDeletedRecentlyException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return deprovisionResult;
        }
        // Deprovision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest = request.Manifest;
            string devOptions = request.DeveloperOptions;

            try
            {
                AmazonGlacierClient client;
                var conInfo = ConnectionInfo.Parse(connectionData);
                var developerOptions = DeveloperOptions.Parse(devOptions);

                var establishClientResult = EstablishClient(manifest, developerOptions, out client);
                if (!establishClientResult.IsSuccess)
                {
                    deprovisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return deprovisionResult;
                }
                var getArchivesInVault = client.DescribeVault(new DescribeVaultRequest() { AccountId = conInfo.AccountId, VaultName = conInfo.VaultName });
                var response =
                    client.DeleteVault(new DeleteVaultRequest()
                    {
                        AccountId = conInfo.AccountId,
                        VaultName = conInfo.VaultName
                    });
                // 5/22/14 fixing amazon aws deprecation
                if (response.HttpStatusCode != null)
                {
                    do
                    {
                        var verificationResponse = client.DescribeVault(new DescribeVaultRequest()
                        {

                        });
                        // 5/22/14 fixing amazaon aws deprecration
                        if (verificationResponse == null)
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));

                    } while (true);
                }
            }
            catch (ResourceNotFoundException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return deprovisionResult;
        }
        // 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;
        }
        // Deprovision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest = request.Manifest;
            string devOptions = request.DeveloperOptions;

            try
            {
                AmazonRDSClient client;
                var conInfo = ConnectionInfo.Parse(connectionData);
                var developerOptions = DeveloperOptions.Parse(devOptions);

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

                var response =
                    client.DeleteDBInstance(new DeleteDBInstanceRequest()
                        {
                            DBInstanceIdentifier = conInfo.DbInstanceIdentifier,
                            SkipFinalSnapshot = true
                        });
                // 5/22/14 fixing amazon aws deprecation
                if (response.DBInstance != null)
                {
                    do
                    {
                        var verificationResponse = client.DescribeDBInstances(new DescribeDBInstancesRequest()
                            {
                                DBInstanceIdentifier = conInfo.DbInstanceIdentifier
                            });
                        // 5/22/14 fixing amazaon aws deprecration
                        if (!verificationResponse.DBInstances.Any())
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (DBInstanceNotFoundException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return deprovisionResult;
        }
Esempio n. 12
0
        // Deprovision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: OperationResult
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var           deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest          = request.Manifest;
            string        devOptions        = request.DeveloperOptions;

            try
            {
                AmazonRDSClient client;
                var             conInfo          = ConnectionInfo.Parse(connectionData);
                var             developerOptions = DeveloperOptions.Parse(devOptions);

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

                var response =
                    client.DeleteDBInstance(new DeleteDBInstanceRequest()
                {
                    DBInstanceIdentifier = conInfo.DbInstanceIdentifier,
                    SkipFinalSnapshot    = true
                });
                // 5/22/14 fixing amazon aws deprecation
                if (response.DBInstance != null)
                {
                    do
                    {
                        var verificationResponse = client.DescribeDBInstances(new DescribeDBInstancesRequest()
                        {
                            DBInstanceIdentifier = conInfo.DbInstanceIdentifier
                        });
                        // 5/22/14 fixing amazaon aws deprecration
                        if (!verificationResponse.DBInstances.Any())
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (DBInstanceNotFoundException)
            {
                deprovisionResult.IsSuccess = true;
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message;
            }

            return(deprovisionResult);
        }
Esempio n. 13
0
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var           deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest          = request.Manifest;
            string        devOptions        = request.DeveloperOptions;

            try
            {
                AmazonSimpleNotificationServiceClient client;
                var conInfo               = ConnectionInfo.Parse(connectionData);
                var developerOptions      = DeveloperOptions.Parse(devOptions);
                var establishClientResult = EstablishClient(manifest, developerOptions, out client);
                if (!establishClientResult.IsSuccess)
                {
                    deprovisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return(deprovisionResult);
                }
                var response =
                    client.DeleteTopic(new DeleteTopicRequest()
                {
                    TopicArn = conInfo.TopicArn
                });
                if (response.HttpStatusCode != null)
                {
                    do
                    {
                        // ok, to verify deletion, we need to list all of the topics and search for the one we just deleted.
                        // if it's still there, its probably in queue to be deleted, we'll sleep the thread and give it a minute.
                        // once its gone, we'll return true.
                        // if after an intolerable amount of time the queue is still there, throw an error.
                        var verificationResponse = client.ListTopics(new ListTopicsRequest());
                        // if there are no topics, ok!
                        if (verificationResponse.Topics.Count == 0)
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        // if there are existing topics, search for the one we just deleted.
                        if (verificationResponse.Topics.Find(m => m.TopicArn.Equals(conInfo.TopicArn)) == null)
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        // otherwise, the topic still exists and we need to wait a little longer.
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage += "An error occurred during deletion. Your SNS queue may be deleted, but we were unable to verify. Please check your AWS Console.";
                deprovisionResult.EndUserMessage += e.Message;
            }
            return(deprovisionResult);
        }
Esempio n. 14
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);
        }
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest = request.Manifest;
            string devOptions = request.DeveloperOptions;
            try
            {
                AmazonSimpleNotificationServiceClient client;
                var conInfo = ConnectionInfo.Parse(connectionData);
                var developerOptions = DeveloperOptions.Parse(devOptions);
                var establishClientResult = EstablishClient(manifest, developerOptions, out client);
                if (!establishClientResult.IsSuccess)
                {
                    deprovisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return deprovisionResult;
                }
                var response =
                    client.DeleteTopic(new DeleteTopicRequest()
                    {
                        TopicArn = conInfo.TopicArn
                    });
                if (response.HttpStatusCode != null)
                {
                    do
                    {
                        // ok, to verify deletion, we need to list all of the topics and search for the one we just deleted.
                        // if it's still there, its probably in queue to be deleted, we'll sleep the thread and give it a minute.
                        // once its gone, we'll return true.
                        // if after an intolerable amount of time the queue is still there, throw an error.
                        var verificationResponse = client.ListTopics(new ListTopicsRequest());
                        // if there are no topics, ok!
                        if (verificationResponse.Topics.Count == 0)
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        // if there are existing topics, search for the one we just deleted.
                        if(verificationResponse.Topics.Find(m => m.TopicArn.Equals(conInfo.TopicArn)) == null)
                        {
                            deprovisionResult.IsSuccess = true;
                            break;
                        }
                        // otherwise, the topic still exists and we need to wait a little longer.
                        Thread.Sleep(TimeSpan.FromSeconds(10d));

                    } while (true);
                }
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage += "An error occurred during deletion. Your SNS queue may be deleted, but we were unable to verify. Please check your AWS Console.";
                deprovisionResult.EndUserMessage += e.Message;
            }
            return deprovisionResult;
        }
Esempio n. 16
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("");
            var manifest        = request.Manifest;
            var inputDevParams  = request.DeveloperParameters;

            try
            {
                // parse required options here, use developer options class to do so.
                var manifestProperties = manifest.GetProperties();
                // Developer Options will be instantiated first time here (hence, null).
                var devParams = DeveloperParameters.Parse(inputDevParams, manifestProperties);
                // establish MSFT Azure Storage client
                var client = EstablishClient(devParams);

                // ok now we need to understand what the developer wants to do.
                // ------------------------------------------------------------
                // logic:
                //    - if the developer wishes to create a storage account, we go that route first
                //    - if a storage account exists, test it (including above)
                //    - create the blob container
                // ------------------------------------------------------------
                var parameters = CreateStorageAccountParameters(devParams);
                var mResponse  = client.StorageAccounts.Create(parameters);
                do
                {
                    StorageAccountGetResponse verificationResponse = client.StorageAccounts.Get(parameters.Name);

                    if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Created))
                    {
                        StorageAccountGetResponse azureconnectioninfo =
                            client.StorageAccounts.Get(devParams.StorageAccountName);
                        StorageAccountGetKeysResponse keysForStorageUnit =
                            client.StorageAccounts.GetKeys(devParams.StorageAccountName);

                        var connectionInfo = new ConnectionInfo
                        {
                            PrimaryKey         = keysForStorageUnit.PrimaryKey,
                            SecondaryKey       = keysForStorageUnit.SecondaryKey,
                            StorageAccountName = azureconnectioninfo.StorageAccount.Name,
                            URI = keysForStorageUnit.Uri.ToString()
                        };
                        provisionResult.ConnectionData = connectionInfo.ToString();
                        // deprovision request of storage account was successful.
                        provisionResult.IsSuccess = true;
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(10d));
                } while (true);
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return(provisionResult);
        }
Esempio n. 17
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("");
            var manifest = request.Manifest;
            var inputDevParams = request.DeveloperParameters;
            try
            {
                // parse required options here, use developer options class to do so.
                var manifestProperties = manifest.GetProperties();
                // Developer Options will be instantiated first time here (hence, null).
                var devParams = DeveloperParameters.Parse(inputDevParams,manifestProperties);
                // establish MSFT Azure Storage client
                var client = EstablishClient(devParams);

                // ok now we need to understand what the developer wants to do.
                // ------------------------------------------------------------
                // logic:
                //    - if the developer wishes to create a storage account, we go that route first
                //    - if a storage account exists, test it (including above)
                //    - create the blob container
                // ------------------------------------------------------------
                var parameters = CreateStorageAccountParameters(devParams);
                var mResponse = client.StorageAccounts.Create(parameters);
                do
                {
                    StorageAccountGetResponse verificationResponse = client.StorageAccounts.Get(parameters.Name);

                    if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Created))
                    {
                        StorageAccountGetResponse azureconnectioninfo =
                            client.StorageAccounts.Get(devParams.StorageAccountName);
                        StorageAccountGetKeysResponse keysForStorageUnit =
                            client.StorageAccounts.GetKeys(devParams.StorageAccountName);

                        var connectionInfo = new ConnectionInfo
                        {
                            PrimaryKey = keysForStorageUnit.PrimaryKey,
                            SecondaryKey = keysForStorageUnit.SecondaryKey,
                            StorageAccountName = azureconnectioninfo.StorageAccount.Name,
                            URI = keysForStorageUnit.Uri.ToString()
                        };
                        provisionResult.ConnectionData = connectionInfo.ToString();
                        // deprovision request of storage account was successful.
                        provisionResult.IsSuccess = true;
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(10d));
                } while (true);
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return provisionResult;
        }
Esempio n. 18
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            /*The Provision method provisions the instance for the service you are setting up. Within this method, you can access the information
             * requested from the developer (if any) by iterating through the request.DeveloperParameters object.
             * At the end of the provisioning process, simply return the connection information for the service that was provisioned.*/
            //Retrieving developer parameters
            var parameter = request.DeveloperParameters.First(param => param.Key == "RequiredParameter");
            var result    = new ProvisionAddOnResult(string.Format("addon-location: {0}", parameter.Value), true, string.Format("The Add-On was provisioned successfully."));

            return(result);
        }
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest = request.Manifest;
            string devOptions = request.DeveloperOptions;

            try
            {
                AmazonS3Client client;
                var conInfo = ConnectionInfo.Parse(connectionData);
                var developerOptions = S3DeveloperOptions.Parse(devOptions);
                // heh, need to know which bucket to remove...
                developerOptions.BucketName = conInfo.BucketName;

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

                var response =
                    client.DeleteBucket(new DeleteBucketRequest
                    {
                        BucketName = developerOptions.BucketName
                    });
                // 5/22/14 fixing amazon aws deprecation
                if (response.HttpStatusCode.Equals(HttpStatusCode.OK))
                {
                    var verificationResponse = client.ListBuckets(new ListBucketsRequest());
                    // 5/22/14 fixing amazaon aws deprecration
                    if (verificationResponse.Buckets.All(x => x.BucketName != conInfo.BucketName))
                    {
                        deprovisionResult.IsSuccess = true;
                        deprovisionResult.EndUserMessage = "Successfully deleted bucket: " + conInfo.BucketName;
                    }
                }
                else
                {
                    // error occurred during deletion
                    deprovisionResult.EndUserMessage = "Error during deprovision. Check S3 to ensure bucket was deleted.";
                }
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message + e.StackTrace;
            }

            return deprovisionResult;
        }
Esempio n. 20
0
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            string connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var           deprovisionResult = new ProvisionAddOnResult(connectionData);
            AddonManifest manifest          = request.Manifest;
            string        devOptions        = request.DeveloperOptions;

            try
            {
                AmazonS3Client client;
                var            conInfo          = ConnectionInfo.Parse(connectionData);
                var            developerOptions = S3DeveloperOptions.Parse(devOptions);
                // heh, need to know which bucket to remove...
                developerOptions.BucketName = conInfo.BucketName;

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

                var response =
                    client.DeleteBucket(new DeleteBucketRequest
                {
                    BucketName = developerOptions.BucketName
                });
                // 5/22/14 fixing amazon aws deprecation
                if (response.HttpStatusCode.Equals(HttpStatusCode.OK))
                {
                    var verificationResponse = client.ListBuckets(new ListBucketsRequest());
                    // 5/22/14 fixing amazaon aws deprecration
                    if (verificationResponse.Buckets.All(x => x.BucketName != conInfo.BucketName))
                    {
                        deprovisionResult.IsSuccess      = true;
                        deprovisionResult.EndUserMessage = "Successfully deleted bucket: " + conInfo.BucketName;
                    }
                }
                else
                {
                    // error occurred during deletion
                    deprovisionResult.EndUserMessage = "Error during deprovision. Check S3 to ensure bucket was deleted.";
                }
            }
            catch (Exception e)
            {
                deprovisionResult.EndUserMessage = e.Message + e.StackTrace;
            }

            return(deprovisionResult);
        }
Esempio n. 21
0
        // Provision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var           provisionResult  = new ProvisionAddOnResult("");
            AddonManifest manifest         = request.Manifest;
            string        developerOptions = request.DeveloperOptions;

            try
            {
                AmazonGlacierClient client;
                DeveloperOptions    devOptions;

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

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

                var response = client.CreateVault(CreateVaultRequest(devOptions));
                // fix 5/22/14 resolves amazon aws deprecation
                // wait for response to come back with a location
                while (true)
                {
                    if (response.Location != null)
                    {
                        var conInfo = new ConnectionInfo()
                        {
                            AccountId = devOptions.AccountId,
                            VaultName = devOptions.VaultName,
                            Location  = response.Location
                        };
                        provisionResult.IsSuccess      = true;
                        provisionResult.ConnectionData = conInfo.ToString();
                        break;
                    }
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }
            return(provisionResult);
        }
Esempio n. 22
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("");

            try
            {
                var devParameters = DeveloperParameters.Parse(request.DeveloperParameters, request.Manifest.GetProperties());

                SubscriptionCloudCredentials creds = CertificateAuthenticationHelper.GetCredentials(devParameters.AzureManagementSubscriptionId, devParameters.AzureAuthenticationKey, devParameters.PFXPassword);

                // ok so if we need a storage account, we need to use the storage management client.
                if (devParameters.NewStorageAccountFlag)
                {
                    var client     = new StorageManagementClient(creds);
                    var parameters = CreateStorageAccountParameters(devParameters);
                    client.StorageAccounts.Create(parameters);
                    do
                    {
                        var verificationResponse = client.StorageAccounts.Get(parameters.Name);

                        if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Created))
                        {
                            var azureconnectioninfo = client.StorageAccounts.Get(devParameters.StorageAccountName);
                            var keysForStorageUnit  = client.StorageAccounts.GetKeys(devParameters.StorageAccountName);

                            var connectionInfo = new ConnectionInfo
                            {
                                PrimaryKey         = keysForStorageUnit.PrimaryKey,
                                SecondaryKey       = keysForStorageUnit.SecondaryKey,
                                StorageAccountName = azureconnectioninfo.StorageAccount.Name,
                                Uri = keysForStorageUnit.Uri.ToString()
                            };
                            provisionResult.ConnectionData = connectionInfo.ToString();
                            provisionResult.IsSuccess      = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (Exception e)
            {
                provisionResult.IsSuccess      = false;
                provisionResult.EndUserMessage = e.Message + "\n We're in an error\n";
            }

            return(provisionResult);
        }
Esempio n. 23
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            /*The Provision method provisions the instance for the service you are setting up. Within this method, you can access the information
             * requested from the developer (if any) by iterating through the request.DeveloperParameters object.
             * At the end of the provisioning process, simply return the connection information for the service that was provisioned.*/
            //Retrieving developer parameters
            //var parameter = request.DeveloperParameters.First(param => param.Key == "RequiredParameter");

            // Retrieving manifest properties
            var splunkURL   = request.Manifest.Properties.First(param => param.Key == "SplunkServerURL");
            var splunkToken = request.Manifest.Properties.First(param => param.Key == "SplunkHTTPToken");

            var result = new ProvisionAddOnResult(string.Format("{{'SplunkEndpoint': '{0}', 'AccessToken': '{1}'}}", splunkURL.Value, splunkToken.Value), true, string.Format("The Add-On was provisioned successfully."));

            return(result);
        }
Esempio n. 24
0
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var deprovisionResult  = new ProvisionAddOnResult(connectionData);
            var manifest           = request.Manifest;
            var inputDevParameters = request.DeveloperParameters;
            // parse required options here, use developer options class to do so.
            var manifestProperties = manifest.GetProperties();
            // Developer Options will be instantiated first time here.
            var devParams = DeveloperParameters.Parse(inputDevParameters, manifestProperties);

            // set up the credentials for azure
            var creds = CertificateAuthenticationHelper.GetCredentials(devParams.AzureManagementSubscriptionId,
                                                                       devParams.AzureAuthenticationKey);
            // set up the storage management client
            var client = new StorageManagementClient();

            var mResponse = client.StorageAccounts.Delete(devParams.StorageAccountName);

            if (mResponse.StatusCode.Equals(HttpStatusCode.OK))
            {
                do
                {
                    var verificationResponse =
                        client.StorageAccounts.Get(devParams.StorageAccountName);

                    if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Deleting))
                    {
                        deprovisionResult.IsSuccess      = true;
                        deprovisionResult.EndUserMessage =
                            "Deprovision Request Complete, please allow a few minutes for resources to be fully deleted.";
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(10d));
                } while (true);
                return(deprovisionResult);
            }
            else
            {
                return(new OperationResult()
                {
                    EndUserMessage = "Azure Query failed. Please check your syntax and credetials.",
                    IsSuccess = false
                });
            }
        }
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("");
            try
            {
                var devParameters = DeveloperParameters.Parse(request.DeveloperParameters, request.Manifest.GetProperties());

                SubscriptionCloudCredentials creds = CertificateAuthenticationHelper.GetCredentials(devParameters.AzureManagementSubscriptionId, devParameters.AzureAuthenticationKey);

                // ok so if we need a storage account, we need to use the storage management client.
                if (devParameters.NewStorageAccountFlag)
                {
                    var client = new StorageManagementClient(creds);
                    var parameters = CreateStorageAccountParameters(devParameters);
                    client.StorageAccounts.Create(parameters);
                    do
                    {
                        var verificationResponse = client.StorageAccounts.Get(parameters.Name);

                        if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Created))
                        {
                            var azureconnectioninfo = client.StorageAccounts.Get(devParameters.StorageAccountName);
                            var keysForStorageUnit = client.StorageAccounts.GetKeys(devParameters.StorageAccountName);

                            var connectionInfo = new ConnectionInfo
                            {
                                PrimaryKey = keysForStorageUnit.PrimaryKey,
                                SecondaryKey = keysForStorageUnit.SecondaryKey,
                                StorageAccountName = azureconnectioninfo.StorageAccount.Name,
                                Uri = keysForStorageUnit.Uri.ToString()
                            };
                            provisionResult.ConnectionData = connectionInfo.ToString();
                            provisionResult.IsSuccess = true;
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (Exception e)
            {
                provisionResult.IsSuccess = false;
                provisionResult.EndUserMessage = e.Message + "\n We're in an error\n";
            }

            return provisionResult;
        }
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            /*The Provision method provisions the instance for the service you are setting up. Within this method, you can access the information
             * requested from the developer (if any) by iterating through the request.DeveloperParameters object.
             * At the end of the provisioning process, simply return the connection information for the service that was provisioned.*/
            //Retrieving developer parameters
            //var parameter = request.DeveloperParameters.First(param => param.Key == "RequiredParameter");

            // Retrieving manifest properties
            var accessKey       = request.Manifest.ProvisioningUsername;
            var secretAccessKey = request.Manifest.ProvisioningPassword;
            var regionEndpoint  = request.Manifest.Properties.First(param => param.Key == "AWSRegion");

            var result = new ProvisionAddOnResult(string.Format("{{'AWSAccessKey': '{0}', 'AWSSecretAccessKey': '{1}', 'AWSRegionEndpoint': '{2}'}}", accessKey, secretAccessKey, regionEndpoint.Value), true, string.Format("The Add-On was provisioned successfully."));

            return(result);
        }
Esempio n. 27
0
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var connectionData = request.ConnectionData;
            // changing to overloaded constructor - 5/22/14
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            var manifest = request.Manifest;
            var inputDevParameters = request.DeveloperParameters;
            // parse required options here, use developer options class to do so.
            var manifestProperties = manifest.GetProperties();
            // Developer Options will be instantiated first time here.
            var devParams = DeveloperParameters.Parse(inputDevParameters, manifestProperties);

            // set up the credentials for azure
            var creds = CertificateAuthenticationHelper.GetCredentials(devParams.AzureManagementSubscriptionId,
                    devParams.AzureAuthenticationKey);
            // set up the storage management client
            var client = new StorageManagementClient();

            var mResponse = client.StorageAccounts.Delete(devParams.StorageAccountName);
            if (mResponse.StatusCode.Equals(HttpStatusCode.OK))
            {
                do
                {
                    var verificationResponse =
                        client.StorageAccounts.Get(devParams.StorageAccountName);

                    if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Deleting))
                    {
                        deprovisionResult.IsSuccess = true;
                        deprovisionResult.EndUserMessage =
                            "Deprovision Request Complete, please allow a few minutes for resources to be fully deleted.";
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(10d));
                } while (true);
                return deprovisionResult;
            }
            else
            {
                return new OperationResult()
                {
                    EndUserMessage = "Azure Query failed. Please check your syntax and credetials.",
                    IsSuccess = false
                };
            }
        }
        public override ProvisionAddOnResult Provision(AddonProvisionRequest _request)
        {
            /*The Provision method provisions the instance for the service you are setting up. Within this method, you can access the information
             * requested from the developer (if any) by iterating through the request.DeveloperParameters object.
             * At the end of the provisioning process, simply return the connection information for the service that was provisioned.*/
            //Retrieving developer parameters
            //var parameter = request.DeveloperParameters.First(param => param.Key == "RequiredParameter");

            var provisionResult = new ProvisionAddOnResult(string.Empty)
            {
                IsSuccess = false
            };

            var manifest      = _request.Manifest;
            var devParameters = _request.DeveloperParameters;
            var devOptions    = WCDeveloperOptions.Parse(devParameters, manifest);
            var appURL        = "";

            cloud_url = devOptions.cloudurl;
            appname   = devOptions.name;
            appalias  = devOptions.alias;

            JObject instanceDetails = new JObject();

            try
            {
                var token = authenticate(devOptions.apprendausername, devOptions.apprendapassword, devOptions.apprendatenant);
                createApp(token, appname, appalias, "NodeJS API Server for Watson Conversation");
                var archivePath = createArchive(devOptions.workspace, devOptions.conversationusername, devOptions.conversationpassword);
                setArchive(token, appalias, valias, archivePath);
                promoteApp(token, appalias, valias);
                appURL = getAppURL(token, appalias, valias);
                log.Info("WatsonConversationAddon Provisioned Successfully");
            }
            catch (Exception ex) {
                var errorMessage = string.Format("WatsonConversationAddon Provisioning Error: {0}\n{1}", ex, ex.StackTrace);
                log.Error(errorMessage);
                provisionResult.EndUserMessage = errorMessage;
                return(provisionResult);
            }

            provisionResult.IsSuccess      = true;
            provisionResult.ConnectionData = appURL;
            return(provisionResult);
        }
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var rabbitConfig = new RabbitMQConfig(request);
            var client       = new RestClient(rabbitConfig.ManagementUri);

            client.Authenticator = new HttpBasicAuthenticator(rabbitConfig.AdminUser, rabbitConfig.AdminPassword);

            // Delete vhost
            var vhostName          = request.Manifest.CallingDeveloperAlias + "_" + request.Manifest.InstanceAlias;
            var deleteVhostPath    = $"vhosts/{vhostName}";
            var deleteVhostRequest = new RestRequest(deleteVhostPath, Method.DELETE)
            {
                RequestFormat = DataFormat.Json
            };

            deleteVhostRequest.AddHeader("content-type", "application/json");

            var deleteVhostResponse = client.Execute(deleteVhostRequest);

            if (deleteVhostResponse.ResponseStatus != ResponseStatus.Completed)
            {
                return(ProvisionAddOnResult.Failure("Unable to delete vhost"));
            }

            // Delete user
            var user = request.Manifest.CallingDeveloperAlias + "_" + request.Manifest.InstanceAlias;

            var deleteUserPath = $"users/{user}";

            var deleteUserRequest = new RestRequest(deleteUserPath, Method.DELETE)
            {
                RequestFormat = DataFormat.Json
            };

            deleteUserRequest.AddHeader("content-type", "application/json");

            var deleteUserResponse = client.Execute(deleteUserRequest);

            if (deleteUserResponse.ResponseStatus != ResponseStatus.Completed)
            {
                return(ProvisionAddOnResult.Failure("Unable to delete user"));
            }

            return(ProvisionAddOnResult.Success("RabbitMQ Addon Instance Deprovisioned Successfully"));
        }
 // Provision NetApp Volume
 // Input: AddonDeprovisionRequest request
 // Output: ProvisionAddOnResult
 public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
 {
     var provisionResult = new ProvisionAddOnResult("") {IsSuccess = false};
     try
     {
         var developerParameters = DeveloperParameters.Parse(request.DeveloperParameters, request.Manifest);
         var netappresponse = NetAppFactory.CreateVolume(developerParameters);
         provisionResult = netappresponse.ToAddOnResult();
         // this appears to be wrong. we need to check what's coming back from the powershell script
         //provisionResult.IsSuccess = true;
         provisionResult.ConnectionData = developerParameters.VolumeToProvision.BuildConnectionString();
     }
     catch (Exception e)
     {
         provisionResult.IsSuccess = false;
         provisionResult.EndUserMessage = e.Message + "\n" + e.StackTrace;
     }
     return provisionResult;
 }
Esempio n. 31
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            return(Task.Run(async() =>
            {
                try
                {
                    var volumeSize = request.DeveloperParameters.First(p => p.Key == "VolumeSize").Value;

                    await new Logic(request.Manifest).ProvisionVolume(
                        request.Manifest.InstanceAlias, volumeSize);

                    return ProvisionAddOnResult.Success(request.Manifest.InstanceAlias);
                }
                catch (Exception ex)
                {
                    return ProvisionAddOnResult.Failure($"Error provisioning Kubernetes volume: {ex}");
                }
            }).GetAwaiter().GetResult());
        }
Esempio n. 32
0
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var deprovisionResult = new ProvisionAddOnResult("")
            {
                IsSuccess = true
            };

            deprovisionResult.ConnectionData = "deprovision";
            AddonManifest manifest       = request.Manifest;
            string        connectionData = request.ConnectionData;
            string        devOptions     = request.DeveloperOptions;

            //string jobid = null;

            try
            {
                IAmazonElasticMapReduce client;
                //var conInfo = ConnectionInfo.Parse(connectionData);
                var developerOptions = EMRDeveloperOptions.Parse(devOptions);

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

                var result = client.TerminateJobFlows(new TerminateJobFlowsRequest()
                {
                    JobFlowIds = { connectionData }
                });

                deprovisionResult.IsSuccess      = true;
                deprovisionResult.EndUserMessage = "EMR Cluster Termination Request Successfully Invoked.";
            }
            catch (Exception)
            {
                deprovisionResult.EndUserMessage = "An error occurred during deprovisioning, please check the SOC logs for further assistance.";
            }

            return(deprovisionResult);
        }
Esempio n. 33
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var result = new ProvisionAddOnResult();

            try
            {
                NewDatabase = GetDatabaseName(request.Manifest);
                NewUserId   = GetNewUsername(request.Manifest);
                NewPassword = GetPassword();

                log.InfoFormat("Creating MsSql database: {0}", NewDatabase);

                using (var connection = GetConnection(request.Manifest.Properties))
                {
                    CreateDatabase(connection);

                    CreateUser(connection);

                    GrantPrivileges(connection);
                }

                result.IsSuccess      = true;
                result.ConnectionData = NewConnectionString;
                result.EndUserMessage = "Successfully created a MsSql database.";

                log.InfoFormat("Successfully created MsSql database: {0}", NewDatabase);
            }
            catch (Exception ex)
            {
                result.IsSuccess      = false;
                result.ConnectionData = "";
                result.EndUserMessage = ex.Message;

                log.ErrorFormat("Failed to create MsSql database '{0}': {1}", NewDatabase, ex.Message);
                log.Error(ex.StackTrace);
            }

            return(result);
        }
        public override ProvisionAddOnResult Provision(AddonProvisionRequest _request)
        {
            var provisionResult = new ProvisionAddOnResult(string.Empty)
            {
                IsSuccess = false
            };

            var manifest      = _request.Manifest;
            var devParameters = _request.DeveloperParameters;
            var devOptions    = BMDeveloperOptions.Parse(devParameters, manifest);

            end_point  = devOptions.api_url;
            bm_version = devOptions.api_version;

            string instanceDetails = "";

            try
            {
                var    token               = authenticate(devOptions.bluemixuser, devOptions.bluemixpass);
                var    servicePlansURL     = getServicePlansURL(token, devOptions.servicename);
                var    servicePlanGUID     = getServicePlanGUID(token, servicePlansURL);
                string name                = devOptions.name;
                var    spaceGUID           = getSpaceGuid(token, devOptions.space);
                var    serviceInstanceGUID = createServiceInstance(token, name, servicePlanGUID, spaceGUID);
                instanceDetails = createInstanceDetails(token, name, serviceInstanceGUID);
                log.Info("BluemixAddon Provisioned Successfully");
            }
            catch (Exception ex) {
                var errorMessage = string.Format("BluemixAddon Provisioning Error: {0}\n{1}", ex, ex.StackTrace);
                log.Error(errorMessage);
                provisionResult.EndUserMessage = errorMessage;
                return(provisionResult);
            }

            provisionResult.IsSuccess      = true;
            provisionResult.ConnectionData = instanceDetails;
            return(provisionResult);
        }
Esempio n. 35
0
        public override OperationResult Deprovision(AddonDeprovisionRequest request)
        {
            var connectionData    = request.ConnectionData;
            var deprovisionResult = new ProvisionAddOnResult(connectionData);
            var devOptions        = DeveloperParameters.Parse(request.DeveloperParameters, request.Manifest.GetProperties());
            // set up the credentials for azure
            SubscriptionCloudCredentials creds = CertificateAuthenticationHelper.GetCredentials(devOptions.AzureManagementSubscriptionId, devOptions.AzureAuthenticationKey, devOptions.PFXPassword);
            // set up the storage management client
            var client = new StorageManagementClient(creds);

            // check to see if the storage accounts exists...if they do not exist, throw a no-op here.
            var account = client.StorageAccounts.Get(devOptions.StorageAccountName);

            if (account.StatusCode.Equals(HttpStatusCode.NotFound))
            {
                // no account found. return a no-op as something went wrong, proceed to deletion
                deprovisionResult.IsSuccess      = true;
                deprovisionResult.EndUserMessage = "Storage account not found, may have been deleted via 3rd party.";
                return(deprovisionResult);
            }

            // then if requested, delete the storage account name
            client.StorageAccounts.Delete(devOptions.StorageAccountName);

            do
            {
                var verificationResponse = client.StorageAccounts.Get(devOptions.StorageAccountName);

                if (verificationResponse.StorageAccount.Properties.Status.Equals(StorageAccountStatus.Deleting))
                {
                    deprovisionResult.IsSuccess      = true;
                    deprovisionResult.EndUserMessage = "Deprovision Request Complete, please allow a few minutes for resources to be fully deleted.";
                    break;
                }
                Thread.Sleep(TimeSpan.FromSeconds(10d));
            }while (true);
            return(deprovisionResult);
        }
Esempio n. 36
0
        // Provision NetApp Volume
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("")
            {
                IsSuccess = false
            };

            try
            {
                var developerParameters = DeveloperParameters.Parse(request.DeveloperParameters, request.Manifest);
                var netappresponse      = NetAppFactory.CreateVolume(developerParameters);
                provisionResult = netappresponse.ToAddOnResult();
                // this appears to be wrong. we need to check what's coming back from the powershell script
                //provisionResult.IsSuccess = true;
                provisionResult.ConnectionData = developerParameters.VolumeToProvision.BuildConnectionString();
            }
            catch (Exception e)
            {
                provisionResult.IsSuccess      = false;
                provisionResult.EndUserMessage = e.Message + "\n" + e.StackTrace;
            }
            return(provisionResult);
        }
Esempio n. 37
0
        // Provision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var           provisionResult  = new ProvisionAddOnResult("");
            AddonManifest manifest         = request.Manifest;
            string        developerOptions = request.DeveloperOptions;

            try
            {
                AmazonRDSClient  client;
                DeveloperOptions devOptions;

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

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

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

                    do
                    {
                        var verificationResponse = client.DescribeDBInstances(new DescribeDBInstancesRequest()
                        {
                            DBInstanceIdentifier = devOptions.DbInstanceIdentifier
                        });
                        // fix on next few lines 5/22/14 resolve amazon aws deprecation.
                        if (verificationResponse.DBInstances.Any() && verificationResponse.DBInstances[0].DBInstanceStatus == "available")
                        {
                            var dbInstance = verificationResponse.DBInstances[0];
                            var conInfo    = new ConnectionInfo()
                            {
                                DbInstanceIdentifier = devOptions.DbInstanceIdentifier,
                                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);
        }
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var rabbitConfig = new RabbitMQConfig(request);
            var client       = new RestClient(rabbitConfig.ManagementUri);

            client.Authenticator = new HttpBasicAuthenticator(rabbitConfig.AdminUser, rabbitConfig.AdminPassword);

            // Create new user
            var user = request.Manifest.CallingDeveloperAlias + "_" + request.Manifest.InstanceAlias;
            var pass = Guid.NewGuid().ToString("N");

            var createUserPath = $"users/{user}";
            var createUserBody = new { password = pass, tags = "monitoring,management,administrator" };

            var createUserRequest = new RestRequest(createUserPath, Method.PUT)
            {
                RequestFormat = DataFormat.Json
            };

            createUserRequest.AddBody(createUserBody);
            createUserRequest.AddHeader("content-type", "application/json");

            log.DebugFormat("The following user is being created: {0} using the following URI: ", user, createUserPath.ToString());
            var createUserResponse = client.Execute(createUserRequest);

            log.DebugFormat("The response code for the user creation REST call is: {0}", createUserResponse.StatusCode);
            if (createUserResponse.StatusCode != HttpStatusCode.Created)
            {
                return(ProvisionAddOnResult.Failure("Unable to create user"));
            }

            Thread.Sleep(5000);
            // Create new vhost
            var vhostName          = request.Manifest.CallingDeveloperAlias + "_" + request.Manifest.InstanceAlias;
            var createVhostPath    = $"vhosts/{vhostName}";
            var createVhostRequest = new RestRequest(createVhostPath, Method.PUT)
            {
                RequestFormat = DataFormat.Json
            };

            createVhostRequest.AddHeader("content-type", "application/json");

            log.DebugFormat("The following vhost is being created: {0} using the following URI:", vhostName, createVhostPath.ToString());
            var createVhostResponse = client.Execute(createVhostRequest);

            log.DebugFormat("The response code for the vhost creationg REST call is: {0}", createVhostResponse.StatusCode);
            if (createVhostResponse.StatusCode != HttpStatusCode.Created)
            {
                //If this fails, we need to clean up the previous command

                // Delete user
                var deleteUserPath = $"users/{user}";

                var deleteUserRequest = new RestRequest(deleteUserPath, Method.DELETE)
                {
                    RequestFormat = DataFormat.Json
                };
                deleteUserRequest.AddHeader("content-type", "application/json");

                var deleteUserResponse = client.Execute(deleteUserRequest);

                return(ProvisionAddOnResult.Failure("Unable to create vhost"));
            }

            Thread.Sleep(5000);
            // Set permissions
            var permissionsPath    = $"permissions/{vhostName}/{user}";
            var permissionsBody    = new { configure = ".*", write = ".*", read = ".*" };
            var permissionsRequest = new RestRequest(permissionsPath, Method.PUT)
            {
                RequestFormat = DataFormat.Json
            };

            permissionsRequest.AddHeader("content-type", "application/json");
            permissionsRequest.AddBody(permissionsBody);

            log.DebugFormat("The permissions are being configuring using the following URI: {0}", permissionsPath);
            var permissionsResponse = client.Execute(permissionsRequest);

            log.DebugFormat("The response code for configuring the permissions is: {0}", permissionsResponse.StatusCode);
            if (permissionsResponse.StatusCode != HttpStatusCode.Created)
            {
                //If this fails, we need to clean up the previous command

                // Delete user
                var deleteUserPath = $"users/{user}";

                var deleteUserRequest = new RestRequest(deleteUserPath, Method.DELETE)
                {
                    RequestFormat = DataFormat.Json
                };
                deleteUserRequest.AddHeader("content-type", "application/json");

                var deleteUserResponse = client.Execute(deleteUserRequest);

                // Delete Vhost
                var deleteVhostPath    = $"vhosts/{vhostName}";
                var deleteVhostRequest = new RestRequest(deleteVhostPath, Method.DELETE)
                {
                    RequestFormat = DataFormat.Json
                };
                deleteVhostRequest.AddHeader("content-type", "application/json");

                var deleteVhostResponse = client.Execute(deleteVhostRequest);

                return(ProvisionAddOnResult.Failure("Unable to set permissions"));
            }

            var connectionString = $"amqp://{user}:{pass}@{rabbitConfig.Hostname}:{rabbitConfig.Port}/{vhostName}";

            return(ProvisionAddOnResult.Success(connectionString));
        }
        // Provision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var provisionResult = new ProvisionAddOnResult("");
            AddonManifest manifest = request.Manifest;
            string developerOptions = request.DeveloperOptions;

            try
            {
                AmazonRDSClient client;
                DeveloperOptions devOptions;

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

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

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

                    do
                    {
                        var verificationResponse = client.DescribeDBInstances(new DescribeDBInstancesRequest()
                            {
                                DBInstanceIdentifier = devOptions.DbInstanceIdentifier
                            });
                        // fix on next few lines 5/22/14 resolve amazon aws deprecation.
                        if (verificationResponse.DBInstances.Any() && verificationResponse.DBInstances[0].DBInstanceStatus == "available")
                        {
                            var dbInstance = verificationResponse.DBInstances[0];
                            var conInfo = new ConnectionInfo()
                                {
                                    DbInstanceIdentifier = devOptions.DbInstanceIdentifier,
                                    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;
        }
Esempio n. 40
0
        /// <summary>
        /// Provisions an instance of this add-on.
        /// </summary>
        /// <param name="_request">A request object encapsulating all the parameters available to provision an add-on.</param>
        /// <returns>
        /// A <see cref="T:Apprenda.SaaSGrid.Addons.ProvisionAddOnResult"/> object containing the results of the operation as well as the data needed to connect to / use the newly provisioned instance.
        /// </returns>
        public override ProvisionAddOnResult Provision(AddonProvisionRequest _request)
        {
            if (_request == null)
            {
                throw new ArgumentNullException("_request");
            }
            // developerOptions is a string of arbitrary arguments used at provisioning time.
            // In this case, we need to know the username and password of the user to be assigned to this DB.
            // The expected format is: username=<username>,password=<password>
            //
            // NOTE: In the real world it may not be the best idea to pass in the username and password.
            //       Instead they could be derived and guaranteed unique from data in the manifest.
            //       However, this illustrates how one might use the developerOptions parameter.

            var parameters = DeveloperParameters.Parse(_request.DeveloperParameters, _request.Manifest.Properties);
            // since there is no connection data yet, this constructor doesn't make sense. but just throw an empty string for now.
            var result = new ProvisionAddOnResult("", false, "");

            try
            {
                string port;
                try
                {
                    port = _request.Manifest.Properties.Find(_x => _x.Key.Equals("port")).Value;
                }
                catch (ArgumentNullException)
                {
                    port = "27017";
                }
                //var connectionString = string.Format("mongodb://{0}:{1}", _request.Manifest.ProvisioningLocation, port);
                var connectionString = GetConnectionString(_request.Manifest.ProvisioningLocation,
                                                           port,
                                                           _request.Manifest.ProvisioningUsername,
                                                           _request.Manifest.ProvisioningPassword);
                var client       = new MongoClient(connectionString);
                var databaseName = GetDatabaseName(_request.Manifest, parameters);
                var database     = client.GetDatabase(databaseName);
                var document     = CreateUserAdd(parameters.Username, parameters.Password, databaseName);
                database.RunCommand <BsonDocument>(document);
                // creates a new database. note - the database will not be created until something is written to it
                var newCollection = database.GetCollection <ProvisioningData>("__provisioningData");
                newCollection.InsertOne(new ProvisioningData());

                // Set the connection string that the app will use.
                // This connection string includes the username and password given for this instance.
                result.ConnectionData = GetConnectionString(_request.Manifest.ProvisioningLocation, port, parameters.Username, parameters.Password, databaseName);
                //result.ConnectionData = string.Format("mongodb://{0}:{1}/{2}", _request.Manifest.ProvisioningLocation, port, databaseName);
                result.IsSuccess = true;
            }
            catch (MongoException mongoException)
            {
                Logger.ErrorFormat("Error occurred during provisioning: {0} \n {1}", mongoException.Message, mongoException.StackTrace);
                result.EndUserMessage = mongoException.Message;
                result.IsSuccess      = false;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                Logger.ErrorFormat("General error occurred during provisioning: {0} \n {1}", e.Message, e.StackTrace);
            }

            return(result);
        }
Esempio n. 41
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("") { IsSuccess = true };
            AddonManifest manifest = request.Manifest;
            string developerOptions = request.DeveloperOptions;

            try
            {
                IAmazonElasticMapReduce client;
                EMRDeveloperOptions devOptions;

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

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

                var stepFactory = new StepFactory();

                StepConfig enabledebugging = null;

                if (devOptions.EnableDebugging)
                {
                    enabledebugging = new StepConfig
                    {
                        Name = "Enable debugging",
                        ActionOnFailure = "TERMINATE_JOB_FLOW",
                        HadoopJarStep = stepFactory.NewEnableDebuggingStep()
                    };
                }

                var installHive = new StepConfig
                {
                    Name = "Install Hive",
                    ActionOnFailure = "TERMINATE_JOB_FLOW",
                    HadoopJarStep = stepFactory.NewInstallHiveStep()
                };

                var instanceConfig = new JobFlowInstancesConfig
                {
                    Ec2KeyName = devOptions.Ec2KeyName,
                    HadoopVersion = "0.20",
                    InstanceCount = devOptions.InstanceCount,
                    // this is important. the EMR job flow must be kept alive for the application to see it during provisioning
                    KeepJobFlowAliveWhenNoSteps = true,
                    MasterInstanceType = devOptions.MasterInstanceType,
                    SlaveInstanceType = devOptions.SlaveInstanceType
                };

                var _request = new RunJobFlowRequest
                {
                    Name = devOptions.JobFlowName,
                    Steps = { enabledebugging, installHive },
                    // revisit this one in ne
                    LogUri = "s3://myawsbucket",
                    Instances = instanceConfig
                };

                // if debugging is enabled, add to top of the list of steps.
                if (devOptions.EnableDebugging)
                {
                    _request.Steps.Insert(0, enabledebugging);
                }

                var result = client.RunJobFlow(_request);

                // wait for JobFlowID to come back.
                while (result.JobFlowId == null)
                {
                    Thread.Sleep(1000);
                }

                provisionResult.IsSuccess = true;
                provisionResult.ConnectionData = string.Format(result.JobFlowId);
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return provisionResult;
        }
        // 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;
        }
        // Provision SNS Topic
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var provisionResult = new ProvisionAddOnResult("");
            AddonManifest manifest = request.Manifest;
            string developerOptions = request.DeveloperOptions;
            try
            {
                AmazonSimpleNotificationServiceClient client;
                DeveloperOptions devOptions;
                var parseOptionsResult = ParseDevOptions(developerOptions, out devOptions);
                if (!parseOptionsResult.IsSuccess)
                {
                    provisionResult.EndUserMessage = parseOptionsResult.EndUserMessage;
                    return provisionResult;
                }
                var establishClientResult = EstablishClient(manifest, DeveloperOptions.Parse(developerOptions), out client);
                if (!establishClientResult.IsSuccess)
                {
                    provisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return provisionResult;
                }
                var response = client.CreateTopic(CreateTopicRequest(devOptions));
                do
                    {
                        var verificationResponse = client.GetTopicAttributes(new GetTopicAttributesRequest()
                            {
                                TopicArn = response.TopicArn
                            });
                        // ok so the attributes works as follows:
                        // attributes[0] - topicarn
                        // attributes[1] - owner
                        // attributes[2] - policy
                        // attributes[3] - displayname
                        // attributes[4] - subscriptionspending
                        // attributes[5] - subscriptionsconfirmed
                        // attributes[6] - subscriptionsdeleted
                        // attributes[7] - deliverypolicy
                        // attributes[8] - effectivedeliverypolicy
                        if (verificationResponse.Attributes["TopicArn"].Equals(response.TopicArn))
                        {
                            var conInfo = new ConnectionInfo()
                            {
                                TopicArn = verificationResponse.Attributes["TopicArn"],
                                QueueName = verificationResponse.Attributes["DisplayName"]

                            };
                            provisionResult.IsSuccess = true;
                            provisionResult.ConnectionData = conInfo.ToString();
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);

            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return provisionResult;
        }
Esempio n. 44
0
        // Provision SNS Topic
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var           provisionResult  = new ProvisionAddOnResult("");
            AddonManifest manifest         = request.Manifest;
            string        developerOptions = request.DeveloperOptions;

            try
            {
                AmazonSimpleNotificationServiceClient client;
                DeveloperOptions devOptions;
                var parseOptionsResult = ParseDevOptions(developerOptions, out devOptions);
                if (!parseOptionsResult.IsSuccess)
                {
                    provisionResult.EndUserMessage = parseOptionsResult.EndUserMessage;
                    return(provisionResult);
                }
                var establishClientResult = EstablishClient(manifest, DeveloperOptions.Parse(developerOptions), out client);
                if (!establishClientResult.IsSuccess)
                {
                    provisionResult.EndUserMessage = establishClientResult.EndUserMessage;
                    return(provisionResult);
                }
                var response = client.CreateTopic(CreateTopicRequest(devOptions));
                do
                {
                    var verificationResponse = client.GetTopicAttributes(new GetTopicAttributesRequest()
                    {
                        TopicArn = response.TopicArn
                    });
                    // ok so the attributes works as follows:
                    // attributes[0] - topicarn
                    // attributes[1] - owner
                    // attributes[2] - policy
                    // attributes[3] - displayname
                    // attributes[4] - subscriptionspending
                    // attributes[5] - subscriptionsconfirmed
                    // attributes[6] - subscriptionsdeleted
                    // attributes[7] - deliverypolicy
                    // attributes[8] - effectivedeliverypolicy
                    if (verificationResponse.Attributes["TopicArn"].Equals(response.TopicArn))
                    {
                        var conInfo = new ConnectionInfo()
                        {
                            TopicArn  = verificationResponse.Attributes["TopicArn"],
                            QueueName = verificationResponse.Attributes["DisplayName"]
                        };
                        provisionResult.IsSuccess      = true;
                        provisionResult.ConnectionData = conInfo.ToString();
                        break;
                    }
                    Thread.Sleep(TimeSpan.FromSeconds(10d));
                } while (true);
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return(provisionResult);
        }
Esempio n. 45
0
        // Provision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var           provisionResult  = new ProvisionAddOnResult("");
            AddonManifest manifest         = request.Manifest;
            string        developerOptions = request.DeveloperOptions;

            try
            {
                AmazonSQSClient  client;
                DeveloperOptions devOptions;

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

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

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

                    do
                    {
                        var verificationResponse = client.GetQueueAttributes(new GetQueueAttributesRequest()
                        {
                            QueueUrl = response.QueueUrl
                        });
                        // fix on next few lines 5/22/14 resolve amazon aws deprecation.
                        if (verificationResponse.Attributes != null)
                        {
                            var conInfo = new ConnectionInfo()
                            {
                                queueName = devOptions.QueueName,
                                queueURL  = response.QueueUrl
                            };
                            provisionResult.IsSuccess      = true;
                            provisionResult.ConnectionData = conInfo.ToString();
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));
                    } while (true);
                }
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return(provisionResult);
        }
Esempio n. 46
0
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            var provisionResult = new ProvisionAddOnResult("")
            {
                IsSuccess = true
            };
            AddonManifest manifest         = request.Manifest;
            string        developerOptions = request.DeveloperOptions;

            try
            {
                IAmazonElasticMapReduce client;
                EMRDeveloperOptions     devOptions;

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

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

                var stepFactory = new StepFactory();

                StepConfig enabledebugging = null;

                if (devOptions.EnableDebugging)
                {
                    enabledebugging = new StepConfig
                    {
                        Name            = "Enable debugging",
                        ActionOnFailure = "TERMINATE_JOB_FLOW",
                        HadoopJarStep   = stepFactory.NewEnableDebuggingStep()
                    };
                }

                var installHive = new StepConfig
                {
                    Name            = "Install Hive",
                    ActionOnFailure = "TERMINATE_JOB_FLOW",
                    HadoopJarStep   = stepFactory.NewInstallHiveStep()
                };

                var instanceConfig = new JobFlowInstancesConfig
                {
                    Ec2KeyName    = devOptions.Ec2KeyName,
                    HadoopVersion = "0.20",
                    InstanceCount = devOptions.InstanceCount,
                    // this is important. the EMR job flow must be kept alive for the application to see it during provisioning
                    KeepJobFlowAliveWhenNoSteps = true,
                    MasterInstanceType          = devOptions.MasterInstanceType,
                    SlaveInstanceType           = devOptions.SlaveInstanceType
                };

                var _request = new RunJobFlowRequest
                {
                    Name  = devOptions.JobFlowName,
                    Steps = { enabledebugging, installHive },
                    // revisit this one in ne
                    LogUri    = "s3://myawsbucket",
                    Instances = instanceConfig
                };

                // if debugging is enabled, add to top of the list of steps.
                if (devOptions.EnableDebugging)
                {
                    _request.Steps.Insert(0, enabledebugging);
                }

                var result = client.RunJobFlow(_request);

                // wait for JobFlowID to come back.
                while (result.JobFlowId == null)
                {
                    Thread.Sleep(1000);
                }

                provisionResult.IsSuccess      = true;
                provisionResult.ConnectionData = string.Format(result.JobFlowId);
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return(provisionResult);
        }
        // Provision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var provisionResult = new ProvisionAddOnResult("");
            AddonManifest manifest = request.Manifest;
            string developerOptions = request.DeveloperOptions;

            try
            {
                AmazonGlacierClient client;
                DeveloperOptions devOptions;

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

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

                var response = client.CreateVault(CreateVaultRequest(devOptions));
                // fix 5/22/14 resolves amazon aws deprecation
                // wait for response to come back with a location
                while (true)
                {
                    if (response.Location != null)
                    {
                        var conInfo = new ConnectionInfo()
                        {
                            AccountId = devOptions.AccountId,
                            VaultName = devOptions.VaultName,
                            Location = response.Location
                        };
                        provisionResult.IsSuccess = true;
                        provisionResult.ConnectionData = conInfo.ToString();
                        break;
                    }
                    Thread.Sleep(10);
                }
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }
            return provisionResult;
        }
        // Provision RDS Instance
        // Input: AddonDeprovisionRequest request
        // Output: ProvisionAddOnResult
        public override ProvisionAddOnResult Provision(AddonProvisionRequest request)
        {
            // i think this is a bug. but I'm going to throw an empty string to it to clear the warning.
            var provisionResult = new ProvisionAddOnResult("");
            AddonManifest manifest = request.Manifest;
            string developerOptions = request.DeveloperOptions;

            try
            {
                AmazonSQSClient client;
                DeveloperOptions devOptions;

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

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

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

                    do
                    {
                        var verificationResponse = client.GetQueueAttributes(new GetQueueAttributesRequest()
                            {
                                QueueUrl = response.QueueUrl
                            });
                        // fix on next few lines 5/22/14 resolve amazon aws deprecation.
                        if(verificationResponse.Attributes != null)
                        {
                            var conInfo = new ConnectionInfo()
                            {
                                queueName = devOptions.QueueName,
                                queueURL = response.QueueUrl
                            };
                            provisionResult.IsSuccess = true;
                            provisionResult.ConnectionData = conInfo.ToString();
                            break;
                        }
                        Thread.Sleep(TimeSpan.FromSeconds(10d));

                    } while (true);
                }
            }
            catch (Exception e)
            {
                provisionResult.EndUserMessage = e.Message;
            }

            return provisionResult;
        }
Esempio n. 49
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);
        }