Search in sources :

Example 1 with CloudNoSqlTables

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

the class CredentialPlatformResourceController method getNoSqlTables.

@Override
@CustomPermissionCheck
public PlatformNoSqlTablesResponse getNoSqlTables(String credentialName, String credentialCrn, String region, String platformVariant, String availabilityZone) {
    customCheckUtil.run(() -> permissionCheckByCredential(credentialName, credentialCrn));
    String accountId = getAccountId();
    PlatformResourceRequest request = platformParameterService.getPlatformResourceRequest(accountId, credentialName, credentialCrn, region, platformVariant, availabilityZone);
    LOGGER.info("Get /platform_resources/nosql_tables, request: {}", request);
    CloudNoSqlTables noSqlTables = platformParameterService.getNoSqlTables(request);
    PlatformNoSqlTablesResponse response = cloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter.convert(noSqlTables);
    LOGGER.info("Resp /platform_resources/nosql_tables, request: {}, noSqlTables: {}, response: {}", request, noSqlTables, response);
    return response;
}
Also used : CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) PlatformNoSqlTablesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse) CustomPermissionCheck(com.sequenceiq.authorization.annotation.CustomPermissionCheck)

Example 2 with CloudNoSqlTables

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

the class EnvironmentPlatformResourceController method getNoSqlTables.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)
public PlatformNoSqlTablesResponse getNoSqlTables(@ResourceCrn String environmentCrn, String region, String platformVariant, String availabilityZone) {
    String accountId = getAccountId();
    validateEnvironmentCrnPattern(environmentCrn);
    PlatformResourceRequest request = platformParameterService.getPlatformResourceRequestByEnvironment(accountId, environmentCrn, region, platformVariant, availabilityZone, null);
    LOGGER.info("Get /platform_resources/nosql_tables, request: {}", request);
    CloudNoSqlTables noSqlTables = platformParameterService.getNoSqlTables(request);
    PlatformNoSqlTablesResponse response = cloudNoSqlTablesToPlatformNoSqlTablesV1ResponseConverter.convert(noSqlTables);
    LOGGER.info("Resp /platform_resources/nosql_tables, request: {}, noSqlTables: {}, response: {}", request, noSqlTables, response);
    return response;
}
Also used : CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) PlatformNoSqlTablesResponse(com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 3 with CloudNoSqlTables

use of com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables 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 4 with CloudNoSqlTables

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

the class GetPlatformNoSqlTablesHandler method accept.

@Override
public void accept(Event<GetPlatformNoSqlTablesRequest> event) {
    LOGGER.debug("Received event: {}", event);
    GetPlatformNoSqlTablesRequest request = event.getData();
    try {
        CloudPlatformVariant cloudPlatformVariant = new CloudPlatformVariant(Platform.platform(request.getExtendedCloudCredential().getCloudPlatform()), Variant.variant(request.getVariant()));
        CloudNoSqlTables cloudNoSqlTables = cloudPlatformConnectors.get(cloudPlatformVariant).platformResources().noSqlTables(request.getExtendedCloudCredential(), Region.region(request.getRegion()), request.getFilters());
        GetPlatformNoSqlTablesResult result = new GetPlatformNoSqlTablesResult(request.getResourceId(), cloudNoSqlTables);
        request.getResult().onNext(result);
        LOGGER.debug("Query platform NoSQL tables finished.");
    } catch (RuntimeException e) {
        request.getResult().onNext(new GetPlatformNoSqlTablesResult(e.getMessage(), e, request.getResourceId()));
    }
}
Also used : GetPlatformNoSqlTablesResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesResult) GetPlatformNoSqlTablesRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) CloudNoSqlTables(com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables)

Example 5 with CloudNoSqlTables

use of com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables 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)

Aggregations

CloudNoSqlTables (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables)8 CloudNoSqlTable (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable)4 PlatformNoSqlTablesResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTablesResponse)4 Test (org.junit.jupiter.api.Test)4 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)3 ListTablesRequest (com.amazonaws.services.dynamodbv2.model.ListTablesRequest)2 ListTablesResult (com.amazonaws.services.dynamodbv2.model.ListTablesResult)2 GetPlatformNoSqlTablesRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest)2 GetPlatformNoSqlTablesResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesResult)2 ArrayList (java.util.ArrayList)2 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 CustomPermissionCheck (com.sequenceiq.authorization.annotation.CustomPermissionCheck)1 AmazonDynamoDBClient (com.sequenceiq.cloudbreak.cloud.aws.common.client.AmazonDynamoDBClient)1 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.common.view.AwsCredentialView)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)1 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)1 PlatformNoSqlTableResponse (com.sequenceiq.environment.api.v1.platformresource.model.PlatformNoSqlTableResponse)1 List (java.util.List)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1