Search in sources :

Example 46 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class CcmKeyDeregisterHandler method accept.

@Override
public void accept(Event<CcmKeyDeregisterRequest> requestEvent) {
    CcmKeyDeregisterRequest request = requestEvent.getData();
    Selectable result;
    try {
        Stack stack = stackService.getByIdWithListsInTransaction(request.getResourceId());
        try {
            if (request.getTunnel().useCcmV1()) {
                LOGGER.debug("De-registering MinaSshdServiceId '{}' from CCM. Cluster CRN: {}", stack.getMinaSshdServiceId(), stack.getResourceCrn());
                ccmResourceTerminationListener.deregisterCcmSshTunnelingKey(request.getActorCrn(), request.getAccountId(), request.getKeyId(), stack.getMinaSshdServiceId());
                LOGGER.debug("De-registered MinaSshdServiceId '{}' from CCM. Cluster CRN: {}", stack.getMinaSshdServiceId(), stack.getResourceCrn());
            } else if (request.getTunnel().useCcmV2OrJumpgate() && StringUtils.isNotBlank(stack.getCcmV2AgentCrn())) {
                LOGGER.debug("De-registering CcmV2AgentCrn '{}' from CCM. Cluster CRN: {}", stack.getCcmV2AgentCrn(), stack.getResourceCrn());
                ccmV2AgentTerminationListener.deregisterInvertingProxyAgent(stack.getCcmV2AgentCrn());
                LOGGER.debug("De-registered CcmV2AgentCrn '{}' from CCM. Cluster CRN: {}", stack.getCcmV2AgentCrn(), stack.getResourceCrn());
            } else {
                LOGGER.debug("CCM is DISABLED, skipping de-registering of key from CCM. Cluster CRN: {}", stack.getResourceCrn());
            }
        } catch (Exception ex) {
            LOGGER.warn("CCM key deregistration failed", ex);
        }
        result = new CcmKeyDeregisterSuccess(stack.getId());
    } catch (Exception ex) {
        LOGGER.error("Stack retrieval for CCM key deregistration failed", ex);
        result = new StackFailureEvent(StackTerminationEvent.CCM_KEY_DEREGISTER_FAILED_EVENT.event(), request.getResourceId(), ex);
    }
    eventBus.notify(result.selector(), new Event<>(requestEvent.getHeaders(), result));
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) CcmKeyDeregisterRequest(com.sequenceiq.cloudbreak.reactor.api.event.recipe.CcmKeyDeregisterRequest) CcmKeyDeregisterSuccess(com.sequenceiq.cloudbreak.reactor.api.event.recipe.CcmKeyDeregisterSuccess) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 47 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class FlowChainHandler method restoreFlowChain.

public void restoreFlowChain(String flowChainId) {
    Optional<FlowChainLog> chainLog = flowLogService.findFirstByFlowChainIdOrderByCreatedDesc(flowChainId);
    if (chainLog.isPresent()) {
        String flowChainType = chainLog.get().getFlowChainType();
        Queue<Selectable> queue = (Queue<Selectable>) JsonReader.jsonToJava(chainLog.get().getChain());
        Payload triggerEvent = tryDeserializeTriggerEvent(chainLog.get());
        FlowTriggerEventQueue chain = new FlowTriggerEventQueue(flowChainType, triggerEvent, queue);
        if (chainLog.get().getParentFlowChainId() != null) {
            chain.setParentFlowChainId(chainLog.get().getParentFlowChainId());
        }
        flowChains.putFlowChain(flowChainId, chainLog.get().getParentFlowChainId(), chain);
        Selectable selectable = queue.peek();
        if (selectable != null) {
            OperationType operationType = flowChainOperationTypeConfig.getFlowTypeOperationTypeMap().getOrDefault(flowChainType, OperationType.UNKNOWN);
            flowStatCache.putByFlowChainId(flowChainId, selectable.getResourceId(), operationType.name(), true);
        }
        if (chainLog.get().getParentFlowChainId() != null) {
            restoreFlowChain(chainLog.get().getParentFlowChainId());
        }
    }
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) Payload(com.sequenceiq.cloudbreak.common.event.Payload) OperationType(com.sequenceiq.flow.api.model.operation.OperationType) FlowChainLog(com.sequenceiq.flow.domain.FlowChainLog) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Queue(java.util.Queue)

Example 48 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class FlowChains method triggerNextFlow.

public void triggerNextFlow(String flowChainId, String flowTriggerUserCrn, Map<Object, Object> contextParams, String operationType, Optional<Runnable> finalizerCallback) {
    FlowTriggerEventQueue flowTriggerEventQueue = flowChainMap.get(flowChainId);
    if (flowTriggerEventQueue != null) {
        Queue<Selectable> queue = flowTriggerEventQueue.getQueue();
        if (queue != null) {
            Selectable selectable = queue.peek();
            if (selectable != null) {
                sendEvent(flowTriggerEventQueue.getFlowChainName(), flowChainId, flowTriggerUserCrn, selectable, contextParams, operationType);
            } else {
                String parentFlowChainId = getParentFlowChainId(flowChainId);
                if (parentFlowChainId != null) {
                    flowChainMap.get(parentFlowChainId).getQueue().poll();
                    flowLogService.saveChain(parentFlowChainId, getParentFlowChainId(parentFlowChainId), flowChainMap.get(parentFlowChainId), flowTriggerUserCrn);
                }
                triggerParentFlowChain(flowChainId, flowTriggerUserCrn, contextParams, operationType, finalizerCallback);
            }
        }
    }
}
Also used : FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable)

Example 49 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class HelloWorldFlowChainFactory method createFlowTriggerEventQueue.

@Override
public FlowTriggerEventQueue createFlowTriggerEventQueue(BaseFlowEvent event) {
    Queue<Selectable> flowEventChain = new ConcurrentLinkedDeque<>();
    flowEventChain.add(new BaseFlowEvent(HELLOWORLD_TRIGGER_EVENT.event(), event.getResourceId(), event.getResourceCrn(), event.accepted()));
    return new FlowTriggerEventQueue(getName(), event, flowEventChain);
}
Also used : BaseFlowEvent(com.sequenceiq.flow.reactor.api.event.BaseFlowEvent) FlowTriggerEventQueue(com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Example 50 with Selectable

use of com.sequenceiq.cloudbreak.common.event.Selectable in project cloudbreak by hortonworks.

the class StopStartDownscaleDecommissionViaCMHandlerTest method testErrorFromCmHostCollection.

@Test
void testErrorFromCmHostCollection() {
    int instancesToDecommissionCount = 5;
    int expcetedInstanceToCollectCount = 5;
    int expectedInstancesDecommissionedCount = 5;
    List<InstanceMetaData> instancesToDecommission = getInstancesToDecommission(instancesToDecommissionCount);
    HostGroup hostGroup = createHostGroup(instancesToDecommission);
    Map<String, InstanceMetaData> collected = instancesToDecommission.stream().limit(expcetedInstanceToCollectCount).collect(Collectors.toMap(i -> i.getDiscoveryFQDN(), i -> i));
    List<InstanceMetaData> decommissionedMetadataList = collected.values().stream().limit(expectedInstancesDecommissionedCount).collect(Collectors.toList());
    Set<String> fqdnsDecommissioned = decommissionedMetadataList.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toUnmodifiableSet());
    Set<Long> instanceIdsToDecommission = instancesToDecommission.stream().map(InstanceMetaData::getPrivateId).collect(Collectors.toUnmodifiableSet());
    Set<String> hostnamesToDecommission = instancesToDecommission.stream().map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toUnmodifiableSet());
    setupAdditionalMocks(hostGroup, instancesToDecommission, collected, fqdnsDecommissioned);
    when(clusterDecomissionService.collectHostsToRemove(eq(hostGroup), eq(hostnamesToDecommission))).thenThrow(new RuntimeException("collectHostsToDecommissionError"));
    StopStartDownscaleDecommissionViaCMRequest request = new StopStartDownscaleDecommissionViaCMRequest(1L, INSTANCE_GROUP_NAME, instanceIdsToDecommission);
    HandlerEvent handlerEvent = new HandlerEvent(Event.wrap(request));
    Selectable selectable = underTest.doAccept(handlerEvent);
    verify(clusterDecomissionService).collectHostsToRemove(eq(hostGroup), eq(hostnamesToDecommission));
    assertThat(selectable).isInstanceOf(StopStartDownscaleDecommissionViaCMResult.class);
    StopStartDownscaleDecommissionViaCMResult result = (StopStartDownscaleDecommissionViaCMResult) selectable;
    assertThat(result.getNotDecommissionedHostFqdns()).hasSize(0);
    assertThat(result.getDecommissionedHostFqdns()).hasSize(0);
    assertThat(result.getErrorDetails().getMessage()).isEqualTo("collectHostsToDecommissionError");
    assertThat(result.getStatus()).isEqualTo(EventStatus.FAILED);
    assertThat(result.selector()).isEqualTo("STOPSTARTDOWNSCALEDECOMMISSIONVIACMRESULT_ERROR");
    verifyNoMoreInteractions(instanceMetaDataService);
    verifyNoMoreInteractions(flowMessageService);
    verifyNoMoreInteractions(clusterDecomissionService);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) BeforeEach(org.junit.jupiter.api.BeforeEach) ClusterDecomissionService(com.sequenceiq.cloudbreak.cluster.api.ClusterDecomissionService) StopStartDownscaleDecommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartDownscaleDecommissionViaCMResult) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTEREDCMMAINTMODE(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTEREDCMMAINTMODE) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) Mockito.lenient(org.mockito.Mockito.lenient) ArrayList(java.util.ArrayList) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) HashSet(java.util.HashSet) UPDATE_IN_PROGRESS(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.UPDATE_IN_PROGRESS) CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTERINGCMMAINTMODE(com.sequenceiq.cloudbreak.event.ResourceEvent.CLUSTER_SCALING_STOPSTART_DOWNSCALE_ENTERINGCMMAINTMODE) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Event(reactor.bus.Event) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) CloudbreakFlowMessageService(com.sequenceiq.cloudbreak.core.flow2.stack.CloudbreakFlowMessageService) Map(java.util.Map) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Mockito.when(org.mockito.Mockito.when) EventStatus(com.sequenceiq.cloudbreak.cloud.event.model.EventStatus) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) StopStartDownscaleDecommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest) List(java.util.List) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterApiConnectors(com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StopStartDownscaleDecommissionViaCMResult(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.StopStartDownscaleDecommissionViaCMResult) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) StopStartDownscaleDecommissionViaCMRequest(com.sequenceiq.cloudbreak.reactor.api.event.cluster.StopStartDownscaleDecommissionViaCMRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Test(org.junit.jupiter.api.Test)

Aggregations

Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)283 Test (org.junit.jupiter.api.Test)93 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)48 Map (java.util.Map)47 List (java.util.List)36 FlowTriggerEventQueue (com.sequenceiq.flow.core.chain.config.FlowTriggerEventQueue)35 Collectors (java.util.stream.Collectors)35 PollerException (com.dyngr.exception.PollerException)32 PollerStoppedException (com.dyngr.exception.PollerStoppedException)32 UserBreakException (com.dyngr.exception.UserBreakException)32 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)30 Optional (java.util.Optional)30 Set (java.util.Set)30 Bean (org.springframework.context.annotation.Bean)28 Event (reactor.bus.Event)28 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)27 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)27 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)27 Inject (javax.inject.Inject)24 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)23