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);
}
};
}
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);
}
}
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));
}
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));
}
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));
}
Aggregations