Search in sources :

Example 1 with DatalakeChangeImageWaitRequest

use of com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest in project cloudbreak by hortonworks.

the class DatalakeUpgradeActions method imageChange.

@Bean(name = "DATALAKE_IMAGE_CHANGE_STATE")
public Action<?, ?> imageChange() {
    return new AbstractSdxAction<>(DatalakeImageChangeEvent.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeImageChangeEvent payload, Map<Object, Object> variables) {
            LOGGER.info("Start Datalake upgrade image change for {} ", payload.getResourceId());
            sdxUpgradeService.updateRuntimeVersionFromCloudbreak(payload.getResourceId());
            String catalogName = sdxUpgradeService.getCurrentImageCatalogName(payload.getResourceId());
            UpgradeOptionV4Response upgrade = new UpgradeOptionV4Response().upgrade(new ImageInfoV4Response().imageId(payload.getImageId()).imageCatalogName(catalogName));
            sdxUpgradeService.changeImage(payload.getResourceId(), upgrade);
            sendEvent(context, new DatalakeChangeImageWaitRequest(DATALAKE_IMAGE_CHANGE_IN_PROGRESS_EVENT.event(), context.getSdxId(), context.getUserId(), upgrade));
        }

        @Override
        protected Object getFailurePayload(DatalakeImageChangeEvent payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeUpgradeFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) UpgradeOptionV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) DatalakeImageChangeEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeImageChangeEvent) ImageInfoV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response) DatalakeChangeImageWaitRequest(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with DatalakeChangeImageWaitRequest

use of com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest in project cloudbreak by hortonworks.

the class DatalakeUpgradeActions method imageChangeWait.

@Bean(name = "DATALAKE_IMAGE_CHANGE_IN_PROGRESS_STATE")
public Action<?, ?> imageChangeWait() {
    return new AbstractSdxAction<>(DatalakeChangeImageWaitRequest.class) {

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

        @Override
        protected void doExecute(SdxContext context, DatalakeChangeImageWaitRequest payload, Map<Object, Object> variables) {
            LOGGER.info("Datalake upgrade image change is in progress for {} ", payload.getResourceId());
            sendEvent(context, new DatalakeChangeImageWaitRequest(context, payload.getUpgradeOption()));
        }

        @Override
        protected Object getFailurePayload(DatalakeChangeImageWaitRequest payload, Optional<SdxContext> flowContext, Exception ex) {
            return DatalakeUpgradeFailedEvent.from(payload, ex);
        }
    };
}
Also used : FlowParameters(com.sequenceiq.flow.core.FlowParameters) AbstractSdxAction(com.sequenceiq.datalake.service.AbstractSdxAction) Optional(java.util.Optional) StateContext(org.springframework.statemachine.StateContext) DatalakeChangeImageWaitRequest(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest) Map(java.util.Map) SdxContext(com.sequenceiq.datalake.flow.SdxContext) Bean(org.springframework.context.annotation.Bean)

Example 3 with DatalakeChangeImageWaitRequest

use of com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest in project cloudbreak by hortonworks.

the class DatalakeChangeImageWaitHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<DatalakeChangeImageWaitRequest> event) {
    DatalakeChangeImageWaitRequest request = event.getData();
    Long sdxId = request.getResourceId();
    String userId = request.getUserId();
    Selectable response;
    try {
        LOGGER.info("Start polling change image process for id: {}", sdxId);
        PollingConfig pollingConfig = new PollingConfig(sleepTimeInSec, TimeUnit.SECONDS, durationInMinutes, TimeUnit.MINUTES);
        upgradeService.waitCloudbreakFlow(sdxId, pollingConfig, "Change image");
        String imageId = upgradeService.getImageId(sdxId);
        String expectedImageId = request.getUpgradeOption().getUpgrade().getImageId();
        if (Objects.equals(imageId, expectedImageId)) {
            LOGGER.info("Image changed in cloudbreak side for SDX {}, actual image: {}", sdxId, imageId);
            response = new DatalakeVmReplaceEvent(sdxId, userId);
        } else {
            String message = String.format("Image not changed in cloudbreak side, expected image: %s, actual image: %s", expectedImageId, imageId);
            LOGGER.info(message);
            response = new DatalakeUpgradeFailedEvent(sdxId, userId, new IllegalStateException(message));
        }
    } catch (UserBreakException userBreakException) {
        LOGGER.error("Change image polling exited before timeout. Cause: ", userBreakException);
        response = new DatalakeUpgradeFailedEvent(sdxId, userId, userBreakException);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Change image poller stopped for cluster: {}", sdxId);
        response = new DatalakeUpgradeFailedEvent(sdxId, userId, new PollerStoppedException("Change image poller timed out after " + durationInMinutes + " minutes"));
    } catch (PollerException exception) {
        LOGGER.error("Change image polling failed for cluster: {}", sdxId);
        response = new DatalakeUpgradeFailedEvent(sdxId, userId, exception);
    }
    return response;
}
Also used : UserBreakException(com.dyngr.exception.UserBreakException) DatalakeVmReplaceEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeVmReplaceEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) PollerException(com.dyngr.exception.PollerException) DatalakeUpgradeFailedEvent(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFailedEvent) DatalakeChangeImageWaitRequest(com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest) PollingConfig(com.sequenceiq.datalake.service.sdx.PollingConfig) PollerStoppedException(com.dyngr.exception.PollerStoppedException)

Aggregations

DatalakeChangeImageWaitRequest (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeChangeImageWaitRequest)3 SdxContext (com.sequenceiq.datalake.flow.SdxContext)2 AbstractSdxAction (com.sequenceiq.datalake.service.AbstractSdxAction)2 FlowParameters (com.sequenceiq.flow.core.FlowParameters)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Bean (org.springframework.context.annotation.Bean)2 StateContext (org.springframework.statemachine.StateContext)2 PollerException (com.dyngr.exception.PollerException)1 PollerStoppedException (com.dyngr.exception.PollerStoppedException)1 UserBreakException (com.dyngr.exception.UserBreakException)1 ImageInfoV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.image.ImageInfoV4Response)1 UpgradeOptionV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.upgrade.UpgradeOptionV4Response)1 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 DatalakeImageChangeEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeImageChangeEvent)1 DatalakeUpgradeFailedEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFailedEvent)1 DatalakeVmReplaceEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeVmReplaceEvent)1 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)1