use of reactor.bus.Event.Headers in project cloudbreak by hortonworks.
the class ErrorHandlerAwareReactorEventFactory method createEventWithErrHandler.
public <P> Event<P> createEventWithErrHandler(Map<String, Object> headers, P payLoad) {
Map<String, Object> extendedHeaders = new HashMap<>(headers);
extendedHeaders.put(MDCBuilder.MDC_CONTEXT_ID, MDCBuilder.getMdcContextMap());
return new Event<>(new Headers(extendedHeaders), payLoad, errorHandler);
}
use of reactor.bus.Event.Headers in project cloudbreak by hortonworks.
the class DecommissionHandlerTest method shouldContinueSingleHostDecommissionIfForcedAndFailed.
@Test
public void shouldContinueSingleHostDecommissionIfForcedAndFailed() throws CloudbreakException, ClusterClientInitException {
when(entitlementService.bulkHostsRemovalFromCMSupported(any())).thenReturn(Boolean.FALSE);
when(stackService.getInstanceMetadata(any(), eq(PRIVATE_ID))).thenReturn(Optional.of(instance));
when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
when(clusterApi.clusterDecomissionService()).thenReturn(clusterDecomissionService);
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
when(hostGroupService.getByClusterIdAndName(CLUSTER_ID, HOST_GROUP_NAME)).thenReturn(Optional.of(hostGroup));
when(clusterDecomissionService.collectHostsToRemove(hostGroup, Set.of(FQDN))).thenReturn(Map.of(FQDN, instance));
doThrow(new CloudbreakException("Restart stale services failed.")).when(clusterDecomissionService).restartStaleServices(true);
underTest.accept(new Event<>(new Headers(), forcedDecommissionRequest()));
verify(eventService).fireCloudbreakEvent(STACK_ID, "UPDATE_IN_PROGRESS", CLUSTER_DECOMMISSION_FAILED_FORCE_DELETE_CONTINUE, List.of("Restart stale services failed."));
verify(eventBus).notify(eq("DECOMMISSIONRESULT"), captor.capture());
Event<DecommissionResult> resultEvent = captor.getValue();
assertNotNull(resultEvent);
DecommissionResult decommissionResult = resultEvent.getData();
assertEquals("", decommissionResult.getErrorPhase());
assertNull(decommissionResult.getErrorDetails());
assertEquals(Set.of(FQDN), decommissionResult.getHostNames());
verify(clusterDecomissionService, never()).removeHostsFromCluster(anyList());
verify(clusterDecomissionService, never()).decommissionClusterNodes(anyMap());
verify(clusterDecomissionService, times(1)).deleteHostFromCluster(any());
}
use of reactor.bus.Event.Headers in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testFlowChainFailureOnNotTriggerableFlowCreatesFailedFlow.
@Test
public void testFlowChainFailureOnNotTriggerableFlowCreatesFailedFlow() throws TransactionExecutionException {
Map<String, Object> headers = new HashMap<>();
headers.put(FlowConstants.FLOW_CHAIN_ID, FLOW_CHAIN_ID);
headers.put(FlowConstants.FLOW_TRIGGER_USERCRN, FLOW_TRIGGER_USERCRN);
dummyEvent = new Event<>(new Headers(headers), payload);
dummyEvent.setKey("KEY");
BDDMockito.<FlowConfiguration<?>>given(flowConfigurationMap.get(any())).willReturn(flowConfig);
given(flowConfig.getFlowTriggerCondition()).willReturn(flowTriggerCondition);
given(flowTriggerCondition.isFlowTriggerable(anyLong())).willReturn(new FlowTriggerConditionResult("Not triggerable."));
FlowNotTriggerableException exception = assertThrows(FlowNotTriggerableException.class, () -> underTest.accept(dummyEvent));
assertEquals("Not triggerable.", exception.getMessage());
flowLogService.save(any(), eq(FLOW_CHAIN_ID), any(), eq(payload), any(), eq(flowConfig.getClass()), eq(FlowStateConstants.INIT_STATE));
flowLogService.close(eq(payload.getResourceId()), any(), eq(true));
flowChains.removeFullFlowChain(FLOW_CHAIN_ID, false);
}
use of reactor.bus.Event.Headers in project cloudbreak by hortonworks.
the class DecommissionHandlerTest method testBulkHostDecommission.
@Test
public void testBulkHostDecommission() throws ClusterClientInitException {
when(entitlementService.bulkHostsRemovalFromCMSupported(any())).thenReturn(Boolean.TRUE);
when(runtimeVersionService.getRuntimeVersion(any())).thenReturn(Optional.of(CMRepositoryVersionUtil.CLOUDERA_STACK_VERSION_7_2_14.getVersion()));
when(stackService.getInstanceMetadata(any(), eq(PRIVATE_ID))).thenReturn(Optional.of(instance));
when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
when(clusterApi.clusterDecomissionService()).thenReturn(clusterDecomissionService);
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
when(hostGroupService.getByClusterIdAndName(CLUSTER_ID, HOST_GROUP_NAME)).thenReturn(Optional.of(hostGroup));
when(clusterDecomissionService.collectHostsToRemove(hostGroup, Set.of(FQDN))).thenReturn(Map.of(FQDN, instance));
underTest.accept(new Event<>(new Headers(), decommissionRequest()));
verify(eventBus).notify(eq("DECOMMISSIONRESULT"), captor.capture());
Event<DecommissionResult> resultEvent = captor.getValue();
assertNotNull(resultEvent);
DecommissionResult decommissionResult = resultEvent.getData();
assertNull(decommissionResult.getStatusReason());
assertNotNull(decommissionResult.getErrorPhase());
assertEquals(Set.of(FQDN), decommissionResult.getHostNames());
verify(clusterDecomissionService, times(1)).removeHostsFromCluster(List.of(instance));
verify(clusterDecomissionService, never()).decommissionClusterNodes(anyMap());
verify(clusterDecomissionService, never()).deleteHostFromCluster(any());
}
use of reactor.bus.Event.Headers in project cloudbreak by hortonworks.
the class DecommissionHandlerTest method shouldContinueSingleHostDecommissionFailIfNotForced.
@Test
public void shouldContinueSingleHostDecommissionFailIfNotForced() throws CloudbreakException, ClusterClientInitException {
when(entitlementService.bulkHostsRemovalFromCMSupported(any())).thenReturn(Boolean.FALSE);
when(stackService.getInstanceMetadata(any(), eq(PRIVATE_ID))).thenReturn(Optional.of(instance));
when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
when(clusterApi.clusterDecomissionService()).thenReturn(clusterDecomissionService);
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
when(hostGroupService.getByClusterIdAndName(CLUSTER_ID, HOST_GROUP_NAME)).thenReturn(Optional.of(hostGroup));
when(clusterDecomissionService.collectHostsToRemove(hostGroup, Set.of(FQDN))).thenReturn(Map.of(FQDN, instance));
when(clusterDecomissionService.decommissionClusterNodes(Map.of(FQDN, instance))).thenReturn(Set.of(FQDN));
CloudbreakException cloudbreakException = new CloudbreakException("Restart stale services failed.");
doThrow(cloudbreakException).when(clusterDecomissionService).restartStaleServices(false);
underTest.accept(new Event<>(new Headers(), decommissionRequest()));
verify(eventBus).notify(eq("DECOMMISSIONRESULT_ERROR"), captor.capture());
Event<DecommissionResult> resultEvent = captor.getValue();
assertNotNull(resultEvent);
DecommissionResult decommissionResult = resultEvent.getData();
assertEquals("Restart stale services failed.", decommissionResult.getStatusReason());
assertEquals("", decommissionResult.getErrorPhase());
assertEquals(cloudbreakException, decommissionResult.getErrorDetails());
assertEquals(Set.of(FQDN), decommissionResult.getHostNames());
verify(clusterDecomissionService, never()).removeHostsFromCluster(anyList());
verify(clusterDecomissionService, times(1)).decommissionClusterNodes(anyMap());
verify(clusterDecomissionService, times(1)).deleteHostFromCluster(any());
}
Aggregations