Search in sources :

Example 1 with Headers

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);
}
Also used : HashMap(java.util.HashMap) Headers(reactor.bus.Event.Headers) Event(reactor.bus.Event)

Example 2 with Headers

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());
}
Also used : Headers(reactor.bus.Event.Headers) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) DecommissionResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 3 with Headers

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);
}
Also used : FlowNotTriggerableException(com.sequenceiq.flow.core.exception.FlowNotTriggerableException) HashMap(java.util.HashMap) Headers(reactor.bus.Event.Headers) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 4 with Headers

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());
}
Also used : Headers(reactor.bus.Event.Headers) DecommissionResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 5 with Headers

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());
}
Also used : Headers(reactor.bus.Event.Headers) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) DecommissionResult(com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

Headers (reactor.bus.Event.Headers)8 Test (org.junit.jupiter.api.Test)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)3 DecommissionResult (com.sequenceiq.cloudbreak.reactor.api.event.resource.DecommissionResult)3 HashMap (java.util.HashMap)3 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)2 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)2 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Event (reactor.bus.Event)2 FlowNotTriggerableException (com.sequenceiq.flow.core.exception.FlowNotTriggerableException)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1