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); }
private OperationResult ParseDevOptions(string developerOptions, out DeveloperOptions devOptions) { devOptions = null; var result = new OperationResult() { IsSuccess = false }; var progress = ""; try { progress += "Parsing developer options...\n"; devOptions = DeveloperOptions.Parse(developerOptions); } catch (ArgumentException e) { result.EndUserMessage = e.Message; return(result); } result.IsSuccess = true; result.EndUserMessage = progress; return(result); }
// 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); }