Search in sources :

Example 1 with UpdateDomainDnsResolverResult

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult 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 UpdateDomainDnsResolverResult

use of com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult 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 UpdateDomainDnsResolverResult

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

the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNeededAndAllowed.

// Note: this implicitly tests getPrevalidateAction().createRequest() as well.
@Test
void prevalidateTestDoExecuteWhenScalingNeededAndAllowed() throws Exception {
    when(cloudContext.getId()).thenReturn(STACK_ID);
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, ADJUSTMENT.longValue());
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    when(stackUpscaleService.getInstanceCountToCreate(stack, INSTANCE_GROUP_NAME, ADJUSTMENT, false)).thenReturn(ADJUSTMENT);
    Stack updatedStack = mock(Stack.class);
    when(instanceMetaDataService.saveInstanceAndGetUpdatedStack(stack, Map.of(INSTANCE_GROUP_NAME, 3), Map.of(), false, false, context.getStackNetworkScaleDetails())).thenReturn(updatedStack);
    CloudStack convertedCloudStack = mock(CloudStack.class);
    when(cloudStackConverter.convert(updatedStack)).thenReturn(convertedCloudStack);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(getPrevalidateAction()).doExecute(context, payload, createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
    verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), adjustmentTypeWithThreshold);
    verify(stackUpscaleService).startAddInstances(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT));
    verify(reactorEventFactory).createEvent(anyMap(), payloadArgumentCaptor.capture());
    verify(eventBus).notify("UPSCALESTACKVALIDATIONREQUEST", event);
    Object responsePayload = payloadArgumentCaptor.getValue();
    assertThat(responsePayload).isInstanceOf(UpscaleStackValidationRequest.class);
    UpscaleStackValidationRequest<UpscaleStackValidationResult> upscaleStackValidationRequest = (UpscaleStackValidationRequest<UpscaleStackValidationResult>) responsePayload;
    assertThat(upscaleStackValidationRequest.getResourceId()).isEqualTo(STACK_ID);
    assertThat(upscaleStackValidationRequest.getCloudContext()).isSameAs(cloudContext);
    assertThat(upscaleStackValidationRequest.getCloudStack()).isSameAs(convertedCloudStack);
    assertThat(upscaleStackValidationRequest.getCloudCredential()).isSameAs(cloudCredential);
}
Also used : AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) UpscaleStackValidationResult(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) UpscaleStackValidationRequest(com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest) Test(org.junit.jupiter.api.Test)

Example 4 with UpdateDomainDnsResolverResult

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

the class StackUpscaleActionsTest method prevalidateTestDoExecuteWhenScalingNeededAndNotAllowed.

@Test
void prevalidateTestDoExecuteWhenScalingNeededAndNotAllowed() throws Exception {
    AdjustmentTypeWithThreshold adjustmentTypeWithThreshold = new AdjustmentTypeWithThreshold(AdjustmentType.EXACT, ADJUSTMENT.longValue());
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    when(stackUpscaleService.getInstanceCountToCreate(stack, INSTANCE_GROUP_NAME, ADJUSTMENT, false)).thenReturn(ADJUSTMENT_ZERO);
    List<CloudResourceStatus> resourceStatuses = List.of(cloudResourceStatus);
    when(reactorEventFactory.createEvent(anyMap(), isNotNull())).thenReturn(event);
    new AbstractActionTestSupport<>(getPrevalidateAction()).doExecute(context, payload, createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), Map.of(), NetworkScaleDetails.getEmpty(), adjustmentTypeWithThreshold, VARIANT));
    verify(stackUpscaleService).addInstanceFireEventAndLog(stack, Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT), adjustmentTypeWithThreshold);
    verifyEventForExtendMetadata(resourceStatuses);
}
Also used : CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) AdjustmentTypeWithThreshold(com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

Example 5 with UpdateDomainDnsResolverResult

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

the class StackUpscaleActionsTest method prevalidateTestCreateContextWhenTriggeredVariantNotSet.

@Test
void prevalidateTestCreateContextWhenTriggeredVariantNotSet() {
    NetworkScaleDetails networkScaleDetails = new NetworkScaleDetails();
    UpdateDomainDnsResolverResult payload = new UpdateDomainDnsResolverResult(STACK_ID);
    Map<Object, Object> variables = createVariables(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), networkScaleDetails, null, null);
    new AbstractActionTestSupport<>(getPrevalidateAction()).prepareExecution(payload, variables);
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, ADJUSTMENT_ZERO), variables.get(HOST_GROUP_WITH_ADJUSTMENT));
    Assertions.assertEquals(Map.of(INSTANCE_GROUP_NAME, Set.of("hostname")), variables.get(HOST_GROUP_WITH_HOSTNAMES));
    Assertions.assertEquals(false, variables.get(REPAIR));
    Assertions.assertNull(variables.get(TRIGGERED_VARIANT));
    Assertions.assertEquals(networkScaleDetails, variables.get(NETWORK_SCALE_DETAILS));
}
Also used : NetworkScaleDetails(com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails) UpdateDomainDnsResolverResult(com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult) Test(org.junit.jupiter.api.Test)

Aggregations

UpdateDomainDnsResolverResult (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverResult)8 Test (org.junit.jupiter.api.Test)5 StackScalingFlowContext (com.sequenceiq.cloudbreak.core.flow2.stack.downscale.StackScalingFlowContext)3 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 AdjustmentTypeWithThreshold (com.sequenceiq.common.api.adjustment.AdjustmentTypeWithThreshold)3 UpscaleStackValidationRequest (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationRequest)2 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)2 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2 NetworkScaleDetails (com.sequenceiq.cloudbreak.core.flow2.dto.NetworkScaleDetails)2 UpdateDomainDnsResolverRequest (com.sequenceiq.cloudbreak.reactor.api.event.stack.UpdateDomainDnsResolverRequest)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Bean (org.springframework.context.annotation.Bean)2 UpscaleStackValidationResult (com.sequenceiq.cloudbreak.cloud.event.resource.UpscaleStackValidationResult)1 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 DnsResolverType (com.sequenceiq.cloudbreak.domain.stack.DnsResolverType)1 StackEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackEvent)1 StackFailureEvent (com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent)1