Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions streampark-flink/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<name>StreamPark : Flink Parent</name>

<modules>
<module>streampark-flink-core</module>
<module>streampark-flink-shims</module>
<module>streampark-flink-sqlclient</module>
<module>streampark-flink-udf</module>
Expand Down
67 changes: 67 additions & 0 deletions streampark-flink/streampark-flink-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<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>org.apache.streampark</groupId>
<artifactId>streampark-flink</artifactId>
<version>${revision}</version>
</parent>

<artifactId>streampark-flink-core</artifactId>
<name>StreamPark : Flink Core</name>

<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients</artifactId>
<version>${flink.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>apache-release</id>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.streampark.flink.core;

/** Thrown when a {@link FlinkStreamingJob} fails during lifecycle execution. */
public class FlinkJobException extends Exception {

public FlinkJobException(String message, Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.streampark.flink.core;

import org.apache.flink.api.common.JobExecutionResult;
import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public abstract class FlinkStreamingJob {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We greatly appreciate your contribution. I have observed that the current Java implementation differs considerably from the Scala version, and that several core classes (FlinkStreamTable, FlinkTable) are not yet updated. The recommendation is to keep the original Scala module's logic unchanged and only reimplement it in Java, which would reduce the risk to a minimum. Subsequent iterations and modifications can be made thereafter.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review @wolfboys !

  1. Regarding FlinkStreamTable and FlinkTable — this PR intentionally covers only Phase 0.1 of the [Proposal] Remove Scala from StreamPark — design and migration plan #4408 roadmap, limiting the scope to FlinkStreamingJob. The remaining classes are planned for subsequent phases. I apologize if that context wasn't clear enough in the PR description. If my approach is off track, I would really appreciate your feedback.

  2. Regarding the difference from the Scala version — the lifecycle structure (init → ready → handle → execute → destroy) follows the original. The differences are intentional: since FlinkStreamingInitializer and StreamingContext are themselves Scala components targeted for removal in later phases, the Java version uses Flink's standard APIs directly instead of depending on them. This was a deliberate decision to avoid StreamPark's own wrapper classes, but I'd love your thoughts on whether this direction is the right one.


protected StreamExecutionEnvironment env;
protected ParameterTool parameter;
protected JobExecutionResult jobExecutionResult;

public final void run(String[] args) throws FlinkJobException {
try {
init(args);
ready();
handle();
jobExecutionResult =
env.execute(parameter.get("app.name", getClass().getSimpleName()));
destroy();
} catch (Exception e) {
throw new FlinkJobException("Failed to run Flink job: " + getClass().getSimpleName(), e);
}
}

private void init(String[] args) {
this.parameter = ParameterTool.fromArgs(args);
this.env = StreamExecutionEnvironment.getExecutionEnvironment();
configure(env, parameter);
env.getConfig().setGlobalJobParameters(parameter);
}

protected void configure(StreamExecutionEnvironment env, ParameterTool parameter) {
}

protected void ready() {
}

protected abstract void handle() throws FlinkJobException;

protected void destroy() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.streampark.flink.core;

import org.apache.flink.api.java.utils.ParameterTool;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

class FlinkStreamingJobTest {

@Test
void lifecycleExecutesInOrder() throws Exception {
List<String> trace = new ArrayList<>();

FlinkStreamingJob job =
new FlinkStreamingJob() {

@Override
protected void configure(StreamExecutionEnvironment env, ParameterTool parameter) {
trace.add("configure");
}

@Override
protected void ready() {
trace.add("ready");
}

@Override
protected void handle() {
trace.add("handle");
env.fromElements(1, 2, 3).map(i -> i * 2).print();
}

@Override
protected void destroy() {
trace.add("destroy");
}
};

job.run(new String[0]);

assertThat(trace).containsExactly("configure", "ready", "handle", "destroy");
assertThat(job.jobExecutionResult).isNotNull();
}

static class NoOpJob extends FlinkStreamingJob {

@Override
protected void handle() throws FlinkJobException {
env.fromElements(1).print();
}
}

@Test
void appNameDefaultsToClassName() throws Exception {
NoOpJob job = new NoOpJob();
job.run(new String[0]);
assertThat(job.getClass().getSimpleName()).isEqualTo("NoOpJob");
assertThat(job.jobExecutionResult).isNotNull();
}

@Test
void parameterToolPropagatedToEnv() throws Exception {
FlinkStreamingJob job =
new FlinkStreamingJob() {

@Override
protected void handle() {
env.fromElements(1).print();
}
};

job.run(new String[]{"--app.name", "test-job"});

assertThat(job.parameter.get("app.name")).isEqualTo("test-job");
}
}
Loading