Search in sources :

Example 1 with CleanupFreeIpaEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent in project cloudbreak by hortonworks.

the class StackUpscaleActions method cleanupFreeIpaAction.

@Bean(name = "CLEANUP_FREEIPA_UPSCALE_STATE")
public Action<?, ?> cleanupFreeIpaAction() {
    return new AbstractStackUpscaleAction<>(ExtendHostMetadataResult.class) {

        @Inject
        private InstanceMetaDataService instanceMetaDataService;

        @Override
        protected void doExecute(StackScalingFlowContext context, ExtendHostMetadataResult payload, Map<Object, Object> variables) {
            Set<InstanceMetaData> instanceMetaData = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(context.getStack().getId());
            Set<String> ips = payload.getRequest().getUpscaleCandidateAddresses();
            Set<String> hostNames = instanceMetaData.stream().filter(im -> ips.contains(im.getPrivateIp())).filter(im -> im.getDiscoveryFQDN() != null).map(InstanceMetaData::getDiscoveryFQDN).collect(Collectors.toSet());
            CleanupFreeIpaEvent cleanupFreeIpaEvent = new CleanupFreeIpaEvent(context.getStack().getId(), hostNames, ips, context.isRepair());
            sendEvent(context, cleanupFreeIpaEvent);
        }
    };
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Action(org.springframework.statemachine.action.Action) StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) LoggerFactory(org.slf4j.LoggerFactory) StackToCloudStackConverter(com.sequenceiq.cloudbreak.converter.spi.StackToCloudStackConverter) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) InstanceMetaDataToCloudInstanceConverter(com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter) Map(java.util.Map) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) BootstrapNewNodesResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesResult) UpscaleStackRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackRequest) AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Collection(java.util.Collection) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) Set(java.util.Set) HOST_GROUP_WITH_HOSTNAMES(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_HOSTNAMES) Collectors(java.util.stream.Collectors) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) Configuration(org.springframework.context.annotation.Configuration) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) AdjustmentType(com.sequenceiq.common.api.type.AdjustmentType) List(java.util.List) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) ExtendHostMetadataRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataRequest) Optional(java.util.Optional) StackCreationEvent(com.sequenceiq.cloudbreak.core.flow2.stack.provision.StackCreationEvent) BootstrapNewNodesRequest(com.sequenceiq.cloudbreak.reactor.api.event.resource.BootstrapNewNodesRequest) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) HashMap(java.util.HashMap) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) ClusterPublicEndpointManagementService(com.sequenceiq.cloudbreak.service.publicendpoint.ClusterPublicEndpointManagementService) HOST_GROUP_WITH_ADJUSTMENT(com.sequenceiq.cloudbreak.core.flow2.stack.upscale.AbstractStackUpscaleAction.HOST_GROUP_WITH_ADJUSTMENT) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceToCloudResourceConverter(com.sequenceiq.cloudbreak.converter.spi.ResourceToCloudResourceConverter) ExtendHostMetadataResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataResult) UpscaleStackResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpscaleStackResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) GetSSHFingerprintsResult(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult) UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Logger(org.slf4j.Logger) GetSSHFingerprintsRequest(com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest) CollectMetadataResult(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult) CollectMetadataRequest(com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) EnvironmentClientService(com.sequenceiq.cloudbreak.service.environment.EnvironmentClientService) ClusterProxyEnablementService(com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService) ClusterProxyReRegistrationRequest(com.sequenceiq.cloudbreak.reactor.api.event.orchestration.ClusterProxyReRegistrationRequest) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) MetricType(com.sequenceiq.cloudbreak.service.metrics.MetricType) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Bean(org.springframework.context.annotation.Bean) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) ExtendHostMetadataResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.ExtendHostMetadataResult) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) Map(java.util.Map) HashMap(java.util.HashMap) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) Bean(org.springframework.context.annotation.Bean)

Example 2 with CleanupFreeIpaEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent in project cloudbreak by hortonworks.

the class CleanupFreeIpaHandler method accept.

@Override
public void accept(Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent) {
    CleanupFreeIpaEvent event = cleanupFreeIpaEvent.getData();
    try {
        LOGGER.debug("Handle cleanup request for hosts: {} and IPs: {}", event.getHostNames(), event.getIps());
        Stack stack = stackService.get(event.getResourceId());
        if (event.isRecover()) {
            LOGGER.debug("Invoke cleanup on recover");
            freeIpaCleanupService.cleanupOnRecover(stack, event.getHostNames(), event.getIps());
        } else {
            LOGGER.debug("Invoke cleanup on scale");
            freeIpaCleanupService.cleanupOnScale(stack, event.getHostNames(), event.getIps());
        }
        LOGGER.debug("Cleanup finished for hosts: {} and IPs: {}", event.getHostNames(), event.getIps());
    } catch (Exception e) {
        LOGGER.error("FreeIPA cleanup failed for hosts {} and IPs: {}", event.getHostNames(), event.getIps(), e);
    } finally {
        CleanupFreeIpaEvent response = new CleanupFreeIpaEvent(CLEANUP_FREEIPA_FINISHED_EVENT.event(), event.getResourceId(), event.getHostNames(), event.getIps(), event.isRecover());
        Event<StackEvent> responseEvent = new Event<>(cleanupFreeIpaEvent.getHeaders(), response);
        eventBus.notify(CLEANUP_FREEIPA_FINISHED_EVENT.event(), responseEvent);
    }
}
Also used : CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) Event(reactor.bus.Event) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 3 with CleanupFreeIpaEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent in project cloudbreak by hortonworks.

the class CleanupFreeIpaHandlerTest method testEventSentOnErrorNotRecover.

@Test
public void testEventSentOnErrorNotRecover() {
    Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent = mock(Event.class);
    when(cleanupFreeIpaEvent.getData()).thenReturn(new CleanupFreeIpaEvent(1L, Set.of(), Set.of(), false));
    when(stackService.get(1L)).thenReturn(new Stack());
    doThrow(new RuntimeException()).when(freeIpaCleanupService).cleanupOnScale(any(Stack.class), anySet(), anySet());
    underTest.accept(cleanupFreeIpaEvent);
    verify(eventBus).notify(eq(CLEANUP_FREEIPA_FINISHED_EVENT.event()), any(Event.class));
}
Also used : CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) Event(reactor.bus.Event) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with CleanupFreeIpaEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent in project cloudbreak by hortonworks.

the class CleanupFreeIpaHandlerTest method testNotRecover.

@Test
public void testNotRecover() {
    Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent = mock(Event.class);
    Set<String> hostNames = Set.of("asdfg");
    Set<String> ips = Set.of("1.1.1.1");
    when(cleanupFreeIpaEvent.getData()).thenReturn(new CleanupFreeIpaEvent(1L, hostNames, ips, false));
    Stack stack = new Stack();
    when(stackService.get(1L)).thenReturn(stack);
    underTest.accept(cleanupFreeIpaEvent);
    verify(freeIpaCleanupService).cleanupOnScale(stack, hostNames, ips);
    verify(freeIpaCleanupService, never()).cleanupOnRecover(any(Stack.class), anySet(), anySet());
    verify(eventBus).notify(eq(CLEANUP_FREEIPA_FINISHED_EVENT.event()), any(Event.class));
}
Also used : CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) Event(reactor.bus.Event) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with CleanupFreeIpaEvent

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent in project cloudbreak by hortonworks.

the class CleanupFreeIpaHandlerTest method testRecover.

@Test
public void testRecover() {
    Event<CleanupFreeIpaEvent> cleanupFreeIpaEvent = mock(Event.class);
    Set<String> hostNames = Set.of("asdfg");
    Set<String> ips = Set.of("1.1.1.1");
    when(cleanupFreeIpaEvent.getData()).thenReturn(new CleanupFreeIpaEvent(1L, hostNames, ips, true));
    Stack stack = new Stack();
    when(stackService.get(1L)).thenReturn(stack);
    underTest.accept(cleanupFreeIpaEvent);
    verify(freeIpaCleanupService).cleanupOnRecover(stack, hostNames, ips);
    verify(freeIpaCleanupService, never()).cleanupOnScale(any(Stack.class), anySet(), anySet());
    verify(eventBus).notify(eq(CLEANUP_FREEIPA_FINISHED_EVENT.event()), any(Event.class));
}
Also used : CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) CleanupFreeIpaEvent(com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent) Event(reactor.bus.Event) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)7 CleanupFreeIpaEvent (com.sequenceiq.cloudbreak.reactor.api.event.stack.CleanupFreeIpaEvent)7 Event (reactor.bus.Event)4 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)3 Test (org.junit.jupiter.api.Test)3 CollectMetadataRequest (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataRequest)2 CollectMetadataResult (com.sequenceiq.cloudbreak.cloud.event.instance.CollectMetadataResult)2 GetSSHFingerprintsRequest (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsRequest)2 GetSSHFingerprintsResult (com.sequenceiq.cloudbreak.cloud.event.instance.GetSSHFingerprintsResult)2 UpscaleStackValidationRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest)2 UpscaleStackValidationResult (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)2 ClusterProxyEnablementService (com.sequenceiq.cloudbreak.clusterproxy.ClusterProxyEnablementService)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)2 InstanceMetaDataToCloudInstanceConverter (com.sequenceiq.cloudbreak.converter.spi.InstanceMetaDataToCloudInstanceConverter)2