Search in sources :

Example 6 with Subscription

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

the class NotificationUtils method findSubscription.

/**
 * This is a pain-in-the-butt way to determine if a subscription already exists
 * @param topicArn
 * @param protocol
 * @param endpoint
 * @return
 */
public static Subscription findSubscription(AmazonSNSClient client, String topicArn, String protocol, String endpoint) {
    // Fill this list with all of the pages
    List<Subscription> fullList = new LinkedList<Subscription>();
    ListSubscriptionsByTopicResult subList = client.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest().withTopicArn(topicArn));
    fullList.addAll(subList.getSubscriptions());
    while (subList.getNextToken() != null) {
        subList = client.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest().withTopicArn(topicArn));
        fullList.addAll(subList.getSubscriptions());
    }
    // Scan the full list for this results
    for (Subscription sub : fullList) {
        if (protocol.equals(sub.getProtocol()) && endpoint.equals(sub.getEndpoint())) {
            return sub;
        }
    }
    // Did not find it
    return null;
}
Also used : ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription) LinkedList(java.util.LinkedList)

Example 7 with Subscription

use of com.amazonaws.services.sns.model.Subscription 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 8 with Subscription

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

the class NotificationUtilsTest method testCreateSubscriptionDoesNotExist.

@Test
public void testCreateSubscriptionDoesNotExist() {
    String topicArn = "arn:123";
    String protocol = "email";
    String endpoint = "testing@domain.com";
    ListSubscriptionsByTopicRequest tRequest = new ListSubscriptionsByTopicRequest().withTopicArn(topicArn);
    ListSubscriptionsByTopicResult result = new ListSubscriptionsByTopicResult().withSubscriptions(new Subscription().withEndpoint("nomatch").withProtocol("noMatch"));
    when(mockClient.listSubscriptionsByTopic(tRequest)).thenReturn(result);
    // This should call create
    SubscribeRequest expectedRequest = new SubscribeRequest();
    expectedRequest.setTopicArn(topicArn);
    expectedRequest.setProtocol(protocol);
    expectedRequest.setEndpoint(endpoint);
    Subscription sub = NotificationUtils.createSubScription(mockClient, topicArn, protocol, endpoint);
    assertNull(sub);
    verify(mockClient, times(1)).subscribe(expectedRequest);
}
Also used : SubscribeRequest(com.amazonaws.services.sns.model.SubscribeRequest) ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription) Test(org.junit.Test)

Example 9 with Subscription

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

the class NotificationUtilsTest method testfindSubscriptionDoesNotExist.

@Test
public void testfindSubscriptionDoesNotExist() {
    String topicArn = "arn:123";
    String protocol = "email";
    String endpoint = "testing@domain.com";
    ListSubscriptionsByTopicRequest tRequest = new ListSubscriptionsByTopicRequest().withTopicArn(topicArn);
    ListSubscriptionsByTopicResult result = new ListSubscriptionsByTopicResult().withSubscriptions(new Subscription().withEndpoint("nomatch").withProtocol("noMatch"));
    when(mockClient.listSubscriptionsByTopic(tRequest)).thenReturn(result);
    // For this case it should not be found
    Subscription sub = NotificationUtils.findSubscription(mockClient, topicArn, protocol, endpoint);
    assertNull(sub);
}
Also used : ListSubscriptionsByTopicResult(com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult) ListSubscriptionsByTopicRequest(com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest) Subscription(com.amazonaws.services.sns.model.Subscription) Test(org.junit.Test)

Example 10 with Subscription

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

Subscription (com.amazonaws.services.sns.model.Subscription)10 ListSubscriptionsByTopicRequest (com.amazonaws.services.sns.model.ListSubscriptionsByTopicRequest)8 ListSubscriptionsByTopicResult (com.amazonaws.services.sns.model.ListSubscriptionsByTopicResult)8 Test (org.junit.Test)5 CreateTopicResult (com.amazonaws.services.sns.model.CreateTopicResult)4 CreateTopicRequest (com.amazonaws.services.sns.model.CreateTopicRequest)3 SubscribeRequest (com.amazonaws.services.sns.model.SubscribeRequest)3 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