Search in sources :

Example 1 with CloudNoSqlTable

use of com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable in project cloudbreak by hortonworks.

the class CloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverterTest method convert.

@Test
void convert() {
    List<CloudNoSqlTable> tables = List.of(new CloudNoSqlTable("a"), new CloudNoSqlTable("b"));
    CloudNoSqlTables source = new CloudNoSqlTables(tables);
    PlatformNoSqlTablesResponse result = underTest.convert(source);
    List<PlatformNoSqlTableResponse> noSqlTables = result.getNoSqlTables();
    assertNotNull(noSqlTables);
    assertEquals(tables.size(), noSqlTables.size());
    tables.forEach(t -> {
        assertTrue(noSqlTables.stream().anyMatch(s -> t.getName().equals(s.getName())));
    });
}
Also used : Test(org.junit.jupiter.api.Test) PlatformNoSqlTableResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTableResponse) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) List(java.util.List) CloudNoSqlTable(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PlatformNoSqlTablesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) CloudNoSqlTable(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable) PlatformNoSqlTablesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse) PlatformNoSqlTableResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTableResponse) Test(org.junit.jupiter.api.Test)

Example 2 with CloudNoSqlTable

use of com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable in project cloudbreak by hortonworks.

the class AwsPlatformResources method noSqlTables.

@Override
public CloudNoSqlTables noSqlTables(ExtendedCloudCredential cloudCredential, Region region, Map<String, String> filters) {
    List<CloudNoSqlTable> noSqlTables = new ArrayList<>();
    AmazonDynamoDBClient dynamoDbClient = getAmazonDynamoDBClient(cloudCredential, region);
    ListTablesRequest listTablesRequest = new ListTablesRequest();
    ListTablesResult listTablesResult = null;
    boolean first = true;
    while (first || !isNullOrEmpty(listTablesResult.getLastEvaluatedTableName())) {
        first = false;
        listTablesRequest.setExclusiveStartTableName(listTablesResult == null ? null : listTablesResult.getLastEvaluatedTableName());
        listTablesResult = dynamoDbClient.listTables(listTablesRequest);
        List<String> partialTableNames = listTablesResult.getTableNames();
        List<CloudNoSqlTable> partialResult = partialTableNames.stream().map(CloudNoSqlTable::new).collect(Collectors.toList());
        noSqlTables.addAll(partialResult);
    }
    return new CloudNoSqlTables(noSqlTables);
}
Also used : ListTablesResult(com.amazonaws.services.dynamodbv2.model.ListTablesResult) ArrayList(java.util.ArrayList) AmazonDynamoDBClient(com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient) ListTablesRequest(com.amazonaws.services.dynamodbv2.model.ListTablesRequest) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) CloudNoSqlTable(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable)

Example 3 with CloudNoSqlTable

use of com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable in project cloudbreak by hortonworks.

the class CloudParameterServiceTest method getNoSqlTables.

@Test
void getNoSqlTables() {
    CloudNoSqlTables expected = new CloudNoSqlTables(List.of(new CloudNoSqlTable("a"), new CloudNoSqlTable("b")));
    GetPlatformNoSqlTablesResult response = new GetPlatformNoSqlTablesResult(1L, expected);
    doAnswer(invocation -> {
        Event<GetPlatformNoSqlTablesRequest> ev = invocation.getArgument(1);
        ev.getData().getResult().onNext(response);
        return null;
    }).when(eventBus).notify(anyString(), any(Event.class));
    CloudNoSqlTables noSqlTables = underTest.getNoSqlTables(new ExtendedCloudCredential(new CloudCredential("id", "name", "acc"), "aws", "desc", "crn", "account", new ArrayList<>()), "region", "aws", null);
    assertEquals(expected, noSqlTables);
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) GetPlatformNoSqlTablesResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesResult) GetPlatformNoSqlTablesRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ArrayList(java.util.ArrayList) Event(reactor.bus.Event) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) CloudNoSqlTable(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable) Test(org.junit.jupiter.api.Test)

Example 4 with CloudNoSqlTable

use of com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable in project cloudbreak by hortonworks.

the class AwsPlatformResourcesTest method noSqlTables.

@Test
public void noSqlTables() {
    when(awsClient.createDynamoDbClient(any(AwsCredentialView.class), anyString())).thenReturn(amazonDynamoDB);
    when(amazonDynamoDB.listTables(any(ListTablesRequest.class))).thenReturn(new ListTablesResult().withTableNames("a", "b").withLastEvaluatedTableName("b"), new ListTablesResult().withTableNames("c", "d"));
    CloudNoSqlTables cloudNoSqlTables = underTest.noSqlTables(cloudCredential, region("region"), null);
    assertThat(cloudNoSqlTables.getCloudNoSqlTables()).hasSameElementsAs(List.of(new CloudNoSqlTable("a"), new CloudNoSqlTable("b"), new CloudNoSqlTable("c"), new CloudNoSqlTable("d")));
}
Also used : AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView) ListTablesResult(com.amazonaws.services.dynamodbv2.model.ListTablesResult) ListTablesRequest(com.amazonaws.services.dynamodbv2.model.ListTablesRequest) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) CloudNoSqlTable(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable) Test(org.junit.jupiter.api.Test)

Aggregations

CloudNoSqlTable (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable)4 CloudNoSqlTables (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables)4 Test (org.junit.jupiter.api.Test)3 ListTablesRequest (com.amazonaws.services.dynamodbv2.model.ListTablesRequest)2 ListTablesResult (com.amazonaws.services.dynamodbv2.model.ListTablesResult)2 ArrayList (java.util.ArrayList)2 AmazonDynamoDBClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 GetPlatformNoSqlTablesRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest)1 GetPlatformNoSqlTablesResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesResult)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 PlatformNoSqlTableResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTableResponse)1 PlatformNoSqlTablesResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse)1 List (java.util.List)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Event (reactor.bus.Event)1