Search in sources :

Example 46 with StackContext

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

the class FreeIpaDownscaleActions method removeInstancesAction.

@Bean(name = "DOWNSCALE_REMOVE_INSTANCES_STATE")
public Action<?, ?> removeInstancesAction() {
    return new AbstractDownscaleAction<>(DownscaleStackCollectResourcesResult.class) {

        @Override
        protected void doExecute(StackContext context, DownscaleStackCollectResourcesResult payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Decommissioning instances");
            List<String> repairInstanceIds = getInstanceIds(variables);
            List<CloudResource> cloudResources = getCloudResources(stack);
            List<CloudInstance> cloudInstances = getNonTerminatedCloudInstances(stack, repairInstanceIds);
            DownscaleStackRequest request = new DownscaleStackRequest(context.getCloudContext(), context.getCloudCredential(), context.getCloudStack(), cloudResources, cloudInstances, payload.getResourcesToScale());
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) DownscaleStackCollectResourcesResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackCollectResourcesResult) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) DownscaleStackRequest(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Map(java.util.Map) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 47 with StackContext

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

the class FreeIpaDownscaleActions method removeServersAction.

@Bean(name = "DOWNSCALE_REMOVE_SERVERS_STATE")
public Action<?, ?> removeServersAction() {
    return new AbstractDownscaleAction<>(DownscaleStackResult.class) {

        @Override
        protected void doExecute(StackContext context, DownscaleStackResult payload, Map<Object, Object> variables) {
            CleanupEvent cleanupEvent = buildCleanupEvent(context, getDownscaleHosts(variables));
            stackUpdater.updateStackStatus(context.getStack().getId(), getInProgressStatus(variables), "Removing servers");
            RemoveServersRequest request = new RemoveServersRequest(cleanupEvent);
            sendEvent(context, request);
        }
    };
}
Also used : RemoveServersRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removeserver.RemoveServersRequest) DownscaleStackResult(com.sequenceiq.cloudbreak.cloud.event.resource.DownscaleStackResult) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 48 with StackContext

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

the class FreeIpaDownscaleActions method removeHostsFromOrchestrationAction.

@Bean(name = "DOWNSCALE_REMOVE_HOSTS_FROM_ORCHESTRATION_STATE")
public Action<?, ?> removeHostsFromOrchestrationAction() {
    return new AbstractDownscaleAction<>(UpdateDnsSoaRecordsResponse.class) {

        @Override
        protected void doExecute(StackContext context, UpdateDnsSoaRecordsResponse payload, Map<Object, Object> variables) {
            stackUpdater.updateStackStatus(context.getStack().getId(), getInProgressStatus(variables), "Removing hosts from orchestration");
            CleanupEvent cleanupEvent = buildCleanupEvent(context, getDownscaleHosts(variables));
            RemoveHostsFromOrchestrationRequest request = new RemoveHostsFromOrchestrationRequest(cleanupEvent);
            sendEvent(context, request);
        }
    };
}
Also used : StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) Map(java.util.Map) UpdateDnsSoaRecordsResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse) RemoveHostsFromOrchestrationRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.removehosts.RemoveHostsFromOrchestrationRequest) Bean(org.springframework.context.annotation.Bean)

Example 49 with StackContext

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

Example 50 with StackContext

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

the class FreeIpaDownscaleActions method startingDownscaleAction.

@Bean(name = "STARTING_DOWNSCALE_STATE")
public Action<?, ?> startingDownscaleAction() {
    return new AbstractDownscaleAction<>(DownscaleEvent.class) {

        @Override
        protected void doExecute(StackContext context, DownscaleEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            List<String> instanceIds = payload.getInstanceIds();
            setInstanceIds(variables, instanceIds);
            String operationId = payload.getOperationId();
            setOperationId(variables, operationId);
            List<String> fqdns = getInstanceMetadataFromStack(stack, instanceIds).stream().map(InstanceMetaData::getDiscoveryFQDN).filter(Objects::nonNull).collect(Collectors.toList());
            setDownscaleHosts(variables, fqdns);
            setRepair(variables, payload.isRepair());
            setChainedAction(variables, payload.isChained());
            setFinalChain(variables, payload.isFinalChain());
            setInstanceCountByGroup(variables, payload.getInstanceCountByGroup());
            LOGGER.info("Starting downscale {}", payload);
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Starting downscale");
            sendEvent(context, STARTING_DOWNSCALE_FINISHED_EVENT.selector(), new StackEvent(stack.getId()));
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) DownscaleEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleEvent) 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)

Aggregations

StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)57 Map (java.util.Map)49 Bean (org.springframework.context.annotation.Bean)48 Stack (com.sequenceiq.freeipa.entity.Stack)45 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)30 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)30 FlowParameters (com.sequenceiq.flow.core.FlowParameters)11 List (java.util.List)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)10 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)10 ClientErrorException (javax.ws.rs.ClientErrorException)10 EnvironmentEndpoint (com.sequenceiq.environment.api.v1.environment.endpoint.EnvironmentEndpoint)9 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)9 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)9 Collectors (java.util.stream.Collectors)9 Inject (javax.inject.Inject)9 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)8 Flow (com.sequenceiq.flow.core.Flow)8 Configuration (org.springframework.context.annotation.Configuration)8 Action (org.springframework.statemachine.action.Action)8