Search in sources :

Example 1 with CollectAdditionalHostnamesRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method downscaleCollectAdditionalHostnamesAction.

@Bean(name = "DOWNSCALE_COLLECT_ADDITIONAL_HOSTNAMES_STATE")
public Action<?, ?> downscaleCollectAdditionalHostnamesAction() {
    return new AbstractDownscaleAction<>(ClusterProxyUpdateRegistrationSuccess.class) {

        @Override
        protected void doExecute(StackContext context, ClusterProxyUpdateRegistrationSuccess payload, Map<Object, Object> variables) throws Exception {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Collecting additional hostnames.");
            CollectAdditionalHostnamesRequest request = new CollectAdditionalHostnamesRequest(stack.getId());
            sendEvent(context, request.selector(), request);
        }
    };
}
Also used : StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CollectAdditionalHostnamesRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest) Map(java.util.Map) ClusterProxyUpdateRegistrationSuccess(com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationSuccess) Stack(com.sequenceiq.freeipa.entity.Stack) Bean(org.springframework.context.annotation.Bean)

Example 2 with CollectAdditionalHostnamesRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest in project cloudbreak by hortonworks.

the class CollectAdditionalHostnamesHandlerTest method testResultContainsServerFqdns.

@Test
void testResultContainsServerFqdns() throws Exception {
    String fqdn1 = "foo1.example.com";
    String fqdn2 = "foo2.example.com";
    FreeIpaClient mockIpaClient = Mockito.mock(FreeIpaClient.class);
    IpaServer mockIpaServer1 = Mockito.mock(IpaServer.class);
    IpaServer mockIpaServer2 = Mockito.mock(IpaServer.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(any())).thenReturn(mockIpaClient);
    when(mockIpaClient.findAllServers()).thenReturn(Set.of(mockIpaServer1, mockIpaServer2));
    when(mockIpaServer1.getFqdn()).thenReturn(fqdn1);
    when(mockIpaServer2.getFqdn()).thenReturn(fqdn2);
    CollectAdditionalHostnamesRequest request = new CollectAdditionalHostnamesRequest(1L);
    underTest.accept(new Event<>(request));
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(eq("COLLECTADDITIONALHOSTNAMESRESPONSE"), eventCaptor.capture());
    Event event = eventCaptor.getValue();
    assertTrue(event.getData() instanceof CollectAdditionalHostnamesResponse);
    CollectAdditionalHostnamesResponse response = (CollectAdditionalHostnamesResponse) event.getData();
    assertEquals(Set.of(fqdn1, fqdn2), response.getHostnames());
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) CollectAdditionalHostnamesRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest) CollectAdditionalHostnamesResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesResponse) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test)

Example 3 with CollectAdditionalHostnamesRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest in project cloudbreak by hortonworks.

the class CollectAdditionalHostnamesHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<CollectAdditionalHostnamesRequest> event) {
    CollectAdditionalHostnamesRequest request = event.getData();
    Selectable result;
    try {
        Long stackId = request.getResourceId();
        Set<String> fqdns = getHostnamesFromFreeIpaServers(stackId);
        result = new CollectAdditionalHostnamesResponse(request.getResourceId(), fqdns);
    } catch (Exception e) {
        LOGGER.error("Collecting additional hostnames failed", e);
        result = new DownscaleFailureEvent(DOWNSCALE_COLLECT_ADDITIONAL_HOSTNAMES_FAILED_EVENT.event(), request.getResourceId(), "Downscale Collect Additional Hostnames", Set.of(), Map.of(), e);
    }
    return result;
}
Also used : Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) CollectAdditionalHostnamesRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest) CollectAdditionalHostnamesResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesResponse) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException)

Aggregations

CollectAdditionalHostnamesRequest (com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesRequest)3 CollectAdditionalHostnamesResponse (com.sequenceiq.freeipa.flow.freeipa.downscale.event.collecthostnames.CollectAdditionalHostnamesResponse)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 IpaServer (com.sequenceiq.freeipa.client.model.IpaServer)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 DownscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)1 ClusterProxyUpdateRegistrationSuccess (com.sequenceiq.freeipa.flow.freeipa.provision.event.clusterproxy.ClusterProxyUpdateRegistrationSuccess)1 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)1 Map (java.util.Map)1 Test (org.junit.jupiter.api.Test)1 Bean (org.springframework.context.annotation.Bean)1 Event (reactor.bus.Event)1