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);
}
};
}
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());
}
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);
}
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);
}
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));
}
Aggregations