Search in sources :

Example 1 with UpdateDnsSoaRecordsRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest in project cloudbreak by hortonworks.

the class FreeIpaDownscaleActions method updateDnsSoaRecordsAction.

@Bean(name = "DOWNSCALE_UPDATE_DNS_SOA_RECORDS_STATE")
public Action<?, ?> updateDnsSoaRecordsAction() {
    return new AbstractDownscaleAction<>(RemoveDnsResponse.class) {

        @Override
        protected void doExecute(StackContext context, RemoveDnsResponse payload, Map<Object, Object> variables) {
            stackUpdater.updateStackStatus(context.getStack().getId(), getInProgressStatus(variables), "Update DNS SOA records");
            CleanupEvent cleanupEvent = buildCleanupEvent(context, getDownscaleHosts(variables));
            UpdateDnsSoaRecordsRequest request = new UpdateDnsSoaRecordsRequest(cleanupEvent);
            sendEvent(context, request);
        }
    };
}
Also used : RemoveDnsResponse(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.dns.RemoveDnsResponse) StackContext(com.sequenceiq.freeipa.flow.stack.StackContext) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 2 with UpdateDnsSoaRecordsRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest in project cloudbreak by hortonworks.

the class UpdateDnsSoaRecordsHandlerTest method testResultContainsServerFqdns.

@Test
void testResultContainsServerFqdns() throws Exception {
    String zoneName = "example.com.";
    String fqdn1 = "foo1.example.com";
    String fqdn2 = "foo2.example.com";
    FreeIpaClient mockIpaClient = mock(FreeIpaClient.class);
    IpaServer mockIpaServer1 = mock(IpaServer.class);
    IpaServer mockIpaServer2 = mock(IpaServer.class);
    DnsZone dnsZone = mock(DnsZone.class);
    when(freeIpaClientFactory.getFreeIpaClientForStackId(any())).thenReturn(mockIpaClient);
    when(mockIpaClient.findAllServers()).thenReturn(Set.of(mockIpaServer1, mockIpaServer2));
    Mockito.lenient().when(mockIpaServer1.getFqdn()).thenReturn(fqdn1);
    when(mockIpaServer2.getFqdn()).thenReturn(fqdn2);
    when(mockIpaClient.findAllDnsZone()).thenReturn(Set.of(dnsZone));
    when(dnsZone.getIdnssoamname()).thenReturn(fqdn1 + ".");
    when(dnsZone.getIdnsname()).thenReturn(zoneName);
    CleanupEvent cleanupEvent = new CleanupEvent(1L, Set.of(), Set.of(fqdn1), Set.of(), Set.of(), Set.of(), "", "", "", "");
    UpdateDnsSoaRecordsRequest request = new UpdateDnsSoaRecordsRequest(cleanupEvent);
    underTest.accept(new Event<>(request));
    verify(eventBus).notify(eq("UPDATEDNSSOARECORDSRESPONSE"), any(Event.class));
    verify(mockIpaClient).setDnsZoneAuthoritativeNameserver(eq(zoneName), eq(fqdn2 + "."));
}
Also used : FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) Event(reactor.bus.Event) CleanupEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Test(org.junit.jupiter.api.Test)

Example 3 with UpdateDnsSoaRecordsRequest

use of com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest in project cloudbreak by hortonworks.

the class UpdateDnsSoaRecordsHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<UpdateDnsSoaRecordsRequest> event) {
    UpdateDnsSoaRecordsRequest request = event.getData();
    Selectable result;
    try {
        Long stackId = request.getResourceId();
        Set<String> fqdns = request.getHosts().stream().map(hostname -> StringUtils.appendIfMissing(hostname, ".")).collect(Collectors.toSet());
        updateSoaRecords(stackId, fqdns);
        result = new UpdateDnsSoaRecordsResponse(request.getResourceId());
    } catch (Exception e) {
        LOGGER.error("Downscale updating DNS SOA records failed", e);
        result = new DownscaleFailureEvent(DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT.event(), request.getResourceId(), "Downscale Update DNS SOA Records", Set.of(), Map.of(), e);
    }
    return result;
}
Also used : DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT(com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) EventSelectorUtil(com.sequenceiq.flow.event.EventSelectorUtil) IpaServer(com.sequenceiq.freeipa.client.model.IpaServer) Set(java.util.Set) HandlerEvent(com.sequenceiq.flow.reactor.api.handler.HandlerEvent) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) UpdateDnsSoaRecordsResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) Objects(java.util.Objects) Inject(javax.inject.Inject) DnsZone(com.sequenceiq.freeipa.client.model.DnsZone) Component(org.springframework.stereotype.Component) ExceptionCatcherEventHandler(com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) Event(reactor.bus.Event) Map(java.util.Map) FreeIpaClientFactory(com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory) Selectable(com.sequenceiq.cloudbreak.common.event.Selectable) UpdateDnsSoaRecordsRequest(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest) DownscaleFailureEvent(com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent) UpdateDnsSoaRecordsResponse(com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException)

Aggregations

UpdateDnsSoaRecordsRequest (com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsRequest)3 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)2 DnsZone (com.sequenceiq.freeipa.client.model.DnsZone)2 IpaServer (com.sequenceiq.freeipa.client.model.IpaServer)2 CleanupEvent (com.sequenceiq.freeipa.flow.freeipa.cleanup.CleanupEvent)2 Map (java.util.Map)2 Event (reactor.bus.Event)2 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)1 EventSelectorUtil (com.sequenceiq.flow.event.EventSelectorUtil)1 ExceptionCatcherEventHandler (com.sequenceiq.flow.reactor.api.handler.ExceptionCatcherEventHandler)1 HandlerEvent (com.sequenceiq.flow.reactor.api.handler.HandlerEvent)1 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)1 RemoveDnsResponse (com.sequenceiq.freeipa.flow.freeipa.cleanup.event.dns.RemoveDnsResponse)1 DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT (com.sequenceiq.freeipa.flow.freeipa.downscale.DownscaleFlowEvent.DOWNSCALE_UPDATE_DNS_SOA_RECORDS_FAILED_EVENT)1 DownscaleFailureEvent (com.sequenceiq.freeipa.flow.freeipa.downscale.event.DownscaleFailureEvent)1 UpdateDnsSoaRecordsResponse (com.sequenceiq.freeipa.flow.freeipa.downscale.event.dnssoarecords.UpdateDnsSoaRecordsResponse)1 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)1 FreeIpaClientFactory (com.sequenceiq.freeipa.service.freeipa.FreeIpaClientFactory)1 Objects (java.util.Objects)1 Set (java.util.Set)1