Search in sources :

Example 1 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class EnvironmentInstancesNotificationSetupTest method expectedReq.

private CreateTopicRequest expectedReq(StackEnvironmentType env, String topicName) {
    CreateTopicRequest expectedReq = new CreateTopicRequest();
    expectedReq.setName(topicName);
    return expectedReq;
}
Also used : CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest)

Example 2 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class StackInstanceNotificationSetupTest method testSetupNotificationTopics.

@Test
public void testSetupNotificationTopics() {
    String topicArn = "arn:123";
    String protocol = Constants.TOPIC_SUBSCRIBE_PROTOCOL_EMAIL;
    String endpoint = config.getRDSAlertSubscriptionEndpoint();
    CreateTopicRequest expectedTopic = new CreateTopicRequest();
    expectedTopic.setName(config.getRDSAlertTopicName());
    CreateTopicResult expectedResult = new CreateTopicResult().withTopicArn(topicArn);
    when(mockClient.createTopic(expectedTopic)).thenReturn(expectedResult);
    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);
    // Make the call
    setup.setupResources();
    verify(mockClient, times(1)).createTopic(expectedTopic);
    // Make sure it was set the resources
    assertEquals("The expected topic was not set in the resoruces", expectedResult.getTopicArn(), resources.getStackInstanceNotificationTopicArn());
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription) Test(org.junit.Test)

Example 3 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest in project Synapse-Stack-Builder by Sage-Bionetworks.

the class BuildStackMainTest method before.

@Before
public void before() throws IOException {
    inputProps = TestHelper.createInputProperties("dev");
    InputConfiguration config = TestHelper.createTestConfig("dev");
    defaultProps = TestHelper.createDefaultProperties();
    clientFactory = new MockAmazonClientFactory();
    AmazonS3Client mockS3Client = clientFactory.createS3Client();
    AmazonEC2Client mockEC2Client = clientFactory.createEC2Client();
    AmazonSNSClient mockSNSnsClient = clientFactory.createSNSClient();
    AmazonRDSClient mockRdsClient = clientFactory.createRDSClient();
    // Write the default properties.
    when(mockS3Client.getObject(any(GetObjectRequest.class), any(File.class))).thenAnswer(new Answer<ObjectMetadata>() {

        public ObjectMetadata answer(InvocationOnMock invocation) throws Throwable {
            // Write the property file
            File file = (File) invocation.getArguments()[1];
            FileWriter writer = new FileWriter(file);
            try {
                defaultProps.store(writer, "test generated");
            } finally {
                writer.close();
            }
            return new ObjectMetadata();
        }
    });
    // Return a valid EC2 security group.
    DescribeSecurityGroupsRequest dsgr = new DescribeSecurityGroupsRequest().withGroupNames(config.getElasticSecurityGroupName());
    when(mockEC2Client.describeSecurityGroups(dsgr)).thenReturn(new DescribeSecurityGroupsResult().withSecurityGroups(new SecurityGroup().withGroupName(config.getElasticSecurityGroupName())));
    // Return a valid topic
    String topicArn = "some:arn";
    when(mockSNSnsClient.createTopic(new CreateTopicRequest(config.getRDSAlertTopicName()))).thenReturn(new CreateTopicResult().withTopicArn(topicArn));
    when(mockSNSnsClient.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicArn))).thenReturn(new ListSubscriptionsByTopicResult().withSubscriptions(new Subscription()));
    // return a valid group
    when(mockRdsClient.describeDBParameterGroups(new DescribeDBParameterGroupsRequest().withDBParameterGroupName(config.getDatabaseParameterGroupName()))).thenReturn(new DescribeDBParameterGroupsResult().withDBParameterGroups(new DBParameterGroup().withDBParameterGroupName(config.getDatabaseParameterGroupName())));
    when(mockRdsClient.describeDBParameters(new DescribeDBParametersRequest().withDBParameterGroupName(config.getDatabaseParameterGroupName()))).thenReturn(new DescribeDBParametersResult().withParameters(new Parameter().withParameterName(Constants.DB_PARAM_KEY_SLOW_QUERY_LOG)).withParameters(new Parameter().withParameterName(Constants.DB_PARAM_KEY_LONG_QUERY_TIME)));
}
Also used : DescribeSecurityGroupsRequest(com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest) DescribeDBParameterGroupsResult(com.amazonaws.services.rds.model.DescribeDBParameterGroupsResult) FileWriter(java.io.FileWriter) AmazonSNSClient(com.amazonaws.services.sns.AmazonSNSClient) CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) DescribeDBParametersRequest(com.amazonaws.services.rds.model.DescribeDBParametersRequest) DescribeDBParameterGroupsRequest(com.amazonaws.services.rds.model.DescribeDBParameterGroupsRequest) DescribeSecurityGroupsResult(com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult) Subscription(com.amazonaws.services.sns.model.Subscription) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest) AmazonEC2Client(com.amazonaws.services.ec2.AmazonEC2Client) DBParameterGroup(com.amazonaws.services.rds.model.DBParameterGroup) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) DescribeDBParametersResult(com.amazonaws.services.rds.model.DescribeDBParametersResult) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) MockAmazonClientFactory(org.sagebionetworks.factory.MockAmazonClientFactory) AmazonRDSClient(com.amazonaws.services.rds.AmazonRDSClient) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) InputConfiguration(org.sagebionetworks.stack.config.InputConfiguration) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) Parameter(com.amazonaws.services.rds.model.Parameter) File(java.io.File) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Before(org.junit.Before)

Example 4 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest in project glacier-cli by carlossg.

the class Glacier method setupSNS.

private QueueConfig setupSNS(QueueConfig config, String snsTopicName) {
    CreateTopicRequest request = new CreateTopicRequest().withName(snsTopicName);
    CreateTopicResult result = snsClient.createTopic(request);
    config.snsTopicARN = result.getTopicArn();
    SubscribeRequest request2 = new SubscribeRequest().withTopicArn(config.snsTopicARN).withEndpoint(config.sqsQueueARN).withProtocol("sqs");
    SubscribeResult result2 = snsClient.subscribe(request2);
    config.snsSubscriptionARN = result2.getSubscriptionArn();
    return config;
}
Also used : CreateTopicResult(com.amazonaws.services.sns.model.CreateTopicResult) SubscribeRequest(com.amazonaws.services.sns.model.SubscribeRequest) CreateTopicRequest(com.amazonaws.services.sns.model.CreateTopicRequest) SubscribeResult(com.amazonaws.services.sns.model.SubscribeResult)

Example 5 with CreateTopicRequest

use of com.amazonaws.services.sns.model.CreateTopicRequest 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)

Aggregations

CreateTopicRequest (com.amazonaws.services.sns.model.CreateTopicRequest)8 CreateTopicResult (com.amazonaws.services.sns.model.CreateTopicResult)6 Subscription (com.amazonaws.services.sns.model.Subscription)3 ListSubscriptionsByTopicRequest (com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest)2 ListSubscriptionsByTopicResult (com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult)2 Test (org.junit.Test)2 AmazonSQSExtendedClient (com.amazon.sqs.javamessaging.AmazonSQSExtendedClient)1 ExtendedClientConfiguration (com.amazon.sqs.javamessaging.ExtendedClientConfiguration)1 AmazonServiceException (com.amazonaws.AmazonServiceException)1 Regions (com.amazonaws.regions.Regions)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