Search in sources :

Example 1 with StackCreationSuccessEvent

use of com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent in project cloudbreak by hortonworks.

the class SdxCreateActions method finishedAction.

@Bean(name = "SDX_CREATION_FINISHED_STATE")
public Action<?, ?> finishedAction() {
    return new AbstractSdxAction<>(StackCreationSuccessEvent.class) {

        @Override
        protected SdxContext createFlowContext(FlowParameters flowParameters, StateContext<FlowState, FlowEvent> stateContext, StackCreationSuccessEvent payload) {
            return SdxContext.from(flowParameters, payload);
        }

        @Override
        protected void doExecute(SdxContext context, StackCreationSuccessEvent payload, Map<Object, Object> variables) throws Exception {
            SdxCluster sdxCluster = sdxStatusService.setStatusForDatalakeAndNotify(DatalakeStatusEnum.RUNNING, "Datalake is running", payload.getResourceId());
            metricService.incrementMetricCounter(MetricType.SDX_CREATION_FINISHED, sdxCluster);
            jobService.schedule(context.getSdxId(), SdxClusterJobAdapter.class);
            eventSenderService.notifyEvent(context, ResourceEvent.SDX_CLUSTER_PROVISION_FINISHED);
            sendEvent(context, SDX_CREATE_FINALIZED_EVENT.event(), payload);
        }

        @Override
        protected Object getFailurePayload(StackCreationSuccessEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return null;
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) StackCreationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent) Map(java.util.Map) DatalakeStatusUpdateException(com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with StackCreationSuccessEvent

use of com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent in project cloudbreak by hortonworks.

the class StackCreationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<StackCreationWaitRequest> handlerEvent) {
    StackCreationWaitRequest stackCreationWaitRequest = handlerEvent.getData();
    Long sdxId = stackCreationWaitRequest.getResourceId();
    String userId = stackCreationWaitRequest.getUserId();
    Selectable response;
    try {
        LOGGER.debug("start polling stack creation process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        StackV4Response stackV4Response = provisionerService.waitCloudbreakClusterCreation(sdxId, pollingConfig);
        SdxCluster sdxCluster = sdxService.getById(sdxId);
        sdxService.updateRuntimeVersionFromStackResponse(sdxCluster, stackV4Response);
        setStackCreatedStatus(sdxId);
        response = new StackCreationSuccessEvent(sdxId, userId);
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Polling exited before timeout for SDX: {}. Cause: ", sdxId, userBreakException);
        response = new SdxCreateFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Poller stopped for SDX: {}", sdxId, pollerStoppedException);
        response = new SdxCreateFailedEvent(sdxId, userId, new PollerStoppedException("Datalake stack creation timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Polling failed for stack: {}", sdxId, exception);
        response = new SdxCreateFailedEvent(sdxId, userId, exception);
    } catch (Exception anotherException) {
        LOGGER.error("Something wrong happened in stack creation wait phase", anotherException);
        response = new SdxCreateFailedEvent(sdxId, userId, anotherException);
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) UserBreakException(com.dyngr.exception.UserBreakException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackCreationWaitRequest(com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) SdxCluster(com.sequenceiq.datalake.entity.SdxCluster) StackCreationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Example 3 with StackCreationSuccessEvent

use of com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent in project cloudbreak by hortonworks.

the class StackCreationHandlerTest method acceptTest.

@Test
void acceptTest() {
    long stackId = 2L;
    StackCreationWaitRequest stackCreationWaitRequest = new StackCreationWaitRequest(stackId, userId);
    Event receivedEvent = new Event<>(stackCreationWaitRequest);
    StackV4Response stackV4Response = new StackV4Response();
    when(provisionerService.waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class))).thenReturn(stackV4Response);
    stackCreationHandler.accept(receivedEvent);
    verify(provisionerService, times(1)).waitCloudbreakClusterCreation(eq(stackId), any(PollingConfig.class));
    final ArgumentCaptor<String> eventSelector = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Event> sentEvent = ArgumentCaptor.forClass(Event.class);
    verify(sdxService, times(1)).updateRuntimeVersionFromStackResponse(any(), eq(stackV4Response));
    verify(eventBus, times(1)).notify(eventSelector.capture(), sentEvent.capture());
    String eventNotified = eventSelector.getValue();
    Event event = sentEvent.getValue();
    Assertions.assertEquals("StackCreationSuccessEvent", eventNotified);
    Assertions.assertEquals(StackCreationSuccessEvent.class, event.getData().getClass());
    Assertions.assertEquals(stackId, ((StackCreationSuccessEvent) event.getData()).getResourceId());
    verify(sdxStatusService, times(1)).setStatusForDatalakeAndNotify(STACK_CREATION_FINISHED, "Datalake stack created", (Long) stackId);
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) StackCreationWaitRequest(com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest) SdxCreateFailedEvent(com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent) Event(reactor.bus.Event) StackCreationSuccessEvent(com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) Test(org.junit.jupiter.api.Test)

Aggregations

StackCreationSuccessEvent (com.sequenceiq.datalake.flow.create.event.StackCreationSuccessEvent)3 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)2 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)2 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)2 StackCreationWaitRequest (com.sequenceiq.datalake.flow.create.event.StackCreationWaitRequest)2 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 SdxContext (com.sequenceiq.datalake.flow.SdxContext)1 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)1 DatalakeStatusUpdateException (com.sequenceiq.datalake.service.sdx.status.DatalakeStatusUpdateException)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1 StateContext (org.springframework.statemachine.StateContext)1