static void Main(string[] args) { var addon = new Addon(); var manifest = new AddonManifest { Author = "Abraham Sultan", Vendor = "Apprenda Inc.", Version = "1.0.0.0", IsEnabled = true, Name = "AWS RDS", Properties = new List <AddonProperty>() { new AddonProperty() { Key = "requireDevCredentials", Value = "true" } } }; var request = new AddonTestRequest { Manifest = manifest, DeveloperOptions = "" }; addon.Test(request); }
private static string GetNewUsername(AddonManifest manifest) { var developmentTeamAlias = manifest.CallingDeveloperAlias; var instanceAlias = manifest.InstanceAlias; return(string.Format(DatabaseUsernameFormatter, developmentTeamAlias, instanceAlias)); }
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); }
private bool ValidateManifest(AddonManifest manifest, out OperationResult testResult) { testResult = new OperationResult(); var prop = manifest.Properties.FirstOrDefault( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (prop == null || !prop.HasValue) { testResult.IsSuccess = false; testResult.EndUserMessage = "Missing required property 'requireDevCredentials'. This property needs to be provided as part of the manifest"; return(false); } if (string.IsNullOrWhiteSpace(manifest.ProvisioningUsername) || string.IsNullOrWhiteSpace(manifest.ProvisioningPassword)) { testResult.IsSuccess = false; testResult.EndUserMessage = "Missing credentials 'provisioningUsername' & 'provisioningPassword' . These values needs to be provided as part of the manifest"; return(false); } return(true); }
public bool ValidateManifest(AddonManifest manifest, out OperationResult testResult) { testResult = new OperationResult(); var prop = manifest.Properties.FirstOrDefault( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (prop == null || !prop.HasValue) { testResult.IsSuccess = false; testResult.EndUserMessage = "Missing required property 'requireDevCredentials'. This property needs to be provided as part of the manifest"; return false; } if (string.IsNullOrWhiteSpace(manifest.ProvisioningUsername) || string.IsNullOrWhiteSpace(manifest.ProvisioningPassword)) { testResult.IsSuccess = false; testResult.EndUserMessage = "Missing credentials 'provisioningUsername' & 'provisioningPassword' . These values needs to be provided as part of the manifest"; return false; } return true; }
private OperationResult ParseDevOptions(string developerOptions, AddonManifest manifest, out DeveloperOptions devOptions) { devOptions = null; var result = new OperationResult() { IsSuccess = false }; var progress = ""; try { progress += "Parsing developer options...\n"; devOptions = DeveloperOptions.Parse(developerOptions); // we're probably going to need these lines a few times Dictionary <string, string> manifestProperties = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); devOptions.AccessKey = manifestProperties["AWSClientKey"]; devOptions.SecretAccessKey = manifestProperties["AWSSecretKey"]; devOptions.AccountId = manifestProperties["AWSAccountID"]; //devOptions.RegionEndpoint = manifestProperties["RegionEndpoint"]; } catch (ArgumentException e) { result.EndUserMessage = e.Message; return(result); } result.IsSuccess = true; result.EndUserMessage = progress; return(result); }
internal void LoadItemsFromManifest(AddonManifest manifest) { try { var manifestProperties = manifest.GetProperties(); foreach (var manifestProperty in manifestProperties) { //Console.WriteLine("Debug- manifestProperty Key: " + manifestProperty.DisplayName + " Value: " + manifestProperty.Value); switch (manifestProperty.Key.Trim().ToLowerInvariant()) { case ("acesskey"): AccessKey = manifestProperty.Value; break; case ("secretkey"): SecretAccessKey = manifestProperty.Value; break; case ("useclientregion"): bool tmp; bool.TryParse(manifestProperty.Value, out tmp); UseClientRegion = tmp; break; case ("regionEndpoint"): RegionEndpont = manifestProperty.Value; break; case ("amiid"): AmiId = manifestProperty.Value; break; case ("ec2keypair"): Ec2KeyPair = manifestProperty.Value; break; case ("securityGroups"): SecurityGroupId = manifestProperty.Value; break; case ("defaultinstancetype"): InstanceType = manifestProperty.Value; break; case ("instancecommonname"): InstanceCommonName = manifestProperty.Value; break; default: // means there are other manifest properties we don't need. Console.WriteLine("Key not added: " + manifestProperty.DisplayName); break; } } } catch (Exception e) { throw new Exception(e.Message + "\n Debug information: " + manifest.GetProperties()); } }
// 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); }
internal void LoadItemsFromManifest(AddonManifest manifest) { try { var manifestProperties = manifest.GetProperties(); foreach (var manifestProperty in manifestProperties) { //Console.WriteLine("Debug- manifestProperty Key: " + manifestProperty.DisplayName + " Value: " + manifestProperty.Value); switch (manifestProperty.Key.Trim().ToLowerInvariant()) { case ("acesskey"): AccessKey = manifestProperty.Value; break; case ("secretkey"): SecretAccessKey = manifestProperty.Value; break; case ("useclientregion"): bool tmp; bool.TryParse(manifestProperty.Value, out tmp); UseClientRegion = tmp; break; case ("regionEndpoint"): RegionEndpont = manifestProperty.Value; break; case ("amiid"): AmiId = manifestProperty.Value; break; case ("ec2keypair"): Ec2KeyPair = manifestProperty.Value; break; case ("securityGroups"): SecurityGroupId = manifestProperty.Value; break; case ("defaultinstancetype"): InstanceType = manifestProperty.Value; break; case ("instancecommonname"): InstanceCommonName = manifestProperty.Value; break; default: // means there are other manifest properties we don't need. Console.WriteLine("Key not added: " + manifestProperty.DisplayName); break; } } } catch (Exception e) { throw new Exception(e.Message + "\n Debug information: " + manifest.GetProperties()); } }
// 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); }
private string GetListenerUrl(AddonManifest manifest) { var hostname = manifest.Properties.Single(p => p.Key == "hostname").Value; var port = manifest.Properties.Single(p => p.Key == "port").Value; var protocol = manifest.Properties.Single(p => p.Key == "protocol").Value; return($"{protocol}://{hostname}:{port}"); }
public override OperationResult Test(AddonTestRequest request) { AddonManifest manifest = request.Manifest; string developerOptions = request.DeveloperOptions; var testResult = new OperationResult { IsSuccess = false }; var testProgress = ""; //string jobid = null; if (manifest.Properties != null && manifest.Properties.Any()) { EMRDeveloperOptions devOptions; testProgress += "Evaluating required manifest properties...\n"; if (!ValidateManifest(manifest, out testResult)) { return(testResult); } var parseOptionsResult = ParseDevOptions(developerOptions, out devOptions); if (!parseOptionsResult.IsSuccess) { return(parseOptionsResult); } testProgress += parseOptionsResult.EndUserMessage; try { testProgress += "Establishing connection to AWS...\n"; IAmazonElasticMapReduce client; var establishClientResult = EstablishClient(manifest, devOptions, out client); if (!establishClientResult.IsSuccess) { return(establishClientResult); } testProgress += establishClientResult.EndUserMessage; testProgress += "Successfully passed all testing criteria!"; testResult.IsSuccess = true; testResult.EndUserMessage = testProgress; } catch (Exception e) { testResult.EndUserMessage = e.Message; } } else { testResult.EndUserMessage = "Missing required manifest properties (requireDevCredentials)"; } return(testResult); }
// 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); }
// 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); }
private bool ValidateManifest(AddonManifest addonManifest) { return(addonManifest != null && addonManifest.GetType().GetProperties() .Where(pi => pi.PropertyType == typeof(string)) .Select(pi => (string)pi.GetValue(addonManifest)) .All(value => !string.IsNullOrEmpty(value)) && addonManifest.Type.Equals(WellKnownData.AddOnUploadType, StringComparison.OrdinalIgnoreCase)); }
// handled on a policy-basis via the manifest // Method takes in a string and parses it into a DeveloperOptions class. public static DeveloperParameters Parse(IEnumerable<AddonParameter> developerParameters, AddonManifest manifest) { var dParams = new DeveloperParameters(new Volume()); foreach (var param in developerParameters) { MapToOption(dParams, param.Key.Trim().ToLowerInvariant(), param.Value.Trim()); } dParams = LoadItemsFromManifest(dParams, manifest); return dParams; }
private static AddonManifest SetupPropertiesAndParameters() { var plist = new List <DevParameter>(); plist.Add(new DevParameter() { Key = "username", DisplayName = "Username" }); plist.Add(new DevParameter() { Key = "password", DisplayName = "Password", IsEncrypted = true }); plist.Add(new DevParameter() { Key = "database", DisplayName = "Database" }); var port = new AddonProperty { Key = "port", Value = "32770" }; var manifest = new AddonManifest { AllowUserDefinedParameters = true, Author = "Chris Dutra", DeploymentNotes = "", Description = "", DeveloperHelp = "", IsEnabled = true, ManifestVersionString = "2.0", Name = "MongoDB", // we'll handle parameters below. Parameters = new ParameterList { AllowUserDefinedParameters = "true", Items = plist.ToArray() }, Properties = new List <AddonProperty>(), ProvisioningLocation = "54.167.117.101", ProvisioningPassword = "******", ProvisioningPasswordHasValue = false, ProvisioningUsername = "******", Vendor = "Apprenda", Version = "3.1" }; manifest.Properties.Add(port); return(manifest); }
// 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); }
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); }
private static AddonManifest SetupPropertiesAndParameters() { var manifest = new AddonManifest() { AllowUserDefinedParameters = true, Author = "Chris Dutra", DeploymentNotes = "", Description = "", DeveloperHelp = "", IsEnabled = true, ManifestVersionString = "2.0", Name = "Azure Storage", // we'll handle parameters below. Parameters = new ParameterList { AllowUserDefinedParameters = "true", Items = addParameters().ToArray() as IAddOnParameterDefinition[] }, Properties = new List <AddonProperty> { new AddonProperty() { Key = "AzureManagementSubscriptionId", Value = ConfigurationManager.AppSettings["AzureManagementSubscriptionId"] }, new AddonProperty() { Key = "AzureAuthenticationKey", Value = ConfigurationManager.AppSettings["AzureAuthenticationKey"] }, new AddonProperty() { Key = "AzureURL", Value = ConfigurationManager.AppSettings["AzureURL"] }, new AddonProperty() { Key = "GeoReplicationEnabled", Value = ConfigurationManager.AppSettings["GeoReplicationEnabled"] } }, ProvisioningLocation = "US East", ProvisioningPassword = "", ProvisioningPasswordHasValue = false, ProvisioningUsername = "", Vendor = "Microsoft", Version = "6.0" }; return(manifest); }
public void SetupTest() { var manifest = new AddonManifest { Parameters = new ParameterList(), AllowUserDefinedParameters = false, Author = "Chris Dutra", Properties = new List<AddonProperty> { // properties go here new AddonProperty() { Key = "", Value = "" } }, DeploymentNotes = "", Description = "", DeveloperHelp = "", IsEnabled = true, ManifestVersionString = "2", Name = "Altibase", ProvisioningLocation = "", ProvisioningPassword = "", ProvisioningUsername = "", Vendor = "Apprenda", Version = "1.0" }; _request = new AddonProvisionRequest { DeveloperParameters = new List<AddonParameter> { new AddonParameter() { Key = "asodfasod", Value = "aodifsad" }, new AddonParameter() { Key = "", Value = "" } }, Manifest = manifest }; }
static void Main(string[] args) { var addon = new Addon(); var manifest = new AddonManifest { Author = "Abraham Sultan", Vendor = "Apprenda Inc.", Version = "1.0.0.0", IsEnabled = true, Name = "AWS RDS", Properties = new List<AddonProperty>() { new AddonProperty(){Key = "requireDevCredentials", Value = "true"} } }; var request = new AddonTestRequest { Manifest = manifest, DeveloperOptions = "" }; addon.Test(request); }
private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonGlacierClient client) { OperationResult result; bool requireCreds; //var accessKey = manifest.ProvisioningUsername; //var secretAccessKey = manifest.ProvisioningPassword; var accessKey = devOptions.AccessKey; var secretAccessKey = devOptions.SecretAccessKey; var prop = manifest.Properties.First( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return(result); } accessKey = devOptions.AccessKey; secretAccessKey = devOptions.SecretAccessKey; } AmazonGlacierConfig config = new AmazonGlacierConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonGlacierClient(devOptions.AccessKey, devOptions.SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; return(result); }
private void DeployAddon(AddonManifest addonManifest, string tempFolder) { try { _logger.Debug($"Add-on manifest source folder: {addonManifest.SourceFolder}"); _logger.Debug($"Add-on manifest assembly: {addonManifest.Assembly}"); var addonPath = Path.Combine(WellKnownData.AddonServiceStageDirPath, addonManifest.SourceFolder, addonManifest.Assembly); _logger.Debug($"Looking for Add-on module at {addonPath}"); if (!File.Exists(addonPath)) { throw LogAndException("Failed to find the Add-on module."); } _logger.Debug($"Loading Add-on assembly from {addonPath}"); var assembly = Assembly.LoadFrom(addonPath); var deployAddonClass = assembly.GetTypes().FirstOrDefault(t => t.IsClass && t.Name.Equals(addonManifest.DeployClassName) && typeof(IDeployAddon).IsAssignableFrom(t)); if (deployAddonClass != null) { _logger.Information($"Loading the Add-on service from path {addonPath}."); var deployAddon = (IDeployAddon)Activator.CreateInstance(deployAddonClass); if (deployAddon == null) { _logger.Warning($"Unable to instantiate the Add-on service from {addonPath}"); } else { deployAddon.SetLogger(_logger); deployAddon.SetTempDirectory(tempFolder); deployAddon.Deploy(addonManifest, _configDb.GetWebSslPemCertificate()); } } } catch (Exception ex) { throw LogAndException($"Failed to deploy the Add-on service {addonManifest.Name}: {ex.Message}."); } }
private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonSimpleNotificationServiceClient client) { OperationResult result; bool requireCreds; var manifestprops = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); var AccessKey = manifestprops["AWSClientKey"]; var SecretAccessKey = manifestprops["AWSSecretKey"]; var _RegionEndpoint = manifestprops["AWSRegionEndpoint"]; var prop = manifest.Properties.First( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return(result); } //accessKey = devOptions.AccessKey; //secretAccessKey = devOptions.SecretAccessKey; } AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonSimpleNotificationServiceClient(AccessKey, SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; return(result); }
private OperationResult EstablishClient(AddonManifest manifest, EMRDeveloperOptions devOptions, out IAmazonElasticMapReduce client) { OperationResult result; bool requireCreds; var accessKey = manifest.ProvisioningUsername; var secretAccessKey = manifest.ProvisioningPassword; var prop = manifest.Properties.First(p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); //jobid = null; if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return(result); } accessKey = devOptions.AccessKey; secretAccessKey = devOptions.SecretAccessKey; } AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretAccessKey); client = AWSClientFactory.CreateAmazonElasticMapReduceClient(credentials, RegionEndpoint.USEast1); //jobid = job.JobFlowId; result = new OperationResult() { IsSuccess = true }; return(result); }
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); }
internal InstanceOperations(AddonManifest manifest, GoogleCloudDeveloperOptions developerOptions) { try { var manifestprops = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); ProjectId = manifestprops["ProjectID"]; ServiceAccountEmail = manifestprops["Email"]; CertificateFile = manifestprops["CertFile"]; InstanceName = developerOptions.InstanceName; SourceImage = developerOptions.SourceImage; DiskType = developerOptions.DiskType; Zone = developerOptions.Zone; MachineType = developerOptions.MachineType; SourceImageProject = developerOptions.SourceImageProject; } catch (Exception e) { throw new ArgumentException("Argument syntax is incorrect - " + e.Message); } }
internal Logic(AddonManifest manifest) { var @namespace = manifest.Properties.First(p => p.Key == "Namespace").Value; var certificateFile = manifest.Properties.First(p => p.Key == "Certificate").Value; var certificatePassword = manifest.Properties.First(p => p.Key == "Password").Value; storageClass = manifest.Properties.First(p => p.Key == "StorageClass").Value; if (!string.IsNullOrWhiteSpace(manifest.ProvisioningUsername) && string.IsNullOrWhiteSpace(certificateFile)) { client = KubernetesClient.FromUsername( manifest.ProvisioningLocation, @namespace, manifest.ProvisioningUsername, manifest.ProvisioningPassword); } if (!string.IsNullOrWhiteSpace(certificateFile) && string.IsNullOrWhiteSpace(manifest.ProvisioningUsername)) { var certificate = new X509Certificate2(); var assemblyFolder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).AbsolutePath); certificate.Import( Path.Combine(assemblyFolder, certificateFile), certificatePassword.ToSecureString(), X509KeyStorageFlags.DefaultKeySet); client = KubernetesClient.FromCertificate( manifest.ProvisioningLocation, @namespace, certificate); } if (client == null) { throw new Exception("Specify either a username or a certificate for authentication."); } }
private static AddonManifest GetAWSAddonManifest() { var manifest = new AddonManifest { Author = "Abraham Sultan", Vendor = "Apprenda Inc.", Version = "1.0.0.0", IsEnabled = true, Name = "AWS RDS", ProvisioningUsername = "******", ProvisioningPassword = "******", Properties = new List <AddonProperty>() { new AddonProperty() { Key = "requireDevCredentials", Value = "true" } } }; return(manifest); }
private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonGlacierClient client) { OperationResult result; bool requireCreds; //var accessKey = manifest.ProvisioningUsername; //var secretAccessKey = manifest.ProvisioningPassword; var accessKey = devOptions.AccessKey; var secretAccessKey = devOptions.SecretAccessKey; var prop = manifest.Properties.First( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return result; } accessKey = devOptions.AccessKey; secretAccessKey = devOptions.SecretAccessKey; } AmazonGlacierConfig config = new AmazonGlacierConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonGlacierClient(devOptions.AccessKey, devOptions.SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; return result; }
private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonSimpleNotificationServiceClient client) { OperationResult result; bool requireCreds; var manifestprops = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); var AccessKey = manifestprops["AWSClientKey"]; var SecretAccessKey = manifestprops["AWSSecretKey"]; var _RegionEndpoint = manifestprops["AWSRegionEndpoint"]; var prop = manifest.Properties.First( p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return result; } //accessKey = devOptions.AccessKey; //secretAccessKey = devOptions.SecretAccessKey; } AmazonSimpleNotificationServiceConfig config = new AmazonSimpleNotificationServiceConfig() { RegionEndpoint = RegionEndpoint.USEast1 }; client = new AmazonSimpleNotificationServiceClient(AccessKey, SecretAccessKey, config); result = new OperationResult { IsSuccess = true }; return result; }
private static AddonManifest SetupPropertiesAndParameters() { var paramConstructor = new List<AddonParameter> { new AddonParameter() { Key = "NewStorageAccount", Value = ConfigurationManager.AppSettings["NewStorageAccount"] }, new AddonParameter() { Key = "StorageAccountName", Value = ConfigurationManager.AppSettings["StorageAccountName"] }, new AddonParameter() { Key = "ContainerName", Value = ConfigurationManager.AppSettings["ContainerName"] } }; var manifest = new AddonManifest() { AllowUserDefinedParameters = true, Author = "Chris Dutra", DeploymentNotes = "", Description = "", DeveloperHelp = "", IsEnabled = true, ManifestVersionString = "2.0", Name = "Azure Storage", // we'll handle parameters below. Parameters = new ParameterList { AllowUserDefinedParameters = "true", Items = paramConstructor.ToArray() as IAddOnParameterDefinition[] }, Properties = new List<AddonProperty> { new AddonProperty() { Key = "AzureManagementSubscriptionId", Value = ConfigurationManager.AppSettings["AzureManagementSubscriptionId"] }, new AddonProperty() { Key = "AzureAuthenticationKey", Value = ConfigurationManager.AppSettings["AzureAuthenticationKey"] }, new AddonProperty() { Key = "AzureURL", Value = ConfigurationManager.AppSettings["AzureURL"] }, new AddonProperty() { Key = "GeoReplicationEnabled", Value = ConfigurationManager.AppSettings["GeoReplicationEnabled"] } }, ProvisioningLocation = "US East", ProvisioningPassword = "", ProvisioningPasswordHasValue = false, ProvisioningUsername = "", Vendor = "Microsoft", Version = "6.0" }; return manifest; }
public static DeveloperParameters LoadItemsFromManifest(DeveloperParameters parameters, AddonManifest manifest) { try { var manifestProperties = manifest.GetProperties(); foreach (var manifestProperty in manifestProperties) { switch (manifestProperty.Key.Trim().ToLowerInvariant()) { case ("vserver"): parameters.VServer = manifestProperty.Value; break; case ("adminusername"): parameters.AdminUserName = manifestProperty.Value; break; case ("adminpassword"): parameters.AdminPassword = manifestProperty.Value; break; case ("clustermgtendpoint"): parameters.ClusterMgtEndpoint = manifestProperty.Value; break; case ("defaultprotocol"): parameters.VolumeToProvision.Protocol = manifestProperty.Value; break; case ("defaultaggregate"): parameters.VolumeToProvision.AggregateName = manifestProperty.Value; break; case ("defaultrootpath"): parameters.VolumeToProvision.JunctionPath = manifestProperty.Value; break; case ("snapenable"): bool snaptest; bool.TryParse(manifestProperty.Value, out snaptest); parameters.VolumeToProvision.SnapEnable = snaptest; break; case ("vaultenable"): bool test; bool.TryParse(manifestProperty.Value, out test); parameters.VolumeToProvision.VaultEnable = test; break; case ("snapshotschedule"): parameters.VolumeToProvision.SnapshotSchedule = manifestProperty.Value; break; case ("defaultacl"): break; case ("snapmirrorpolicyname"): parameters.VolumeToProvision.SnapMirrorPolicyName = manifestProperty.Value; break; case ("snapvaultpolicyname"): parameters.VolumeToProvision.SnapVaultPolicyName = manifestProperty.Value; break; case ("snapmirrorschedule"): parameters.VolumeToProvision.SnapMirrorSchedule = manifestProperty.Value; break; case ("snapvaultschedule"): parameters.VolumeToProvision.SnapVaultSchedule = manifestProperty.Value; break; case ("snaptype"): parameters.VolumeToProvision.SnapType = manifestProperty.Value; break; case ("shareendpoint"): parameters.VolumeToProvision.CifsRootServer = manifestProperty.Value; break; case ("scriptrepotype"): parameters.ScriptRepositoryType = manifestProperty.Value; break; case ("scriptrepo"): parameters.ScriptRepository = manifestProperty.Value; break; case ("maxallocatedstorage"): parameters.MaxAllocatedStorage = manifestProperty.Value; break; default: // means there are other manifest properties we don't need. Console.WriteLine("Parse failed on key: " + manifestProperty.Key); break; } } return parameters; } catch (Exception e) { throw new Exception(e.Message + "\n Debug information: " + manifest.GetProperties()); } }
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); }
public static DeveloperParameters LoadItemsFromManifest(DeveloperParameters parameters, AddonManifest manifest) { try { var manifestProperties = manifest.GetProperties(); foreach (var manifestProperty in manifestProperties) { switch (manifestProperty.Key.Trim().ToLowerInvariant()) { case ("vserver"): parameters.VServer = manifestProperty.Value; break; case ("adminusername"): parameters.AdminUserName = manifestProperty.Value; break; case ("adminpassword"): parameters.AdminPassword = manifestProperty.Value; break; case ("clustermgtendpoint"): parameters.ClusterMgtEndpoint = manifestProperty.Value; break; case ("defaultprotocol"): parameters.VolumeToProvision.Protocol = manifestProperty.Value; break; case ("defaultaggregate"): parameters.VolumeToProvision.AggregateName = manifestProperty.Value; break; case ("defaultrootpath"): parameters.VolumeToProvision.JunctionPath = manifestProperty.Value; break; case ("snapenable"): bool snaptest; bool.TryParse(manifestProperty.Value, out snaptest); parameters.VolumeToProvision.SnapEnable = snaptest; break; case ("vaultenable"): bool test; bool.TryParse(manifestProperty.Value, out test); parameters.VolumeToProvision.VaultEnable = test; break; case ("snapshotschedule"): parameters.VolumeToProvision.SnapshotSchedule = manifestProperty.Value; break; case ("defaultacl"): break; case ("snapmirrorpolicyname"): parameters.VolumeToProvision.SnapMirrorPolicyName = manifestProperty.Value; break; case ("snapvaultpolicyname"): parameters.VolumeToProvision.SnapVaultPolicyName = manifestProperty.Value; break; case ("snapmirrorschedule"): parameters.VolumeToProvision.SnapMirrorSchedule = manifestProperty.Value; break; case ("snapvaultschedule"): parameters.VolumeToProvision.SnapVaultSchedule = manifestProperty.Value; break; case ("snaptype"): parameters.VolumeToProvision.SnapType = manifestProperty.Value; break; case ("shareendpoint"): parameters.VolumeToProvision.CifsRootServer = manifestProperty.Value; break; case ("scriptrepotype"): parameters.ScriptRepositoryType = manifestProperty.Value; break; case ("scriptrepo"): parameters.ScriptRepository = manifestProperty.Value; break; case ("maxallocatedstorage"): parameters.MaxAllocatedStorage = manifestProperty.Value; break; default: // means there are other manifest properties we don't need. Console.WriteLine("Parse failed on key: " + manifestProperty.Key); break; } } return(parameters); } catch (Exception e) { throw new Exception(e.Message + "\n Debug information: " + manifest.GetProperties()); } }
private static string GetDatabaseName(AddonManifest manifest, DeveloperParameters p) { return(p.Database != null?string.Format("{0}", p.Database) : string.Format("{0}-{1}", manifest.CallingDeveloperAlias, manifest.InstanceAlias)); }
// handled on a policy-basis via the manifest // Method takes in a string and parses it into a DeveloperOptions class. public static DeveloperParameters Parse(IEnumerable <AddonParameter> developerParameters, AddonManifest manifest) { var dParams = new DeveloperParameters(new Volume()); foreach (var param in developerParameters) { MapToOption(dParams, param.Key.Trim().ToLowerInvariant(), param.Value.Trim()); } dParams = LoadItemsFromManifest(dParams, manifest); return(dParams); }
private OperationResult ParseDevOptions(string developerOptions, AddonManifest manifest, out DeveloperOptions devOptions) { devOptions = null; var result = new OperationResult() { IsSuccess = false }; var progress = ""; try { progress += "Parsing developer options...\n"; devOptions = DeveloperOptions.Parse(developerOptions); // we're probably going to need these lines a few times Dictionary<string, string> manifestProperties = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value); devOptions.AccessKey = manifestProperties["AWSClientKey"]; devOptions.SecretAccessKey = manifestProperties["AWSSecretKey"]; devOptions.AccountId = manifestProperties["AWSAccountID"]; //devOptions.RegionEndpoint = manifestProperties["RegionEndpoint"]; } catch (ArgumentException e) { result.EndUserMessage = e.Message; return result; } result.IsSuccess = true; result.EndUserMessage = progress; return result; }
internal static DeveloperParameters Parse(AddonManifest manifest, IEnumerable<AddonParameter> developerParams) { // construct main model for parsing manifest and developerParams var developerParameters = new DeveloperParameters(); // parse manifest foreach (var property in manifest.Properties) { switch (property.Key.ToLowerInvariant()) { case "altibasehost": developerParameters.AltibaseHost = property.Value; break; case "altibaseport": int tmp; if (int.TryParse(property.Value, out tmp)) developerParameters.AltibasePort = tmp; else { Log.Error($"Port provided ({property.Value}) was invalid format, defaulting to 20300"); developerParameters.AltibasePort = 20300; } break; case "altibaseusername": developerParameters.AltibaseUsername = property.Value; break; case "altibasepassword": developerParameters.AltibasePassword = property.Value; break; case "altibasedb": developerParameters.AltibaseDB = property.Value; break; default: Log.Warn($"Unrecognized property: {property.Key}"); break; } } // parse developerParams foreach (var addonParam in developerParams) { switch (addonParam.Key.ToLowerInvariant()) { case "schemaname": developerParameters.SchemaName = addonParam.Value; break; default: Log.Warn($"Unrecognized argument: {addonParam.Key}"); break; } } return developerParameters; }
private OperationResult EstablishClient(AddonManifest manifest, EMRDeveloperOptions devOptions, out IAmazonElasticMapReduce client) { OperationResult result; bool requireCreds; var accessKey = manifest.ProvisioningUsername; var secretAccessKey = manifest.ProvisioningPassword; var prop = manifest.Properties.First(p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase)); //jobid = null; if (bool.TryParse(prop.Value, out requireCreds) && requireCreds) { if (!ValidateDevCreds(devOptions)) { client = null; result = new OperationResult() { IsSuccess = false, EndUserMessage = "The add on requires that developer credentials are specified but none were provided." }; return result; } accessKey = devOptions.AccessKey; secretAccessKey = devOptions.SecretAccessKey; } AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretAccessKey); client = AWSClientFactory.CreateAmazonElasticMapReduceClient(credentials, RegionEndpoint.USEast1); //jobid = job.JobFlowId; result = new OperationResult() { IsSuccess = true }; return result; }