Search in sources :

Example 1 with AllocateDatabaseServerFailed

use of com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed in project cloudbreak by hortonworks.

the class AllocateDatabaseServerHandler method defaultFailureEvent.

@Override
protected Selectable defaultFailureEvent(Long resourceId, Exception e, Event<AllocateDatabaseServerRequest> event) {
    AllocateDatabaseServerFailed failure = new AllocateDatabaseServerFailed(resourceId, e);
    LOGGER.warn("Error launching the database stack:", e);
    return failure;
}
Also used : AllocateDatabaseServerFailed(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed)

Example 2 with AllocateDatabaseServerFailed

use of com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed in project cloudbreak by hortonworks.

the class AllocateDatabaseServerHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<AllocateDatabaseServerRequest> handlerEvent) {
    Event<AllocateDatabaseServerRequest> event = handlerEvent.getEvent();
    LOGGER.debug("Received event: {}", event);
    AllocateDatabaseServerRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    Selectable response;
    try {
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        CloudCredential cloudCredential = request.getCloudCredential();
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
        DatabaseStack databaseStack = request.getDatabaseStack();
        DBStack dbStack = dbStackService.getById(request.getResourceId());
        databaseServerSslCertificatePrescriptionService.prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, dbStack, databaseStack);
        List<CloudResourceStatus> resourceStatuses = connector.resources().launchDatabaseServer(ac, databaseStack, persistenceNotifier);
        List<CloudResource> resources = ResourceLists.transform(resourceStatuses);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatuses);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        validateResourcesState(cloudContext, statePollerResult);
        response = new AllocateDatabaseServerSuccess(request.getResourceId());
        LOGGER.debug("Launching the database stack successfully finished for {}", cloudContext);
    } catch (Exception e) {
        response = new AllocateDatabaseServerFailed(request.getResourceId(), e);
        LOGGER.warn("Error launching the database stack:", e);
    }
    return response;
}
Also used : AllocateDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess) AllocateDatabaseServerFailed(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AllocateDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Example 3 with AllocateDatabaseServerFailed

use of com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed in project cloudbreak by hortonworks.

the class AllocateDatabaseServerHandlerTest method verifyFailureEvent.

private void verifyFailureEvent(Selectable selectable) {
    assertThat(selectable).isInstanceOf(AllocateDatabaseServerFailed.class);
    AllocateDatabaseServerFailed allocateDatabaseServerFailed = (AllocateDatabaseServerFailed) selectable;
    assertThat(allocateDatabaseServerFailed.getResourceId()).isEqualTo(RESOURCE_ID);
}
Also used : AllocateDatabaseServerFailed(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed)

Example 4 with AllocateDatabaseServerFailed

use of com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed in project cloudbreak by hortonworks.

the class AllocateDatabaseServerHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent handlerEvent) {
    Event<AllocateDatabaseServerRequest> event = handlerEvent.getEvent();
    LOGGER.debug("Received event: {}", event);
    AllocateDatabaseServerRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    Selectable response;
    try {
        CloudConnector<Object> connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
        CloudCredential cloudCredential = request.getCloudCredential();
        AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, cloudCredential);
        DatabaseStack databaseStack = request.getDatabaseStack();
        databaseServerSslCertificatePrescriptionService.prescribeSslCertificateIfNeeded(cloudContext, cloudCredential, request.getDbStack(), databaseStack);
        List<CloudResourceStatus> resourceStatuses = connector.resources().launchDatabaseServer(ac, databaseStack, persistenceNotifier);
        List<CloudResource> resources = ResourceLists.transform(resourceStatuses);
        PollTask<ResourcesStatePollerResult> task = statusCheckFactory.newPollResourcesStateTask(ac, resources, true);
        ResourcesStatePollerResult statePollerResult = ResourcesStatePollerResults.build(cloudContext, resourceStatuses);
        if (!task.completed(statePollerResult)) {
            statePollerResult = syncPollingScheduler.schedule(task);
        }
        validateResourcesState(cloudContext, statePollerResult);
        response = new AllocateDatabaseServerSuccess(request.getResourceId());
        // request.getResult().onNext(success);
        LOGGER.debug("Launching the database stack successfully finished for {}", cloudContext);
    } catch (Exception e) {
        response = new AllocateDatabaseServerFailed(request.getResourceId(), e);
        LOGGER.warn("Error launching the database stack:", e);
    // request.getResult().onNext(failure);
    }
    return response;
}
Also used : AllocateDatabaseServerSuccess(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess) AllocateDatabaseServerFailed(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) DatabaseStack(com.sequenceiq.cloudbreak.cloud.model.DatabaseStack) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AllocateDatabaseServerRequest(com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) ResourcesStatePollerResult(com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)

Aggregations

AllocateDatabaseServerFailed (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerFailed)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)2 ResourcesStatePollerResult (com.sequenceiq.cloudbreak.cloud.task.ResourcesStatePollerResult)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 OperationException (com.sequenceiq.cloudbreak.service.OperationException)2 AllocateDatabaseServerRequest (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerRequest)2 AllocateDatabaseServerSuccess (com.sequenceiq.redbeams.flow.redbeams.provision.event.allocate.AllocateDatabaseServerSuccess)2 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)1