Search in sources :

Example 11 with Flow

use of com.google.cloud.dialogflow.cx.v3beta1.Flow 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());
}
Also used : FlowState(com.sequenceiq.cloudbreak.core.flow2.FlowState) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow) FlowEvent(com.sequenceiq.cloudbreak.core.flow2.FlowEvent) Transition(org.springframework.statemachine.transition.Transition) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with Flow

use of com.google.cloud.dialogflow.cx.v3beta1.Flow 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;
}
Also used : AbstractFlowConfiguration(com.sequenceiq.cloudbreak.core.flow2.config.AbstractFlowConfiguration) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow)

Example 13 with Flow

use of com.google.cloud.dialogflow.cx.v3beta1.Flow in project cloudbreak by hortonworks.

the class AbstractStackFailureAction method createFlowContext.

@Override
protected StackFailureContext createFlowContext(String flowId, StateContext<S, E> stateContext, StackFailureEvent payload) {
    Flow flow = getFlow(flowId);
    StackView stack = stackService.getByIdView(payload.getStackId());
    MDCBuilder.buildMdcContext(stack);
    flow.setFlowFailed(payload.getException());
    return new StackFailureContext(flowId, stack);
}
Also used : StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow)

Example 14 with Flow

use of com.google.cloud.dialogflow.cx.v3beta1.Flow in project java-dialogflow-cx by googleapis.

the class FlowsClientTest method listFlowsTest.

@Test
public void listFlowsTest() throws Exception {
    Flow responsesElement = Flow.newBuilder().build();
    ListFlowsResponse expectedResponse = ListFlowsResponse.newBuilder().setNextPageToken("").addAllFlows(Arrays.asList(responsesElement)).build();
    mockFlows.addResponse(expectedResponse);
    AgentName parent = AgentName.of("[PROJECT]", "[LOCATION]", "[AGENT]");
    ListFlowsPagedResponse pagedListResponse = client.listFlows(parent);
    List<Flow> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getFlowsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFlows.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListFlowsRequest actualRequest = ((ListFlowsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListFlowsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.FlowsClient.ListFlowsPagedResponse) Test(org.junit.Test)

Example 15 with Flow

use of com.google.cloud.dialogflow.cx.v3beta1.Flow in project java-dialogflow-cx by googleapis.

the class FlowsClientTest method listFlowsTest2.

@Test
public void listFlowsTest2() throws Exception {
    Flow responsesElement = Flow.newBuilder().build();
    ListFlowsResponse expectedResponse = ListFlowsResponse.newBuilder().setNextPageToken("").addAllFlows(Arrays.asList(responsesElement)).build();
    mockFlows.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListFlowsPagedResponse pagedListResponse = client.listFlows(parent);
    List<Flow> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getFlowsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockFlows.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListFlowsRequest actualRequest = ((ListFlowsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListFlowsPagedResponse(com.google.cloud.dialogflow.cx.v3beta1.FlowsClient.ListFlowsPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 Flow (com.google.cloud.dialogflow.cx.v3beta1.Flow)6 Flow (com.sequenceiq.cloudbreak.core.flow2.Flow)6 AbstractMessage (com.google.protobuf.AbstractMessage)5 StackView (com.sequenceiq.cloudbreak.domain.view.StackView)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 FlowsClient (com.google.cloud.dialogflow.cx.v3beta1.FlowsClient)2 ListFlowsPagedResponse (com.google.cloud.dialogflow.cx.v3beta1.FlowsClient.ListFlowsPagedResponse)2 Page (com.google.cloud.dialogflow.cx.v3beta1.Page)2 StackFailureContext (com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext)2 List (java.util.List)2 Agent (com.google.cloud.dialogflow.cx.v3beta1.Agent)1 AgentName (com.google.cloud.dialogflow.cx.v3beta1.AgentName)1 CreateEntityTypeRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateEntityTypeRequest)1 CreateFlowRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateFlowRequest)1 CreateIntentRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateIntentRequest)1 CreatePageRequest (com.google.cloud.dialogflow.cx.v3beta1.CreatePageRequest)1 CreateTransitionRouteGroupRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateTransitionRouteGroupRequest)1 CreateVersionRequest (com.google.cloud.dialogflow.cx.v3beta1.CreateVersionRequest)1