Search in sources :

Example 1 with NoSqlTableMetadataResponse

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

the class AwsNoSqlConnectorTest method getNoSqlTableMetaDataOk.

@Test
public void getNoSqlTableMetaDataOk() {
    TableDescription tableDescription = new TableDescription().withTableArn(ARN).withTableStatus(ACTIVE_STATUS);
    DescribeTableResult describeResult = new DescribeTableResult().withTable(tableDescription);
    when(dynamoDb.describeTable(argThat((ArgumentMatcher<String>) argument -> true))).thenReturn(describeResult);
    NoSqlTableMetadataResponse result = underTest.getNoSqlTableMetaData(new NoSqlTableMetadataRequest());
    assertEquals(ARN, result.getId());
    assertEquals(ACTIVE_STATUS, result.getTableStatus());
    assertEquals(ResponseStatus.OK, result.getStatus());
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) NoSqlTableMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse) Test(org.junit.Test)

Example 2 with NoSqlTableMetadataResponse

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

the class AwsNoSqlConnectorTest method getNoSqlTableMetaDataResourceNotFound.

@Test
public void getNoSqlTableMetaDataResourceNotFound() {
    when(dynamoDb.describeTable(argThat((ArgumentMatcher<String>) argument -> true))).thenThrow(new ResourceNotFoundException("not found"));
    NoSqlTableMetadataResponse result = underTest.getNoSqlTableMetaData(new NoSqlTableMetadataRequest());
    assertNull(result.getId());
    assertNull(result.getTableStatus());
    assertEquals(ResponseStatus.RESOURCE_NOT_FOUND, result.getStatus());
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) NoSqlTableMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse) Test(org.junit.Test)

Example 3 with NoSqlTableMetadataResponse

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

the class NoSqlTableCreationModeDeterminerServiceTest method determineCreationModeCreateNew.

@Test
void determineCreationModeCreateNew() {
    NoSqlTableMetadataResponse metadataResponse = NoSqlTableMetadataResponse.builder().withStatus(ResponseStatus.RESOURCE_NOT_FOUND).build();
    when(noSql.getNoSqlTableMetaData(any())).thenReturn(metadataResponse);
    Credential credential = new Credential();
    credential.setCloudPlatform("platform");
    S3GuardTableCreation mode = underTest.determineCreationMode(LocationAwareCredential.builder().withLocation("location").withCredential(credential).build(), "tablename");
    assertEquals(S3GuardTableCreation.CREATE_NEW, mode);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) LocationAwareCredential(com.sequenceiq.environment.environment.domain.LocationAwareCredential) S3GuardTableCreation(com.sequenceiq.environment.parameter.dto.s3guard.S3GuardTableCreation) NoSqlTableMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse) Test(org.junit.jupiter.api.Test)

Example 4 with NoSqlTableMetadataResponse

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

the class NoSqlTableCreationModeDeterminerServiceTest method determineCreationModeExisting.

@Test
void determineCreationModeExisting() {
    NoSqlTableMetadataResponse metadataResponse = NoSqlTableMetadataResponse.builder().withId("id").withStatus(ResponseStatus.OK).withTableStatus("ACTIVE").build();
    when(noSql.getNoSqlTableMetaData(any())).thenReturn(metadataResponse);
    Credential credential = new Credential();
    credential.setCloudPlatform("platform");
    S3GuardTableCreation mode = underTest.determineCreationMode(LocationAwareCredential.builder().withLocation("location").withCredential(credential).build(), "tablename");
    assertEquals(S3GuardTableCreation.USE_EXISTING, mode);
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) LocationAwareCredential(com.sequenceiq.environment.environment.domain.LocationAwareCredential) S3GuardTableCreation(com.sequenceiq.environment.parameter.dto.s3guard.S3GuardTableCreation) NoSqlTableMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse) Test(org.junit.jupiter.api.Test)

Example 5 with NoSqlTableMetadataResponse

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

the class S3GuardTableDeleteHandler method deleteNoSqlTable.

private ResponseStatus deleteNoSqlTable(LocationAwareCredential locationAwareCredential, String dynamoDbTablename) {
    Credential credential = locationAwareCredential.getCredential();
    String cloudPlatform = credential.getCloudPlatform();
    String location = locationAwareCredential.getLocation();
    NoSqlConnector noSqlConnector = getNoSqlConnector(cloudPlatform);
    CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
    NoSqlTableMetadataRequest noSqlTableMetadataRequest = NoSqlTableMetadataRequest.builder().withCloudPlatform(cloudPlatform).withCredential(cloudCredential).withRegion(location).withTableName(dynamoDbTablename).build();
    NoSqlTableMetadataResponse noSqlTableMetaData = noSqlConnector.getNoSqlTableMetaData(noSqlTableMetadataRequest);
    if (ResponseStatus.OK.equals(noSqlTableMetaData.getStatus())) {
        NoSqlTableDeleteRequest request = NoSqlTableDeleteRequest.builder().withCloudPlatform(cloudPlatform).withCredential(cloudCredential).withRegion(location).withTableName(dynamoDbTablename).build();
        NoSqlTableDeleteResponse response = noSqlConnector.deleteNoSqlTable(request);
        return response.getStatus();
    } else {
        return ResponseStatus.OK;
    }
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) LocationAwareCredential(com.sequenceiq.environment.environment.domain.LocationAwareCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) NoSqlConnector(com.sequenceiq.cloudbreak.cloud.NoSqlConnector) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) NoSqlTableDeleteResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteResponse) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) NoSqlTableMetadataResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse)

Aggregations

NoSqlTableMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse)5 NoSqlTableMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest)3 Credential (com.sequenceiq.environment.credential.domain.Credential)3 LocationAwareCredential (com.sequenceiq.environment.environment.domain.LocationAwareCredential)3 S3GuardTableCreation (com.sequenceiq.environment.parameter.dto.s3guard.S3GuardTableCreation)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 DescribeTableResult (com.amazonaws.services.dynamodbv2.model.DescribeTableResult)1 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)1 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)1 NoSqlConnector (com.sequenceiq.cloudbreak.cloud.NoSqlConnector)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 NoSqlTableDeleteRequest (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest)1 NoSqlTableDeleteResponse (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteResponse)1