diff options
| author | doufenghu <[email protected]> | 2023-12-03 14:22:32 +0800 |
|---|---|---|
| committer | doufenghu <[email protected]> | 2023-12-03 14:22:32 +0800 |
| commit | ffa3ed3dded18d086e72046e89b72b7a0dd60e7f (patch) | |
| tree | 59a97f1bfa5cb75e28cc1071e35b9a7fc15f4d7e | |
| parent | 5f21adf326bd9c1db7f1bb9faf65d63643c596b9 (diff) | |
[feature][docs] add readme.md for groot stream platform
| -rw-r--r-- | README.md | 141 | ||||
| -rw-r--r-- | docs/develop-guide.md | 41 | ||||
| -rw-r--r-- | docs/images/groot_stream_architecture.jpeg | bin | 0 -> 5167458 bytes | |||
| -rw-r--r-- | groot-bootstrap/pom.xml | 2 | ||||
| -rw-r--r-- | groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/main/GrootStreamServerTmp.java | 342 | ||||
| -rw-r--r-- | groot-example/pom.xml | 1 | ||||
| -rw-r--r-- | groot-tests/pom.xml | 20 | ||||
| -rw-r--r-- | groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/EvalExpressionResolverTest.java | 81 | ||||
| -rw-r--r-- | groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/CalcCodeConvertorTest.java | 94 | ||||
| -rw-r--r-- | groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/EvalCodeGeneratorTest.java | 34 | ||||
| -rw-r--r-- | pom.xml | 3 |
11 files changed, 115 insertions, 644 deletions
@@ -1,92 +1,91 @@ -# groot-platform +# Groot Stream Platform +Groot Stream Platform helps you process netflow data - logs, metrics etc. - in real time, high reliability and high performance, distributed data integration tool. +## Table of contents -## Getting started +- [Features](#features) -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +## Features -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +Groot Stream is is designed to simplify the operation of ETL (Extract, Transform, Load). It efficiently collects data from multiple sources and processes and enriches it. +- **Real-time data processing**: Using Flink as the execution engine, it can provide high throughput and low-latency processing capabilities for large-scale data streams. +- **Designed for extension**: Plugin-based management that support for User-defined Functions, Sources, and Sinks. +- **Highly Configurable**: Customize data flow through YML templates to swiftly fulfill ETL requirements without development. +- **Out-of-the-box Functions**: Built-in functions for data processing, including data type conversion, data filtering, data aggregation, and data enrichment. -## Add your files +## Groot Stream Workflow -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: + -``` -cd existing_repo -git remote add origin https://git.mesalab.cn/bigdata/tsg/flink/groot-platform.git -git branch -M main -git push -uf origin main -``` - -## Integrate with your tools - -- [ ] [Set up project integrations](https://git.mesalab.cn/bigdata/tsg/flink/groot-platform/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** +Configure a job, you'll set up Sources, Filters, Processing Pipeline, and Sinks, and will assemble several built-in functions into a Processing Pipeline. The job will then be deployed to a Flink cluster for execution. +- **Source**: The data source of the job, which can be a Kafka topic, a IPFIX Collector, or a file. +- **Filter**: Filters data based on specified conditions. +- **Pipelines**: The fundamental unit of data stream processing is the processor, categorized by functionality into stateless and stateful processors. Each processor can assemble built-in functions into a pipeline. + - **Pre-processing Pipeline**: Optional. Processes data before it enters the processing pipeline. + - **Processing Pipeline**: Core data transformation pipeline. + - **Post-processing Pipeline**: Optional. Processes data after it exits the processing pipeline. +- **Sink**: The data sink of the job, which can be a Kafka topic, a ClickHouse table, or a file. -# Editing this README +## Supported Connectors & Functions -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. +- [Source Connectors](docs/sources) +- [Sink Connectors](docs/sinks) +- [Functions](docs/functions) -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. +## Minimum Requirements -## Name -Choose a self-explaining name for your project. +- Java 8 +- Maven 3.5.4 +- Scala 2.12 +- Flink 1.13.1 -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. +## Getting Started -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. +### Building -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. +Run the following Maven command to build the project modules using parallel threads: +```shell +mvn clean install -T2C +``` +Run the following Maven command to build the project modules and Skip Tests: +```shell +mvn clean install -DskipTests +``` +### Deploying -## Contributing -State if you are open to contributions and what your requirements are for accepting them. +Copy the `groot-release/target/groot-stream-${version}-bin.tar.gz` file to the target machine and extract it: +```shell +tar -zxvf groot-stream-${version}-bin.tar.gz +ls -lh groot-stream-${version} +``` +### Starting + +### Running job in your IDE +1. Set `groot-bootstrap` module pom.xml scope to `compile`. +2. Open the `Run/Debug Configurations` window. +3. Choose -cp `groot-bootstrap` +4. Choose Main Class `com.geedgenetworks.bootstrap.main.GrootStreamServer`. +5. Add VM options `-e client --target local -c /...../groot-stream/config/grootstream_job_template.yaml`. +6. Click the `Run` button. + +#### Running the CLI +- Run the following command to start the groot-stream server for Standalone Mode: +```shell +cd "groot-stream-${version}" +./bin/start.sh -c ./config/grootstream_job_template.yaml --target remote -d -n groot-stream-job +``` +- Run the following command to start the groot-stream server for Yarn Per-job Mode: +```shell +cd "groot-stream-${version}" +./bin/start.sh -c ./config/grootstream_job_template.yaml --target yarn-per-job -d -n groot-stream-job +``` +### Configuring -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. +The [Groot User Guide](docs/user-guide) provides detailed information on how to configure a job. -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. +## Documentation -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. +See the [Groot Stream Documentation](https://docs.geedge.net/pages/viewpage.action?pageId=91325479) for more information. -## License -For open source projects, say how it is licensed. -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/docs/develop-guide.md b/docs/develop-guide.md index d0bbf6f..ededf14 100644 --- a/docs/develop-guide.md +++ b/docs/develop-guide.md @@ -1,5 +1,22 @@ # Develop Guide +## Modules Overview + +| Module Name | Description | +|:----------------|:-----------------------------------------------------------------------------------------------------------| +| groot-bootstrap | The main module of groot-stream, which is responsible for starting the groot-stream server. | +| groot-common | Common module of groot-stream, which is responsible for providing common functions. | +| groot-core | Core module of groot-stream, which is responsible for providing core functions. | +| groot-connectors| Connector module of groot-stream, which is responsible for providing connectors. | +| groot-formats | Format module of groot-stream, which is responsible for providing the ability of formatting data. | +| groot-shade | Shaded module of groot-stream, which is responsible for providing the ability of solving package conflict. | +| groot-example | Example module of groot-stream, which is responsible for providing examples. | +|groot-test | Test module of groot-stream, which is responsible for providing test cases. | +|groot-docs | Docs module of groot-stream, which is responsible for providing documents. | +|groot-release | Release module of groot-stream, which is responsible for providing release scripts. | + + + ## How to write a high quality Git commit message > [purpose] [module name] [sub-module name] Description (JIRA Issue ID) @@ -25,26 +42,11 @@ When throwing an exception with a hint message and ensure that the exception has } ``` -## How to run a job in IDEA -1. Set `groot-bootstrap` module pom.xml scope to `compile`. -2. Open the `Run/Debug Configurations` window. -3. Choose -cp `groot-bootstrap` -4. Choose Main Class `com.geedgenetworks.bootstrap.main.GrootStreamServer`. -5. Add VM options `-e client --target local -c /...../groot-stream/config/grootstream_job_template.yaml`. -6. Click the `Run` button. - -## How to run a job in command line -- Standalone Mode -```shell -cd "groot-stream-${version}" -./bin/start.sh -c ./config/grootstream_job_template.yaml --target remote -d -n groot-stream-job -``` -- Yarn Per-job Mode -```shell -cd "groot-stream-${version}" -./bin/start.sh -c ./config/grootstream_job_template.yaml --target yarn-per-job -d -n groot-stream-job -``` +## Design Principles +1. Package structure: `com.geedgenetworks.[module].[sub-module]`. `groot-stream` is the parent module, and other modules are dependent on it. +2. Module naming: `groot-[module]`. e.g. `groot-common`, `groot-core`, `groot-connectors`, `groot-bootstrap`, `groot-example`, etc. +3. For unchecked exception (RuntimeException) within the 'groot-common' module, a global exception handling class named 'GrootRuntimeException' is defined. ## Run a job example All examples are in module `groot-stream-example`. You can run the example [ running or debugging a job in IDEA]. @@ -53,4 +55,3 @@ e.g. we use `groot-stream-example/src/main/java/com/geedgenetworks/example/Boots {"ip_string":"8.8.8.9","fqdn_string":"www.geedgenetworks.com","port_int32":80} ``` - diff --git a/docs/images/groot_stream_architecture.jpeg b/docs/images/groot_stream_architecture.jpeg Binary files differnew file mode 100644 index 0000000..7daf2e1 --- /dev/null +++ b/docs/images/groot_stream_architecture.jpeg diff --git a/groot-bootstrap/pom.xml b/groot-bootstrap/pom.xml index fe78bd7..e76a55b 100644 --- a/groot-bootstrap/pom.xml +++ b/groot-bootstrap/pom.xml @@ -12,7 +12,7 @@ <name>Groot : Bootstrap </name> <properties> - <scope>provided</scope> + <scope>compile</scope> </properties> <dependencies> diff --git a/groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/main/GrootStreamServerTmp.java b/groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/main/GrootStreamServerTmp.java deleted file mode 100644 index 4130d15..0000000 --- a/groot-bootstrap/src/main/java/com/geedgenetworks/bootstrap/main/GrootStreamServerTmp.java +++ /dev/null @@ -1,342 +0,0 @@ -package com.geedgenetworks.bootstrap.main; - -import com.alibaba.fastjson.JSONObject; -import com.geedgenetworks.common.config.GrootYamlParser; -import com.geedgenetworks.core.filter.AviatorFilter; -import com.geedgenetworks.core.pojo.*; -import com.geedgenetworks.core.processor.aggregate.AggregateProcessor; -import com.geedgenetworks.core.processor.projection.ProjectionProcessor; -import com.geedgenetworks.core.sink.Sink; -import com.geedgenetworks.core.source.Source; -import com.geedgenetworks.utils.StringUtil; -import org.apache.flink.configuration.Configuration; -import org.apache.flink.configuration.RestOptions; -import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator; -import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Map; - -public class GrootStreamServerTmp { - private static final Logger logger = LoggerFactory.getLogger(GrootStreamServerTmp.class); - - public static void main(String[] args) throws Exception { - - //便于调试,临时支持本地环境执行 -local - boolean useLocalEnvironment = checkLocalExecution(args); - StreamExecutionEnvironment env = null; - if (useLocalEnvironment) { - Configuration conf = new Configuration(); - conf.setInteger(RestOptions.PORT, 8082); - env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(conf); - } else { - env = StreamExecutionEnvironment.getExecutionEnvironment(); - } - - env.getConfig().enableObjectReuse(); - - Map<String, Object> yamlMap = - GrootYamlParser.loadYaml( - GrootStreamServerTmp.class - .getClassLoader() - .getResourceAsStream("groot-platform-schedule.yaml")); - - - YamlEntity yamlEntity = new YamlEntity(); - Map<String, Object> sources = GrootYamlParser.getMap("sources", yamlMap); - Map<String, Object> sinks = GrootYamlParser.getMap("sinks", yamlMap); - Map<String, Object> filters = GrootYamlParser.getMap("filters", yamlMap); - Map<String, Object> pre_processing_pipelines = - GrootYamlParser.getMap("pre_processing_pipelines", yamlMap); - Map<String, Object> processing_pipelines = - GrootYamlParser.getMap("processing_pipelines", yamlMap); - Map<String, Object> post_processing_pipelines = - GrootYamlParser.getMap("post_processing_pipelines", yamlMap); - Map<String, Object> application = GrootYamlParser.getMap("application", yamlMap); - Map<String, Object> topologylist = (Map<String, Object>) application.get("topology"); - yamlEntity.setApplication(application); - yamlEntity.setFilters(filters); - yamlEntity.setPre_processing_pipelines(pre_processing_pipelines); - yamlEntity.setProcessing_pipelines(processing_pipelines); - yamlEntity.setPost_processing_pipelines(post_processing_pipelines); - yamlEntity.setSinks(sinks); - yamlEntity.setSources(sources); - - if (topologylist != null) { - for (Map.Entry<String, Object> entry : topologylist.entrySet()) { - SingleOutputStreamOperator<Event> streamlineEventSingleOutputStreamOperator = null; - - if (sources.containsKey(entry.getKey())) { - JSONObject jo = - new JSONObject((Map<String, Object>) sources.get(entry.getKey())); - JSONObject to = new JSONObject((Map<String, Object>) entry.getValue()); - Topology topology = to.toJavaObject(Topology.class); - SourceConfigOld sourceConfig = jo.toJavaObject(SourceConfigOld.class); - checkSourceConfig(sourceConfig); - String type = sourceConfig.getType(); - Class cls = null; - Source source = null; - try { - cls = Class.forName(type); - source = (Source) cls.newInstance(); - sourceConfig.setName(entry.getKey()); - if (topology.getParallelism() != 0) { - - sourceConfig.setParallelism(topology.getParallelism()); - } - streamlineEventSingleOutputStreamOperator = - source.source(env, sourceConfig); - } catch (Exception e) { - e.printStackTrace(); - } - try { - for (String name : topology.getNext()) { - excute( - name, - streamlineEventSingleOutputStreamOperator, - yamlEntity, - topologylist); - } - } catch (Exception e) { - throw new Exception("校验未通过"); - } - } - } - env.execute((String) application.getOrDefault("name", "job")); - } else { - logger.error("无可执行topologylist"); - throw new Exception("无可执行topologylist"); - } - } - - private static boolean checkLocalExecution(String[] args) { - for (String arg : args) { - if (arg.equals("-local")) { - return true; - } - } - return false; - } - - private static void excute( - String name, - SingleOutputStreamOperator<Event> streamlineEventSingleOutputStreamOperator, - YamlEntity yamlEntity, - Map<String, Object> topologyList) - throws Exception { - - SingleOutputStreamOperator<Event> singleOutputStreamOperator = - instantiatedTopology( - name, streamlineEventSingleOutputStreamOperator, yamlEntity, topologyList); - JSONObject to = new JSONObject((Map<String, Object>) topologyList.get(name)); - Topology topology = to.toJavaObject(Topology.class); - - for (String s : topology.getNext()) { - - excute(s, singleOutputStreamOperator, yamlEntity, topologyList); - } - } - - private static SingleOutputStreamOperator<Event> instantiatedTopology( - String name, - SingleOutputStreamOperator<Event> streamlineEventSingleOutputStreamOperator, - YamlEntity yamlEntity, - Map<String, Object> topologyList) - throws Exception { - - SingleOutputStreamOperator<Event> event = null; - - if (yamlEntity.getFilters() != null && yamlEntity.getFilters().containsKey(name)) { - JSONObject jsonObject = - new JSONObject((Map<String, Object>) yamlEntity.getFilters().get(name)); - FilterConfig filterConfig = jsonObject.toJavaObject(FilterConfig.class); - checkFilterConfig(filterConfig); - String className = filterConfig.getType(); - Class cls = null; - AviatorFilter aviatorFilter = null; - try { - cls = Class.forName(className); - aviatorFilter = (AviatorFilter) cls.newInstance(); - JSONObject to = new JSONObject((Map<String, Object>) topologyList.get(name)); - Topology topology = to.toJavaObject(Topology.class); - if (topology.getParallelism() != 0) { - filterConfig.setParallelism(topology.getParallelism()); - } - filterConfig.setName(name); - event = - aviatorFilter.filterFunction( - streamlineEventSingleOutputStreamOperator, filterConfig); - - } catch (Exception e) { - logger.error("实例化filter:" + name + "失败"); - } - - } else if (yamlEntity.getPre_processing_pipelines() != null - && yamlEntity.getPre_processing_pipelines().containsKey(name)) { - - JSONObject jsonObject = - new JSONObject( - (Map<String, Object>) - yamlEntity.getPre_processing_pipelines().get(name)); - event = - InstantiateProcessor( - event, - jsonObject, - name, - streamlineEventSingleOutputStreamOperator, - yamlEntity, - topologyList); - - } else if (yamlEntity.getProcessing_pipelines() != null - && yamlEntity.getProcessing_pipelines().containsKey(name)) { - - JSONObject jsonObject = - new JSONObject( - (Map<String, Object>) yamlEntity.getProcessing_pipelines().get(name)); - event = - InstantiateProcessor( - event, - jsonObject, - name, - streamlineEventSingleOutputStreamOperator, - yamlEntity, - topologyList); - - } else if (yamlEntity.getPost_processing_pipelines() != null - && yamlEntity.getPost_processing_pipelines().containsKey(name)) { - - JSONObject jsonObject = - new JSONObject( - (Map<String, Object>) - yamlEntity.getPost_processing_pipelines().get(name)); - event = - InstantiateProcessor( - event, - jsonObject, - name, - streamlineEventSingleOutputStreamOperator, - yamlEntity, - topologyList); - - } else if (yamlEntity.getSinks() != null && yamlEntity.getSinks().containsKey(name)) { - - JSONObject jsonObject = - new JSONObject((Map<String, Object>) yamlEntity.getSinks().get(name)); - JSONObject to = new JSONObject((Map<String, Object>) topologyList.get(name)); - Topology topology = to.toJavaObject(Topology.class); - SinkConfigOld kafkaSinkConfig = jsonObject.toJavaObject(SinkConfigOld.class); - checkSinkConfig(kafkaSinkConfig); - String sinkclassName = kafkaSinkConfig.getType(); - Class cls = null; - Sink sink = null; - try { - cls = Class.forName(sinkclassName); - sink = (Sink) cls.newInstance(); - if (topology.getParallelism() != 0) { - kafkaSinkConfig.setParallelism(topology.getParallelism()); - } - kafkaSinkConfig.setName(name); - sink.sink(streamlineEventSingleOutputStreamOperator, kafkaSinkConfig); - } catch (Exception e) { - e.printStackTrace(); - } - - } else { - logger.error("实例化sink:" + name + "失败"); - } - return event; - } - - private static SingleOutputStreamOperator<Event> InstantiateProcessor( - SingleOutputStreamOperator<Event> event, - JSONObject jsonObject, - String name, - SingleOutputStreamOperator<Event> streamlineEventSingleOutputStreamOperator, - YamlEntity yamlEntity, - Map<String, Object> topologyList) - throws Exception { - - if (!jsonObject.containsKey("window_type")) { - ProjectionConfig projectionConfig = jsonObject.toJavaObject(ProjectionConfig.class); - - checkProjectionConfig(projectionConfig); - - Class cls = null; - ProjectionProcessor projectionProcessor = null; - try { - cls = Class.forName(projectionConfig.getType()); - projectionProcessor = (ProjectionProcessor) cls.newInstance(); - JSONObject to = new JSONObject((Map<String, Object>) topologyList.get(name)); - Topology topology = to.toJavaObject(Topology.class); - if (topology.getParallelism() != 0) { - - projectionConfig.setParallelism(topology.getParallelism()); - } - projectionConfig.setName(name); - event = - projectionProcessor.projectionProcessorFunction( - streamlineEventSingleOutputStreamOperator, projectionConfig); - } catch (Exception e) { - logger.error("实例化pipelines的projectionprocessor:" + name + "失败"); - } - - } else { - AggregateConfig aggregateConfig = jsonObject.toJavaObject(AggregateConfig.class); - checkAggregateProjectionConfig(aggregateConfig); - - Class cls = null; - AggregateProcessor aggregateProcessor = null; - try { - cls = Class.forName(aggregateConfig.getType()); - aggregateProcessor = (AggregateProcessor) cls.newInstance(); - event = - aggregateProcessor.aggregateProcessorFunction( - streamlineEventSingleOutputStreamOperator, aggregateConfig); - if (aggregateConfig.getParallelism() != 0) { - aggregateConfig.setParallelism(aggregateConfig.getParallelism()); - } - aggregateConfig.setName(name); - } catch (Exception e) { - logger.error("实例化pipelines的aggregateProcessor:" + name + "失败"); - } - } - return event; - } - - private static void checkSourceConfig(SourceConfigOld sourceConfig) throws Exception { - - if (!StringUtil.isNotBlank(sourceConfig.getType())) { - throw new Exception("校验未通过 source " + sourceConfig.getName() + " type 为空!"); - } - } - - private static void checkSinkConfig(SinkConfigOld sinkConfig) throws Exception { - - if (!StringUtil.isNotBlank(sinkConfig.getType())) { - throw new Exception("校验未通过 sink " + sinkConfig.getName() + " type 为空!"); - } - } - - private static void checkFilterConfig(FilterConfig filterConfig) throws Exception { - - if (!StringUtil.isNotBlank(filterConfig.getType())) { - throw new Exception("校验未通过 filter " + filterConfig.getName() + " type 为空!"); - } - } - - private static void checkProjectionConfig(ProjectionConfig projectionConfig) throws Exception { - - if (!StringUtil.isNotBlank(projectionConfig.getType())) { - throw new Exception("校验未通过 projection " + projectionConfig.getName() + " type 为空!"); - } - } - - private static void checkAggregateProjectionConfig(AggregateConfig aggregateConfig) - throws Exception { - - if (!StringUtil.isNotBlank(aggregateConfig.getType())) { - throw new Exception("校验未通过 projection " + aggregateConfig.getName() + " type 为空!"); - } - } -} diff --git a/groot-example/pom.xml b/groot-example/pom.xml index 17dc259..723dd1b 100644 --- a/groot-example/pom.xml +++ b/groot-example/pom.xml @@ -10,6 +10,7 @@ </parent> <artifactId>groot-example</artifactId> + <name>Groot : Example </name> <properties> <scope>compile</scope> diff --git a/groot-tests/pom.xml b/groot-tests/pom.xml new file mode 100644 index 0000000..2c39a58 --- /dev/null +++ b/groot-tests/pom.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>com.geedgenetworks</groupId> + <artifactId>groot-stream</artifactId> + <version>${revision}</version> + </parent> + + <artifactId>groot-tests</artifactId> + <name>Groot : Tests </name> + <properties> + <maven.compiler.source>8</maven.compiler.source> + <maven.compiler.target>8</maven.compiler.target> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + +</project>
\ No newline at end of file diff --git a/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/EvalExpressionResolverTest.java b/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/EvalExpressionResolverTest.java deleted file mode 100644 index e6b8ff2..0000000 --- a/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/EvalExpressionResolverTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.geedgenetworks.core.udf.test; - -import com.geedgenetworks.core.expressions.*; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.math.BigDecimal; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class EvalExpressionResolverTest { - - private static EvalExpressionResolver resolver; - - @BeforeAll - static void setUp() { - resolver = new EvalExpressionResolver(); - } - - @Test - void testValueExpression() { - // constant - assertEquals(resolver.resolve("'name'"), new ValueExpression.StringConstantExpression("name")); - assertEquals(resolver.resolve("5"), new ValueExpression.NumberConstantExpression(5)); - assertEquals(resolver.resolve("5L"), new ValueExpression.NumberConstantExpression(5L)); - assertEquals(resolver.resolve("5D"), new ValueExpression.NumberConstantExpression((double) 5L)); - assertEquals(resolver.resolve("5BD"), new ValueExpression.NumberConstantExpression(BigDecimal.valueOf(5))); - assertEquals(resolver.resolve("TRUE"), new ValueExpression.BooleanConstantExpression(true)); - assertEquals(resolver.resolve("FALSE"), new ValueExpression.BooleanConstantExpression(false)); - - // variable - assertEquals(resolver.resolve("common_client_ip"), - new ValueExpression.FieldRefExpression("common_client_ip")); - assertEquals(resolver.resolve("common_client_port"), - new ValueExpression.FieldRefExpression("common_client_port")); - } - - @Test - void testConditionExpression() { - - assertEquals( - resolver.resolve("common_client_port > common_server_port ? common_c2s_pkt_num : common_s2c_pkt_num"), - new ValueExpression.TernaryExpression( - new BooleanExpression.ComparisonExpression(ComparisonOperator.GT, - new ValueExpression.FieldRefExpression("common_client_port"), - new ValueExpression.FieldRefExpression("common_server_port")), - new ValueExpression.FieldRefExpression("common_c2s_pkt_num"), - new ValueExpression.FieldRefExpression("common_s2c_pkt_num")) - ); - assertEquals( - resolver.resolve("common_client_port > common_server_port " + - "? 'C2S:' + common_c2s_pkt_num : 'S2C:' + common_s2c_pkt_num"), - new ValueExpression.TernaryExpression( - new BooleanExpression.ComparisonExpression(ComparisonOperator.GT, - new ValueExpression.FieldRefExpression("common_client_port"), - new ValueExpression.FieldRefExpression("common_server_port")), - new ValueExpression.ArithmeticExpression(ArithmeticOperator.PLUS, - new ValueExpression.StringConstantExpression("C2S:"), - new ValueExpression.FieldRefExpression("common_c2s_pkt_num")), - new ValueExpression.ArithmeticExpression(ArithmeticOperator.PLUS, - new ValueExpression.StringConstantExpression("S2C:"), - new ValueExpression.FieldRefExpression("common_s2c_pkt_num"))) - ); - assertEquals( - resolver.resolve("common_c2s_pkt_num > common_s2c_pkt_num " + - "& common_c2s_byte_num > common_s2c_byte_num ? common_client_port : common_server_port"), - new ValueExpression.TernaryExpression( - new BooleanExpression.PredicateExpression(PredicateOperator.AND, - new BooleanExpression.ComparisonExpression(ComparisonOperator.GT, - new ValueExpression.FieldRefExpression("common_c2s_pkt_num"), - new ValueExpression.FieldRefExpression("common_s2c_pkt_num")), - new BooleanExpression.ComparisonExpression(ComparisonOperator.GT, - new ValueExpression.FieldRefExpression("common_c2s_byte_num"), - new ValueExpression.FieldRefExpression("common_s2c_byte_num"))), - new ValueExpression.FieldRefExpression("common_client_port"), - new ValueExpression.FieldRefExpression("common_server_port")) - ); - } - - -}
\ No newline at end of file diff --git a/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/CalcCodeConvertorTest.java b/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/CalcCodeConvertorTest.java deleted file mode 100644 index fc842e7..0000000 --- a/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/CalcCodeConvertorTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.geedgenetworks.core.udf.test.codegen; - - -import com.geedgenetworks.core.expressions.InvalidProgramException; -import com.geedgenetworks.core.expressions.SyntaxErrorException; -import com.geedgenetworks.core.expressions.codegen.CalcCodeConvertor; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -class CalcCodeConvertorTest { - - private static Map<String, Object> origin; - - @BeforeAll - static void setUp() { - origin = new HashMap<>(); - origin.put("common_schema_type", "RTP"); - origin.put("common_sessions", 1); - origin.put("common_stream_dir", 3); - origin.put("common_vsys_id", 24); - - origin.put("common_server_ip", "172.17.200.50"); - origin.put("common_server_port", 36682); - origin.put("common_s2c_byte_num", 7570); - origin.put("common_s2c_pkt_num", 5); - - origin.put("common_client_ip", "172.17.201.16"); - origin.put("common_client_port", 42924); - origin.put("common_c2s_byte_num", 1834); - origin.put("common_c2s_pkt_num", 6); - - origin.put("common_out_dest_mac", "02:fc:08:dc:92:d7"); - origin.put("common_out_src_mac", "02:fc:08:dc:91:c3"); - } - - @Test - void testValueExpression() throws Exception { - // constant - assertEquals(CalcCodeConvertor.convert("'name'").eval(origin), "name"); - assertEquals(CalcCodeConvertor.convert("5").eval(origin), 5); - assertEquals(CalcCodeConvertor.convert("5L").eval(origin), 5L); - assertEquals(CalcCodeConvertor.convert("5D").eval(origin), (double) 5L); - assertEquals(CalcCodeConvertor.convert("5BD").eval(origin), BigDecimal.valueOf(5)); - assertEquals(CalcCodeConvertor.convert("TRUE").eval(origin), true); - assertEquals(CalcCodeConvertor.convert("FALSE").eval(origin), false); - - // variable - assertEquals(CalcCodeConvertor.convert("common_client_ip").eval(origin), - origin.get("common_client_ip")); - assertEquals(CalcCodeConvertor.convert("common_client_port").eval(origin), - origin.get("common_client_port")); - } - - @Test - void testConditionExpression() throws Exception { - int commonClientPort = (int) origin.get("common_client_port"); - int commonServerPort = (int) origin.get("common_server_port"); - int commonC2sPktNum = (int) origin.get("common_c2s_pkt_num"); - int commonS2cPktNum = (int) origin.get("common_s2c_pkt_num"); - int commonC2sByteNum = (int) origin.get("common_c2s_byte_num"); - int commonS2cByteNum = (int) origin.get("common_s2c_byte_num"); - assertEquals( - CalcCodeConvertor.convert("common_client_port > common_server_port " + - "? common_c2s_pkt_num : common_s2c_pkt_num").eval(origin), - commonClientPort > commonServerPort ? commonC2sPktNum : commonS2cPktNum); - assertEquals( - CalcCodeConvertor.convert("common_client_port > common_server_port " + - "? 'C2S:' + common_c2s_pkt_num : 'S2C:' + common_s2c_pkt_num").eval(origin), - commonClientPort > commonServerPort ? "C2S:" + commonC2sPktNum : "S2C:" + commonS2cPktNum); - assertEquals( - CalcCodeConvertor.convert("common_c2s_pkt_num > common_s2c_pkt_num " + - "& common_c2s_byte_num > common_s2c_byte_num ? common_client_port : common_server_port").eval(origin), - commonC2sPktNum > commonS2cPktNum - && commonC2sByteNum > commonS2cByteNum ? commonClientPort : commonServerPort - ); - } - - @Test - void testError() { - assertThrows(SyntaxErrorException.class, - () -> CalcCodeConvertor.convert("common_c2s_pkt_num > common_s2c_pkt_num")); - assertThrows(SyntaxErrorException.class, - () -> CalcCodeConvertor.convert("2 = 3")); - assertThrows(InvalidProgramException.class, - () -> CalcCodeConvertor.convert("common_client_ip - 10")); - } -}
\ No newline at end of file diff --git a/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/EvalCodeGeneratorTest.java b/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/EvalCodeGeneratorTest.java deleted file mode 100644 index 6a0d4d2..0000000 --- a/groot-tests/src/test/java/com/geedgenetworks/core/udf/expressions/codegen/EvalCodeGeneratorTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.geedgenetworks.core.udf.test.codegen; - - -import com.geedgenetworks.core.expressions.EvalExpressionResolver; -import com.geedgenetworks.core.expressions.Expression; -import com.geedgenetworks.core.expressions.codegen.CodeGeneratorContext; -import com.geedgenetworks.core.expressions.codegen.EvalCodeGenerator; -import org.apache.commons.lang3.StringUtils; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertTrue; - -class EvalCodeGeneratorTest { - - private static EvalExpressionResolver resolver; - - @BeforeAll - static void setUp() { - resolver = new EvalExpressionResolver(); - } - - @Test - void testCodeGen() { - Expression expression = resolver.resolve("common_client_port > common_server_port " + - " ? 'C2S:' + common_c2s_pkt_num : 'S2C:' + common_s2c_pkt_num"); - CodeGeneratorContext context = new CodeGeneratorContext(); - expression.accept(new EvalCodeGenerator(context)); - String memberCode = context.reuseMemberCode(); - assertTrue(StringUtils.contains(memberCode, "C2S:")); - assertTrue(StringUtils.contains(memberCode, "S2C:")); - } - -} @@ -19,6 +19,7 @@ <module>groot-shade</module> <module>groot-example</module> <module>groot-formats</module> + <module>groot-tests</module> </modules> <properties> @@ -479,7 +480,7 @@ <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> <!-- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> - <mainClass>com.geedgenetworks.bootstrap.main.GrootStreamServerTmp</mainClass> + <mainClass>com.geedgenetworks.bootstrap.main.GrootStreamServer</mainClass> </transformer>--> </transformers> </configuration> |
