use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.
the class AbstractFlowConfiguration method createFlow.
@Override
public Flow createFlow(String flowId, Long stackId) {
StateMachine<S, E> sm = stateMachineFactory.getStateMachine();
FlowStructuredEventHandler<S, E> fl = applicationContext.getBean(FlowStructuredEventHandler.class, getEdgeConfig().initState, getEdgeConfig().finalState, getClass().getSimpleName(), flowId, stackId);
Flow flow = new FlowAdapter<>(flowId, sm, new MessageFactory<>(), new StateConverterAdapter<>(stateType), new EventConverterAdapter<>(eventType), (Class<? extends FlowConfiguration<E>>) getClass(), fl);
sm.addStateListener(fl);
return flow;
}
use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.
the class Flow2Config method flowConfigurationMap.
@Bean
public Map<String, FlowConfiguration<?>> flowConfigurationMap() {
Map<String, FlowConfiguration<?>> flowConfigMap = new HashMap<>();
for (FlowConfiguration<?> flowConfig : flowConfigs) {
for (FlowEvent event : flowConfig.getInitEvents()) {
String key = event.event();
if (flowConfigMap.get(key) != null) {
throw new UnsupportedOperationException("Event already registered: " + key);
}
flowConfigMap.put(key, flowConfig);
}
}
return ImmutableMap.copyOf(flowConfigMap);
}
use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.
the class OfflineStateGenerator method generate.
private void generate() throws Exception {
StringBuilder builder = new StringBuilder("digraph {\n");
inject(flowConfiguration, "applicationContext", APP_CONTEXT);
Flow flow = initializeFlow();
StateMachine<FlowState, FlowEvent> stateMachine = getStateMachine(flow);
FlowState init = stateMachine.getInitialState().getId();
builder.append(generateStartPoint(init, flowConfiguration.getClass().getSimpleName())).append('\n');
List<Transition<FlowState, FlowEvent>> transitions = (List<Transition<FlowState, FlowEvent>>) stateMachine.getTransitions();
Map<String, FlowState> transitionsAlreadyDefined = new HashMap<>();
transitionsAlreadyDefined.put(init.toString(), init);
while (!transitions.isEmpty()) {
for (Transition<FlowState, FlowEvent> transition : new ArrayList<>(transitions)) {
FlowState source = transition.getSource().getId();
FlowState target = transition.getTarget().getId();
if (transitionsAlreadyDefined.values().contains(source)) {
String id = generateTransitionId(source, target, transition.getTrigger().getEvent());
if (!transitionsAlreadyDefined.keySet().contains(id)) {
if (target.action() != null && !transitionsAlreadyDefined.values().contains(target)) {
builder.append(generateState(target, target.action().getSimpleName())).append('\n');
}
builder.append(generateTransition(source, target, transition.getTrigger().getEvent())).append('\n');
transitionsAlreadyDefined.put(id, target);
}
transitions.remove(transition);
}
}
}
saveToFile(builder.append('}').toString());
}
use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.
the class OfflineStateGenerator method initializeFlow.
private Flow initializeFlow() throws Exception {
((AbstractFlowConfiguration<?, ?>) flowConfiguration).init();
Flow flow = flowConfiguration.createFlow("", 0L);
flow.initialize();
return flow;
}
use of com.sequenceiq.cloudbreak.core.flow2.config.FlowConfiguration in project cloudbreak by hortonworks.
the class Flow2ConfigTest method testFlowConfigurationMapInit.
@Test
public void testFlowConfigurationMapInit() {
List<FlowConfiguration<?>> flowConfigs = new ArrayList<>();
flowConfigs.add(new StackSyncFlowConfig());
flowConfigs.add(new StackTerminationFlowConfig());
given(this.flowConfigs.iterator()).willReturn(flowConfigs.iterator());
Map<String, FlowConfiguration<?>> flowConfigMap = underTest.flowConfigurationMap();
assertEquals("Not all flow type appeared in map!", countEvents(flowConfigs), flowConfigMap.size());
}
Aggregations