Search in sources :

Example 6 with Flow

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

the class CreateFlowIT method testCreateFlowGlobal.

@Test
public void testCreateFlowGlobal() throws Exception {
    Flow result = CreateFlow.createFlow(DISPLAY_NAME, PROJECT_ID, LOCATION_GLOBAL, AGENT_ID_GLOBAL, EVENT_TO_FULFILLMENT_MESSAGES);
    newFlowNameGlobal = result.getName();
    assertEquals(result.getDisplayName(), DISPLAY_NAME);
    // Number of added event handlers + 2 default event handlers.
    assertEquals(result.getEventHandlersCount(), EVENT_TO_FULFILLMENT_MESSAGES.size() + 2);
}
Also used : Flow(com.google.cloud.dialogflow.cx.v3beta1.Flow) Test(org.junit.Test)

Example 7 with Flow

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

the class StackTerminationFailureAction method createFlowContext.

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

Example 8 with Flow

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

the class StackCreationActions method stackCreationFailureAction.

@Bean(name = "STACK_CREATION_FAILED_STATE")
public Action<?, ?> stackCreationFailureAction() {
    return new AbstractStackFailureAction<StackCreationState, StackCreationEvent>() {

        @Override
        protected StackFailureContext createFlowContext(String flowId, StateContext<StackCreationState, StackCreationEvent> stateContext, StackFailureEvent payload) {
            Flow flow = getFlow(flowId);
            StackView stackView = stackService.getByIdView(payload.getStackId());
            MDCBuilder.buildMdcContext(stackView);
            flow.setFlowFailed(payload.getException());
            return new StackFailureContext(flowId, stackView);
        }

        @Override
        protected void doExecute(StackFailureContext context, StackFailureEvent payload, Map<Object, Object> variables) {
            stackCreationService.handleStackCreationFailure(context.getStackView(), payload.getException());
            metricService.incrementMetricCounter(MetricType.STACK_CREATION_FAILED, context.getStackView());
            sendEvent(context);
        }

        @Override
        protected Selectable createRequest(StackFailureContext context) {
            return new StackEvent(StackCreationEvent.STACKCREATION_FAILURE_HANDLED_EVENT.event(), context.getStackView().getId());
        }
    };
}
Also used : AbstractStackFailureAction(com.sequenceiq.cloudbreak.core.flow2.stack.AbstractStackFailureAction) StackEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackEvent) StackFailureEvent(com.sequenceiq.cloudbreak.reactor.api.event.StackFailureEvent) StateContext(org.springframework.statemachine.StateContext) StackFailureContext(com.sequenceiq.cloudbreak.core.flow2.stack.StackFailureContext) StackView(com.sequenceiq.cloudbreak.domain.view.StackView) Map(java.util.Map) Flow(com.sequenceiq.cloudbreak.core.flow2.Flow) Bean(org.springframework.context.annotation.Bean)

Example 9 with Flow

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

Example 10 with Flow

use of com.google.cloud.dialogflow.cx.v3beta1.Flow in project openflowplugin by opendaylight.

the class FlowMessageSerializer method writeInstructions.

/**
 * Serialize OpenFlowPlugin instructions and set ip protocol of set-tp-src and set-tp-dst actions of need.
 *
 * @param message   OpenFlow flow mod message
 * @param outBuffer output buffer
 */
private void writeInstructions(final FlowMessage message, final ByteBuf outBuffer) {
    final var instructions = message.getInstructions();
    if (instructions == null) {
        // Nothing to do
        return;
    }
    // Extract all instructions ...
    Stream<Instruction> flowInstructions = instructions.nonnullInstruction().values().stream().filter(Objects::nonNull).sorted(OrderComparator.build()).map(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Instruction::getInstruction).filter(Objects::nonNull);
    // ... updated them if needed ...
    final Uint8 protocol = extractProtocol(message);
    if (protocol != null) {
        flowInstructions = flowInstructions.map(insn -> updateInstruction(insn, protocol));
    }
    // ... and serialize them
    flowInstructions.forEach(i -> InstructionUtil.writeInstruction(i, EncodeConstants.OF_VERSION_1_3, registry, outBuffer));
}
Also used : PushVlanActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PushVlanActionCaseBuilder) FlowMessageBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessageBuilder) InstructionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder) SetTpDstActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.dst.action._case.SetTpDstActionBuilder) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) SetTpDstActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCaseBuilder) Nullable(org.eclipse.jdt.annotation.Nullable) Uint8(org.opendaylight.yangtools.yang.common.Uint8) Map(java.util.Map) SetTpDstActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpDstActionCase) VlanMatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder) PushVlanActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.push.vlan.action._case.PushVlanActionBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action) BindingMap(org.opendaylight.yangtools.yang.binding.util.BindingMap) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction) Uint16(org.opendaylight.yangtools.yang.common.Uint16) InstructionUtil(org.opendaylight.openflowplugin.impl.protocol.serialization.util.InstructionUtil) FlowCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie) ApplyActionsCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCaseBuilder) ApplyActionsBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActionsBuilder) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) SetTpSrcActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.tp.src.action._case.SetTpSrcActionBuilder) ApplyActions(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.apply.actions._case.ApplyActions) Optional(java.util.Optional) ByteBufUtils(org.opendaylight.openflowjava.util.ByteBufUtils) SerializerRegistry(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry) Uint64(org.opendaylight.yangtools.yang.common.Uint64) VlanMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch) SetVlanIdActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetVlanIdActionCase) SerializerRegistryInjector(org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistryInjector) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) ArrayList(java.util.ArrayList) ByteBuf(io.netty.buffer.ByteBuf) Objects.requireNonNull(java.util.Objects.requireNonNull) VlanCfi(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.VlanCfi) Flow(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow) FlowMessage(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowMessage) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) InstructionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder) OFSerializer(org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer) Uint32(org.opendaylight.yangtools.yang.common.Uint32) OrderComparator(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.OrderComparator) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder) ApplyActionsCase(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase) Match(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match) OFConstants(org.opendaylight.openflowplugin.api.OFConstants) SetTpSrcActionCase(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCase) VlanIdBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder) EncodeConstants(org.opendaylight.openflowjava.protocol.api.util.EncodeConstants) SetTpSrcActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetTpSrcActionCaseBuilder) FlowModFlags(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags) VlanId(org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder) Uint8(org.opendaylight.yangtools.yang.common.Uint8) Objects(java.util.Objects) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.Instruction)

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