Search in sources :

Example 1 with SqsConnectionBuilder

use of com.formkiq.aws.sqs.SqsConnectionBuilder in project formkiq-core by formkiq.

the class StagingS3CreateTest method beforeClass.

/**
 * Before Class.
 *
 * @throws URISyntaxException URISyntaxException
 * @throws InterruptedException InterruptedException
 * @throws IOException IOException
 */
@BeforeAll
public static void beforeClass() throws URISyntaxException, InterruptedException, IOException {
    Region region = Region.US_EAST_1;
    AwsCredentialsProvider cred = StaticCredentialsProvider.create(AwsSessionCredentials.create("ACCESSKEY", "SECRETKEY", "TOKENKEY"));
    localstack.start();
    snsBuilder = new SnsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SNS).toString()).setRegion(region).setCredentials(cred);
    sqsBuilder = new SqsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SQS).toString()).setRegion(region).setCredentials(cred);
    sqsService = new SqsService(sqsBuilder);
    s3Builder = new S3ConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.S3).toString()).setRegion(region).setCredentials(cred);
    dbBuilder = DynamoDbTestServices.getDynamoDbConnection(null);
    service = new DocumentServiceImpl(dbBuilder, "Documents");
    dbHelper = DynamoDbTestServices.getDynamoDbHelper(null);
    s3 = new S3Service(s3Builder);
    try (S3Client c = s3.buildClient()) {
        s3.createBucket(c, DOCUMENTS_BUCKET);
        s3.createBucket(c, STAGING_BUCKET);
    }
    if (!sqsService.exists(SNS_SQS_DELETE_QUEUE)) {
        snsSqsDeleteQueueUrl = sqsService.createQueue(SNS_SQS_DELETE_QUEUE).queueUrl();
    }
    if (!sqsService.exists(SNS_SQS_CREATE_QUEUE)) {
        snsSqsCreateQueueUrl = sqsService.createQueue(SNS_SQS_CREATE_QUEUE).queueUrl();
    }
    if (!sqsService.exists(ERROR_SQS_QUEUE)) {
        sqsErrorUrl = sqsService.createQueue(ERROR_SQS_QUEUE).queueUrl();
    }
    snsService = new SnsService(snsBuilder);
    snsDeleteTopic = snsService.createTopic("deleteDocument").topicArn();
    snsService.subscribe(snsDeleteTopic, "sqs", "arn:aws:sqs:us-east-1:000000000000:" + SNS_SQS_DELETE_QUEUE);
    snsCreateTopic = snsService.createTopic("createDocument").topicArn();
    snsService.subscribe(snsCreateTopic, "sqs", "arn:aws:sqs:us-east-1:000000000000:" + SNS_SQS_CREATE_QUEUE);
    if (!dbHelper.isDocumentsTableExists()) {
        dbHelper.createDocumentsTable();
        dbHelper.createCacheTable();
    }
}
Also used : DocumentServiceImpl(com.formkiq.stacks.dynamodb.DocumentServiceImpl) SqsConnectionBuilder(com.formkiq.aws.sqs.SqsConnectionBuilder) SnsService(com.formkiq.aws.sns.SnsService) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) SqsService(com.formkiq.aws.sqs.SqsService) S3ConnectionBuilder(com.formkiq.aws.s3.S3ConnectionBuilder) Region(software.amazon.awssdk.regions.Region) SnsConnectionBuilder(com.formkiq.aws.sns.SnsConnectionBuilder) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Service(com.formkiq.aws.s3.S3Service) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 2 with SqsConnectionBuilder

use of com.formkiq.aws.sqs.SqsConnectionBuilder in project formkiq-core by formkiq.

the class TestServices method getSqsConnection.

/**
 * Get Singleton {@link SqsConnectionBuilder}.
 * @return {@link SqsConnectionBuilder}
 * @throws URISyntaxException URISyntaxException
 */
@SuppressWarnings("resource")
public static SqsConnectionBuilder getSqsConnection() throws URISyntaxException {
    if (sqsConnection == null) {
        AwsCredentialsProvider cred = StaticCredentialsProvider.create(AwsSessionCredentials.create("ACCESSKEY", "SECRETKEY", "TOKENKEY"));
        sqsConnection = new SqsConnectionBuilder().setCredentials(cred).setRegion(AWS_REGION).setEndpointOverride(getLocalStack().getEndpointOverride(Service.SQS).toString());
    }
    return sqsConnection;
}
Also used : SqsConnectionBuilder(com.formkiq.aws.sqs.SqsConnectionBuilder) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)

Example 3 with SqsConnectionBuilder

use of com.formkiq.aws.sqs.SqsConnectionBuilder in project formkiq-core by formkiq.

the class WebsocketTest method beforeClass.

/**
 * beforeclass.
 *
 * @throws IOException IOException
 * @throws URISyntaxException URISyntaxException
 */
@BeforeClass
public static void beforeClass() throws IOException, URISyntaxException {
    Region awsregion = Region.of(System.getProperty("testregion"));
    String awsprofile = System.getProperty("testprofile");
    String app = System.getProperty("testappenvironment");
    SqsConnectionBuilder sqsConnection = new SqsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
    sqsService = new SqsService(sqsConnection);
    SsmConnectionBuilder ssmBuilder = new SsmConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
    SsmService ssmService = new SsmServiceImpl(ssmBuilder);
    websocketSqsUrl = ssmService.getParameterValue("/formkiq/" + app + "/sqs/WebsocketUrl");
    websocketUrl = ssmService.getParameterValue("/formkiq/" + app + "/api/WebsocketUrl");
    String cognitoUserPoolId = ssmService.getParameterValue("/formkiq/" + app + "/cognito/UserPoolId");
    String cognitoClientId = ssmService.getParameterValue("/formkiq/" + app + "/cognito/UserPoolClientId");
    String cognitoIdentitypool = ssmService.getParameterValue("/formkiq/" + app + "/cognito/IdentityPoolId");
    CognitoConnectionBuilder adminBuilder = new CognitoConnectionBuilder(cognitoClientId, cognitoUserPoolId, cognitoIdentitypool).setCredentials(awsprofile).setRegion(awsregion);
    adminCognitoService = new CognitoService(adminBuilder);
    addAndLoginCognito(USER_EMAIL, GROUP);
    token = adminCognitoService.login(USER_EMAIL, USER_PASSWORD);
    String rootHttpUrl = ssmService.getParameterValue("/formkiq/" + app + "/api/DocumentsHttpUrl");
    FormKiqClientConnection connection = new FormKiqClientConnection(rootHttpUrl).cognitoIdToken(token.idToken()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
    httpClient = new FormKiqClientV1(connection);
    webconnectionsTable = ssmService.getParameterValue("/formkiq/" + app + "/dynamodb/WebConnectionsTableName");
    dbConnection = new DynamoDbConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
}
Also used : SsmService(com.formkiq.aws.ssm.SsmService) SsmServiceImpl(com.formkiq.aws.ssm.SsmServiceImpl) CognitoConnectionBuilder(com.formkiq.aws.cognito.CognitoConnectionBuilder) SqsConnectionBuilder(com.formkiq.aws.sqs.SqsConnectionBuilder) SsmConnectionBuilder(com.formkiq.aws.ssm.SsmConnectionBuilder) SqsService(com.formkiq.aws.sqs.SqsService) FormKiqClientConnection(com.formkiq.stacks.client.FormKiqClientConnection) Region(software.amazon.awssdk.regions.Region) CognitoService(com.formkiq.aws.cognito.CognitoService) DynamoDbConnectionBuilder(com.formkiq.stacks.dynamodb.DynamoDbConnectionBuilder) FormKiqClientV1(com.formkiq.stacks.client.FormKiqClientV1) BeforeClass(org.junit.BeforeClass)

Example 4 with SqsConnectionBuilder

use of com.formkiq.aws.sqs.SqsConnectionBuilder in project formkiq-core by formkiq.

the class DocumentsS3UpdateTest method beforeClass.

/**
 * Before Class.
 *
 * @throws URISyntaxException URISyntaxException
 * @throws InterruptedException InterruptedException
 * @throws IOException IOException
 */
@BeforeAll
public static void beforeClass() throws URISyntaxException, InterruptedException, IOException {
    Region region = Region.US_EAST_1;
    AwsCredentialsProvider cred = StaticCredentialsProvider.create(AwsSessionCredentials.create("ACCESSKEY", "SECRETKEY", "TOKENKEY"));
    localstack.start();
    snsBuilder = new SnsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SNS).toString()).setRegion(region).setCredentials(cred);
    sqsBuilder = new SqsConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.SQS).toString()).setRegion(region).setCredentials(cred);
    sqsService = new SqsService(sqsBuilder);
    s3Builder = new S3ConnectionBuilder().setEndpointOverride(localstack.getEndpointOverride(Service.S3).toString()).setRegion(region).setCredentials(cred);
    dbBuilder = DynamoDbTestServices.getDynamoDbConnection(null);
    service = new DocumentServiceImpl(dbBuilder, "Documents");
    if (!sqsService.exists(ERROR_SQS_QUEUE)) {
        sqsService.createQueue(ERROR_SQS_QUEUE);
    }
    if (!sqsService.exists(SNS_SQS_CREATE_QUEUE)) {
        sqsDocumentEventUrl = sqsService.createQueue(SNS_SQS_CREATE_QUEUE).queueUrl();
    }
    s3service = new S3Service(s3Builder);
    try (S3Client s3 = s3service.buildClient()) {
        s3service.createBucket(s3, "example-bucket");
    }
    snsService = new SnsService(snsBuilder);
    snsDocumentEvent = snsService.createTopic("createDocument1").topicArn();
    snsService.subscribe(snsDocumentEvent, "sqs", sqsDocumentEventUrl);
    dbHelper = new DynamoDbHelper(dbBuilder);
    if (!dbHelper.isDocumentsTableExists()) {
        dbHelper.createDocumentsTable();
        dbHelper.createCacheTable();
    }
}
Also used : DocumentServiceImpl(com.formkiq.stacks.dynamodb.DocumentServiceImpl) DynamoDbHelper(com.formkiq.stacks.dynamodb.DynamoDbHelper) SqsConnectionBuilder(com.formkiq.aws.sqs.SqsConnectionBuilder) SnsService(com.formkiq.aws.sns.SnsService) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) SqsService(com.formkiq.aws.sqs.SqsService) S3ConnectionBuilder(com.formkiq.aws.s3.S3ConnectionBuilder) Region(software.amazon.awssdk.regions.Region) SnsConnectionBuilder(com.formkiq.aws.sns.SnsConnectionBuilder) S3Client(software.amazon.awssdk.services.s3.S3Client) S3Service(com.formkiq.aws.s3.S3Service) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with SqsConnectionBuilder

use of com.formkiq.aws.sqs.SqsConnectionBuilder in project formkiq-core by formkiq.

the class AbstractAwsTest method beforeClass.

/**
 * beforeclass.
 *
 * @throws IOException IOException
 */
@BeforeClass
public static void beforeClass() throws IOException {
    awsregion = Region.of(System.getProperty("testregion"));
    String awsprofile = System.getProperty("testprofile");
    appenvironment = System.getProperty("testappenvironment");
    final SqsConnectionBuilder sqsConnection = new SqsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
    final SsmConnectionBuilder ssmBuilder = new SsmConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
    final S3ConnectionBuilder s3Builder = new S3ConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
    final SnsConnectionBuilder snsBuilder = new SnsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
    sqsService = new SqsService(sqsConnection);
    s3Service = new S3Service(s3Builder);
    ssmService = new SsmServiceImpl(ssmBuilder);
    snsService = new SnsService(snsBuilder);
    sesbucketname = ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/DocumentsSesS3Bucket");
    documentsbucketname = ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/DocumentsS3Bucket");
    stagingdocumentsbucketname = ssmService.getParameterValue("/formkiq/" + appenvironment + "/s3/DocumentsStageS3Bucket");
    snsDocumentEventArn = ssmService.getParameterValue("/formkiq/" + appenvironment + "/sns/DocumentEventArn");
    String documentsTable = ssmService.getParameterValue("/formkiq/" + appenvironment + "/dynamodb/DocumentsTableName");
    DynamoDbConnectionBuilder dbConnection = new DynamoDbConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
    documentService = new DocumentServiceImpl(dbConnection, documentsTable);
}
Also used : DocumentServiceImpl(com.formkiq.stacks.dynamodb.DocumentServiceImpl) SsmServiceImpl(com.formkiq.aws.ssm.SsmServiceImpl) SqsConnectionBuilder(com.formkiq.aws.sqs.SqsConnectionBuilder) SsmConnectionBuilder(com.formkiq.aws.ssm.SsmConnectionBuilder) SnsService(com.formkiq.aws.sns.SnsService) S3ConnectionBuilder(com.formkiq.aws.s3.S3ConnectionBuilder) SqsService(com.formkiq.aws.sqs.SqsService) SnsConnectionBuilder(com.formkiq.aws.sns.SnsConnectionBuilder) S3Service(com.formkiq.aws.s3.S3Service) DynamoDbConnectionBuilder(com.formkiq.stacks.dynamodb.DynamoDbConnectionBuilder) BeforeClass(org.junit.BeforeClass)

Aggregations

SqsConnectionBuilder (com.formkiq.aws.sqs.SqsConnectionBuilder)6 SqsService (com.formkiq.aws.sqs.SqsService)5 S3ConnectionBuilder (com.formkiq.aws.s3.S3ConnectionBuilder)4 S3Service (com.formkiq.aws.s3.S3Service)4 SnsConnectionBuilder (com.formkiq.aws.sns.SnsConnectionBuilder)4 SnsService (com.formkiq.aws.sns.SnsService)4 Region (software.amazon.awssdk.regions.Region)4 SsmConnectionBuilder (com.formkiq.aws.ssm.SsmConnectionBuilder)3 SsmServiceImpl (com.formkiq.aws.ssm.SsmServiceImpl)3 DocumentServiceImpl (com.formkiq.stacks.dynamodb.DocumentServiceImpl)3 BeforeClass (org.junit.BeforeClass)3 AwsCredentialsProvider (software.amazon.awssdk.auth.credentials.AwsCredentialsProvider)3 SsmService (com.formkiq.aws.ssm.SsmService)2 DynamoDbConnectionBuilder (com.formkiq.stacks.dynamodb.DynamoDbConnectionBuilder)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 S3Client (software.amazon.awssdk.services.s3.S3Client)2 CognitoConnectionBuilder (com.formkiq.aws.cognito.CognitoConnectionBuilder)1 CognitoService (com.formkiq.aws.cognito.CognitoService)1 FormKiqClientConnection (com.formkiq.stacks.client.FormKiqClientConnection)1 FormKiqClientV1 (com.formkiq.stacks.client.FormKiqClientV1)1