Search in sources :

Example 16 with Payload

use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.

the class EventBusConfigTest method uncaughtErrorButFlowFound.

@Test
@DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD)
public void uncaughtErrorButFlowFound() {
    FlowLog flowLog = new FlowLog();
    flowLog.setFlowId("123");
    when(flowLogDBService.getLastFlowLog("123")).thenReturn(Optional.of(flowLog));
    Event.Headers headers = new Event.Headers();
    headers.set("FLOW_ID", "123");
    eventBus.on(Selectors.regex("exampleselector"), (Consumer<Event<? extends Payload>>) event -> {
        throw new RuntimeException("uncaught exception");
    });
    eventBus.notify("exampleselector", new Event<>(headers, null));
    verify(flowLogDBService, timeout(2000).times(1)).getLastFlowLog("123");
    verify(applicationFlowInformation, timeout(1000).times(1)).handleFlowFail(flowLog);
    verify(flowLogDBService, timeout(1000).times(1)).updateLastFlowLogStatus(flowLog, true);
    verify(flowLogDBService, timeout(1000).times(1)).finalize(flowLog.getFlowId());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DirtiesContext(org.springframework.test.annotation.DirtiesContext) FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) RunWith(org.junit.runner.RunWith) Mockito.times(org.mockito.Mockito.times) EventBus(reactor.bus.EventBus) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Mockito.verify(org.mockito.Mockito.verify) Inject(javax.inject.Inject) Test(org.junit.jupiter.api.Test) Mockito.timeout(org.mockito.Mockito.timeout) Selectors(reactor.bus.selector.Selectors) ApplicationFlowInformation(com.sequenceiq.flow.core.ApplicationFlowInformation) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Event(reactor.bus.Event) Optional(java.util.Optional) FlowLogDBService(com.sequenceiq.flow.service.flowlog.FlowLogDBService) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Consumer(reactor.fn.Consumer) MockBean(org.springframework.boot.test.mock.mockito.MockBean) FlowLog(com.sequenceiq.flow.domain.FlowLog) Event(reactor.bus.Event) Payload(com.sequenceiq.cloudbreak.common.event.Payload) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 17 with Payload

use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.

the class FlowCancelService method cancelRunningFlows.

public void cancelRunningFlows(Long resourceId) {
    LOGGER.info("Cancel running flow for id: [{}]", resourceId);
    Payload cancelEvent = () -> resourceId;
    reactor.notify(FlowConstants.FLOW_CANCEL, eventFactory.createEventWithErrHandler(eventParameterFactory.createEventParameters(resourceId), cancelEvent));
}
Also used : Payload(com.sequenceiq.cloudbreak.common.event.Payload)

Example 18 with Payload

use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.

the class FlowLogDBServiceTest method updateLastFlowLogPayload.

@Test
public void updateLastFlowLogPayload() {
    FlowLog flowLog = new FlowLog();
    flowLog.setId(ID);
    Payload payload = mock(Selectable.class);
    Map<Object, Object> variables = Map.of("repeated", 2);
    underTest.updateLastFlowLogPayload(flowLog, payload, variables);
    ArgumentCaptor<FlowLog> flowLogCaptor = ArgumentCaptor.forClass(FlowLog.class);
    verify(flowLogRepository, times(1)).save(flowLogCaptor.capture());
    FlowLog savedFlowLog = flowLogCaptor.getValue();
    assertEquals(flowLog.getId(), savedFlowLog.getId());
    String payloadJson = JsonWriter.objectToJson(payload, Map.of());
    String variablesJson = JsonWriter.objectToJson(variables, Map.of());
    assertEquals(payloadJson, savedFlowLog.getPayload());
    assertEquals(variablesJson, savedFlowLog.getVariables());
}
Also used : FlowLog(com.sequenceiq.flow.domain.FlowLog) Payload(com.sequenceiq.cloudbreak.common.event.Payload) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 19 with Payload

use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.

the class FillInMemoryStateStoreRestartAction method restart.

@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
    Payload stackPayload = (Payload) payload;
    Stack stack = stackService.getByIdWithListsInTransaction(stackPayload.getResourceId());
    restart(flowParameters, flowChainId, event, payload, stack);
}
Also used : Payload(com.sequenceiq.cloudbreak.common.event.Payload) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 20 with Payload

use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.

the class StackStopRestartAction method restart.

@Override
public void restart(FlowParameters flowParameters, String flowChainId, String event, Object payload) {
    Payload stackPayload = (Payload) payload;
    stackUpdater.updateStackStatus(stackPayload.getResourceId(), DetailedStackStatus.STOP_REQUESTED, "Stop/restart");
    Stack stack = stackService.getByIdWithListsInTransaction(stackPayload.getResourceId());
    MDCBuilder.buildMdcContext(stack);
    super.restart(flowParameters, flowChainId, event, payload);
}
Also used : Payload(com.sequenceiq.cloudbreak.common.event.Payload) Stack(com.sequenceiq.freeipa.entity.Stack)

Aggregations

Payload (com.sequenceiq.cloudbreak.common.event.Payload)36 Test (org.junit.jupiter.api.Test)11 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)10 Optional (java.util.Optional)10 Inject (javax.inject.Inject)10 Event (reactor.bus.Event)10 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)9 MDCBuilder (com.sequenceiq.cloudbreak.logger.MDCBuilder)8 List (java.util.List)8 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)7 AvailabilityZone.availabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone.availabilityZone)7 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)7 Location (com.sequenceiq.cloudbreak.cloud.model.Location)7 Location.location (com.sequenceiq.cloudbreak.cloud.model.Location.location)7 Region.region (com.sequenceiq.cloudbreak.cloud.model.Region.region)7 FlowParameters (com.sequenceiq.flow.core.FlowParameters)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 StateContext (org.springframework.statemachine.StateContext)7 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)6