Search in sources :

Example 6 with CreateTopicResult

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");
    }
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) ListTopicsResult(com.amazonaws.services.sns.model.ListTopicsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) SetTopicAttributesRequest(com.amazonaws.services.sns.model.SetTopicAttributesRequest) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) Topic(com.amazonaws.services.sns.model.Topic)

Example 7 with CreateTopicResult

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());
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult)

Example 8 with CreateTopicResult

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;
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription)

Example 9 with CreateTopicResult

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));
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) Test(org.junit.Test)

Example 10 with CreateTopicResult

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;
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription)

Aggregations

CreateTopicResult (com.amazonaws.services.sns.model.CreateTopicResult)11 CreateTopicRequest (com.amazonaws.services.sns.model.CreateTopicRequest)6 Subscription (com.amazonaws.services.sns.model.Subscription)4 ListSubscriptionsByTopicRequest (com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest)3 ListSubscriptionsByTopicResult (com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult)3 Test (org.junit.Test)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 DescribeSecurityGroupsRequest (com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest)1 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)1 SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)1 AmazonRDSClient (com.amazonaws.services.rds.AmazonRDSClient)1 DBParameterGroup (com.amazonaws.services.rds.model.DBParameterGroup)1 DescribeDBParameterGroupsRequest (com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest)1 DescribeDBParameterGroupsResult (com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult)1 DescribeDBParametersRequest (com.amazonaws.services.rds.model.DescribeDBParametersRequest)1 DescribeDBParametersResult (com.amazonaws.services.rds.model.DescribeDBParametersResult)1 Parameter (com.amazonaws.services.rds.model.Parameter)1 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1