Search in sources :

Example 1 with ClusterProxyRegistrationFailed

use of com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed in project cloudbreak by hortonworks.

the class ClusterProxyRegistrationHandler method accept.

@Override
public void accept(Event<ClusterProxyRegistrationRequest> event) {
    ClusterProxyRegistrationRequest request = event.getData();
    try {
        Set<InstanceMetaData> ims = instanceMetaDataService.findNotTerminatedForStack(request.getResourceId());
        if (ims.isEmpty()) {
            LOGGER.error("Cluster Proxy registration has failed. No available instances  found for FreeIPA");
            ClusterProxyRegistrationFailed response = new ClusterProxyRegistrationFailed(request.getResourceId(), new NotFoundException("Cluster Proxy registration has failed. No available instances  found for FreeIPA"));
            sendEvent(response, event);
        } else {
            boolean allInstanceHasFqdn = ims.stream().allMatch(im -> StringUtils.isNotBlank(im.getDiscoveryFQDN()));
            if (allInstanceHasFqdn) {
                LOGGER.info("All instances already have FQDN set, register all to cluster proxy");
                clusterProxyService.registerFreeIpa(request.getResourceId());
            } else {
                LOGGER.info("Instances missing FQDN, fallback to PGW registration");
                clusterProxyService.registerFreeIpaForBootstrap(request.getResourceId());
            }
            sendEvent(new ClusterProxyRegistrationSuccess(request.getResourceId()), event);
        }
    } catch (Exception e) {
        LOGGER.error("Cluster Proxy bootstrap registration has failed", e);
        sendEvent(new ClusterProxyRegistrationFailed(request.getResourceId(), e), event);
    }
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) ClusterProxyRegistrationFailed(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed) ClusterProxyRegistrationRequest(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) ClusterProxyRegistrationSuccess(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationSuccess) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 2 with ClusterProxyRegistrationFailed

use of com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed in project cloudbreak by hortonworks.

the class ClusterProxyRegistrationHandlerTest method testRegistrationFailsWithNoInstancesFound.

@Test
public void testRegistrationFailsWithNoInstancesFound() {
    when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of());
    underTest.accept(new Event<>(new ClusterProxyRegistrationRequest(1L)));
    verifyNoInteractions(clusterProxyService);
    ArgumentCaptor<String> selectorCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(selectorCaptor.capture(), eventCaptor.capture());
    String selector = selectorCaptor.getValue();
    assertEquals(EventSelectorUtil.selector(ClusterProxyRegistrationFailed.class), selector);
    ClusterProxyRegistrationFailed event = (ClusterProxyRegistrationFailed) eventCaptor.getValue().getData();
    assertEquals(1L, event.getResourceId());
}
Also used : ClusterProxyRegistrationFailed(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed) ClusterProxyRegistrationRequest(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterProxyRegistrationFailed

use of com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed in project cloudbreak by hortonworks.

the class ClusterProxyRegistrationHandlerTest method testRegistrationFails.

@Test
public void testRegistrationFails() {
    when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(createInstanceMetadata("aa"), createInstanceMetadata(null)));
    when(clusterProxyService.registerFreeIpaForBootstrap(1L)).thenThrow(new RuntimeException("bumm"));
    underTest.accept(new Event<>(new ClusterProxyRegistrationRequest(1L)));
    verifyNoMoreInteractions(clusterProxyService);
    ArgumentCaptor<String> selectorCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(selectorCaptor.capture(), eventCaptor.capture());
    String selector = selectorCaptor.getValue();
    assertEquals(EventSelectorUtil.selector(ClusterProxyRegistrationFailed.class), selector);
    ClusterProxyRegistrationFailed event = (ClusterProxyRegistrationFailed) eventCaptor.getValue().getData();
    assertEquals(1L, event.getResourceId());
}
Also used : ClusterProxyRegistrationFailed(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed) ClusterProxyRegistrationRequest(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test)

Example 4 with ClusterProxyRegistrationFailed

use of com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed in project cloudbreak by hortonworks.

the class ClusterProxyRegistrationHandlerTest method testRegistrationFailsWithFqdnFilled.

@Test
public void testRegistrationFailsWithFqdnFilled() {
    when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(createInstanceMetadata("aa"), createInstanceMetadata("test")));
    when(clusterProxyService.registerFreeIpa(1L)).thenThrow(new RuntimeException("bumm"));
    underTest.accept(new Event<>(new ClusterProxyRegistrationRequest(1L)));
    verifyNoMoreInteractions(clusterProxyService);
    ArgumentCaptor<String> selectorCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
    verify(eventBus).notify(selectorCaptor.capture(), eventCaptor.capture());
    String selector = selectorCaptor.getValue();
    assertEquals(EventSelectorUtil.selector(ClusterProxyRegistrationFailed.class), selector);
    ClusterProxyRegistrationFailed event = (ClusterProxyRegistrationFailed) eventCaptor.getValue().getData();
    assertEquals(1L, event.getResourceId());
}
Also used : ClusterProxyRegistrationFailed(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed) ClusterProxyRegistrationRequest(com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest) Event(reactor.bus.Event) Test(org.junit.jupiter.api.Test)

Aggregations

ClusterProxyRegistrationFailed (com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationFailed)4 ClusterProxyRegistrationRequest (com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationRequest)4 Test (org.junit.jupiter.api.Test)3 Event (reactor.bus.Event)3 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)1 ClusterProxyRegistrationSuccess (com.sequenceiq.freeipa.flow.stack.provision.event.clusterproxy.ClusterProxyRegistrationSuccess)1