Search in sources :

Example 1 with NoSqlTableDeleteRequest

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

the class AwsNoSqlConnectorTest method deleteNoSqlTable.

@Test
public void deleteNoSqlTable() {
    TableDescription tableDescription = new TableDescription().withTableArn(ARN).withTableStatus(DELETING_STATUS);
    DeleteTableResult deleteResult = new DeleteTableResult().withTableDescription(tableDescription);
    when(dynamoDb.deleteTable(argThat((ArgumentMatcher<String>) argument -> true))).thenReturn(deleteResult);
    NoSqlTableDeleteResponse result = underTest.deleteNoSqlTable(new NoSqlTableDeleteRequest());
    assertEquals(ARN, result.getId());
    assertEquals(DELETING_STATUS, result.getTableStatus());
    assertEquals(ResponseStatus.OK, result.getStatus());
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) DeleteTableResult(com.amazonaws.services.dynamodbv2.model.DeleteTableResult) NoSqlTableDeleteResponse(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteResponse) TableDescription(com.amazonaws.services.dynamodbv2.model.TableDescription) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) Test(org.junit.Test)

Example 2 with NoSqlTableDeleteRequest

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

the class S3GuardTableDeleteHandlerTest method acceptTestEnvironmentAwsFailure.

@Test
void acceptTestEnvironmentAwsFailure() {
    when(cloudPlatformConnectors.get(any(), any())).thenReturn(cloudConnector);
    when(cloudConnector.noSql()).thenReturn(noSql);
    CloudCredential cloudCredential = new CloudCredential();
    when(credentialToCloudCredentialConverter.convert(any())).thenReturn(cloudCredential);
    AwsParameters awsParameters = getAwsParameters(S3GuardTableCreation.CREATE_NEW);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(awsParameters)));
    when(noSql.getNoSqlTableMetaData(any(NoSqlTableMetadataRequest.class))).thenReturn(NoSqlTableMetadataResponse.builder().withStatus(ResponseStatus.OK).build());
    Exception exception = new CloudConnectorException(String.format("Cannot delete NoSQL table %s. " + "Provider error message: %s", DYNAMO_TABLE_NAME, "errorMessage"));
    when(noSql.deleteNoSqlTable(any(NoSqlTableDeleteRequest.class))).thenThrow(exception);
    underTest.accept(environmentDtoEvent);
    NoSqlTableDeleteRequest request = getNoSqlTableDeleteRequest(cloudCredential);
    verify(cloudPlatformConnectors).get(any(), any());
    verify(noSql).deleteNoSqlTable(request);
    verify(mockExceptionProcessor, times(1)).handle(any(), any(), any(), any());
    verify(mockExceptionProcessor, times(1)).handle(any(HandlerFailureConjoiner.class), any(Logger.class), eq(eventSender), eq(DELETE_S3GUARD_TABLE_EVENT.selector()));
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) Logger(org.slf4j.Logger) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Test(org.junit.jupiter.api.Test)

Example 3 with NoSqlTableDeleteRequest

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

the class S3GuardTableDeleteHandlerTest method acceptTestEnvironmentSuccessWhenDynamoDbTableMissingOnAwsSide.

@Test
void acceptTestEnvironmentSuccessWhenDynamoDbTableMissingOnAwsSide() {
    when(cloudPlatformConnectors.get(any(), any())).thenReturn(cloudConnector);
    when(cloudConnector.noSql()).thenReturn(noSql);
    CloudCredential cloudCredential = new CloudCredential();
    when(credentialToCloudCredentialConverter.convert(any())).thenReturn(cloudCredential);
    AwsParameters awsParameters = getAwsParameters(S3GuardTableCreation.CREATE_NEW);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(awsParameters)));
    when(noSql.getNoSqlTableMetaData(any(NoSqlTableMetadataRequest.class))).thenReturn(NoSqlTableMetadataResponse.builder().withStatus(ResponseStatus.RESOURCE_NOT_FOUND).build());
    underTest.accept(environmentDtoEvent);
    NoSqlTableDeleteRequest request = getNoSqlTableDeleteRequest(cloudCredential);
    verify(cloudPlatformConnectors).get(any(), any());
    verify(noSql, times(0)).deleteNoSqlTable(request);
    verify(eventSender).sendEvent(eventArgumentCaptor.capture(), headersArgumentCaptor.capture());
    verifyEnvDeleteEvent();
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) Test(org.junit.jupiter.api.Test)

Example 4 with NoSqlTableDeleteRequest

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

the class S3GuardTableDeleteHandlerTest method acceptTestEnvironmentSuccess.

@Test
void acceptTestEnvironmentSuccess() {
    when(cloudPlatformConnectors.get(any(), any())).thenReturn(cloudConnector);
    when(cloudConnector.noSql()).thenReturn(noSql);
    CloudCredential cloudCredential = new CloudCredential();
    when(credentialToCloudCredentialConverter.convert(any())).thenReturn(cloudCredential);
    AwsParameters awsParameters = getAwsParameters(S3GuardTableCreation.CREATE_NEW);
    when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(createEnvironment(awsParameters)));
    when(noSql.getNoSqlTableMetaData(any(NoSqlTableMetadataRequest.class))).thenReturn(NoSqlTableMetadataResponse.builder().withStatus(ResponseStatus.OK).build());
    when(noSql.deleteNoSqlTable(any(NoSqlTableDeleteRequest.class))).thenReturn(NoSqlTableDeleteResponse.builder().withStatus(ResponseStatus.OK).build());
    underTest.accept(environmentDtoEvent);
    NoSqlTableDeleteRequest request = getNoSqlTableDeleteRequest(cloudCredential);
    verify(cloudPlatformConnectors).get(any(), any());
    verify(noSql).deleteNoSqlTable(request);
    verify(eventSender).sendEvent(eventArgumentCaptor.capture(), headersArgumentCaptor.capture());
    verifyEnvDeleteEvent();
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) NoSqlTableMetadataRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest) NoSqlTableDeleteRequest(com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest) Test(org.junit.jupiter.api.Test)

Example 5 with NoSqlTableDeleteRequest

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

NoSqlTableDeleteRequest (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteRequest)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 NoSqlTableMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataRequest)4 NoSqlTableDeleteResponse (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableDeleteResponse)3 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 ArgumentMatcher (org.mockito.ArgumentMatcher)3 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)1 DeleteTableResult (com.amazonaws.services.dynamodbv2.model.DeleteTableResult)1 ResourceNotFoundException (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)1 TableDescription (com.amazonaws.services.dynamodbv2.model.TableDescription)1 NoSqlConnector (com.sequenceiq.cloudbreak.cloud.NoSqlConnector)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 NoSqlTableMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.nosql.NoSqlTableMetadataResponse)1 Credential (com.sequenceiq.environment.credential.domain.Credential)1 LocationAwareCredential (com.sequenceiq.environment.environment.domain.LocationAwareCredential)1 Logger (org.slf4j.Logger)1