Search in sources :

Example 16 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method recordHostnamesAction.

@Bean(name = "UPSCALE_RECORD_HOSTNAMES_STATE")
public Action<?, ?> recordHostnamesAction() {
    return new AbstractUpscaleAction<>(HostMetadataSetupSuccess.class) {

        @Override
        protected void doExecute(StackContext context, HostMetadataSetupSuccess payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Recording hostnames");
            List<String> instanceIds = getInstanceIds(variables);
            List<String> hosts = stack.getNotDeletedInstanceMetaDataList().stream().filter(instanceMetaData -> instanceIds.contains(instanceMetaData.getInstanceId())).map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toList());
            setUpscaleHosts(variables, hosts);
            sendEvent(context, UPSCALE_RECORD_HOSTNAMES_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) HostMetadataSetupSuccess(com.sequenceiq.freeipa.flow.freeipa.provision.event.hostmetadatasetup.HostMetadataSetupSuccess) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 17 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class FreeIpaUpscaleActions method collectingHostMetadataAction.

@Bean(name = "UPSCALE_COLLECTING_HOST_METADATA_STATE")
public Action<?, ?> collectingHostMetadataAction() {
    return new AbstractUpscaleAction<>(BootstrapMachinesSuccess.class) {

        @Override
        protected void doExecute(StackContext context, BootstrapMachinesSuccess payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Collecting host metadata");
            HostMetadataSetupRequest request = new HostMetadataSetupRequest(stack.getId());
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) BootstrapMachinesSuccess(com.sequenceiq.freeipa.flow.freeipa.provision.event.bootstrap.BootstrapMachinesSuccess) HostMetadataSetupRequest(com.sequenceiq.freeipa.flow.freeipa.provision.event.hostmetadatasetup.HostMetadataSetupRequest) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Bean(org.springframework.context.annotation.Bean)

Example 18 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method updateMetadataForDeletionRequestAction.

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

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Updating metadata for deletion request");
            List<String> repairInstanceIds = getInstanceIds(variables);
            terminationService.requestDeletion(stack.getId(), repairInstanceIds);
            sendEvent(context, UPDATE_METADATA_FOR_DELETION_REQUEST_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 19 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method downscaleCollectAdditionalHostnamesAction.

@Bean(name = "DOWNSCALE_COLLECT_ADDITIONAL_HOSTNAMES_STATE")
public Action<?, ?> downscaleCollectAdditionalHostnamesAction() {
    return new AbstractDownscaleAction<>(ClusterProxyUpdateRegistrationSuccess.class) {

        @Override
        protected void doExecute(StackContext context, ClusterProxyUpdateRegistrationSuccess payload, Map<Object, Object> variables) throws Exception {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Collecting additional hostnames.");
            CollectAdditionalHostnamesRequest request = new CollectAdditionalHostnamesRequest(stack.getId());
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CollectAdditionalHostnamesRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest) Map(java.util.Map) ClusterProxyUpdateRegistrationSuccess(com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationSuccess) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 20 with Stack

use of com.sequenceiq.freeipa.entity.Stack in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method downscaleFailureAction.

@Bean(name = "DOWNSCALE_FAIL_STATE")
public Action<?, ?> downscaleFailureAction() {
    return new AbstractDownscaleAction<>(DownscaleFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected StackContext createFlowContext(FlowParameters flowParameters, StateContext<DownscaleState, DownscaleFlowEvent> stateContext, DownscaleFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected void doExecute(StackContext context, DownscaleFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Downscale failed with payload: " + payload);
            Stack stack = context.getStack();
            String environmentCrn = stack.getEnvironmentCrn();
            SuccessDetails successDetails = new SuccessDetails(environmentCrn);
            successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
            String message = "Downscale failed during " + payload.getFailedPhase();
            FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
            if (payload.getFailureDetails() != null) {
                failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
            }
            String errorReason = getErrorReason(payload.getException());
            stackUpdater.updateStackStatus(context.getStack().getId(), getFailedStatus(variables), errorReason);
            operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
            enableStatusChecker(stack, "Failed downscaling FreeIPA");
            enableNodeStatusChecker(stack, "Failed downscaling FreeIPA");
            sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<DownscaleFailureEvent>> payloadConverters) {
            payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter());
            payloadConverters.add(new DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter());
            payloadConverters.add(new DownscaleStackResultToDownscaleFailureEventConverter());
            payloadConverters.add(new RemoveServersResponseToDownscaleFailureEventConverter());
            payloadConverters.add(new RemoveDnsResponseToDownscaleFailureEventConverter());
            payloadConverters.add(new RemoveHostsResponseToDownscaleFailureEventConverter());
            payloadConverters.add(new RevokeCertsResponseToDownscaleFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) DownscaleStackResultToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackResultToDownscaleFailureEventConverter) StateContext(org.springframework.statemachine.StateContext) ArrayList(java.util.ArrayList) RemoveHostsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveHostsResponseToDownscaleFailureEventConverter) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.DownscaleStackCollectResourcesResultToDownscaleFailureEventConverter) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.freeipa.entity.Stack) ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.ClusterProxyUpdateRegistrationFailedToDownscaleFailureEventConverter) RemoveServersResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveServersResponseToDownscaleFailureEventConverter) RemoveDnsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RemoveDnsResponseToDownscaleFailureEventConverter) FlowParameters(com.sequenceiq.flow.core.FlowParameters) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) RevokeCertsResponseToDownscaleFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.downscale.failure.RevokeCertsResponseToDownscaleFailureEventConverter) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)468 Test (org.junit.jupiter.api.Test)237 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)107 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)63 Map (java.util.Map)63 Bean (org.springframework.context.annotation.Bean)50 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)45 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)41 List (java.util.List)37 InstanceGroup (com.sequenceiq.freeipa.entity.InstanceGroup)34 Inject (javax.inject.Inject)30 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)29 Collectors (java.util.stream.Collectors)29 Logger (org.slf4j.Logger)29 LoggerFactory (org.slf4j.LoggerFactory)29 Set (java.util.Set)28 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)25 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)25 ImageSettingsRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest)24 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)23