Search in sources :

Example 36 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayActions method finsihedAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_FINISHED_STATE")
public Action<?, ?> finsihedAction() {
    return new AbstractChangePrimaryGatewayAction<>(StackEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            SuccessDetails successDetails = new SuccessDetails(stack.getEnvironmentCrn());
            if (isFinalChain(variables)) {
                successDetails.getAdditionalDetails().put("DownscaleHosts", getDownscaleHosts(variables));
                successDetails.getAdditionalDetails().put("UpscaleHosts", getUpscaleHosts(variables));
                operationService.completeOperation(stack.getAccountId(), getOperationId(variables), List.of(successDetails), Collections.emptyList());
            } else {
                stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Finished changing the primary gateway");
            }
            sendEvent(context, CHANGE_PRIMARY_GATEWAY_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 37 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class ValidateInstancesHealthHandlerTest method testHealthy.

@Test
public void testHealthy() throws FreeIpaClientException {
    Stack stack = new Stack();
    stack.setId(1L);
    when(stackService.getStackById(1L)).thenReturn(stack);
    List<String> instanceIds = List.of("im1", "im2");
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceId("im1");
    im1.setDiscoveryFQDN("im1Fqdn");
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setInstanceId("im2");
    im2.setDiscoveryFQDN("im2Fqdn");
    when(instanceMetaDataService.getNotTerminatedByInstanceIds(1L, instanceIds)).thenReturn(Set.of(im1, im2));
    when(healthService.getInstanceHealthDetails(stack, im1)).thenReturn(createHealthyNodeDetail(im1));
    when(healthService.getInstanceHealthDetails(stack, im2)).thenReturn(createHealthyNodeDetail(im2));
    StackEvent result = (StackEvent) underTest.doAccept(new HandlerEvent<>(new Event<>(new ValidateInstancesHealthEvent(1L, instanceIds))));
    assertEquals(UPSCALE_VALIDATE_NEW_INSTANCES_HEALTH_FINISHED_EVENT.event(), result.selector());
    assertEquals(1L, result.getResourceId());
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) ValidateInstancesHealthEvent(com.sequenceiq.freeipa.flow.freeipa.upscale.event.ValidateInstancesHealthEvent) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 38 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method updateMetadataAction.

@Bean(name = "DOWNSCALE_UPDATE_METADATA_STATE")
public Action<?, ?> updateMetadataAction() {
    return new AbstractDownscaleAction<>(RemoveHostsFromOrchestrationSuccess.class) {

        @Inject
        private InstanceGroupService instanceGroupService;

        @Override
        protected void doExecute(StackContext context, RemoveHostsFromOrchestrationSuccess payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating metadata");
            List<String> repairInstanceIds = getInstanceIds(variables);
            terminationService.finalizeTermination(stack.getId(), repairInstanceIds);
            terminationService.finalizeTerminationForInstancesWithoutInstanceIds(stack.getId());
            if (!isRepair(variables)) {
                int nodeCount = getInstanceCountByGroup(variables);
                instanceGroupService.findByStackId(stack.getId()).forEach(instanceGroup -> {
                    instanceGroup.setNodeCount(nodeCount);
                    instanceGroupService.save(instanceGroup);
                });
            }
            sendEvent(context, UPDATE_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : InstanceGroupService(com.sequenceiq.freeipa.service.stack.instance.InstanceGroupService) RemoveHostsFromOrchestrationSuccess(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationSuccess) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) EnvironmentEndpoint(com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 39 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent 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)

Example 40 with StackEvent

use of com.sequenceiq.freeipa.flow.stack.StackEvent in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method updateKerberosNameserversConfigAction.

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

        @Inject
        private KerberosConfigUpdateService kerberosConfigUpdateService;

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating kerberos nameserver config");
            try {
                kerberosConfigUpdateService.updateNameservers(stack.getId());
                sendEvent(context, DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
            } catch (Exception e) {
                LOGGER.error("Failed to update the kerberos nameserver config", e);
                sendEvent(context, DOWNSCALE_UPDATE_KERBEROS_NAMESERVERS_CONFIG_FAILED_EVENT.selector(), new DownscaleFailureEvent(stack.getId(), "Updating kerberos nameserver config", Set.of(), Map.of(), e));
            }
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) KerberosConfigUpdateService(com.sequenceiq.freeipa.service.config.KerberosConfigUpdateService) 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

StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)54 Map (java.util.Map)40 Bean (org.springframework.context.annotation.Bean)40 Stack (com.sequenceiq.freeipa.entity.Stack)38 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)28 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)17 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)12 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)11 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)11 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 Flow (com.sequenceiq.flow.core.Flow)9 FlowParameters (com.sequenceiq.flow.core.FlowParameters)8 List (java.util.List)8 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Configuration (org.springframework.context.annotation.Configuration)8