public static void MapToProperty(ConnectionInfo existingInfo, string key, string value) { if ("dbinstanceidentifier".Equals(key)) { existingInfo.ClusterIdentifier = value; return; } if ("endpointaddress".Equals(key)) { existingInfo.EndpointAddress = value; return; } if ("endpointport".Equals(key)) { int result; if (!int.TryParse(value, out result)) { throw new ArgumentException(string.Format("The connection info property '{0}' can only have an integer value but '{1}' was used instead.", key, value)); } existingInfo.EndpointPort = result; return; } throw new ArgumentException(string.Format("The connection info '{0}' was not expected and is not understood.", key)); }
public static ConnectionInfo Parse(string connectionInfo) { ConnectionInfo info = new ConnectionInfo(); if (!string.IsNullOrWhiteSpace(connectionInfo)) { var propertyPairs = connectionInfo.Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries); foreach (var propertyPair in propertyPairs) { var optionPairParts = propertyPair.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries); if (optionPairParts.Length == 2) { MapToProperty(info, optionPairParts[0].Trim().ToLowerInvariant(), optionPairParts[1].Trim()); } else { throw new ArgumentException( string.Format( "Unable to parse connection info which should be in the form of 'property=value&nextproperty=nextValue'. The property '{0}' was not properly constructed", propertyPair)); } } } return info; }
// 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; }