Search in sources :

Example 1 with WebApplicationExceptionMessageExtractor

use of com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method updateEnvironmentStackConfigAction.

@Bean(name = "UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_STATE")
public Action<?, ?> updateEnvironmentStackConfigAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        @Inject
        private EnvironmentEndpoint environmentEndpoint;

        @Inject
        private WebApplicationExceptionMessageExtractor webApplicationExceptionMessageExtractor;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating environment stack config");
            try {
                ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> {
                    environmentEndpoint.updateConfigsInEnvironmentByCrn(stack.getEnvironmentCrn());
                });
                sendEvent(context, UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
            } catch (ClientErrorException e) {
                String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
                LOGGER.error("Failed to update the stack config due to {}", errorMessage, e);
                sendEvent(context, UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new UpscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
            } catch (Exception e) {
                LOGGER.error("Failed to update the stack config", e);
                sendEvent(context, UPSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new UpscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
            }
        }
    };
}
Also used : EnvironmentEndpoint(com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) WebApplicationExceptionMessageExtractor(com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) UpscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent) ClientErrorException(javax.ws.rs.ClientErrorException) Map(java.util.Map) ClientErrorException(javax.ws.rs.ClientErrorException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 2 with WebApplicationExceptionMessageExtractor

use of com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method updateEnvironmentStackConfigAction.

@Bean(name = "DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_STATE")
public Action<?, ?> updateEnvironmentStackConfigAction() {
    return new AbstractDownscaleAction<>(StackEvent.class) {

        @Inject
        private EnvironmentEndpoint environmentEndpoint;

        @Inject
        private WebApplicationExceptionMessageExtractor webApplicationExceptionMessageExtractor;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating environment stack config");
            try {
                if (!isRepair(variables) || !isChainedAction(variables) || isFinalChain(variables)) {
                    ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> environmentEndpoint.updateConfigsInEnvironmentByCrn(stack.getEnvironmentCrn()));
                }
                sendEvent(context, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
            } catch (ClientErrorException e) {
                String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
                LOGGER.error("Failed to update the stack config due to {}", errorMessage, e);
                sendEvent(context, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
            } catch (Exception e) {
                LOGGER.error("Failed to update the stack config", e);
                sendEvent(context, DOWNSCALE_UPDATE_ENVIRONMENT_STACK_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(stack.getId(), "Updating environment stack config", Set.of(), Map.of(), e));
            }
        }
    };
}
Also used : EnvironmentEndpoint(com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) WebApplicationExceptionMessageExtractor(com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) ClientErrorException(javax.ws.rs.ClientErrorException) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) Map(java.util.Map) ClientErrorException(javax.ws.rs.ClientErrorException) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Aggregations

WebApplicationExceptionMessageExtractor (com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor)2 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)2 Stack (com.sequenceiq.freeipa.entity.Stack)2 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)2 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)2 Map (java.util.Map)2 ClientErrorException (javax.ws.rs.ClientErrorException)2 Bean (org.springframework.context.annotation.Bean)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1 DownscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)1 UpscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.upscale.event.UpscaleFailureEvent)1