Search in sources :

Example 1 with UpdateDomainDnsResolverRequest

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

the class StackUpscaleActions method updateDomainDnsResolverAction.

@Bean(name = "UPDATE_DOMAIN_DNS_RESOLVER_STATE")
public Action<?, ?> updateDomainDnsResolverAction() {
    return new AbstractStackUpscaleAction<>(StackScaleTriggerEvent.class) {

        @Override
        protected void prepareExecution(StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            variables.put(HOST_GROUP_WITH_ADJUSTMENT, payload.getHostGroupsWithAdjustment());
            variables.put(HOST_GROUP_WITH_HOSTNAMES, payload.getHostGroupsWithHostNames());
            variables.put(REPAIR, payload.isRepair());
            if (payload.getTriggeredStackVariant() != null) {
                variables.put(TRIGGERED_VARIANT, payload.getTriggeredStackVariant());
            }
            variables.put(NETWORK_SCALE_DETAILS, payload.getNetworkScaleDetails());
            variables.put(ADJUSTMENT_WITH_THRESHOLD, payload.getAdjustmentTypeWithThreshold());
        }

        @Override
        protected void doExecute(StackScalingFlowContext context, StackScaleTriggerEvent payload, Map<Object, Object> variables) {
            if (context.isRepair()) {
                LOGGER.debug("We do not need to update domainDnsResolver in case of repair activity, since it matters only in case of upscale activity.");
                sendEvent(context, new UpdateDomainDnsResolverResult(context.getStack().getId()));
            } else {
                sendEvent(context, new UpdateDomainDnsResolverRequest(context.getStack().getId()));
            }
        }

        @Override
        protected Object getFailurePayload(StackScaleTriggerEvent payload, Optional<StackScalingFlowContext> flowContext, Exception ex) {
            return new StackFailureEvent(EventSelectorUtil.failureSelector(UpdateDomainDnsResolverResult.class), payload.getResourceId(), ex);
        }
    };
}
Also used : StackScaleTriggerEvent(com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent) UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Optional(java.util.Optional) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) Map(java.util.Map) HashMap(java.util.HashMap) StackScalingFlowContext(com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Bean(org.springframework.context.annotation.Bean)

Example 2 with UpdateDomainDnsResolverRequest

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

the class UpdateDomainDnsResolverHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<UpdateDomainDnsResolverRequest> updateDomainDnsResolverRequestHandlerEvent) {
    UpdateDomainDnsResolverRequest event = updateDomainDnsResolverRequestHandlerEvent.getData();
    try {
        Stack stack = stackService.getByIdWithLists(event.getResourceId());
        DnsResolverType actualDnsResolverType = targetedUpscaleSupportService.getActualDnsResolverType(stack);
        if (!actualDnsResolverType.equals(stack.getDomainDnsResolver())) {
            LOGGER.debug("New value of domainDnsResolver field for stack {} is {}", stack.getResourceCrn(), actualDnsResolverType);
            stack.setDomainDnsResolver(actualDnsResolverType);
            stackService.save(stack);
            LOGGER.debug("domainDnsResolver field of stack {} has been successfully updated!", stack.getResourceCrn());
        } else {
            LOGGER.debug("Currently set and actual domainDnsResolverType is the same, not need for update, value {}", actualDnsResolverType);
        }
    } catch (Exception e) {
        LOGGER.debug("We couldn't update domainDnsResolver field of stack, so we move on with current value of the field.", e);
    }
    return new UpdateDomainDnsResolverResult(event.getResourceId());
}
Also used : UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) DnsResolverType(com.sequenceiq.cloudbreak.domain.stack.DnsResolverType) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult)

Example 3 with UpdateDomainDnsResolverRequest

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

the class UpdateDomainDnsResolverHandlerTest method testUpdateIfThereIsErrorDuringUpdate.

@Test
public void testUpdateIfThereIsErrorDuringUpdate() {
    when(stackService.getByIdWithLists(any())).thenReturn(new Stack());
    when(targetedUpscaleSupportService.getActualDnsResolverType(any())).thenThrow(new RuntimeException("whatever"));
    underTest.accept(new Event<>(new UpdateDomainDnsResolverRequest(1L)));
    verify(stackService, times(1)).getByIdWithLists(any());
    verify(stackService, times(0)).save(any());
    verify(targetedUpscaleSupportService, times(1)).getActualDnsResolverType(any());
    verify(eventBus, times(1)).notify(any(Object.class), any(Event.class));
}
Also used : UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Event(reactor.bus.Event) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateDomainDnsResolverRequest

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

the class UpdateDomainDnsResolverHandlerTest method testUpdateDuringUpscale.

@Test
public void testUpdateDuringUpscale() {
    when(stackService.getByIdWithLists(any())).thenReturn(stack(DnsResolverType.FREEIPA_FOR_ENV));
    when(targetedUpscaleSupportService.getActualDnsResolverType(any())).thenReturn(DnsResolverType.LOCAL_UNBOUND);
    when(stackService.save(any())).thenReturn(new Stack());
    underTest.accept(new Event<>(new UpdateDomainDnsResolverRequest(1L)));
    verify(stackService, times(1)).getByIdWithLists(any());
    verify(stackService, times(1)).save(any());
    verify(targetedUpscaleSupportService, times(1)).getActualDnsResolverType(any());
    verify(eventBus, times(1)).notify(any(Object.class), any(Event.class));
}
Also used : UpdateDomainDnsResolverRequest(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest) Event(reactor.bus.Event) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateDomainDnsResolverRequest (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 UpdateDomainDnsResolverResult (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult)2 Test (org.junit.jupiter.api.Test)2 Event (reactor.bus.Event)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 TransactionExecutionException (com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException)1 StackScaleTriggerEvent (com.sequenceiq.cloudbreak.core.flow2.event.StackScaleTriggerEvent)1 StackScalingFlowContext (com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext)1 DnsResolverType (com.sequenceiq.cloudbreak.domain.stack.DnsResolverType)1 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Bean (org.springframework.context.annotation.Bean)1