use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testNewFlowButNotHandled.
@Test
public void testNewFlowButNotHandled() {
Event<Payload> event = new Event<>(payload);
event.setKey("KEY");
CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.accept(event));
assertEquals("Couldn't start process.", exception.getMessage());
verify(flowConfigurationMap, times(1)).get(anyString());
verify(runningFlows, never()).put(any(Flow.class), isNull(String.class));
verify(flowLogService, never()).save(any(FlowParameters.class), anyString(), anyString(), any(Payload.class), anyMap(), any(), any(FlowState.class));
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class Flow2HandlerTest method testRestartFlowNoRestartActionNoFlowChainId.
@Test
public void testRestartFlowNoRestartActionNoFlowChainId() throws TransactionExecutionException {
FlowLog flowLog = createFlowLog(null);
Payload payload = new TestPayload(STACK_ID);
flowLog.setPayloadType(ClassValue.of(TestPayload.class));
flowLog.setPayload(JsonWriter.objectToJson(payload));
when(flowLogService.findFirstByFlowIdOrderByCreatedDesc(FLOW_ID)).thenReturn(Optional.of(flowLog));
HelloWorldFlowConfig helloWorldFlowConfig = new HelloWorldFlowConfig();
setUpFlowConfigCreateFlow(helloWorldFlowConfig);
List<FlowConfiguration<?>> flowConfigs = Lists.newArrayList(helloWorldFlowConfig);
ReflectionTestUtils.setField(underTest, "flowConfigs", flowConfigs);
underTest.restartFlow(FLOW_ID);
verify(flowChainHandler, never()).restoreFlowChain(FLOW_CHAIN_ID);
verify(flowLogService, times(1)).terminate(STACK_ID, FLOW_ID);
verify(defaultRestartAction, never()).restart(any(), any(), any(), any());
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class FlowChains method getRootTriggerEvent.
public Optional<Pair<String, Payload>> getRootTriggerEvent(String flowChainId) {
String rootFlowChainId = getRootFlowChainId(flowChainId);
FlowTriggerEventQueue flowTriggerEventQueue = flowChainMap.get(rootFlowChainId);
if (flowTriggerEventQueue != null) {
return Optional.of(Pair.of(rootFlowChainId, flowTriggerEventQueue.getTriggerEvent()));
}
Optional<FlowChainLog> initFlowChainLog = flowChainLogService.findRootInitFlowChainLog(flowChainId);
if (initFlowChainLog.isEmpty()) {
return Optional.empty();
}
LOGGER.info("Found root init flow chain log {} for flow chain {}", initFlowChainLog.get(), flowChainId);
Payload triggerEvent = FlowLogUtil.tryDeserializeTriggerEvent(initFlowChainLog.get());
if (triggerEvent == null) {
return Optional.empty();
} else {
return Optional.of(Pair.of(initFlowChainLog.get().getFlowChainId(), triggerEvent));
}
}
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 redbeamsPayload = (Payload) payload;
DBStack dbStack = dbStackService.getById(redbeamsPayload.getResourceId());
if (dbStack != null) {
redbeamsInMemoryStateStoreUpdaterService.update(dbStack.getId(), dbStack.getStatus());
MDCBuilder.buildMdcContext(dbStack);
MDCBuilder.addEnvironmentCrn(dbStack.getEnvironmentId());
MDCBuilder.addAccountId(getAccountId(dbStack));
}
super.restart(flowParameters, flowChainId, event, payload);
}
use of com.sequenceiq.cloudbreak.common.event.Payload in project cloudbreak by hortonworks.
the class AbstractStackTerminationAction method createFlowContext.
@Override
protected StackTerminationContext createFlowContext(FlowParameters flowParameters, StateContext<StackTerminationState, StackTerminationEvent> stateContext, P payload) {
Stack stack = stackService.getByIdWithListsInTransaction(payload.getResourceId());
MDCBuilder.buildMdcContext(stack);
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformvariant()).withLocation(location).withUserName(stack.getOwner()).withAccountId(stack.getAccountId()).build();
Credential credential = credentialService.getCredentialByEnvCrn(stack.getEnvironmentCrn());
CloudCredential cloudCredential = credentialConverter.convert(credential);
CloudStack cloudStack = cloudStackConverter.convert(stack);
List<Resource> resourceList = resourceService.findAllByStackId(stack.getId());
List<CloudResource> resources = resourceList.stream().map(r -> resourceConverter.convert(r)).collect(Collectors.toList());
return new StackTerminationContext(flowParameters, stack, cloudContext, cloudCredential, cloudStack, resources);
}
Aggregations