use of com.amazonaws.services.sns.model.CreateTopicResult in project camel by apache.
the class SnsEndpoint method doStart.
@Override
public void doStart() throws Exception {
super.doStart();
snsClient = configuration.getAmazonSNSClient() != null ? configuration.getAmazonSNSClient() : createSNSClient();
// Override the setting Endpoint from url
if (ObjectHelper.isNotEmpty(configuration.getAmazonSNSEndpoint())) {
LOG.trace("Updating the SNS region with : {} " + configuration.getAmazonSNSEndpoint());
snsClient.setEndpoint(configuration.getAmazonSNSEndpoint());
}
// check the setting the headerFilterStrategy
if (headerFilterStrategy == null) {
headerFilterStrategy = new SnsHeaderFilterStrategy();
}
if (configuration.getTopicArn() == null) {
try {
String nextToken = null;
final String arnSuffix = ":" + configuration.getTopicName();
do {
final ListTopicsResult response = snsClient.listTopics(nextToken);
nextToken = response.getNextToken();
for (final Topic topic : response.getTopics()) {
if (topic.getTopicArn().endsWith(arnSuffix)) {
configuration.setTopicArn(topic.getTopicArn());
break;
}
}
} while (nextToken != null);
} catch (final AmazonServiceException ase) {
LOG.trace("The list topics operation return the following error code {}", ase.getErrorCode());
throw ase;
}
}
if (configuration.getTopicArn() == null) {
// creates a new topic, or returns the URL of an existing one
CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());
LOG.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(), request);
CreateTopicResult result = snsClient.createTopic(request);
configuration.setTopicArn(result.getTopicArn());
LOG.trace("Topic created with Amazon resource name: {}", configuration.getTopicArn());
}
if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
LOG.trace("Updating topic [{}] with policy [{}]", configuration.getTopicArn(), configuration.getPolicy());
snsClient.setTopicAttributes(new SetTopicAttributesRequest(configuration.getTopicArn(), "Policy", configuration.getPolicy()));
LOG.trace("Topic policy updated");
}
}
use of com.amazonaws.services.sns.model.CreateTopicResult in project Synapse-Stack-Builder by Sage-Bionetworks.
the class EnvironmentInstancesNotificationSetup method setupResources.
@Override
public void setupResources() throws InterruptedException {
// Portal environment
String topicName = config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.PORTAL);
String endpoint = config.getEnvironmentInstanceNotificationEndpoint(StackEnvironmentType.PORTAL);
CreateTopicResult result = NotificationUtils.setupNotificationTopicAndSubscription(client, topicName, endpoint);
// TODO: CHANGE generated resource
resources.setEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.PORTAL, result.getTopicArn());
// Plfm environments (repo/worker)
topicName = config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.REPO);
endpoint = config.getEnvironmentInstanceNotificationEndpoint(StackEnvironmentType.REPO);
result = NotificationUtils.setupNotificationTopicAndSubscription(client, topicName, endpoint);
// TODO: CHANGE generated resource
resources.setEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.REPO, result.getTopicArn());
topicName = config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.WORKERS);
endpoint = config.getEnvironmentInstanceNotificationEndpoint(StackEnvironmentType.WORKERS);
result = NotificationUtils.setupNotificationTopicAndSubscription(client, topicName, endpoint);
// TODO: CHANGE generated resource
resources.setEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.WORKERS, result.getTopicArn());
}
use of com.amazonaws.services.sns.model.CreateTopicResult in project Synapse-Stack-Builder by Sage-Bionetworks.
the class EnvironmentInstancesNotificationSetupTest method setupExpectedRes.
private CreateTopicResult setupExpectedRes(StackEnvironmentType env, CreateTopicRequest req) {
String topicArn = "arn:" + req.getName();
String protocol = Constants.TOPIC_SUBSCRIBE_PROTOCOL_EMAIL;
String endpoint = config.getEnvironmentInstanceNotificationEndpoint(env);
CreateTopicResult expectedRes = new CreateTopicResult().withTopicArn(topicArn);
when(mockClient.createTopic(req)).thenReturn(expectedRes);
ListSubscriptionsByTopicRequest tRequest = new ListSubscriptionsByTopicRequest().withTopicArn(topicArn);
Subscription expected = new Subscription().withEndpoint(endpoint).withProtocol(protocol);
ListSubscriptionsByTopicResult result = new ListSubscriptionsByTopicResult().withSubscriptions(expected);
when(mockClient.listSubscriptionsByTopic(tRequest)).thenReturn(result);
return expectedRes;
}
use of com.amazonaws.services.sns.model.CreateTopicResult in project Synapse-Stack-Builder by Sage-Bionetworks.
the class EnvironmentInstancesNotificationSetupTest method testSetupResources.
@Test
public void testSetupResources() throws InterruptedException {
CreateTopicRequest expectedReqPortal = expectedReq(StackEnvironmentType.PORTAL, config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.PORTAL));
CreateTopicResult expectedResPortal = setupExpectedRes(StackEnvironmentType.PORTAL, expectedReqPortal);
CreateTopicRequest expectedReqRepo = expectedReq(StackEnvironmentType.REPO, config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.REPO));
CreateTopicResult expectedResRepo = setupExpectedRes(StackEnvironmentType.REPO, expectedReqRepo);
CreateTopicRequest expectedReqWorkers = expectedReq(StackEnvironmentType.WORKERS, config.getEnvironmentInstanceNotificationTopicName(StackEnvironmentType.WORKERS));
CreateTopicResult expectedResWorkers = setupExpectedRes(StackEnvironmentType.WORKERS, expectedReqWorkers);
// Make the call
setup.setupResources();
verify(mockClient).createTopic(expectedReqPortal);
verify(mockClient).createTopic(expectedReqRepo);
verify(mockClient).createTopic(expectedReqWorkers);
// Make sure it was set the resources
assertEquals("The expected topic was not set in the resoruces", expectedResPortal.getTopicArn(), resources.getEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.PORTAL));
assertEquals("The expected topic was not set in the resoruces", expectedResRepo.getTopicArn(), resources.getEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.REPO));
assertEquals("The expected topic was not set in the resoruces", expectedResWorkers.getTopicArn(), resources.getEnvironmentInstanceNotificationTopicArn(StackEnvironmentType.WORKERS));
}
use of com.amazonaws.services.sns.model.CreateTopicResult in project Synapse-Stack-Builder by Sage-Bionetworks.
the class NotificationUtils method setupNotificationTopicAndSubscription.
public static CreateTopicResult setupNotificationTopicAndSubscription(AmazonSNSClient client, String topicName, String endpoint) {
// Create the topic
CreateTopicRequest request = new CreateTopicRequest();
request.setName(topicName);
CreateTopicResult result = client.createTopic(request);
// Create the subscription
Subscription sub = NotificationUtils.createSubScription(client, result.getTopicArn(), Constants.TOPIC_SUBSCRIBE_PROTOCOL_EMAIL, endpoint);
return result;
}
Aggregations