Search in sources :

Example 26 with Stack

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

the class ChangePrimaryGatewayActions method clusterProxyRegistrationAction.

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

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Changing the primary gateway cluster proxy registration");
            List<String> repairInstanceIds = getInstanceIds(variables);
            ClusterProxyUpdateRegistrationRequest request;
            if (Objects.nonNull(repairInstanceIds)) {
                List<String> instanceIdsToRegister = stack.getNotDeletedInstanceMetaDataList().stream().map(InstanceMetaData::getInstanceId).filter(instanceId -> !repairInstanceIds.contains(instanceId)).collect(Collectors.toList());
                LOGGER.debug("When changing the primary gateway cluster proxy in stack {}, [{}] will be reregistered", stack.getId(), instanceIdsToRegister);
                request = new ClusterProxyUpdateRegistrationRequest(stack.getId(), instanceIdsToRegister);
            } else {
                LOGGER.debug("When changing the primary gateway cluster proxy in stack {}, the whole stack will be reregistered", stack.getId());
                request = new ClusterProxyUpdateRegistrationRequest(stack.getId());
            }
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Action(org.springframework.statemachine.action.Action) HealthCheckFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.HealthCheckFailedToChangePrimaryGatewayFailureEventConverter) ChangePrimaryGatewaySelectionRequest(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionRequest) LoggerFactory(org.slf4j.LoggerFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ArrayList(java.util.ArrayList) ChangePrimaryGatewayEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayEvent) Inject(javax.inject.Inject) ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter) HealthCheckRequest(com.sequenceiq.freeipa.flow.stack.HealthCheckRequest) StateContext(org.springframework.statemachine.StateContext) Map(java.util.Map) ChangePrimaryGatewayFlowEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayFlowEvent) ClusterProxyUpdateRegistrationRequest(com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationRequest) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) PayloadConverter(com.sequenceiq.flow.core.PayloadConverter) CHANGE_PRIMARY_GATEWAY_METADATA_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_METADATA_FINISHED_EVENT) Logger(org.slf4j.Logger) FAIL_HANDLED_EVENT(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayFlowEvent.FAIL_HANDLED_EVENT) CHANGE_PRIMARY_GATEWAY_METADATA_FAILED_EVENT(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_METADATA_FAILED_EVENT) CHANGE_PRIMARY_GATEWAY_STARTING_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_STARTING_FINISHED_EVENT) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Set(java.util.Set) FlowParameters(com.sequenceiq.flow.core.FlowParameters) Collectors(java.util.stream.Collectors) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Objects(java.util.Objects) Configuration(org.springframework.context.annotation.Configuration) ChangePrimaryGatewayFailureEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent) CHANGE_PRIMARY_GATEWAY_FINISHED_EVENT(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayFlowEvent.CHANGE_PRIMARY_GATEWAY_FINISHED_EVENT) ChangePrimaryGatewayService(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayService) List(java.util.List) ChangePrimaryGatewayState(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayState) StackUpdater(com.sequenceiq.freeipa.service.stack.StackUpdater) Flow(com.sequenceiq.flow.core.Flow) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Bean(org.springframework.context.annotation.Bean) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) Collections(java.util.Collections) ChangePrimaryGatewaySelectionSuccess(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionSuccess) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ClusterProxyUpdateRegistrationRequest(com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationRequest) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 27 with Stack

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

the class ChangePrimaryGatewayActions method healthCheckAction.

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

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            Selectable request;
            if (isFinalChain(variables)) {
                stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Checking the health");
                request = new HealthCheckRequest(stack.getId(), false);
            } else {
                LOGGER.debug("Repair in progress, skipping the health check");
                request = new HealthCheckSuccess(stack.getId(), null);
            }
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) HealthCheckSuccess(com.sequenceiq.freeipa.flow.stack.HealthCheckSuccess) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) HealthCheckRequest(com.sequenceiq.freeipa.flow.stack.HealthCheckRequest) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 28 with Stack

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

the class ChangePrimaryGatewayActions method orchestrationAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_METADATA_STATE")
public Action<?, ?> orchestrationAction() {
    return new AbstractChangePrimaryGatewayAction<>(ChangePrimaryGatewaySelectionSuccess.class) {

        @Inject
        private ChangePrimaryGatewayService changePrimaryGatewayService;

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, ChangePrimaryGatewaySelectionSuccess payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), DetailedStackStatus.REPAIR_IN_PROGRESS, "Changing the primary gateway metadata");
            try {
                changePrimaryGatewayService.changePrimaryGatewayMetadata(stack, payload.getFormerPrimaryGatewayInstanceId(), payload.getNewPrimaryGatewayInstanceId());
                sendEvent(context, CHANGE_PRIMARY_GATEWAY_METADATA_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
            } catch (Exception e) {
                LOGGER.error("Failed to update the primary gateway metadata", e);
                sendEvent(context, CHANGE_PRIMARY_GATEWAY_METADATA_FAILED_EVENT.selector(), new ChangePrimaryGatewayFailureEvent(stack.getId(), "Updating metadata", Set.of(), Map.of(), e));
            }
        }
    };
}
Also used : ChangePrimaryGatewayService(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayService) StackEvent(com.sequenceiq.freeipa.flow.stack.StackEvent) ChangePrimaryGatewayFailureEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent) ChangePrimaryGatewaySelectionSuccess(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.selection.ChangePrimaryGatewaySelectionSuccess) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 29 with Stack

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

the class RemoveReplicationAgreementsHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<RemoveReplicationAgreementsRequest> event) {
    RemoveReplicationAgreementsRequest request = event.getData();
    try {
        Long stackId = request.getResourceId();
        Stack stack = stackService.getStackById(stackId);
        freeIpaTopologyService.updateReplicationTopologyWithRetry(stack, request.getHosts());
        return new RemoveReplicationAgreementsResponse(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Downscale removing replication agreements failed", e);
        return new DownscaleFailureEvent(REMOVE_REPLICATION_AGREEMENTS_FAILED_EVENT.event(), request.getResourceId(), "Downscale Remove Replication Agreements", Set.of(), Map.of(), e);
    }
}
Also used : RemoveReplicationAgreementsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removereplication.RemoveReplicationAgreementsRequest) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) RemoveReplicationAgreementsResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removereplication.RemoveReplicationAgreementsResponse) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 30 with Stack

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

the class DiagnosticsPreFlightCheckHandler method executeOperation.

@Override
public Selectable executeOperation(HandlerEvent<DiagnosticsCollectionEvent> event) throws Exception {
    DiagnosticsCollectionEvent data = event.getData();
    Long resourceId = data.getResourceId();
    String resourceCrn = data.getResourceCrn();
    DiagnosticParameters parameters = data.getParameters();
    Stack stack = stackService.getByIdWithListsInTransaction(resourceId);
    Set<InstanceMetaData> instanceMetaDataSet = instanceMetaDataService.findNotTerminatedForStack(resourceId);
    instanceMetaDataSet.stream().filter(im -> im.getInstanceMetadataType() == InstanceMetadataType.GATEWAY_PRIMARY).forEach(instance -> executeNetworkReport(stack, instance));
    return DiagnosticsCollectionEvent.builder().withResourceCrn(resourceCrn).withResourceId(resourceId).withSelector(START_DIAGNOSTICS_INIT_EVENT.selector()).withParameters(parameters).build();
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Logger(org.slf4j.Logger) DiagnosticsCollectionEvent(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) LoggerFactory(org.slf4j.LoggerFactory) START_DIAGNOSTICS_INIT_EVENT(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionStateSelectors.START_DIAGNOSTICS_INIT_EVENT) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) NodeStatusProto(com.cloudera.thunderhead.telemetry.nodestatus.NodeStatusProto) InstanceMetadataType(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetadataType) Inject(javax.inject.Inject) FreeIpaNodeStatusService(com.sequenceiq.freeipa.service.stack.FreeIpaNodeStatusService) Component(org.springframework.stereotype.Component) DiagnosticParameters(com.sequenceiq.common.model.diagnostics.DiagnosticParameters) StackService(com.sequenceiq.freeipa.service.stack.StackService) PREFLIGHT_CHECK_DIAGNOSTICS_EVENT(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionHandlerSelectors.PREFLIGHT_CHECK_DIAGNOSTICS_EVENT) UsageProto(com.cloudera.thunderhead.service.common.usage.UsageProto) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) DiagnosticParameters(com.sequenceiq.common.model.diagnostics.DiagnosticParameters) DiagnosticsCollectionEvent(com.sequenceiq.freeipa.flow.freeipa.diagnostics.event.DiagnosticsCollectionEvent) Stack(com.sequenceiq.freeipa.entity.Stack)

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