Search in sources :

Example 1 with GetPlatformNoSqlTablesRequest

use of com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest 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 2 with GetPlatformNoSqlTablesRequest

use of com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest 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 3 with GetPlatformNoSqlTablesRequest

use of com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest in project cloudbreak by hortonworks.

the class CloudParameterService method getNoSqlTables.

@Retryable(value = GetCloudParameterException.class, maxAttempts = 5, backoff = @Backoff(delay = 1000, multiplier = 2, maxDelay = 10000))
public CloudNoSqlTables getNoSqlTables(ExtendedCloudCredential cloudCredential, String region, String platformVariant, Map<String, String> filters) {
    LOGGER.debug("Get platform noSqlTables");
    GetPlatformNoSqlTablesRequest request = new GetPlatformNoSqlTablesRequest(cloudCredential, cloudCredential, platformVariant, region, null);
    eventBus.notify(request.selector(), Event.wrap(request));
    try {
        GetPlatformNoSqlTablesResult result = request.await();
        LOGGER.debug("Platform NoSqlTablesResult result: {}", result);
        if (result.getStatus().equals(EventStatus.FAILED)) {
            LOGGER.debug("Failed to get platform NoSqlTablesResult", result.getErrorDetails());
            throw new GetCloudParameterException(String.format("Failed to get NoSQL tables for the cloud provider: %s. %s", result.getStatusReason(), getCauseMessages(result.getErrorDetails())), result.getErrorDetails());
        }
        return result.getNoSqlTables();
    } catch (InterruptedException e) {
        LOGGER.error("Error while getting the platform NoSqlTablesResult", e);
        throw new OperationException(e);
    }
}
Also used : GetPlatformNoSqlTablesResult(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesResult) GetPlatformNoSqlTablesRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Retryable(org.springframework.retry.annotation.Retryable)

Example 4 with GetPlatformNoSqlTablesRequest

use of com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest in project cloudbreak by hortonworks.

the class GetPlatformNoSqlTablesHandlerTest method accept.

@Test
void accept() {
    when(cloudPlatformConnectors.get(any(CloudPlatformVariant.class))).thenReturn(cloudConnector);
    when(cloudConnector.platformResources()).thenReturn(platformResources);
    CloudCredential cloudCredential = new CloudCredential("id", "name", "acc");
    ExtendedCloudCredential extendedCloudCredential = new ExtendedCloudCredential(cloudCredential, "aws", "desc", "crn", "account", new ArrayList<>());
    GetPlatformNoSqlTablesRequest request = spy(new GetPlatformNoSqlTablesRequest(cloudCredential, extendedCloudCredential, "aws", "region", null));
    underTest.accept(new Event<>(request));
    verify(platformResources).noSqlTables(eq(extendedCloudCredential), eq(Region.region("region")), isNull());
    verify(request).getResult();
}
Also used : ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) ExtendedCloudCredential(com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) GetPlatformNoSqlTablesRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) Test(org.junit.jupiter.api.Test)

Aggregations

GetPlatformNoSqlTablesRequest (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesRequest)4 GetPlatformNoSqlTablesResult (com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformNoSqlTablesResult)3 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 ExtendedCloudCredential (com.sequenceiq.cloudbreak.cloud.model.ExtendedCloudCredential)2 CloudNoSqlTables (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTables)2 Test (org.junit.jupiter.api.Test)2 CloudNoSqlTable (com.sequenceiq.cloudbreak.cloud.model.nosql.CloudNoSqlTable)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 ArrayList (java.util.ArrayList)1 Retryable (org.springframework.retry.annotation.Retryable)1 Event (reactor.bus.Event)1