├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
├── stateful-functions-docs
├── Dockerfile
├── Dockerfile-linter
├── Makefile
├── README.md
├── docs
│ ├── _static
│ │ ├── .gitkeep
│ │ ├── css
│ │ │ └── customize-theme.css
│ │ ├── favicon.png
│ │ ├── images
│ │ │ ├── async_exec.png
│ │ │ ├── example_ride_sharing.png
│ │ │ ├── example_ridesharing_2.png
│ │ │ ├── fault_tolerant.png
│ │ │ ├── flink_dataflow_graph.png
│ │ │ ├── flink_function_multiplexing.png
│ │ │ ├── greeter-function.gif
│ │ │ ├── resource_footprint.png
│ │ │ ├── state_first.png
│ │ │ └── stateful_functions.png
│ │ └── logo.png
│ ├── _templates
│ │ ├── breadcrumbs.html
│ │ ├── footer.html
│ │ ├── layout.html
│ │ └── searchbox.html
│ ├── api_concepts
│ │ ├── index.rst
│ │ ├── io_module
│ │ │ ├── custom.rst
│ │ │ ├── index.rst
│ │ │ ├── kafka.rst
│ │ │ └── source_sink.rst
│ │ ├── match_functions.rst
│ │ ├── persistence.rst
│ │ └── stateful_functions.rst
│ ├── conf.py
│ ├── contribute.rst
│ ├── deployment_operations
│ │ ├── configurations.rst
│ │ ├── index.rst
│ │ ├── metrics.rst
│ │ └── packaging.rst
│ ├── getting_started
│ │ ├── index.rst
│ │ ├── project_setup.rst
│ │ └── walkthrough.rst
│ ├── index.rst
│ ├── index_grid.html
│ ├── overview
│ │ ├── benefits_grid.html
│ │ ├── consistency_model.rst
│ │ ├── execution_model.rst
│ │ ├── index.rst
│ │ ├── stateful_functions.rst
│ │ └── tech_space.rst
│ └── roadmap.rst
├── images
│ ├── stateful_functions_logo.png
│ └── stateful_functions_overview.png
├── pom.xml
├── requirements.txt
├── runtime.txt
└── src
│ └── main
│ └── java
│ └── com
│ └── ververica
│ └── statefun
│ └── docs
│ ├── BasicFunctionModule.java
│ ├── CustomProvider.java
│ ├── FnCaller.java
│ ├── FnHelloWorld.java
│ ├── FnUser.java
│ ├── FnUserGreeter.java
│ ├── FnWithDependency.java
│ ├── FunctionTest.java
│ ├── MyUserMessage.java
│ ├── async
│ ├── EnrichmentFunction.java
│ ├── QueryService.java
│ ├── User.java
│ └── UserEnrichment.java
│ ├── delay
│ ├── DelayedMessage.java
│ ├── FnDelayedMessage.java
│ └── Message.java
│ ├── dependency
│ ├── ProductionDependency.java
│ ├── RuntimeDependency.java
│ └── TestDependency.java
│ ├── io
│ ├── MissingImplementationException.java
│ ├── custom
│ │ ├── MyEgressSpec.java
│ │ ├── MyIngressSpec.java
│ │ └── flink
│ │ │ ├── MyFlinkIoModule.java
│ │ │ ├── MySinkProvider.java
│ │ │ ├── MySourceProvider.java
│ │ │ ├── sink
│ │ │ └── MySinkFunction.java
│ │ │ └── source
│ │ │ └── MySourceFunction.java
│ ├── egress
│ │ ├── FnOutputting.java
│ │ ├── Identifiers.java
│ │ └── ModuleWithEgress.java
│ ├── flink
│ │ ├── FlinkSink.java
│ │ ├── FlinkSource.java
│ │ ├── ModuleWithSinkSpec.java
│ │ └── ModuleWithSourceSpec.java
│ ├── ingress
│ │ ├── Identifiers.java
│ │ ├── ModuleWithIngress.java
│ │ ├── ModuleWithRouter.java
│ │ └── UserRouter.java
│ └── kafka
│ │ ├── EgressSpecs.java
│ │ ├── IngressSpecs.java
│ │ ├── UserDeserializer.java
│ │ └── UserSerializer.java
│ ├── match
│ ├── Customer.java
│ ├── Employee.java
│ ├── FnMatchGreeter.java
│ ├── FnMatchGreeterWithCatchAll.java
│ └── FnUserGreeter.java
│ └── models
│ └── User.java
├── stateful-functions-examples
├── pom.xml
├── stateful-functions-async-example
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── examples
│ │ │ └── async
│ │ │ ├── Constants.java
│ │ │ ├── Module.java
│ │ │ ├── TaskDurationTrackerFunction.java
│ │ │ ├── events
│ │ │ ├── TaskCompletionEvent.java
│ │ │ └── TaskStartedEvent.java
│ │ │ └── service
│ │ │ ├── DummyTaskQueryService.java
│ │ │ ├── TaskQueryService.java
│ │ │ ├── TaskStatus.java
│ │ │ └── package-info.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── ververica
│ │ └── statefun
│ │ └── examples
│ │ └── async
│ │ └── RunnerTest.java
├── stateful-functions-flink-harness-example
│ ├── README.md
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── examples
│ │ │ └── harness
│ │ │ ├── MyConstants.java
│ │ │ ├── MyFunction.java
│ │ │ ├── MyMessages.java
│ │ │ ├── MyModule.java
│ │ │ └── MyRouter.java
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── ververica
│ │ └── statefun
│ │ └── examples
│ │ └── harness
│ │ └── RunnerTest.java
├── stateful-functions-greeter-example
│ ├── Dockerfile
│ ├── README.md
│ ├── docker-compose.yml
│ ├── k8s
│ │ ├── config-map.yaml
│ │ ├── master-deployment.yaml
│ │ ├── master-rest-service.yaml
│ │ ├── master-service.yaml
│ │ └── worker-deployment.yaml
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── examples
│ │ │ └── greeter
│ │ │ ├── GreetRouter.java
│ │ │ ├── GreetStatefulFunction.java
│ │ │ ├── GreetingIO.java
│ │ │ ├── GreetingModule.java
│ │ │ └── generated
│ │ │ ├── GreetRequest.java
│ │ │ ├── GreetRequestOrBuilder.java
│ │ │ ├── GreetResponse.java
│ │ │ ├── GreetResponseOrBuilder.java
│ │ │ └── Greeter.java
│ │ └── protobuf
│ │ └── greeter.proto
├── stateful-functions-ridesharing-example
│ ├── Dockerfile.functions
│ ├── README.md
│ ├── docker-compose.yml
│ ├── pom.xml
│ ├── stateful-functions-ridesharing-example-functions
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── examples
│ │ │ └── ridesharing
│ │ │ ├── FnDriver.java
│ │ │ ├── FnGeoCell.java
│ │ │ ├── FnPassenger.java
│ │ │ ├── FnRide.java
│ │ │ ├── FunctionProvider.java
│ │ │ ├── Identifiers.java
│ │ │ ├── InboundDriverRouter.java
│ │ │ ├── InboundPassengerRouter.java
│ │ │ ├── KafkaSpecs.java
│ │ │ └── Module.java
│ ├── stateful-functions-ridesharing-example-simulator
│ │ ├── Dockerfile
│ │ ├── application.yaml
│ │ ├── pom.xml
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── examples
│ │ │ └── ridesharing
│ │ │ └── simulator
│ │ │ ├── Main.java
│ │ │ ├── configurations
│ │ │ ├── KafkaConsumerConfig.java
│ │ │ ├── KafkaProducerConfig.java
│ │ │ └── WebSocketConfig.java
│ │ │ ├── controllers
│ │ │ └── ApiController.java
│ │ │ ├── model
│ │ │ ├── SimulationStartedEvent.java
│ │ │ ├── WebsocketDriverEvent.java
│ │ │ └── WebsocketPassengerEvent.java
│ │ │ ├── services
│ │ │ ├── KafkaConsumerService.java
│ │ │ ├── KafkaDriverPublisher.java
│ │ │ └── KafkaPassengerPublisher.java
│ │ │ └── simulation
│ │ │ ├── Driver.java
│ │ │ ├── DriverMessaging.java
│ │ │ ├── Passenger.java
│ │ │ ├── PassengerMessaging.java
│ │ │ ├── Simulation.java
│ │ │ ├── StateMachine.java
│ │ │ ├── engine
│ │ │ ├── DaemonThreadFactory.java
│ │ │ ├── EventLoop.java
│ │ │ ├── LifecycleMessages.java
│ │ │ ├── ReadySet.java
│ │ │ ├── Scheduler.java
│ │ │ ├── Simulatee.java
│ │ │ └── Task.java
│ │ │ └── messaging
│ │ │ └── Communication.java
│ └── stateful-functions-ridesharing-protocol
│ │ ├── pom.xml
│ │ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── examples
│ │ │ └── ridesharing
│ │ │ └── generated
│ │ │ ├── DriverInCell.java
│ │ │ ├── DriverInCellOrBuilder.java
│ │ │ ├── DriverJoinsRide.java
│ │ │ ├── DriverJoinsRideOrBuilder.java
│ │ │ ├── DriverRejectsPickup.java
│ │ │ ├── DriverRejectsPickupOrBuilder.java
│ │ │ ├── GeoCellState.java
│ │ │ ├── GeoCellStateOrBuilder.java
│ │ │ ├── GetDriver.java
│ │ │ ├── GetDriverOrBuilder.java
│ │ │ ├── InboundDriverMessage.java
│ │ │ ├── InboundDriverMessageOrBuilder.java
│ │ │ ├── InboundPassengerMessage.java
│ │ │ ├── InboundPassengerMessageOrBuilder.java
│ │ │ ├── JoinCell.java
│ │ │ ├── JoinCellOrBuilder.java
│ │ │ ├── LeaveCell.java
│ │ │ ├── LeaveCellOrBuilder.java
│ │ │ ├── OutboundDriverMessage.java
│ │ │ ├── OutboundDriverMessageOrBuilder.java
│ │ │ ├── OutboundPassengerMessage.java
│ │ │ ├── OutboundPassengerMessageOrBuilder.java
│ │ │ ├── PassengerJoinsRide.java
│ │ │ ├── PassengerJoinsRideOrBuilder.java
│ │ │ ├── PickupPassenger.java
│ │ │ ├── PickupPassengerOrBuilder.java
│ │ │ ├── RideEnded.java
│ │ │ ├── RideEndedOrBuilder.java
│ │ │ ├── RideFailed.java
│ │ │ ├── RideFailedOrBuilder.java
│ │ │ ├── RideStarted.java
│ │ │ ├── RideStartedOrBuilder.java
│ │ │ └── Ridesharing.java
│ │ └── protobuf
│ │ └── ridesharing.proto
└── stateful-functions-shopping-cart-example
│ ├── Dockerfile
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── com
│ │ └── ververica
│ │ └── statefun
│ │ └── examples
│ │ └── shoppingcart
│ │ ├── Identifiers.java
│ │ ├── Inventory.java
│ │ ├── RestockRouter.java
│ │ ├── ShoppingCartModule.java
│ │ ├── UserShoppingCart.java
│ │ └── generated
│ │ └── ProtobufMessages.java
│ └── protobuf
│ └── shoppingcart.proto
├── stateful-functions-flink
├── pom.xml
├── stateful-functions-flink-common
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── ververica
│ │ │ │ └── statefun
│ │ │ │ └── flink
│ │ │ │ └── common
│ │ │ │ ├── ResourceLocator.java
│ │ │ │ ├── SetContextClassLoader.java
│ │ │ │ ├── UnimplementedTypeInfo.java
│ │ │ │ ├── UnimplementedTypeSerializer.java
│ │ │ │ ├── generated
│ │ │ │ ├── ProtobufSerializerSnapshot.java
│ │ │ │ ├── ProtobufSerializerSnapshotOrBuilder.java
│ │ │ │ └── Serializer.java
│ │ │ │ ├── json
│ │ │ │ ├── MissingKeyException.java
│ │ │ │ ├── NamespaceNamePair.java
│ │ │ │ ├── Selectors.java
│ │ │ │ └── WrongTypeException.java
│ │ │ │ ├── protobuf
│ │ │ │ ├── FileDescriptorResolver.java
│ │ │ │ ├── InputStreamView.java
│ │ │ │ ├── OutputStreamView.java
│ │ │ │ ├── ProtobufDescriptorMap.java
│ │ │ │ ├── ProtobufReflectionUtil.java
│ │ │ │ ├── ProtobufSerializer.java
│ │ │ │ ├── ProtobufTypeInformation.java
│ │ │ │ ├── ProtobufTypeSerializer.java
│ │ │ │ └── ProtobufTypeSerializerSnapshot.java
│ │ │ │ └── protopath
│ │ │ │ ├── PathFragment.java
│ │ │ │ ├── PathFragmentDescriptor.java
│ │ │ │ ├── ProtobufDynamicMessageLens.java
│ │ │ │ ├── ProtobufPath.java
│ │ │ │ ├── ProtobufPathCompiler.java
│ │ │ │ └── ProtobufPathParser.java
│ │ └── protobuf
│ │ │ └── serializer.proto
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── flink
│ │ │ └── common
│ │ │ ├── ResourceLocatorTest.java
│ │ │ ├── json
│ │ │ └── SelectorsTest.java
│ │ │ ├── protobuf
│ │ │ ├── ProtobufDescriptorMapTest.java
│ │ │ ├── ProtobufSerializerTest.java
│ │ │ ├── ProtobufTypeSerializerTest.java
│ │ │ └── generated
│ │ │ │ └── TestProtos.java
│ │ │ └── protopath
│ │ │ ├── ProtobufPathParserTest.java
│ │ │ └── ProtobufPathTest.java
│ │ ├── protobuf
│ │ └── test.proto
│ │ └── resources
│ │ ├── bar-module
│ │ └── module.yaml
│ │ ├── dummy-file.txt
│ │ ├── foo-module
│ │ └── module.yaml
│ │ └── test-descriptors.bin
├── stateful-functions-flink-core
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ ├── java
│ │ │ ├── com
│ │ │ │ └── ververica
│ │ │ │ │ └── statefun
│ │ │ │ │ ├── flink
│ │ │ │ │ └── core
│ │ │ │ │ │ ├── StatefulFunctionsJob.java
│ │ │ │ │ │ ├── StatefulFunctionsJobConstants.java
│ │ │ │ │ │ ├── StatefulFunctionsUniverse.java
│ │ │ │ │ │ ├── StatefulFunctionsUniverseProvider.java
│ │ │ │ │ │ ├── StatefulFunctionsUniverseValidator.java
│ │ │ │ │ │ ├── StatefulFunctionsUniverses.java
│ │ │ │ │ │ ├── common
│ │ │ │ │ │ ├── ConfigurationUtil.java
│ │ │ │ │ │ ├── KeyBy.java
│ │ │ │ │ │ ├── MailboxExecutorFacade.java
│ │ │ │ │ │ ├── Maps.java
│ │ │ │ │ │ ├── SerializableFunction.java
│ │ │ │ │ │ └── SerializablePredicate.java
│ │ │ │ │ │ ├── di
│ │ │ │ │ │ ├── Inject.java
│ │ │ │ │ │ ├── Label.java
│ │ │ │ │ │ ├── Lazy.java
│ │ │ │ │ │ └── ObjectContainer.java
│ │ │ │ │ │ ├── feedback
│ │ │ │ │ │ ├── FeedbackChannel.java
│ │ │ │ │ │ ├── FeedbackChannelBroker.java
│ │ │ │ │ │ ├── FeedbackConfiguration.java
│ │ │ │ │ │ ├── FeedbackConsumer.java
│ │ │ │ │ │ ├── FeedbackKey.java
│ │ │ │ │ │ ├── FeedbackQueue.java
│ │ │ │ │ │ ├── FeedbackSinkOperator.java
│ │ │ │ │ │ ├── FeedbackUnionOperator.java
│ │ │ │ │ │ ├── FeedbackUnionOperatorFactory.java
│ │ │ │ │ │ ├── LockFreeBatchFeedbackQueue.java
│ │ │ │ │ │ └── SubtaskFeedbackKey.java
│ │ │ │ │ │ ├── functions
│ │ │ │ │ │ ├── ApplyingContext.java
│ │ │ │ │ │ ├── AsyncMessageDecorator.java
│ │ │ │ │ │ ├── AsyncOperationFailureNotifier.java
│ │ │ │ │ │ ├── AsyncSink.java
│ │ │ │ │ │ ├── DelaySink.java
│ │ │ │ │ │ ├── DelayedMessagesBuffer.java
│ │ │ │ │ │ ├── FlinkStateDelayedMessagesBuffer.java
│ │ │ │ │ │ ├── FlinkTimerServiceFactory.java
│ │ │ │ │ │ ├── FunctionActivation.java
│ │ │ │ │ │ ├── FunctionGroupDispatchFactory.java
│ │ │ │ │ │ ├── FunctionGroupOperator.java
│ │ │ │ │ │ ├── FunctionLoader.java
│ │ │ │ │ │ ├── FunctionRepository.java
│ │ │ │ │ │ ├── LiveFunction.java
│ │ │ │ │ │ ├── LocalFunctionGroup.java
│ │ │ │ │ │ ├── LocalSink.java
│ │ │ │ │ │ ├── Partition.java
│ │ │ │ │ │ ├── PredefinedFunctionLoader.java
│ │ │ │ │ │ ├── Reductions.java
│ │ │ │ │ │ ├── RemoteSink.java
│ │ │ │ │ │ ├── ReusableContext.java
│ │ │ │ │ │ ├── SideOutputSink.java
│ │ │ │ │ │ ├── StatefulFunction.java
│ │ │ │ │ │ ├── StatefulFunctionInvocationException.java
│ │ │ │ │ │ ├── StatefulFunctionRepository.java
│ │ │ │ │ │ ├── TimerServiceFactory.java
│ │ │ │ │ │ └── UnderCheckpointLockExecutor.java
│ │ │ │ │ │ ├── generated
│ │ │ │ │ │ ├── Checkpoint.java
│ │ │ │ │ │ ├── CheckpointOrBuilder.java
│ │ │ │ │ │ ├── Envelope.java
│ │ │ │ │ │ ├── EnvelopeAddress.java
│ │ │ │ │ │ ├── EnvelopeAddressOrBuilder.java
│ │ │ │ │ │ ├── EnvelopeOrBuilder.java
│ │ │ │ │ │ ├── Payload.java
│ │ │ │ │ │ ├── PayloadOrBuilder.java
│ │ │ │ │ │ └── StatefulFunctions.java
│ │ │ │ │ │ ├── jsonmodule
│ │ │ │ │ │ ├── JsonModule.java
│ │ │ │ │ │ ├── JsonServiceLoader.java
│ │ │ │ │ │ ├── ModuleConfigurationException.java
│ │ │ │ │ │ ├── ModuleType.java
│ │ │ │ │ │ ├── Pointers.java
│ │ │ │ │ │ ├── RemoteFunction.java
│ │ │ │ │ │ ├── RemoteFunctionProvider.java
│ │ │ │ │ │ └── RemoteFunctionSpec.java
│ │ │ │ │ │ ├── logger
│ │ │ │ │ │ ├── CheckpointedStreamOperations.java
│ │ │ │ │ │ ├── KeyGroupStream.java
│ │ │ │ │ │ ├── KeyGroupStreamFactory.java
│ │ │ │ │ │ ├── Loggers.java
│ │ │ │ │ │ ├── MemorySegmentPool.java
│ │ │ │ │ │ └── UnboundedFeedbackLogger.java
│ │ │ │ │ │ ├── message
│ │ │ │ │ │ ├── Message.java
│ │ │ │ │ │ ├── MessageFactory.java
│ │ │ │ │ │ ├── MessageFactoryType.java
│ │ │ │ │ │ ├── MessageKeySelector.java
│ │ │ │ │ │ ├── MessagePayloadSerializer.java
│ │ │ │ │ │ ├── MessagePayloadSerializerKryo.java
│ │ │ │ │ │ ├── MessagePayloadSerializerMultiLanguage.java
│ │ │ │ │ │ ├── MessagePayloadSerializerPb.java
│ │ │ │ │ │ ├── MessagePayloadSerializerRaw.java
│ │ │ │ │ │ ├── MessageTypeInformation.java
│ │ │ │ │ │ ├── MessageTypeSerializer.java
│ │ │ │ │ │ ├── ProtobufMessage.java
│ │ │ │ │ │ └── SdkMessage.java
│ │ │ │ │ │ ├── metrics
│ │ │ │ │ │ ├── FlinkFunctionTypeMetrics.java
│ │ │ │ │ │ ├── FlinkMetricsFactory.java
│ │ │ │ │ │ ├── FunctionTypeMetrics.java
│ │ │ │ │ │ └── MetricsFactory.java
│ │ │ │ │ │ ├── pool
│ │ │ │ │ │ └── SimplePool.java
│ │ │ │ │ │ ├── protorouter
│ │ │ │ │ │ ├── AddressResolver.java
│ │ │ │ │ │ ├── ProtobufRouter.java
│ │ │ │ │ │ ├── TemplateEvaluator.java
│ │ │ │ │ │ └── TemplateParser.java
│ │ │ │ │ │ ├── queue
│ │ │ │ │ │ ├── Lock.java
│ │ │ │ │ │ ├── Locks.java
│ │ │ │ │ │ └── MpscQueue.java
│ │ │ │ │ │ ├── spi
│ │ │ │ │ │ ├── Constants.java
│ │ │ │ │ │ ├── ModuleSpecs.java
│ │ │ │ │ │ └── Modules.java
│ │ │ │ │ │ ├── state
│ │ │ │ │ │ ├── BoundState.java
│ │ │ │ │ │ ├── FlinkState.java
│ │ │ │ │ │ ├── FlinkValueAccessor.java
│ │ │ │ │ │ ├── MultiplexedMapStateAccessor.java
│ │ │ │ │ │ ├── MultiplexedState.java
│ │ │ │ │ │ ├── PersistedValues.java
│ │ │ │ │ │ ├── State.java
│ │ │ │ │ │ └── StateBinder.java
│ │ │ │ │ │ ├── translation
│ │ │ │ │ │ ├── CheckpointToMessage.java
│ │ │ │ │ │ ├── DecoratedSink.java
│ │ │ │ │ │ ├── DecoratedSource.java
│ │ │ │ │ │ ├── EgressToSinkTranslator.java
│ │ │ │ │ │ ├── FlinkUniverse.java
│ │ │ │ │ │ ├── IngressRouterOperator.java
│ │ │ │ │ │ ├── IngressToSourceFunctionTranslator.java
│ │ │ │ │ │ ├── RouterTranslator.java
│ │ │ │ │ │ ├── SideOutputTranslator.java
│ │ │ │ │ │ ├── Sinks.java
│ │ │ │ │ │ └── Sources.java
│ │ │ │ │ │ └── types
│ │ │ │ │ │ ├── DynamicallyRegisteredTypes.java
│ │ │ │ │ │ └── StaticallyRegisteredTypes.java
│ │ │ │ │ └── sdk
│ │ │ │ │ └── state
│ │ │ │ │ └── ApiExtension.java
│ │ │ └── it
│ │ │ │ └── unimi
│ │ │ │ └── dsi
│ │ │ │ └── fastutil
│ │ │ │ ├── HashCommon.java
│ │ │ │ └── objects
│ │ │ │ └── ObjectOpenHashMap.java
│ │ └── protobuf
│ │ │ └── stateful-functions.proto
│ │ └── test
│ │ ├── java
│ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── flink
│ │ │ └── core
│ │ │ ├── TestUtils.java
│ │ │ ├── feedback
│ │ │ └── FeedbackChannelTest.java
│ │ │ ├── functions
│ │ │ ├── LocalStatefulFunctionGroupTest.java
│ │ │ └── ReductionsTest.java
│ │ │ ├── jsonmodule
│ │ │ └── JsonModuleTest.java
│ │ │ ├── logger
│ │ │ ├── MemorySegmentPoolTest.java
│ │ │ └── UnboundedFeedbackLoggerTest.java
│ │ │ ├── message
│ │ │ ├── MessageTest.java
│ │ │ └── MessageTypeSerializerTest.java
│ │ │ ├── protorouter
│ │ │ ├── AddressResolverTest.java
│ │ │ ├── TemplateEvaluatorTest.java
│ │ │ ├── TemplateParserTest.java
│ │ │ └── generated
│ │ │ │ └── TestProtos.java
│ │ │ └── state
│ │ │ └── StateBinderTest.java
│ │ ├── protobuf
│ │ └── test.proto
│ │ └── resources
│ │ ├── bar-module
│ │ └── module.yaml
│ │ ├── foo-module
│ │ └── module.yaml
│ │ └── test-descriptors.bin
├── stateful-functions-flink-distribution
│ └── pom.xml
├── stateful-functions-flink-harness
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── flink
│ │ │ └── harness
│ │ │ ├── Harness.java
│ │ │ └── io
│ │ │ ├── ConsumingEgressSpec.java
│ │ │ ├── ConsumingSink.java
│ │ │ ├── HarnessConstants.java
│ │ │ ├── HarnessIoModule.java
│ │ │ ├── SerializableConsumer.java
│ │ │ ├── SerializableSupplier.java
│ │ │ ├── SupplyingIngressSpec.java
│ │ │ └── SupplyingSource.java
│ │ └── resources
│ │ └── log4j.properties
├── stateful-functions-flink-io-bundle
│ ├── pom.xml
│ └── src
│ │ ├── main
│ │ └── java
│ │ │ └── com
│ │ │ └── ververica
│ │ │ └── statefun
│ │ │ └── flink
│ │ │ └── io
│ │ │ ├── common
│ │ │ └── ReflectionUtil.java
│ │ │ └── kafka
│ │ │ ├── KafkaDeserializationSchemaDelegate.java
│ │ │ ├── KafkaFlinkIoModule.java
│ │ │ ├── KafkaSerializationSchemaDelegate.java
│ │ │ ├── KafkaSinkProvider.java
│ │ │ ├── KafkaSourceProvider.java
│ │ │ ├── ProtobufKafkaIngressDeserializer.java
│ │ │ └── ProtobufKafkaSourceProvider.java
│ │ └── test
│ │ ├── com
│ │ └── ververica
│ │ │ └── statefun
│ │ │ └── flink
│ │ │ └── io
│ │ │ ├── common
│ │ │ └── ReflectionUtilTest.java
│ │ │ └── kafka
│ │ │ ├── ProtobufKafkaIngressDeserializerTest.java
│ │ │ └── ProtobufKafkaSourceProviderTest.java
│ │ └── resources
│ │ ├── protobuf-kafka-ingress.yaml
│ │ └── test-descriptors.bin
├── stateful-functions-flink-io
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── com
│ │ └── ververica
│ │ └── statefun
│ │ └── flink
│ │ └── io
│ │ ├── datastream
│ │ ├── SinkFunctionSpec.java
│ │ ├── SourceFunctionSpec.java
│ │ └── SourceSinkModule.java
│ │ └── spi
│ │ ├── FlinkIoModule.java
│ │ ├── JsonIngressSpec.java
│ │ ├── SinkProvider.java
│ │ └── SourceProvider.java
└── stateful-functions-flink-launcher
│ ├── pom.xml
│ └── src
│ └── main
│ └── java
│ └── com
│ └── ververica
│ └── statefun
│ └── flink
│ └── launcher
│ ├── StatefulFunctionsClusterConfiguration.java
│ ├── StatefulFunctionsClusterConfigurationParserFactory.java
│ ├── StatefulFunctionsClusterEntryPoint.java
│ └── StatefulFunctionsJobGraphRetriever.java
├── stateful-functions-kafka-io
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── ververica
│ └── statefun
│ └── sdk
│ └── kafka
│ ├── Constants.java
│ ├── KafkaEgressBuilder.java
│ ├── KafkaEgressSerializer.java
│ ├── KafkaEgressSpec.java
│ ├── KafkaIngressBuilder.java
│ ├── KafkaIngressDeserializer.java
│ ├── KafkaIngressSpec.java
│ └── KafkaProducerSemantic.java
├── stateful-functions-quickstart
├── pom.xml
└── src
│ └── main
│ └── resources
│ ├── META-INF
│ └── maven
│ │ └── archetype-metadata.xml
│ └── archetype-resources
│ ├── Dockerfile
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── Module.java
│ └── resources
│ └── META-INF
│ └── services
│ └── com.ververica.statefun.sdk.spi.StatefulFunctionModule
├── stateful-functions-sdk
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── ververica
│ └── statefun
│ └── sdk
│ ├── Address.java
│ ├── AsyncOperationResult.java
│ ├── Context.java
│ ├── EgressType.java
│ ├── FunctionType.java
│ ├── IngressType.java
│ ├── StatefulFunction.java
│ ├── StatefulFunctionProvider.java
│ ├── annotations
│ ├── ForRuntime.java
│ └── Persisted.java
│ ├── io
│ ├── EgressIdentifier.java
│ ├── EgressSpec.java
│ ├── IngressIdentifier.java
│ ├── IngressSpec.java
│ └── Router.java
│ ├── match
│ ├── MatchBinder.java
│ └── StatefulMatchFunction.java
│ ├── spi
│ └── StatefulFunctionModule.java
│ └── state
│ ├── Accessor.java
│ └── PersistedValue.java
├── stateful-functions-state-processor
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── ververica
│ │ └── statefun
│ │ └── state
│ │ └── processor
│ │ ├── BootstrapDataRouterProvider.java
│ │ ├── Context.java
│ │ ├── StateBootstrapFunction.java
│ │ ├── StateBootstrapFunctionProvider.java
│ │ ├── StatefulFunctionsSavepointCreator.java
│ │ ├── example
│ │ └── GreetStatefulFunctionBootstrapExample.java
│ │ ├── operator
│ │ ├── FunctionsStateBootstrapOperator.java
│ │ ├── StateBootstrapFunctionRegistry.java
│ │ └── StateBootstrapper.java
│ │ └── union
│ │ ├── BootstrapDataset.java
│ │ ├── BootstrapDatasetUnion.java
│ │ ├── TaggedBootstrapData.java
│ │ ├── TaggedBootstrapDataSerializer.java
│ │ └── TaggedBootstrapDataTypeInfo.java
│ └── test
│ └── java
│ └── com
│ └── ververica
│ └── statefun
│ └── state
│ └── processor
│ ├── StatefulFunctionsSavepointCreatorTest.java
│ ├── operator
│ └── StateBootstrapperTest.java
│ └── union
│ ├── BootstrapDatasetUnionTest.java
│ └── TaggedBootstrapDataSerializerTest.java
└── tools
├── docker
├── Dockerfile
├── build-stateful-functions.sh
├── docker-entry-point.sh
└── flink-distribution-template
│ ├── bin
│ ├── flink-console.sh
│ └── standalone-job.sh
│ └── conf
│ └── flink-conf.yaml
└── maven
└── spotbugs-exclude.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled class file
2 | *.class
3 |
4 | # Log file
5 | *.log
6 |
7 | # BlueJ files
8 | *.ctxt
9 |
10 | # Mobile Tools for Java (J2ME)
11 | .mtj.tmp/
12 |
13 | # Package Files #
14 | *.jar
15 | *.war
16 | *.nar
17 | *.ear
18 | *.zip
19 | *.tar.gz
20 | *.rar
21 |
22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23 | hs_err_pid*
24 |
25 | .DS_Store
26 | *.iml
27 | .idea
28 |
29 | # maven shade plugin
30 | dependency-reduced-pom.xml
31 | target
32 |
33 | # documentation
34 | /_build/
35 | /venv/
36 | _build
37 | /dist/html/
38 | build-linter
39 |
--------------------------------------------------------------------------------
/stateful-functions-docs/Dockerfile:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Ververica GmbH.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | FROM python:3
15 |
16 | RUN apt-get update && apt-get -y install texlive-latex-recommended texlive-fonts-recommended texlive-latex-extra latexmk
17 |
18 | COPY requirements.txt /requirements.txt
19 |
20 | RUN set -e; \
21 | pip install --no-cache-dir -r /requirements.txt
22 |
23 | VOLUME "/build"
24 | EXPOSE 8000
25 | CMD ["make" "-C", "/build", "html"]
26 |
--------------------------------------------------------------------------------
/stateful-functions-docs/Dockerfile-linter:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Ververica GmbH.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | FROM alpine:3.8 as docs-linter
16 |
17 | RUN apk add --no-cache \
18 | python3 \
19 | nodejs \
20 | npm
21 |
22 | RUN pip3 install --disable-pip-version-check proselint \
23 | && npm install --global alex markdown-spellcheck retext-mapbox-standard write-good
24 |
--------------------------------------------------------------------------------
/stateful-functions-docs/README.md:
--------------------------------------------------------------------------------
1 | Stateful Functions Documentation
2 | -------------------------
3 |
4 | This documentation is using http://www.sphinx-doc.org/ with the https://pypi.org/project/sphinxcontrib-versioning/ plugin.
5 |
6 | Consult the [requirements.txt](requirements.txt) file for the relevant versions of the packages we're using.
7 |
8 | # Build the documentation locally
9 |
10 | Since we're using the [sphinxcontrib-versioning](https://pypi.org/project/sphinxcontrib-versioning/) plugin to build multiple versions of the documentation, building the docs locally will depend on what you want to achieve.
11 |
12 | If you are only concerend with seeing a particular branch/commit that you're working on, then using `make docker-autobuild` will achieve what you want. You can then navigate to http://localhost:8000/index.html to see the resulting pages, and it will auto rebuild the docs on every edit as well.
13 |
14 | If the build fails or you experience any issues, try doing a `make clean` to remove any old build artifacts first.
15 |
16 | # Export the documentation locally as PDF
17 |
18 | `make docker-latexpdf` will export the current brach/commit of the documentation asd PDF. The final documentation will be located under `_build/pdf/latex/ApplicationManager.pdf`.
19 |
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/.gitkeep
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/css/customize-theme.css:
--------------------------------------------------------------------------------
1 | /* Copyright 2019 Ververica GmbH.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 | */
15 |
16 | .wy-side-nav-search>a, .wy-side-nav-search .wy-dropdown>a {
17 | display: block;
18 | }
19 |
20 | .wy-nav-top {
21 | background-color: #446D6F;
22 | }
23 |
24 | .wy-side-nav-search>a img.logo, .wy-side-nav-search .wy-dropdown>a img.logo {
25 | width: 100%;
26 | height: auto;
27 | }
28 |
29 | .wy-menu-vertical a:active {
30 | background-color: #446D6F;
31 | }
32 |
33 | .wy-side-nav-search {
34 | background-color: #446D6F;
35 | }
36 |
37 | .wy-nav-content a {
38 | color: #446D6F;
39 | }
40 |
41 | .wy-nav-content a:visited {
42 | color: #7A9E9C;
43 | }
44 |
45 | .wy-nav-content a:hover {
46 | text-decoration: underline;
47 | }
48 |
49 | .scv-banner > a {
50 | color: white ! important;
51 | }
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/favicon.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/async_exec.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/async_exec.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/example_ride_sharing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/example_ride_sharing.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/example_ridesharing_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/example_ridesharing_2.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/fault_tolerant.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/fault_tolerant.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/flink_dataflow_graph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/flink_dataflow_graph.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/flink_function_multiplexing.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/flink_function_multiplexing.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/greeter-function.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/greeter-function.gif
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/resource_footprint.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/resource_footprint.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/state_first.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/state_first.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/images/stateful_functions.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/images/stateful_functions.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_static/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_static/logo.png
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_templates/breadcrumbs.html:
--------------------------------------------------------------------------------
1 | {%- extends "sphinx_rtd_theme/breadcrumbs.html" %}
2 |
3 |
4 | {% block breadcrumbs %} {% endblock %}
5 |
6 | {% block breadcrumbs_aside %}
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | {% endblock %}
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_templates/footer.html:
--------------------------------------------------------------------------------
1 | {% extends '!footer.html' %}
2 |
3 | {% block extrafooter %}
4 |
5 |
© Copyright 2019, Ververica GmbH.
6 | Apache Flink, Flink®, Apache®, the squirrel logo, and the Apache feather logo are either registered trademarks or trademarks of The Apache Software Foundation.
7 | Report an issue with this documentation page | Imprint
8 |
9 | {% endblock %}
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_templates/layout.html:
--------------------------------------------------------------------------------
1 | {% extends '!layout.html' %}
2 |
3 | {%- set favicon = 'favicon.png' %}
4 | {%- set logo = 'logo.png' %}
5 | {%- set theme_logo_only = True %}
6 |
7 | {% block extrahead %}
8 |
15 | {% endblock %}
16 |
17 | {% block sidebartitle %}
18 |
19 | {{ super() }}
20 |
21 | A framework for stateful distributed applications by the original creators of Apache Flink®.
22 |
23 | {% endblock %}
24 |
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/_templates/searchbox.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/docs/_templates/searchbox.html
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/api_concepts/index.rst:
--------------------------------------------------------------------------------
1 | .. Copyright 2019 Ververica GmbH.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
15 | .. _api-concepts:
16 |
17 | ############
18 | API Concepts
19 | ############
20 |
21 | .. toctree::
22 | :hidden:
23 |
24 | stateful_functions
25 | match_functions
26 | persistence
27 | io_module/index
28 |
29 | Stateful Functions applications are a collection of virtual stateful functions that can send arbitrary messages between each other and external systems.
30 | The execution can happen on a local JVM, or clusters of many machines.
31 | This section walks you through the basic API's you need to be familiar with to get started.
32 |
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/contribute.rst:
--------------------------------------------------------------------------------
1 | .. Copyright 2019 Ververica GmbH.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
15 | .. _contribute:
16 |
17 | #################
18 | How to Contribute
19 | #################
20 |
21 | **Stateful Functions** is an open source project. Developing in an open community, in close collaboration with real people solving real problems is, for us, the best way to learn and grow.
22 |
23 | If you find these ideas interesting or promising, try **Stateful Functions** out, explore the code and get involved! We strongly encourage you to file an issue or open a pull request on `GitHub `_!
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/deployment_operations/index.rst:
--------------------------------------------------------------------------------
1 | .. Copyright 2019 Ververica GmbH.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
15 | #########################
16 | Deployment and Operations
17 | #########################
18 |
19 | .. toctree::
20 | :hidden:
21 |
22 | packaging
23 | configurations
24 | metrics
25 |
26 | Stateful Functions is a framework built on top of the {flink} runtime, which means it inherits Flink's deployment and operations model, and there are no new concepts you need to learn.
27 | Read through the official `Apache Flink documentation `_ to learn how to run and maintain an application in production.
28 | The following pages outline Stateful Functions' specific configurations and metrics.
--------------------------------------------------------------------------------
/stateful-functions-docs/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. Copyright 2019 Ververica GmbH.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
15 | .. toctree::
16 | :hidden:
17 |
18 | overview/index
19 | getting_started/index
20 | api_concepts/index
21 | deployment_operations/index
22 | roadmap
23 | contribute
24 |
25 | ############################################
26 | Lightweight, Stateful Applications at Scale
27 | ############################################
28 |
29 | **Stateful Functions** is an open source framework that reduces the complexity of building and orchestrating distributed stateful applications at scale. It brings together the benefits of stream processing with Apache Flink® and Function-as-a-Service (FaaS) to provide a powerful abstraction for the next generation of event-driven architectures.
30 |
31 | .. image:: _static/images/stateful_functions.png
32 | :width: 85%
33 | :align: center
34 |
35 | .. raw:: html
36 | :file: index_grid.html
--------------------------------------------------------------------------------
/stateful-functions-docs/images/stateful_functions_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/images/stateful_functions_logo.png
--------------------------------------------------------------------------------
/stateful-functions-docs/images/stateful_functions_overview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-docs/images/stateful_functions_overview.png
--------------------------------------------------------------------------------
/stateful-functions-docs/requirements.txt:
--------------------------------------------------------------------------------
1 | six==1.11.0
2 | Sphinx==1.7.9
3 | sphinx-autobuild==0.7.1
4 | sphinx_rtd_theme==0.4.1
5 | sphinxcontrib-versioning==2.2.1
6 |
--------------------------------------------------------------------------------
/stateful-functions-docs/runtime.txt:
--------------------------------------------------------------------------------
1 | 3.7
2 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/BasicFunctionModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | import com.ververica.statefun.sdk.spi.StatefulFunctionModule;
20 | import java.util.Map;
21 |
22 | public class BasicFunctionModule implements StatefulFunctionModule {
23 |
24 | public void configure(Map globalConfiguration, Binder binder) {
25 |
26 | // Declare the user function and bind it to its type
27 | binder.bindFunctionProvider(FnWithDependency.TYPE, new CustomProvider());
28 |
29 | // Stateful functions that do not require any configuration
30 | // can declare their provider using java 8 lambda syntax
31 | binder.bindFunctionProvider(FnUser.TYPE, unused -> new FnUser());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/CustomProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | import com.ververica.statefun.docs.dependency.ProductionDependency;
20 | import com.ververica.statefun.docs.dependency.RuntimeDependency;
21 | import com.ververica.statefun.sdk.FunctionType;
22 | import com.ververica.statefun.sdk.StatefulFunction;
23 | import com.ververica.statefun.sdk.StatefulFunctionProvider;
24 |
25 | public class CustomProvider implements StatefulFunctionProvider {
26 |
27 | public StatefulFunction functionOfType(FunctionType type) {
28 | RuntimeDependency dependency = new ProductionDependency();
29 | return new FnWithDependency(dependency);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/FnCaller.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | import com.ververica.statefun.sdk.Context;
20 | import com.ververica.statefun.sdk.FunctionType;
21 | import com.ververica.statefun.sdk.StatefulFunction;
22 |
23 | /** A simple stateful function that sends a message to the user with id "user1" */
24 | public class FnCaller implements StatefulFunction {
25 |
26 | public static final FunctionType TYPE = new FunctionType("ververica", "caller");
27 |
28 | @Override
29 | public void invoke(Context context, Object input) {
30 | context.send(FnUser.TYPE, "user1", new MyUserMessage());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/FnHelloWorld.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | import com.ververica.statefun.sdk.Context;
20 | import com.ververica.statefun.sdk.StatefulFunction;
21 |
22 | public class FnHelloWorld implements StatefulFunction {
23 |
24 | @Override
25 | public void invoke(Context context, Object input) {
26 | System.out.println("Hello " + input.toString());
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/FnUser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | import com.ververica.statefun.sdk.Context;
20 | import com.ververica.statefun.sdk.FunctionType;
21 | import com.ververica.statefun.sdk.StatefulFunction;
22 |
23 | /** A simple function that says hello. */
24 | public class FnUser implements StatefulFunction {
25 |
26 | public static final FunctionType TYPE = new FunctionType("ververica", "user");
27 |
28 | @Override
29 | public void invoke(Context context, Object message) {
30 | String userId = context.self().id();
31 | System.out.println("Hello " + userId);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/FnWithDependency.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | import com.ververica.statefun.docs.dependency.RuntimeDependency;
20 | import com.ververica.statefun.sdk.Context;
21 | import com.ververica.statefun.sdk.FunctionType;
22 | import com.ververica.statefun.sdk.StatefulFunction;
23 |
24 | public class FnWithDependency implements StatefulFunction {
25 |
26 | static final FunctionType TYPE = new FunctionType("ververica", "fn-with-dep");
27 |
28 | private final RuntimeDependency dependency;
29 |
30 | public FnWithDependency(RuntimeDependency dependency) {
31 | this.dependency = dependency;
32 | }
33 |
34 | @Override
35 | public void invoke(Context context, Object input) {}
36 | }
37 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/FunctionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | import com.ververica.statefun.docs.dependency.RuntimeDependency;
20 | import com.ververica.statefun.docs.dependency.TestDependency;
21 | import org.junit.Assert;
22 | import org.junit.Test;
23 |
24 | public class FunctionTest {
25 |
26 | @Test
27 | public void testFunctionWithCustomDependency() {
28 | RuntimeDependency dependency = new TestDependency();
29 | FnWithDependency function = new FnWithDependency(dependency);
30 |
31 | Assert.assertEquals("It appears math is broken", 1 + 1, 2);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/MyUserMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs;
18 |
19 | class MyUserMessage {}
20 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/async/QueryService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.async;
18 |
19 | import java.util.concurrent.CompletableFuture;
20 |
21 | interface QueryService {
22 | CompletableFuture getDataAsync(String userId);
23 | }
24 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/async/User.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.async;
18 |
19 | final class User {
20 | String getUserId() {
21 | return "";
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/async/UserEnrichment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.async;
18 |
19 | final class UserEnrichment {}
20 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/delay/DelayedMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.delay;
18 |
19 | class DelayedMessage {}
20 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/delay/FnDelayedMessage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.delay;
18 |
19 | import com.ververica.statefun.sdk.Context;
20 | import com.ververica.statefun.sdk.StatefulFunction;
21 | import java.time.Duration;
22 |
23 | public class FnDelayedMessage implements StatefulFunction {
24 |
25 | @Override
26 | public void invoke(Context context, Object input) {
27 | if (input instanceof Message) {
28 | System.out.println("Hello");
29 | context.sendAfter(Duration.ofMinutes(1), context.self(), new DelayedMessage());
30 | }
31 |
32 | if (input instanceof DelayedMessage) {
33 | System.out.println("Welcome to the future!");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/delay/Message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.delay;
18 |
19 | class Message {}
20 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/dependency/ProductionDependency.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.dependency;
18 |
19 | public class ProductionDependency implements RuntimeDependency {}
20 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/dependency/RuntimeDependency.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.dependency;
18 |
19 | public interface RuntimeDependency {}
20 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/dependency/TestDependency.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.dependency;
18 |
19 | public class TestDependency implements RuntimeDependency {}
20 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/MissingImplementationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io;
18 |
19 | public class MissingImplementationException extends RuntimeException {
20 |
21 | public MissingImplementationException(String message) {
22 | super(message);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/custom/MyEgressSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.custom;
18 |
19 | import com.ververica.statefun.sdk.EgressType;
20 | import com.ververica.statefun.sdk.io.EgressIdentifier;
21 | import com.ververica.statefun.sdk.io.EgressSpec;
22 |
23 | public class MyEgressSpec implements EgressSpec {
24 |
25 | public static final EgressType TYPE = new EgressType("ververica", "my-egress");
26 |
27 | private final EgressIdentifier identifier;
28 |
29 | public MyEgressSpec(EgressIdentifier identifier) {
30 | this.identifier = identifier;
31 | }
32 |
33 | @Override
34 | public EgressType type() {
35 | return TYPE;
36 | }
37 |
38 | @Override
39 | public EgressIdentifier id() {
40 | return identifier;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/custom/MyIngressSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.custom;
18 |
19 | import com.ververica.statefun.sdk.IngressType;
20 | import com.ververica.statefun.sdk.io.IngressIdentifier;
21 | import com.ververica.statefun.sdk.io.IngressSpec;
22 |
23 | public class MyIngressSpec implements IngressSpec {
24 |
25 | public static final IngressType TYPE = new IngressType("ververica", "my-ingress");
26 |
27 | private final IngressIdentifier identifier;
28 |
29 | public MyIngressSpec(IngressIdentifier identifier) {
30 | this.identifier = identifier;
31 | }
32 |
33 | @Override
34 | public IngressType type() {
35 | return TYPE;
36 | }
37 |
38 | @Override
39 | public IngressIdentifier id() {
40 | return identifier;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/custom/flink/MyFlinkIoModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.custom.flink;
18 |
19 | import com.ververica.statefun.docs.io.custom.MyEgressSpec;
20 | import com.ververica.statefun.docs.io.custom.MyIngressSpec;
21 | import com.ververica.statefun.flink.io.spi.FlinkIoModule;
22 | import java.util.Map;
23 |
24 | public final class MyFlinkIoModule implements FlinkIoModule {
25 |
26 | @Override
27 | public void configure(Map globalConfiguration, Binder binder) {
28 | binder.bindSourceProvider(MyIngressSpec.TYPE, new MySourceProvider());
29 | binder.bindSinkProvider(MyEgressSpec.TYPE, new MySinkProvider());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/custom/flink/sink/MySinkFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.custom.flink.sink;
18 |
19 | import org.apache.flink.streaming.api.functions.sink.SinkFunction;
20 |
21 | public class MySinkFunction implements SinkFunction {
22 |
23 | @Override
24 | public void invoke(T value, Context context) {}
25 | }
26 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/custom/flink/source/MySourceFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.custom.flink.source;
18 |
19 | import org.apache.flink.streaming.api.functions.source.SourceFunction;
20 |
21 | public class MySourceFunction implements SourceFunction {
22 |
23 | @Override
24 | public void run(SourceContext ctx) throws Exception {}
25 |
26 | @Override
27 | public void cancel() {}
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/egress/FnOutputting.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.egress;
18 |
19 | import com.ververica.statefun.docs.models.User;
20 | import com.ververica.statefun.sdk.Context;
21 | import com.ververica.statefun.sdk.StatefulFunction;
22 |
23 | /** A simple function that outputs messages to an egress. */
24 | public class FnOutputting implements StatefulFunction {
25 |
26 | @Override
27 | public void invoke(Context context, Object input) {
28 | context.send(Identifiers.EGRESS, new User());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/egress/Identifiers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.egress;
18 |
19 | import com.ververica.statefun.docs.models.User;
20 | import com.ververica.statefun.sdk.io.EgressIdentifier;
21 |
22 | public final class Identifiers {
23 |
24 | public static final EgressIdentifier EGRESS =
25 | new EgressIdentifier<>("ververica", "egress", User.class);
26 | }
27 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/egress/ModuleWithEgress.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.egress;
18 |
19 | import com.ververica.statefun.docs.io.MissingImplementationException;
20 | import com.ververica.statefun.docs.models.User;
21 | import com.ververica.statefun.sdk.io.EgressIdentifier;
22 | import com.ververica.statefun.sdk.io.EgressSpec;
23 | import com.ververica.statefun.sdk.spi.StatefulFunctionModule;
24 | import java.util.Map;
25 |
26 | public class ModuleWithEgress implements StatefulFunctionModule {
27 |
28 | @Override
29 | public void configure(Map globalConfiguration, Binder binder) {
30 | EgressSpec spec = createEgress(Identifiers.EGRESS);
31 | binder.bindEgress(spec);
32 | }
33 |
34 | public EgressSpec createEgress(EgressIdentifier identifier) {
35 | throw new MissingImplementationException("Replace with your specific egress");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/flink/FlinkSink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.flink;
18 |
19 | import org.apache.flink.streaming.api.functions.sink.SinkFunction;
20 |
21 | public class FlinkSink implements SinkFunction {}
22 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/flink/FlinkSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.flink;
18 |
19 | import org.apache.flink.streaming.api.functions.source.SourceFunction;
20 |
21 | public class FlinkSource implements SourceFunction {
22 | @Override
23 | public void run(SourceContext ctx) throws Exception {}
24 |
25 | @Override
26 | public void cancel() {}
27 | }
28 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/flink/ModuleWithSinkSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.flink;
18 |
19 | import com.ververica.statefun.docs.models.User;
20 | import com.ververica.statefun.flink.io.datastream.SinkFunctionSpec;
21 | import com.ververica.statefun.sdk.io.EgressIdentifier;
22 | import com.ververica.statefun.sdk.io.EgressSpec;
23 | import com.ververica.statefun.sdk.spi.StatefulFunctionModule;
24 | import java.util.Map;
25 |
26 | public class ModuleWithSinkSpec implements StatefulFunctionModule {
27 |
28 | @Override
29 | public void configure(Map globalConfiguration, Binder binder) {
30 | EgressIdentifier id = new EgressIdentifier<>("ververica", "user", User.class);
31 | EgressSpec spec = new SinkFunctionSpec<>(id, new FlinkSink<>());
32 | binder.bindEgress(spec);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/flink/ModuleWithSourceSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.flink;
18 |
19 | import com.ververica.statefun.docs.models.User;
20 | import com.ververica.statefun.flink.io.datastream.SourceFunctionSpec;
21 | import com.ververica.statefun.sdk.io.IngressIdentifier;
22 | import com.ververica.statefun.sdk.io.IngressSpec;
23 | import com.ververica.statefun.sdk.spi.StatefulFunctionModule;
24 | import java.util.Map;
25 |
26 | public class ModuleWithSourceSpec implements StatefulFunctionModule {
27 |
28 | @Override
29 | public void configure(Map globalConfiguration, Binder binder) {
30 | IngressIdentifier id = new IngressIdentifier<>(User.class, "ververica", "users");
31 | IngressSpec spec = new SourceFunctionSpec<>(id, new FlinkSource<>());
32 | binder.bindIngress(spec);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/ingress/Identifiers.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.ingress;
18 |
19 | import com.ververica.statefun.docs.models.User;
20 | import com.ververica.statefun.sdk.io.IngressIdentifier;
21 |
22 | public final class Identifiers {
23 |
24 | public static final IngressIdentifier INGRESS =
25 | new IngressIdentifier<>(User.class, "ververica", "user-ingress");
26 | }
27 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/ingress/ModuleWithIngress.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.ingress;
18 |
19 | import com.ververica.statefun.docs.io.MissingImplementationException;
20 | import com.ververica.statefun.docs.models.User;
21 | import com.ververica.statefun.sdk.io.IngressIdentifier;
22 | import com.ververica.statefun.sdk.io.IngressSpec;
23 | import com.ververica.statefun.sdk.spi.StatefulFunctionModule;
24 | import java.util.Map;
25 |
26 | public class ModuleWithIngress implements StatefulFunctionModule {
27 |
28 | @Override
29 | public void configure(Map globalConfiguration, Binder binder) {
30 | IngressSpec spec = createIngress(Identifiers.INGRESS);
31 | binder.bindIngress(spec);
32 | }
33 |
34 | private IngressSpec createIngress(IngressIdentifier identifier) {
35 | throw new MissingImplementationException("Replace with your specific ingress");
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/ingress/UserRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.ingress;
18 |
19 | import com.ververica.statefun.docs.FnUser;
20 | import com.ververica.statefun.docs.models.User;
21 | import com.ververica.statefun.sdk.io.Router;
22 |
23 | public class UserRouter implements Router {
24 |
25 | @Override
26 | public void route(User message, Downstream downstream) {
27 | downstream.forward(FnUser.TYPE, message.getUserId(), message);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/kafka/EgressSpecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.kafka;
18 |
19 | import com.ververica.statefun.docs.models.User;
20 | import com.ververica.statefun.sdk.io.EgressIdentifier;
21 | import com.ververica.statefun.sdk.io.EgressSpec;
22 | import com.ververica.statefun.sdk.kafka.KafkaEgressBuilder;
23 |
24 | public class EgressSpecs {
25 |
26 | public static final EgressIdentifier ID =
27 | new EgressIdentifier<>("ververica", "output-egress", User.class);
28 |
29 | public static final EgressSpec kafkaEgress =
30 | KafkaEgressBuilder.forIdentifier(ID)
31 | .withKafkaAddress("localhost:9092")
32 | .withSerializer(UserSerializer.class)
33 | .build();
34 | }
35 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/io/kafka/IngressSpecs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.io.kafka;
18 |
19 | import com.ververica.statefun.docs.models.User;
20 | import com.ververica.statefun.sdk.io.IngressIdentifier;
21 | import com.ververica.statefun.sdk.io.IngressSpec;
22 | import com.ververica.statefun.sdk.kafka.KafkaIngressBuilder;
23 | import org.apache.kafka.clients.consumer.ConsumerConfig;
24 |
25 | public class IngressSpecs {
26 |
27 | public static final IngressIdentifier ID =
28 | new IngressIdentifier<>(User.class, "ververica", "input-ingress");
29 |
30 | public static final IngressSpec kafkaIngress =
31 | KafkaIngressBuilder.forIdentifier(ID)
32 | .withKafkaAddress("localhost:9092")
33 | .withTopic("my-topic")
34 | .withDeserializer(UserDeserializer.class)
35 | .withProperty(ConsumerConfig.GROUP_ID_CONFIG, "greetings")
36 | .build();
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/match/Customer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.match;
18 |
19 | class Customer {
20 |
21 | String getName() {
22 | return "";
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/match/Employee.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.match;
18 |
19 | class Employee {
20 |
21 | String getEmployeeId() {
22 | return "";
23 | }
24 |
25 | boolean isManager() {
26 | return true;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-docs/src/main/java/com/ververica/statefun/docs/models/User.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.docs.models;
18 |
19 | /** A dummy message type. */
20 | public class User {
21 |
22 | private String userId;
23 |
24 | private String name;
25 |
26 | private long birthday;
27 |
28 | public String getUserId() {
29 | return userId;
30 | }
31 |
32 | public void setUserId(String userId) {
33 | this.userId = userId;
34 | }
35 |
36 | public String getName() {
37 | return name;
38 | }
39 |
40 | public void setName(String name) {
41 | this.name = name;
42 | }
43 |
44 | public long getBirthday() {
45 | return birthday;
46 | }
47 |
48 | public void setBirthday(long birthday) {
49 | this.birthday = birthday;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-async-example/src/main/java/com/ververica/statefun/examples/async/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.async;
18 |
19 | import com.ververica.statefun.examples.async.events.TaskCompletionEvent;
20 | import com.ververica.statefun.examples.async.events.TaskStartedEvent;
21 | import com.ververica.statefun.sdk.io.EgressIdentifier;
22 | import com.ververica.statefun.sdk.io.IngressIdentifier;
23 |
24 | final class Constants {
25 |
26 | static final IngressIdentifier REQUEST_INGRESS =
27 | new IngressIdentifier<>(
28 | TaskStartedEvent.class, "com.ververica.statefun.examples.async", "tasks");
29 |
30 | static final EgressIdentifier RESULT_EGRESS =
31 | new EgressIdentifier<>(
32 | "com.ververica.statefun.examples.async", "out", TaskCompletionEvent.class);
33 | }
34 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-async-example/src/main/java/com/ververica/statefun/examples/async/events/TaskCompletionEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.async.events;
18 |
19 | /** A message represents an event of a task completion. */
20 | public final class TaskCompletionEvent {
21 | private final String taskId;
22 | private final Long startTime;
23 | private final Long endTime;
24 |
25 | public TaskCompletionEvent(String taskId, Long startTime, Long endTime) {
26 | this.taskId = taskId;
27 | this.startTime = startTime;
28 | this.endTime = endTime;
29 | }
30 |
31 | public String getTaskId() {
32 | return taskId;
33 | }
34 |
35 | public Long getStartTime() {
36 | return startTime;
37 | }
38 |
39 | public Long getEndTime() {
40 | return endTime;
41 | }
42 |
43 | @Override
44 | public String toString() {
45 | return String.format("TaskCompletionEvent(id: %s, duration: %d)", taskId, endTime - startTime);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-async-example/src/main/java/com/ververica/statefun/examples/async/events/TaskStartedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.async.events;
18 |
19 | /** A message represents an event of a new task was created. A task has an id and a startingTime. */
20 | public final class TaskStartedEvent {
21 | private final String taskId;
22 | private final Long startTime;
23 |
24 | public TaskStartedEvent(String taskId, Long startTime) {
25 | this.taskId = taskId;
26 | this.startTime = startTime;
27 | }
28 |
29 | public String getTaskId() {
30 | return taskId;
31 | }
32 |
33 | public Long getStartTime() {
34 | return startTime;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-async-example/src/main/java/com/ververica/statefun/examples/async/service/TaskQueryService.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.async.service;
18 |
19 | import java.util.concurrent.CompletableFuture;
20 |
21 | /** A remote service that keeps task status by id. */
22 | public interface TaskQueryService {
23 |
24 | /**
25 | * Retrieves a {@link TaskStatus} of a task with an @taskId.
26 | *
27 | * @param taskId the task to retrieves it's status
28 | * @return the status of the task.
29 | */
30 | CompletableFuture getTaskStatusAsync(String taskId);
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-async-example/src/main/java/com/ververica/statefun/examples/async/service/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * This package represents a fictions service that needs to compute something asynchronously. In
19 | * this example, a query service keeps tack of tasks that are executed elsewhere (perhaps some
20 | * worker pool outside of the application) see: {@link
21 | * com.ververica.statefun.examples.async.service.TaskQueryService}. In reality, functions might want
22 | * to compute something asynchronously like sending an http request, querying a remote database, or
23 | * anything really that needs some time to complete.
24 | */
25 | package com.ververica.statefun.examples.async.service;
26 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-flink-harness-example/README.md:
--------------------------------------------------------------------------------
1 | # Using the Flink Harness to run Stateful Functions applications in the IDE
2 |
3 | This is a simple example to demonstrate how one would run Stateful Functions application in the IDE using the
4 | provided Flink Harness.
5 |
6 | Take a look at the `com.ververica.statefun.examples.harness.RunnerTest` class to see example usages of `Harness`.
7 |
8 | ## Running the example
9 |
10 | Simply run the `com.ververica.statefun.examples.harness.RunnerTest` class.
11 |
12 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-flink-harness-example/src/main/java/com/ververica/statefun/examples/harness/MyFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.harness;
18 |
19 | import com.ververica.statefun.examples.harness.MyMessages.MyInputMessage;
20 | import com.ververica.statefun.examples.harness.MyMessages.MyOutputMessage;
21 | import com.ververica.statefun.sdk.Context;
22 | import com.ververica.statefun.sdk.StatefulFunction;
23 |
24 | final class MyFunction implements StatefulFunction {
25 |
26 | @Override
27 | public void invoke(Context context, Object input) {
28 | if (!(input instanceof MyInputMessage)) {
29 | throw new IllegalArgumentException("Unknown message received " + input);
30 | }
31 | MyInputMessage in = (MyInputMessage) input;
32 | MyOutputMessage out = new MyOutputMessage(in.getUserId(), in.getMessage());
33 |
34 | context.send(MyConstants.RESULT_EGRESS, out);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-flink-harness-example/src/main/java/com/ververica/statefun/examples/harness/MyModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.harness;
18 |
19 | import com.google.auto.service.AutoService;
20 | import com.ververica.statefun.sdk.spi.StatefulFunctionModule;
21 | import java.util.Map;
22 |
23 | @AutoService(StatefulFunctionModule.class)
24 | public class MyModule implements StatefulFunctionModule {
25 |
26 | @Override
27 | public void configure(Map globalConfiguration, Binder binder) {
28 | binder.bindIngressRouter(MyConstants.REQUEST_INGRESS, new MyRouter());
29 | binder.bindFunctionProvider(MyConstants.MY_FUNCTION_TYPE, unused -> new MyFunction());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-flink-harness-example/src/main/java/com/ververica/statefun/examples/harness/MyRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.harness;
18 |
19 | import com.ververica.statefun.examples.harness.MyMessages.MyInputMessage;
20 | import com.ververica.statefun.sdk.io.Router;
21 |
22 | final class MyRouter implements Router {
23 |
24 | @Override
25 | public void route(MyInputMessage message, Downstream downstream) {
26 | downstream.forward(MyConstants.MY_FUNCTION_TYPE, message.getUserId(), message);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/Dockerfile:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | FROM stateful-functions
18 |
19 | RUN mkdir -p /opt/stateful-functions/modules/stateful-functions-greeter-example
20 | COPY target/stateful-functions-greeter-example*jar /opt/stateful-functions/modules/stateful-functions-greeter-example/
21 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/README.md:
--------------------------------------------------------------------------------
1 | # The Greeter Example
2 |
3 | This is a simple example that runs a simple stateful function that accepts requests from a Kafka ingress,
4 | and then responds by sending greeting responses to a Kafka egress. It demonstrates the primitive building blocks
5 | of a Stateful Functions applications, such as ingresses, routing messages to functions, handling state in functions,
6 | and sending messages to egresses.
7 |
8 | ## Running the example
9 |
10 | To run the example:
11 |
12 | ```
13 | docker-compose build
14 | docker-compose up
15 | ```
16 |
17 | Then, to see the example in actions, send some messages to the topic `names`, and see what comes out
18 | out of the topic `greetings`:
19 |
20 | ```
21 | docker-compose exec kafka-broker kafka-console-producer.sh \
22 | --broker-list localhost:9092 \
23 | --topic names
24 | ```
25 |
26 | ```
27 | docker-compose exec kafka-broker kafka-console-consumer.sh \
28 | --bootstrap-server localhost:9092 \
29 | --topic greetings --from-beginning
30 | ```
31 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/k8s/master-rest-service.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | apiVersion: v1
17 | kind: Service
18 | metadata:
19 | name: statefun-master-rest
20 | spec:
21 | type: NodePort
22 | ports:
23 | - name: rest
24 | port: 8081
25 | targetPort: 8081
26 | selector:
27 | app: statefun
28 | component: master
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/k8s/master-service.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | apiVersion: v1
17 | kind: Service
18 | metadata:
19 | name: statefun-master
20 | spec:
21 | type: ClusterIP
22 | ports:
23 | - name: rpc
24 | port: 6123
25 | - name: blob
26 | port: 6124
27 | - name: ui
28 | port: 8081
29 | selector:
30 | app: statefun
31 | component: master
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/src/main/java/com/ververica/statefun/examples/greeter/GreetRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.greeter;
18 |
19 | import com.ververica.statefun.examples.greeter.generated.GreetRequest;
20 | import com.ververica.statefun.sdk.io.Router;
21 |
22 | /**
23 | * The greet router takes each message from an ingress and routes it to a greeter function based on
24 | * the users id.
25 | */
26 | final class GreetRouter implements Router {
27 |
28 | @Override
29 | public void route(GreetRequest message, Downstream downstream) {
30 | downstream.forward(GreetStatefulFunction.TYPE, message.getWho(), message);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/src/main/java/com/ververica/statefun/examples/greeter/generated/GreetRequestOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/greeter.proto
3 |
4 | package com.ververica.statefun.examples.greeter.generated;
5 |
6 | public interface GreetRequestOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.kafka.GreetRequest)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string who = 1;
*/
12 | java.lang.String getWho();
13 | /** string who = 1;
*/
14 | com.google.protobuf.ByteString getWhoBytes();
15 | }
16 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/src/main/java/com/ververica/statefun/examples/greeter/generated/GreetResponseOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/greeter.proto
3 |
4 | package com.ververica.statefun.examples.greeter.generated;
5 |
6 | public interface GreetResponseOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.kafka.GreetResponse)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string who = 1;
*/
12 | java.lang.String getWho();
13 | /** string who = 1;
*/
14 | com.google.protobuf.ByteString getWhoBytes();
15 |
16 | /** string greeting = 2;
*/
17 | java.lang.String getGreeting();
18 | /** string greeting = 2;
*/
19 | com.google.protobuf.ByteString getGreetingBytes();
20 | }
21 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-greeter-example/src/main/protobuf/greeter.proto:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2019 Ververica GmbH.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | syntax = "proto3";
18 |
19 | package com.ververica.statefun.examples.kafka;
20 | option java_package = "com.ververica.statefun.examples.greeter.generated";
21 | option java_multiple_files = true;
22 |
23 | message GreetRequest {
24 | string who = 1;
25 | }
26 |
27 | message GreetResponse {
28 | string who = 1;
29 | string greeting = 2;
30 | }
31 |
32 |
33 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/Dockerfile.functions:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Ververica GmbH.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | FROM stateful-functions
16 |
17 | RUN mkdir -p /opt/stateful-functions/modules/stateful-functions-ridesharing-example
18 | COPY stateful-functions-ridesharing-example-functions/target/stateful-functions-ridesharing-example*jar /opt/stateful-functions/modules/stateful-functions-ridesharing-example/
19 | COPY stateful-functions-ridesharing-protocol/target/stateful-functions-ridesharing-protocol*jar /opt/stateful-functions/modules/stateful-functions-ridesharing-example/
20 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/README.md:
--------------------------------------------------------------------------------
1 | # The Ridesharing Example
2 |
3 | The Ridesharing example is a more complicated Stateful Functions example consisting of 4 different functions, each
4 | corresponding to a real-world entity in a ridesharing scenario: `FnDriver`, `FnGeoCell`, `FnPassenger`, and `FnRide`.
5 |
6 | The whole example also includes a simulator program, which simulates real-world drivers and passengers sending
7 | events to the Stateful Functions application. Driver simulations will be sending their location updates to the
8 | application, while passenger simulations will be sending ride requests.
9 |
10 | ## Running the example
11 |
12 | To run the example:
13 |
14 | ```
15 | docker-compose build
16 | docker-compose up
17 | ```
18 |
19 | This starts both the simulator program and Stateful Functions ridesharing example application.
20 |
21 | After all the components have fully started, you can take a look at the web UI of the Flink Jobmanager to see the
22 | application running, at `localhost:8081`.
23 |
24 | Then, you need to issue a request to the simulator program to start the simulation:
25 |
26 | ```
27 | curl -X POST localhost:5656/api/start
28 | ```
29 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
20 |
21 | stateful-functions-examples
22 | com.ververica
23 | 1.1-SNAPSHOT
24 | ..
25 |
26 | 4.0.0
27 | pom
28 |
29 | stateful-functions-ridesharing-example
30 |
31 |
32 | stateful-functions-ridesharing-protocol
33 | stateful-functions-ridesharing-example-functions
34 | stateful-functions-ridesharing-example-simulator
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-functions/src/main/java/com/ververica/statefun/examples/ridesharing/InboundDriverRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing;
18 |
19 | import com.ververica.statefun.examples.ridesharing.generated.InboundDriverMessage;
20 | import com.ververica.statefun.sdk.io.Router;
21 |
22 | public class InboundDriverRouter implements Router {
23 |
24 | @Override
25 | public void route(InboundDriverMessage message, Downstream downstream) {
26 | downstream.forward(FnDriver.TYPE, message.getDriverId(), message);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-functions/src/main/java/com/ververica/statefun/examples/ridesharing/InboundPassengerRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing;
18 |
19 | import com.ververica.statefun.examples.ridesharing.generated.InboundPassengerMessage;
20 | import com.ververica.statefun.sdk.io.Router;
21 |
22 | public class InboundPassengerRouter implements Router {
23 |
24 | @Override
25 | public void route(
26 | InboundPassengerMessage message, Downstream downstream) {
27 | downstream.forward(FnPassenger.TYPE, message.getPassengerId(), message);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/Dockerfile:
--------------------------------------------------------------------------------
1 | # Start with a base image containing Java runtime
2 | FROM eclipse-temurin:8-jdk-alpine
3 |
4 | # Add a volume pointing to /tmp
5 | VOLUME /tmp
6 |
7 | # Make port 5656 available to the world outside this container
8 | EXPOSE 5656
9 |
10 | ADD target/*-simulator-*.jar simulator.jar
11 | ADD application.yaml application.yaml
12 |
13 | # Run the jar file
14 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-Dspring.profiles.active=dev","-Dspring.config.location=file:/application.yaml","-jar","/simulator.jar"]
15 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/application.yaml:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Ververica GmbH.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | server:
16 | port: 5656
17 |
18 | security.auth.enabled: false
19 | security.basic.enable: false
20 | security.ignored: /**
21 |
22 | simulation:
23 | grid: 50
24 | drivers: 2500
25 | passengers: 10
26 |
27 | kafka:
28 | topic:
29 | from-driver: from-driver
30 | to-driver: to-driver
31 | from-passenger: from-passenger
32 | to-passenger: to-passenger
33 | listeners:
34 | transactions.id: simulator-java-listener
35 | bootstrap-servers: kafka-broker:9092
36 |
37 | web-socket:
38 | topic:
39 | passenger: /topic/passenger
40 | driver: /topic/driver
41 |
42 | management.endpoints.web.exposure.include: mappings, loggers
43 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/src/main/java/com/ververica/statefun/examples/ridesharing/simulator/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing.simulator;
18 |
19 | import org.springframework.boot.SpringApplication;
20 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
21 | import org.springframework.boot.autoconfigure.SpringBootApplication;
22 | import org.springframework.context.annotation.ComponentScan;
23 |
24 | @SpringBootApplication
25 | @EnableAutoConfiguration
26 | @ComponentScan("com.ververica")
27 | public class Main {
28 | public static void main(String[] args) {
29 | SpringApplication.run(Main.class, args);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/src/main/java/com/ververica/statefun/examples/ridesharing/simulator/model/SimulationStartedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing.simulator.model;
18 |
19 | import lombok.AllArgsConstructor;
20 | import lombok.Builder;
21 | import lombok.Data;
22 | import lombok.NoArgsConstructor;
23 |
24 | @Data
25 | @Builder
26 | @NoArgsConstructor
27 | @AllArgsConstructor
28 | public class SimulationStartedEvent {
29 |
30 | boolean started;
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/src/main/java/com/ververica/statefun/examples/ridesharing/simulator/model/WebsocketDriverEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing.simulator.model;
18 |
19 | import lombok.AllArgsConstructor;
20 | import lombok.Builder;
21 | import lombok.Data;
22 | import lombok.NoArgsConstructor;
23 |
24 | @Data
25 | @Builder
26 | @NoArgsConstructor
27 | @AllArgsConstructor
28 | public class WebsocketDriverEvent {
29 | String driverId;
30 | int currentLocation;
31 | DriverStatus driverStatus;
32 | RideInformation ride;
33 |
34 | public enum DriverStatus {
35 | IDLE,
36 | PICKUP,
37 | ENROUTE,
38 | RIDE_COMPLETED
39 | }
40 |
41 | @Data
42 | @Builder
43 | @NoArgsConstructor
44 | @AllArgsConstructor
45 | public static class RideInformation {
46 | String passengerId;
47 | int pickupLocation;
48 | int dropoffLocation;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/src/main/java/com/ververica/statefun/examples/ridesharing/simulator/model/WebsocketPassengerEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing.simulator.model;
18 |
19 | import lombok.AllArgsConstructor;
20 | import lombok.Builder;
21 | import lombok.Data;
22 | import lombok.NoArgsConstructor;
23 |
24 | @Data
25 | @Builder
26 | @NoArgsConstructor
27 | @AllArgsConstructor
28 | public class WebsocketPassengerEvent {
29 | String passengerId;
30 | PassengerStatus status;
31 | String rideId;
32 | String driverId;
33 | int startLocation;
34 | int endLocation;
35 |
36 | public enum PassengerStatus {
37 | IDLE,
38 | REQUESTING,
39 | WAITING_FOR_RIDE_TO_START,
40 | FAIL,
41 | RIDING,
42 | DONE
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/src/main/java/com/ververica/statefun/examples/ridesharing/simulator/simulation/engine/DaemonThreadFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing.simulator.simulation.engine;
18 |
19 | import java.util.concurrent.ThreadFactory;
20 | import javax.annotation.Nonnull;
21 |
22 | public enum DaemonThreadFactory implements ThreadFactory {
23 | INSTANCE;
24 |
25 | @Override
26 | public Thread newThread(@Nonnull Runnable r) {
27 | Thread t = new Thread(r);
28 | t.setDaemon(true);
29 | return t;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/src/main/java/com/ververica/statefun/examples/ridesharing/simulator/simulation/engine/LifecycleMessages.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing.simulator.simulation.engine;
18 |
19 | public final class LifecycleMessages {
20 | private LifecycleMessages() {}
21 |
22 | static Initialization initialization() {
23 | return Initialization.INSTANCE;
24 | }
25 |
26 | static TimeTick timeTick() {
27 | return TimeTick.INSTANCE;
28 | }
29 |
30 | public enum Initialization {
31 | INSTANCE
32 | }
33 |
34 | public enum TimeTick {
35 | INSTANCE
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-example-simulator/src/main/java/com/ververica/statefun/examples/ridesharing/simulator/simulation/engine/Simulatee.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.ridesharing.simulator.simulation.engine;
18 |
19 | public interface Simulatee {
20 |
21 | String id();
22 |
23 | void apply(Object event);
24 |
25 | boolean isDone();
26 |
27 | boolean needReschedule();
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
20 |
21 | stateful-functions-ridesharing-example
22 | com.ververica
23 | 1.1-SNAPSHOT
24 |
25 | 4.0.0
26 |
27 | stateful-functions-ridesharing-protocol
28 |
29 |
30 |
31 | com.google.protobuf
32 | protobuf-java
33 | 3.8.0
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/DriverInCellOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface DriverInCellOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.DriverInCell)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string driver_id = 1;
*/
12 | java.lang.String getDriverId();
13 | /** string driver_id = 1;
*/
14 | com.google.protobuf.ByteString getDriverIdBytes();
15 | }
16 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/DriverJoinsRideOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface DriverJoinsRideOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.DriverJoinsRide)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string driver_id = 1;
*/
12 | java.lang.String getDriverId();
13 | /** string driver_id = 1;
*/
14 | com.google.protobuf.ByteString getDriverIdBytes();
15 |
16 | /** string passenger_id = 2;
*/
17 | java.lang.String getPassengerId();
18 | /** string passenger_id = 2;
*/
19 | com.google.protobuf.ByteString getPassengerIdBytes();
20 |
21 | /** int32 driver_location = 3;
*/
22 | int getDriverLocation();
23 | }
24 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/DriverRejectsPickupOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface DriverRejectsPickupOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.DriverRejectsPickup)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string driver_id = 1;
*/
12 | java.lang.String getDriverId();
13 | /** string driver_id = 1;
*/
14 | com.google.protobuf.ByteString getDriverIdBytes();
15 |
16 | /** string ride_id = 2;
*/
17 | java.lang.String getRideId();
18 | /** string ride_id = 2;
*/
19 | com.google.protobuf.ByteString getRideIdBytes();
20 | }
21 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/GeoCellStateOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface GeoCellStateOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.GeoCellState)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** repeated string driver_id = 1;
*/
12 | java.util.List getDriverIdList();
13 | /** repeated string driver_id = 1;
*/
14 | int getDriverIdCount();
15 | /** repeated string driver_id = 1;
*/
16 | java.lang.String getDriverId(int index);
17 | /** repeated string driver_id = 1;
*/
18 | com.google.protobuf.ByteString getDriverIdBytes(int index);
19 | }
20 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/GetDriverOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface GetDriverOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.GetDriver)
9 | com.google.protobuf.MessageOrBuilder {}
10 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/JoinCellOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface JoinCellOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.JoinCell)
9 | com.google.protobuf.MessageOrBuilder {}
10 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/LeaveCellOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface LeaveCellOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.LeaveCell)
9 | com.google.protobuf.MessageOrBuilder {}
10 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/PassengerJoinsRideOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface PassengerJoinsRideOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.PassengerJoinsRide)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string passenger_id = 1;
*/
12 | java.lang.String getPassengerId();
13 | /** string passenger_id = 1;
*/
14 | com.google.protobuf.ByteString getPassengerIdBytes();
15 |
16 | /** int32 start_geo_cell = 2;
*/
17 | int getStartGeoCell();
18 |
19 | /** int32 end_geo_cell = 3;
*/
20 | int getEndGeoCell();
21 | }
22 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/PickupPassengerOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface PickupPassengerOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.PickupPassenger)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string driver_id = 1;
*/
12 | java.lang.String getDriverId();
13 | /** string driver_id = 1;
*/
14 | com.google.protobuf.ByteString getDriverIdBytes();
15 |
16 | /** string passenger_id = 2;
*/
17 | java.lang.String getPassengerId();
18 | /** string passenger_id = 2;
*/
19 | com.google.protobuf.ByteString getPassengerIdBytes();
20 |
21 | /** int32 passenger_start_cell = 3;
*/
22 | int getPassengerStartCell();
23 |
24 | /** int32 passenger_end_cell = 4;
*/
25 | int getPassengerEndCell();
26 | }
27 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/RideEndedOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface RideEndedOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.RideEnded)
9 | com.google.protobuf.MessageOrBuilder {}
10 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/RideFailedOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface RideFailedOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.RideFailed)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string ride_id = 1;
*/
12 | java.lang.String getRideId();
13 | /** string ride_id = 1;
*/
14 | com.google.protobuf.ByteString getRideIdBytes();
15 | }
16 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-ridesharing-example/stateful-functions-ridesharing-protocol/src/main/java/com/ververica/statefun/examples/ridesharing/generated/RideStartedOrBuilder.java:
--------------------------------------------------------------------------------
1 | // Generated by the protocol buffer compiler. DO NOT EDIT!
2 | // source: src/main/protobuf/ridesharing.proto
3 |
4 | package com.ververica.statefun.examples.ridesharing.generated;
5 |
6 | public interface RideStartedOrBuilder
7 | extends
8 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.examples.ridesharing.RideStarted)
9 | com.google.protobuf.MessageOrBuilder {
10 |
11 | /** string driver_id = 1;
*/
12 | java.lang.String getDriverId();
13 | /** string driver_id = 1;
*/
14 | com.google.protobuf.ByteString getDriverIdBytes();
15 |
16 | /** int32 driver_geo_cell = 2;
*/
17 | int getDriverGeoCell();
18 | }
19 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-shopping-cart-example/Dockerfile:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | FROM stateful-functions
18 |
19 | RUN mkdir -p /opt/stateful-functions/modules/stateful-functions-shopping-cart-example
20 | COPY target/stateful-functions-shopping-cart-example*jar /opt/stateful-functions/modules/stateful-functions-shopping-cart-example/
21 |
--------------------------------------------------------------------------------
/stateful-functions-examples/stateful-functions-shopping-cart-example/src/main/java/com/ververica/statefun/examples/shoppingcart/RestockRouter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.examples.shoppingcart;
18 |
19 | import com.ververica.statefun.examples.shoppingcart.generated.ProtobufMessages.RestockItem;
20 | import com.ververica.statefun.sdk.io.Router;
21 |
22 | final class RestockRouter implements Router {
23 | @Override
24 | public void route(RestockItem message, Downstream downstream) {
25 | downstream.forward(Identifiers.INVENTORY, message.getItemId(), message);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/main/java/com/ververica/statefun/flink/common/SetContextClassLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.common;
18 |
19 | import java.io.Closeable;
20 | import javax.annotation.Nonnull;
21 |
22 | public final class SetContextClassLoader implements Closeable {
23 | private final ClassLoader originalClassLoader;
24 |
25 | public SetContextClassLoader(@Nonnull Object o) {
26 | this(o.getClass().getClassLoader());
27 | }
28 |
29 | public SetContextClassLoader(@Nonnull ClassLoader classLoader) {
30 | this.originalClassLoader = Thread.currentThread().getContextClassLoader();
31 | Thread.currentThread().setContextClassLoader(classLoader);
32 | }
33 |
34 | @Override
35 | public void close() {
36 | Thread.currentThread().setContextClassLoader(originalClassLoader);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/main/java/com/ververica/statefun/flink/common/json/MissingKeyException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.common.json;
17 |
18 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonPointer;
19 |
20 | public class MissingKeyException extends RuntimeException {
21 |
22 | private static final long serialVersionUID = 1;
23 |
24 | public MissingKeyException(JsonPointer pointer) {
25 | super("missing key " + pointer.toString());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/main/java/com/ververica/statefun/flink/common/json/WrongTypeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.common.json;
17 |
18 | import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonPointer;
19 |
20 | public class WrongTypeException extends RuntimeException {
21 |
22 | private static final long serialVersionUID = 1;
23 |
24 | public WrongTypeException(JsonPointer pointer, String message) {
25 | super("Wrong type for key " + pointer + " " + message);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/main/java/com/ververica/statefun/flink/common/protopath/PathFragmentDescriptor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.common.protopath;
17 |
18 | import com.google.protobuf.Descriptors;
19 | import com.google.protobuf.Message;
20 | import java.util.Objects;
21 |
22 | final class PathFragmentDescriptor {
23 | private final Descriptors.FieldDescriptor descriptor;
24 | private final PathFragment pathFragment;
25 |
26 | PathFragmentDescriptor(Descriptors.FieldDescriptor descriptor, PathFragment pathFragment) {
27 | this.descriptor = Objects.requireNonNull(descriptor);
28 | this.pathFragment = Objects.requireNonNull(pathFragment);
29 | }
30 |
31 | Object value(Message message) {
32 | int index = pathFragment.getIndex();
33 | if (index >= 0) {
34 | return message.getRepeatedField(descriptor, index);
35 | }
36 | return message.getField(descriptor);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/main/protobuf/serializer.proto:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2019 Ververica GmbH.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | syntax = "proto3";
18 |
19 | package com.ververica.statefun.flink.common;
20 | option java_package = "com.ververica.statefun.flink.common.generated";
21 | option java_multiple_files = true;
22 |
23 | import "google/protobuf/descriptor.proto";
24 |
25 | message ProtobufSerializerSnapshot {
26 | string generated_java_name = 1;
27 | string message_name = 2;
28 |
29 | google.protobuf.FileDescriptorSet descriptor_set = 3;
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/test/resources/dummy-file.txt:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | this is a file used in a ResourceLocatorTest
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/test/resources/foo-module/module.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | module:
17 | meta:
18 | type: remote
19 | spec:
20 | functions:
21 | function:
22 | meta:
23 | type: com.example/hello
24 | spec:
25 | host: localhost
26 | port: 5000
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-common/src/test/resources/test-descriptors.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-flink/stateful-functions-flink-common/src/test/resources/test-descriptors.bin
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/StatefulFunctionsUniverseProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core;
18 |
19 | import java.io.Serializable;
20 | import org.apache.flink.configuration.Configuration;
21 |
22 | public interface StatefulFunctionsUniverseProvider extends Serializable {
23 |
24 | StatefulFunctionsUniverse get(ClassLoader classLoader, Configuration configuration);
25 | }
26 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/StatefulFunctionsUniverseValidator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core;
18 |
19 | final class StatefulFunctionsUniverseValidator {
20 |
21 | void validate(StatefulFunctionsUniverse statefulFunctionsUniverse) {
22 | // TODO: complete this
23 | if (statefulFunctionsUniverse.ingress().isEmpty()) {
24 | throw new IllegalStateException("There are no ingress defined.");
25 | }
26 | if (statefulFunctionsUniverse.sources().isEmpty()) {
27 | throw new IllegalStateException("There are no source providers defined.");
28 | }
29 | if (statefulFunctionsUniverse.routers().isEmpty()) {
30 | throw new IllegalStateException("There are no routers defined.");
31 | }
32 | if (statefulFunctionsUniverse.functions().isEmpty()) {
33 | throw new IllegalStateException("There are no function providers defined.");
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/common/KeyBy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.common;
18 |
19 | import com.ververica.statefun.sdk.Address;
20 |
21 | public final class KeyBy {
22 | private KeyBy() {}
23 |
24 | public static String apply(Address address) {
25 | return address.id();
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/common/MailboxExecutorFacade.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.common;
17 |
18 | import java.util.Objects;
19 | import java.util.concurrent.Executor;
20 | import org.apache.flink.streaming.api.operators.MailboxExecutor;
21 |
22 | public final class MailboxExecutorFacade implements Executor {
23 | private final MailboxExecutor executor;
24 | private final String name;
25 |
26 | public MailboxExecutorFacade(MailboxExecutor executor, String name) {
27 | this.executor = Objects.requireNonNull(executor);
28 | this.name = Objects.requireNonNull(name);
29 | }
30 |
31 | @Override
32 | public void execute(Runnable command) {
33 | executor.execute(command::run, name);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/common/SerializableFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.common;
17 |
18 | import java.io.Serializable;
19 | import java.util.function.Function;
20 |
21 | public interface SerializableFunction extends Function, Serializable {}
22 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/common/SerializablePredicate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.common;
17 |
18 | import java.io.Serializable;
19 | import java.util.function.Predicate;
20 |
21 | public interface SerializablePredicate extends Predicate, Serializable {}
22 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/di/Inject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.di;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target(ElementType.CONSTRUCTOR)
26 | public @interface Inject {}
27 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/di/Label.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.di;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target(ElementType.PARAMETER)
26 | public @interface Label {
27 | String value();
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/feedback/FeedbackConfiguration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.feedback;
17 |
18 | import org.apache.flink.configuration.ConfigOption;
19 | import org.apache.flink.configuration.ConfigOptions;
20 |
21 | public final class FeedbackConfiguration {
22 | private FeedbackConfiguration() {}
23 |
24 | public static final ConfigOption TOTAL_MEMORY_USED_FOR_FEEDBACK_CHECKPOINTING =
25 | ConfigOptions.key("stateful-functions.feedback.memory.bytes")
26 | .defaultValue(32 * 1024 * 1024)
27 | .withDescription(
28 | "The number of bytes to use for in memory buffering of the feedback channel, before spilling to disk");
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/feedback/FeedbackConsumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.feedback;
18 |
19 | /** HandOffConsumer. */
20 | @FunctionalInterface
21 | public interface FeedbackConsumer {
22 |
23 | void processFeedback(T element) throws Exception;
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/feedback/LockFreeBatchFeedbackQueue.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.feedback;
18 |
19 | import com.ververica.statefun.flink.core.queue.Locks;
20 | import com.ververica.statefun.flink.core.queue.MpscQueue;
21 | import java.util.Deque;
22 |
23 | public final class LockFreeBatchFeedbackQueue implements FeedbackQueue {
24 | private static final int INITIAL_BUFFER_SIZE = 32 * 1024; // 32k
25 |
26 | private final MpscQueue queue = new MpscQueue<>(INITIAL_BUFFER_SIZE, Locks.spinLock());
27 |
28 | @Override
29 | public boolean addAndCheckIfWasEmpty(ElementT element) {
30 | final int size = queue.add(element);
31 | return size == 1;
32 | }
33 |
34 | @Override
35 | public Deque drainAll() {
36 | return queue.drainAll();
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/ApplyingContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.flink.core.message.Message;
20 | import com.ververica.statefun.sdk.Context;
21 |
22 | public interface ApplyingContext extends Context {
23 |
24 | void apply(LiveFunction function, Message inMessage);
25 | }
26 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/DelayedMessagesBuffer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.flink.core.message.Message;
20 |
21 | interface DelayedMessagesBuffer {
22 |
23 | void add(Message message, long untilTimestamp);
24 |
25 | Iterable getForTimestamp(long timestamp);
26 |
27 | void clearForTimestamp(long timestamp);
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/FunctionLoader.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.sdk.FunctionType;
20 | import com.ververica.statefun.sdk.StatefulFunction;
21 |
22 | interface FunctionLoader {
23 |
24 | StatefulFunction load(FunctionType type);
25 | }
26 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/FunctionRepository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.sdk.FunctionType;
20 |
21 | public interface FunctionRepository {
22 |
23 | LiveFunction get(FunctionType type);
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/LiveFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.flink.core.message.Message;
20 | import com.ververica.statefun.flink.core.metrics.FunctionTypeMetrics;
21 | import com.ververica.statefun.flink.core.state.BoundState;
22 | import com.ververica.statefun.sdk.Context;
23 | import java.util.Optional;
24 |
25 | interface LiveFunction {
26 |
27 | void receive(Context context, Message message);
28 |
29 | FunctionTypeMetrics metrics();
30 |
31 | Optional state();
32 | }
33 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/LocalSink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.flink.core.di.Inject;
20 | import com.ververica.statefun.flink.core.di.Label;
21 | import com.ververica.statefun.flink.core.di.Lazy;
22 | import com.ververica.statefun.flink.core.message.Message;
23 | import java.util.Objects;
24 |
25 | final class LocalSink {
26 | private final Lazy functionGroup;
27 |
28 | @Inject
29 | LocalSink(@Label("function-group") Lazy functionGroup) {
30 | this.functionGroup = Objects.requireNonNull(functionGroup);
31 | }
32 |
33 | void accept(Message message) {
34 | Objects.requireNonNull(message);
35 | functionGroup.get().enqueue(message);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/RemoteSink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.flink.core.message.Message;
20 | import java.util.Objects;
21 | import org.apache.flink.streaming.api.operators.Output;
22 | import org.apache.flink.streaming.runtime.streamrecord.StreamRecord;
23 |
24 | final class RemoteSink {
25 | private final Output> output;
26 | private final StreamRecord record;
27 |
28 | RemoteSink(Output> output) {
29 | this.output = Objects.requireNonNull(output);
30 | this.record = new StreamRecord<>(null);
31 | }
32 |
33 | void accept(Message envelope) {
34 | Objects.requireNonNull(envelope);
35 | output.collect(record.replace(envelope));
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/StatefulFunctionInvocationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import com.ververica.statefun.sdk.FunctionType;
20 |
21 | /** A Stateful Functions exception that may be thrown when invoking a function. */
22 | public final class StatefulFunctionInvocationException extends RuntimeException {
23 |
24 | public StatefulFunctionInvocationException(FunctionType functionType, Throwable cause) {
25 | super(
26 | String.format("An error occurred when attempting to invoke function %s.", functionType),
27 | cause);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/functions/TimerServiceFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.functions;
18 |
19 | import org.apache.flink.runtime.state.VoidNamespace;
20 | import org.apache.flink.streaming.api.operators.InternalTimerService;
21 | import org.apache.flink.streaming.api.operators.Triggerable;
22 |
23 | interface TimerServiceFactory {
24 | InternalTimerService createTimerService(
25 | Triggerable triggerable);
26 | }
27 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/generated/CheckpointOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // Generated by the protocol buffer compiler. DO NOT EDIT!
18 | // source: src/main/protobuf/stateful-functions.proto
19 |
20 | package com.ververica.statefun.flink.core.generated;
21 |
22 | public interface CheckpointOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.flink.core.Checkpoint)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /** int64 checkpoint_id = 1;
*/
28 | long getCheckpointId();
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/generated/PayloadOrBuilder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // Generated by the protocol buffer compiler. DO NOT EDIT!
18 | // source: src/main/protobuf/stateful-functions.proto
19 |
20 | package com.ververica.statefun.flink.core.generated;
21 |
22 | public interface PayloadOrBuilder
23 | extends
24 | // @@protoc_insertion_point(interface_extends:com.ververica.statefun.flink.core.Payload)
25 | com.google.protobuf.MessageOrBuilder {
26 |
27 | /** string class_name = 2;
*/
28 | java.lang.String getClassName();
29 | /** string class_name = 2;
*/
30 | com.google.protobuf.ByteString getClassNameBytes();
31 |
32 | /** bytes payload_bytes = 3;
*/
33 | com.google.protobuf.ByteString getPayloadBytes();
34 | }
35 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/jsonmodule/ModuleConfigurationException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.jsonmodule;
17 |
18 | public final class ModuleConfigurationException extends RuntimeException {
19 | private static final long serialVersionUID = 1;
20 |
21 | public ModuleConfigurationException(String message, Throwable cause) {
22 | super(message, cause);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/jsonmodule/ModuleType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.jsonmodule;
17 |
18 | public enum ModuleType {
19 | REMOTE
20 | }
21 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/jsonmodule/RemoteFunction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.jsonmodule;
17 |
18 | import com.ververica.statefun.sdk.Context;
19 | import com.ververica.statefun.sdk.StatefulFunction;
20 | import java.util.Objects;
21 |
22 | public class RemoteFunction implements StatefulFunction {
23 | private final RemoteFunctionSpec functionSpec;
24 |
25 | public RemoteFunction(RemoteFunctionSpec functionSpec) {
26 | this.functionSpec = Objects.requireNonNull(functionSpec);
27 | }
28 |
29 | @Override
30 | public void invoke(Context context, Object input) {
31 | throw new UnsupportedOperationException(functionSpec.functionType() + " is not yet supported.");
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/jsonmodule/RemoteFunctionSpec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.ververica.statefun.flink.core.jsonmodule;
17 |
18 | import com.ververica.statefun.sdk.FunctionType;
19 | import java.net.SocketAddress;
20 | import java.util.Objects;
21 |
22 | final class RemoteFunctionSpec {
23 | private final FunctionType functionType;
24 | private final SocketAddress functionAddress;
25 |
26 | RemoteFunctionSpec(FunctionType functionType, SocketAddress functionAddress) {
27 | this.functionType = Objects.requireNonNull(functionType);
28 | this.functionAddress = Objects.requireNonNull(functionAddress);
29 | }
30 |
31 | FunctionType functionType() {
32 | return functionType;
33 | }
34 |
35 | SocketAddress address() {
36 | return functionAddress;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/logger/CheckpointedStreamOperations.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.logger;
18 |
19 | import java.io.Closeable;
20 | import java.io.IOException;
21 | import java.io.OutputStream;
22 |
23 | public interface CheckpointedStreamOperations {
24 |
25 | void requireKeyedStateCheckpointed(OutputStream keyedStateCheckpointOutputStream);
26 |
27 | void startNewKeyGroup(OutputStream stream, int keyGroup) throws IOException;
28 |
29 | Closeable acquireLease(OutputStream keyedStateCheckpointOutputStream);
30 | }
31 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/message/Message.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.message;
18 |
19 | import com.ververica.statefun.sdk.Address;
20 | import java.io.IOException;
21 | import javax.annotation.Nullable;
22 | import org.apache.flink.core.memory.DataOutputView;
23 |
24 | public interface Message {
25 |
26 | @Nullable
27 | Address source();
28 |
29 | Address target();
30 |
31 | Object payload(MessageFactory context, ClassLoader targetClassLoader);
32 |
33 | boolean isBarrierMessage();
34 |
35 | Message copy(MessageFactory context);
36 |
37 | void writeTo(MessageFactory context, DataOutputView target) throws IOException;
38 |
39 | default void postApply() {}
40 | }
41 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/message/MessageFactoryType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.message;
18 |
19 | public enum MessageFactoryType {
20 | WITH_KRYO_PAYLOADS,
21 | WITH_PROTOBUF_PAYLOADS,
22 | WITH_RAW_PAYLOADS,
23 | WITH_PROTOBUF_PAYLOADS_MULTILANG
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/message/MessageKeySelector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.message;
18 |
19 | import com.ververica.statefun.flink.core.common.KeyBy;
20 | import org.apache.flink.api.java.functions.KeySelector;
21 |
22 | public final class MessageKeySelector implements KeySelector {
23 |
24 | private static final long serialVersionUID = 1;
25 |
26 | @Override
27 | public String getKey(Message value) {
28 | return KeyBy.apply(value.target());
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/message/MessagePayloadSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.message;
18 |
19 | import com.ververica.statefun.flink.core.generated.Payload;
20 | import javax.annotation.Nonnull;
21 |
22 | public interface MessagePayloadSerializer {
23 |
24 | Payload serialize(@Nonnull Object payloadObject);
25 |
26 | Object deserialize(@Nonnull ClassLoader targetClassLoader, @Nonnull Payload payload);
27 |
28 | Object copy(@Nonnull ClassLoader targetClassLoader, @Nonnull Object what);
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/metrics/FlinkMetricsFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.metrics;
18 |
19 | import com.ververica.statefun.sdk.FunctionType;
20 | import java.util.Objects;
21 | import org.apache.flink.metrics.MetricGroup;
22 |
23 | public class FlinkMetricsFactory implements MetricsFactory {
24 |
25 | private final MetricGroup metricGroup;
26 |
27 | public FlinkMetricsFactory(MetricGroup metricGroup) {
28 | this.metricGroup = Objects.requireNonNull(metricGroup);
29 | }
30 |
31 | @Override
32 | public FunctionTypeMetrics forType(FunctionType functionType) {
33 | MetricGroup namespace = metricGroup.addGroup(functionType.namespace());
34 | MetricGroup typeGroup = namespace.addGroup(functionType.name());
35 | return new FlinkFunctionTypeMetrics(typeGroup);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/metrics/FunctionTypeMetrics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.metrics;
18 |
19 | public interface FunctionTypeMetrics {
20 |
21 | void incomingMessage();
22 |
23 | void outgoingLocalMessage();
24 |
25 | void outgoingRemoteMessage();
26 |
27 | void outgoingEgressMessage();
28 | }
29 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/metrics/MetricsFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.metrics;
18 |
19 | import com.ververica.statefun.sdk.FunctionType;
20 |
21 | public interface MetricsFactory {
22 |
23 | FunctionTypeMetrics forType(FunctionType functionType);
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/queue/Lock.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.queue;
18 |
19 | public interface Lock {
20 |
21 | void lockUninterruptibly();
22 |
23 | void unlock();
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/spi/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.spi;
18 |
19 | public class Constants {
20 | private Constants() {}
21 |
22 | public static final String MODULE_DIRECTORY = "/opt/stateful-functions/modules";
23 | public static final String FLINK_JOB_JAR_PATH =
24 | "/opt/flink/lib/stateful-functions-flink-core.jar";
25 | public static final String STATEFUL_FUNCTIONS_PACKAGE = "com.ververica.statefun.";
26 | public static final String STATEFUL_FUNCTIONS_MODULE_NAME = "module.yaml";
27 | }
28 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/state/BoundState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.state;
18 |
19 | import com.ververica.statefun.sdk.state.PersistedValue;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | public class BoundState {
24 |
25 | private final List> persistedValues;
26 |
27 | BoundState(List> persistedValues) {
28 | this.persistedValues = new ArrayList<>(persistedValues);
29 | }
30 |
31 | @SuppressWarnings("unused")
32 | public List> persistedValues() {
33 | return persistedValues;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/flink/core/state/State.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.core.state;
18 |
19 | import com.ververica.statefun.sdk.Address;
20 | import com.ververica.statefun.sdk.FunctionType;
21 | import com.ververica.statefun.sdk.state.Accessor;
22 | import com.ververica.statefun.sdk.state.PersistedValue;
23 |
24 | public interface State {
25 |
26 | Accessor createFlinkStateAccessor(
27 | FunctionType functionType, PersistedValue persistedValue);
28 |
29 | void setCurrentKey(Address address);
30 | }
31 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/java/com/ververica/statefun/sdk/state/ApiExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.state;
18 |
19 | public class ApiExtension {
20 | public static void setPersistedValueAccessor(
21 | PersistedValue persistedValue, Accessor accessor) {
22 | persistedValue.setAccessor(accessor);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/main/protobuf/stateful-functions.proto:
--------------------------------------------------------------------------------
1 | //
2 | // Copyright 2019 Ververica GmbH.
3 | //
4 | // Licensed under the Apache License, Version 2.0 (the "License");
5 | // you may not use this file except in compliance with the License.
6 | // You may obtain a copy of the License at
7 | //
8 | // http://www.apache.org/licenses/LICENSE-2.0
9 | //
10 | // Unless required by applicable law or agreed to in writing, software
11 | // distributed under the License is distributed on an "AS IS" BASIS,
12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | // See the License for the specific language governing permissions and
14 | // limitations under the License.
15 | //
16 |
17 | syntax = "proto3";
18 |
19 | package com.ververica.statefun.flink.core;
20 | option java_package = "com.ververica.statefun.flink.core.generated";
21 | option java_multiple_files = true;
22 |
23 | message EnvelopeAddress {
24 | string namespace = 1;
25 | string type = 2;
26 | string id = 3;
27 | }
28 |
29 | message Payload {
30 | string class_name = 2;
31 | bytes payload_bytes = 3;
32 | }
33 |
34 | message Checkpoint {
35 | int64 checkpoint_id = 1;
36 | }
37 |
38 | message Envelope {
39 | EnvelopeAddress source = 1;
40 | EnvelopeAddress target = 2;
41 |
42 | oneof body {
43 | Checkpoint checkpoint = 4;
44 | Payload payload = 3;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/test/resources/foo-module/module.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | module:
17 | meta:
18 | type: remote
19 | spec:
20 | functions:
21 | function:
22 | meta:
23 | type: com.example/hello
24 | spec:
25 | host: localhost
26 | port: 5000
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-core/src/test/resources/test-descriptors.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-flink/stateful-functions-flink-core/src/test/resources/test-descriptors.bin
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-harness/src/main/java/com/ververica/statefun/flink/harness/io/ConsumingSink.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.harness.io;
18 |
19 | import java.util.Objects;
20 | import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
21 |
22 | final class ConsumingSink extends RichSinkFunction {
23 |
24 | private static final long serialVersionUID = 1;
25 |
26 | private final SerializableConsumer consumer;
27 |
28 | ConsumingSink(SerializableConsumer consumer) {
29 | this.consumer = Objects.requireNonNull(consumer);
30 | }
31 |
32 | @Override
33 | public void invoke(T value, Context context) {
34 | consumer.accept(value);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-harness/src/main/java/com/ververica/statefun/flink/harness/io/HarnessConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.harness.io;
18 |
19 | import com.ververica.statefun.sdk.EgressType;
20 | import com.ververica.statefun.sdk.IngressType;
21 |
22 | @SuppressWarnings("WeakerAccess")
23 | public class HarnessConstants {
24 |
25 | public static final IngressType SUPPLYING_INGRESS_TYPE =
26 | new IngressType("com.ververica.statefun.flink.harness", "supplier");
27 | public static final EgressType CONSUMING_EGRESS_TYPE =
28 | new EgressType("com.ververica.statefun.flink.harness", "consuming-egress");
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-harness/src/main/java/com/ververica/statefun/flink/harness/io/SerializableConsumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.harness.io;
18 |
19 | import java.io.Serializable;
20 | import java.util.function.Consumer;
21 |
22 | public interface SerializableConsumer extends Serializable, Consumer {}
23 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-harness/src/main/java/com/ververica/statefun/flink/harness/io/SerializableSupplier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.harness.io;
18 |
19 | import java.io.Serializable;
20 | import java.util.function.Supplier;
21 |
22 | public interface SerializableSupplier extends Serializable, Supplier {}
23 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-harness/src/main/resources/log4j.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | log4j.rootLogger=INFO, console
18 |
19 | log4j.appender.console=org.apache.log4j.ConsoleAppender
20 | log4j.appender.console.layout=org.apache.log4j.PatternLayout
21 | log4j.appender.console.layout.ConversionPattern=%d{HH:mm:ss,SSS} %-5p %-60c %x - %m%n
22 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-io-bundle/src/main/java/com/ververica/statefun/flink/io/kafka/KafkaFlinkIoModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.io.kafka;
18 |
19 | import com.google.auto.service.AutoService;
20 | import com.ververica.statefun.flink.io.spi.FlinkIoModule;
21 | import com.ververica.statefun.sdk.kafka.Constants;
22 | import java.util.Map;
23 |
24 | @AutoService(FlinkIoModule.class)
25 | public final class KafkaFlinkIoModule implements FlinkIoModule {
26 |
27 | @Override
28 | public void configure(Map globalConfiguration, Binder binder) {
29 | binder.bindSourceProvider(Constants.KAFKA_INGRESS_TYPE, new KafkaSourceProvider());
30 | binder.bindSourceProvider(
31 | Constants.PROTOBUF_KAFKA_INGRESS_TYPE, new ProtobufKafkaSourceProvider());
32 | binder.bindSinkProvider(Constants.KAFKA_EGRESS_TYPE, new KafkaSinkProvider());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-io-bundle/src/main/java/com/ververica/statefun/flink/io/kafka/KafkaSerializationSchemaDelegate.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.io.kafka;
18 |
19 | import com.ververica.statefun.sdk.kafka.KafkaEgressSerializer;
20 | import java.util.Objects;
21 | import javax.annotation.Nullable;
22 | import org.apache.flink.streaming.connectors.kafka.KafkaSerializationSchema;
23 | import org.apache.kafka.clients.producer.ProducerRecord;
24 |
25 | final class KafkaSerializationSchemaDelegate implements KafkaSerializationSchema {
26 |
27 | private static final long serialVersionUID = 1L;
28 |
29 | private final KafkaEgressSerializer serializer;
30 |
31 | KafkaSerializationSchemaDelegate(KafkaEgressSerializer serializer) {
32 | this.serializer = Objects.requireNonNull(serializer);
33 | }
34 |
35 | @Override
36 | public ProducerRecord serialize(T t, @Nullable Long aLong) {
37 | return serializer.serialize(t);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-io-bundle/src/test/resources/protobuf-kafka-ingress.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 | ingress:
17 | meta:
18 | type: com.ververica.statefun.sdk.kafka/protobuf-kafka-connector
19 | id: com.mycomp.igal/names
20 | spec:
21 | address: kafka-broker:9092
22 | topics:
23 | - names
24 | properties:
25 | - consumer.group: greeter
26 | messageType: com.ververica.test.SimpleMessage
27 | descriptorSet: classpath:test-descriptors.bin
28 |
29 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-io-bundle/src/test/resources/test-descriptors.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ververica/stateful-functions/51499bbf48f622ae5fba9f1b9a796f25668c3d58/stateful-functions-flink/stateful-functions-flink-io-bundle/src/test/resources/test-descriptors.bin
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-io/src/main/java/com/ververica/statefun/flink/io/spi/FlinkIoModule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.io.spi;
18 |
19 | import com.ververica.statefun.sdk.EgressType;
20 | import com.ververica.statefun.sdk.IngressType;
21 | import java.util.Map;
22 |
23 | public interface FlinkIoModule {
24 |
25 | void configure(Map globalConfiguration, Binder binder);
26 |
27 | interface Binder {
28 |
29 | void bindSourceProvider(IngressType type, SourceProvider provider);
30 |
31 | void bindSinkProvider(EgressType type, SinkProvider provider);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-io/src/main/java/com/ververica/statefun/flink/io/spi/SinkProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.io.spi;
18 |
19 | import com.ververica.statefun.sdk.io.EgressSpec;
20 | import org.apache.flink.streaming.api.functions.sink.SinkFunction;
21 |
22 | public interface SinkProvider {
23 |
24 | SinkFunction forSpec(EgressSpec spec);
25 | }
26 |
--------------------------------------------------------------------------------
/stateful-functions-flink/stateful-functions-flink-io/src/main/java/com/ververica/statefun/flink/io/spi/SourceProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.flink.io.spi;
18 |
19 | import com.ververica.statefun.sdk.io.IngressSpec;
20 | import org.apache.flink.streaming.api.functions.source.SourceFunction;
21 |
22 | public interface SourceProvider {
23 |
24 | SourceFunction forSpec(IngressSpec spec);
25 | }
26 |
--------------------------------------------------------------------------------
/stateful-functions-kafka-io/src/main/java/com/ververica/statefun/sdk/kafka/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.kafka;
18 |
19 | import com.ververica.statefun.sdk.EgressType;
20 | import com.ververica.statefun.sdk.IngressType;
21 |
22 | public final class Constants {
23 | public static final IngressType KAFKA_INGRESS_TYPE =
24 | new IngressType("com.ververica.statefun.sdk.kafka", "universal-kafka-connector");
25 | public static final EgressType KAFKA_EGRESS_TYPE =
26 | new EgressType("com.ververica.statefun.sdk.kafka", "universal-kafka-connector");
27 | public static final IngressType PROTOBUF_KAFKA_INGRESS_TYPE =
28 | new IngressType("com.ververica.statefun.sdk.kafka", "protobuf-kafka-connector");;
29 |
30 | private Constants() {}
31 | }
32 |
--------------------------------------------------------------------------------
/stateful-functions-kafka-io/src/main/java/com/ververica/statefun/sdk/kafka/KafkaEgressSerializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.kafka;
18 |
19 | import java.io.Serializable;
20 | import org.apache.kafka.clients.producer.ProducerRecord;
21 |
22 | /**
23 | * A {@link KafkaEgressSerializer} defines how to serialize values of type {@code T} into {@link
24 | * ProducerRecord ProducerRecords}.
25 | *
26 | * @param the type of values being serialized
27 | */
28 | public interface KafkaEgressSerializer extends Serializable {
29 |
30 | /**
31 | * Serializes given element and returns it as a {@link ProducerRecord}.
32 | *
33 | * @param t element to be serialized
34 | * @return Kafka {@link ProducerRecord}
35 | */
36 | ProducerRecord serialize(OutT t);
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-kafka-io/src/main/java/com/ververica/statefun/sdk/kafka/KafkaIngressDeserializer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.kafka;
18 |
19 | import java.io.Serializable;
20 | import org.apache.kafka.clients.consumer.ConsumerRecord;
21 |
22 | /**
23 | * The deserialization schema describes how to turn the Kafka ConsumerRecords into data types that
24 | * are processed by the system.
25 | *
26 | * @param The type created by the keyed deserialization schema.
27 | */
28 | public interface KafkaIngressDeserializer extends Serializable {
29 |
30 | /**
31 | * Deserializes the Kafka record.
32 | *
33 | * @param input Kafka record to be deserialized.
34 | * @return The deserialized message as an object (null if the message cannot be deserialized).
35 | */
36 | T deserialize(ConsumerRecord input);
37 | }
38 |
--------------------------------------------------------------------------------
/stateful-functions-kafka-io/src/main/java/com/ververica/statefun/sdk/kafka/KafkaProducerSemantic.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.kafka;
18 |
19 | public enum KafkaProducerSemantic {
20 | EXACTLY_ONCE,
21 | AT_LEAST_ONCE,
22 | NONE
23 | }
24 |
--------------------------------------------------------------------------------
/stateful-functions-quickstart/src/main/resources/archetype-resources/Dockerfile:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | FROM stateful-functions
18 |
19 | RUN mkdir -p /opt/stateful-functions/modules/${artifactId}
20 | COPY target/${artifactId}*jar /opt/stateful-functions/modules/${artifactId}/
--------------------------------------------------------------------------------
/stateful-functions-quickstart/src/main/resources/archetype-resources/src/main/java/Module.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package ${package};
18 |
19 | import com.ververica.statefun.sdk.spi.StatefulFunctionModule;
20 |
21 | import java.util.Map;
22 |
23 | public final class Module implements StatefulFunctionModule {
24 |
25 | @Override
26 | public void configure(Map globalConfiguration, Binder binder) {
27 |
28 | }
29 | }
--------------------------------------------------------------------------------
/stateful-functions-quickstart/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.ververica.statefun.sdk.spi.StatefulFunctionModule:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | ${package}.Module
--------------------------------------------------------------------------------
/stateful-functions-sdk/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
20 |
21 | stateful-functions-parent
22 | com.ververica
23 | 1.1-SNAPSHOT
24 |
25 | 4.0.0
26 |
27 | stateful-functions-sdk
28 |
29 |
30 | 1.3.9
31 |
32 |
33 |
34 |
35 | com.google.code.findbugs
36 | jsr305
37 | ${jsr305.version}
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/stateful-functions-sdk/src/main/java/com/ververica/statefun/sdk/StatefulFunctionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk;
18 |
19 | /** Provides instances of {@link StatefulFunction}s for a given {@link FunctionType}. */
20 | public interface StatefulFunctionProvider {
21 |
22 | /**
23 | * Creates a {@link StatefulFunction} instance for the given {@link FunctionType},
24 | *
25 | * @param type the type of function to create an instance for.
26 | * @return an instance of a function for the given type.
27 | */
28 | StatefulFunction functionOfType(FunctionType type);
29 | }
30 |
--------------------------------------------------------------------------------
/stateful-functions-sdk/src/main/java/com/ververica/statefun/sdk/annotations/ForRuntime.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.annotations;
18 |
19 | import java.lang.annotation.Documented;
20 | import java.lang.annotation.ElementType;
21 | import java.lang.annotation.Target;
22 |
23 | /**
24 | * Methods or constructors annotated with this annotation, are used for the runtime to extend the
25 | * API with specialized implementation
26 | */
27 | @Documented
28 | @Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
29 | public @interface ForRuntime {}
30 |
--------------------------------------------------------------------------------
/stateful-functions-sdk/src/main/java/com/ververica/statefun/sdk/annotations/Persisted.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.annotations;
18 |
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | @Retention(RetentionPolicy.RUNTIME)
25 | @Target(ElementType.FIELD)
26 | public @interface Persisted {}
27 |
--------------------------------------------------------------------------------
/stateful-functions-sdk/src/main/java/com/ververica/statefun/sdk/state/Accessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.sdk.state;
18 |
19 | public interface Accessor {
20 |
21 | void set(T value);
22 |
23 | T get();
24 |
25 | void clear();
26 | }
27 |
--------------------------------------------------------------------------------
/stateful-functions-state-processor/src/main/java/com/ververica/statefun/state/processor/BootstrapDataRouterProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.state.processor;
18 |
19 | import com.ververica.statefun.sdk.io.Router;
20 | import java.io.Serializable;
21 | import javax.annotation.Nonnull;
22 |
23 | /**
24 | * Provides instances of a {@link Router} to route bootstrap data to {@link
25 | * StateBootstrapFunction}s.
26 | *
27 | * @param data type of elements in the bootstrap dataset being routed.
28 | */
29 | public interface BootstrapDataRouterProvider extends Serializable {
30 |
31 | /** Creates a {@link Router} instance. */
32 | @Nonnull
33 | Router provide();
34 | }
35 |
--------------------------------------------------------------------------------
/stateful-functions-state-processor/src/main/java/com/ververica/statefun/state/processor/Context.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.state.processor;
18 |
19 | import com.ververica.statefun.sdk.Address;
20 |
21 | /** Provides context for a single {@link StateBootstrapFunction} invocation. */
22 | public interface Context {
23 |
24 | /**
25 | * Returns the {@link Address} of the function being bootstrapped.
26 | *
27 | * @return the address of the function being bootstrapped.
28 | */
29 | Address self();
30 | }
31 |
--------------------------------------------------------------------------------
/stateful-functions-state-processor/src/main/java/com/ververica/statefun/state/processor/StateBootstrapFunctionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 Ververica GmbH.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.ververica.statefun.state.processor;
18 |
19 | import com.ververica.statefun.sdk.FunctionType;
20 | import java.io.Serializable;
21 |
22 | /** Provides instances of {@link StateBootstrapFunction}s for a given {@link FunctionType}. */
23 | public interface StateBootstrapFunctionProvider extends Serializable {
24 |
25 | /**
26 | * Creates a {@link StateBootstrapFunction} instance for the given {@link FunctionType},
27 | *
28 | * @param type the type of function to create a boostrap function instance for.
29 | * @return an instance of a bootstrap function for the given type.
30 | */
31 | StateBootstrapFunction bootstrapFunctionOfType(FunctionType type);
32 | }
33 |
--------------------------------------------------------------------------------
/tools/docker/docker-entry-point.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #
4 | # Copyright 2019 Ververica GmbH.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | #
20 | # Role types
21 | #
22 | WORKER="worker"
23 | MASTER="master"
24 |
25 | #
26 | # Environment
27 | #
28 | FLINK_HOME=${FLINK_HOME:-"/opt/flink/bin"}
29 | ROLE=${ROLE:-"worker"}
30 | MASTER_HOST=${MASTER_HOST:-"localhost"}
31 |
32 | #
33 | # Start a service depending on the role.
34 | #
35 | if [[ "${ROLE}" == "${WORKER}" ]]; then
36 | #
37 | # start the TaskManager (worker role)
38 | #
39 | exec ${FLINK_HOME}/bin/taskmanager.sh start-foreground \
40 | -Djobmanager.rpc.address=${MASTER_HOST}
41 |
42 | elif [[ "${ROLE}" == "${MASTER}" ]]; then
43 | #
44 | # start the JobManager (master role) with our predefined job.
45 | #
46 | exec $FLINK_HOME/bin/standalone-job.sh \
47 | start-foreground \
48 | -Djobmanager.rpc.address=${MASTER_HOST} \
49 | "$@"
50 | else
51 | #
52 | # unknown role
53 | #
54 | echo "unknown role ${ROLE}"
55 | exit 1
56 | fi
57 |
--------------------------------------------------------------------------------
/tools/docker/flink-distribution-template/conf/flink-conf.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2019 Ververica GmbH.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | # This file is the base for the Apache Flink configuration
18 |
19 | classloader.parent-first-patterns.additional: com.ververica.statefun;org.apache.kafka;com.google.protobuf
20 | state.backend: rocksdb
21 | state.backend.rocksdb.timer-service.factory: ROCKSDB
22 | state.checkpoints.dir: file:///checkpoint-dir
23 | state.backend.incremental: true
24 | taskmanager.memory.process.size: 4g
25 |
--------------------------------------------------------------------------------