Skip to content

Commit ed433ce

Browse files
committed
[FLINK-29469] Generate empty sessionjob jar programatically
1 parent c33e3ef commit ed433ce

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

.dockerignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,3 @@
2121
**/.idea
2222
**/*.iml
2323
**/*.DS_Store
24-
25-
!flink-kubernetes-operator/src/main/resources/noop.jar

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,3 @@ buildNumber.properties
3636
.idea
3737
*.iml
3838
*.DS_Store
39-
40-
!flink-kubernetes-operator/src/main/resources/noop.jar

flink-kubernetes-operator/src/main/java/org/apache/flink/kubernetes/operator/service/AbstractFlinkService.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595
import javax.annotation.Nullable;
9696

9797
import java.io.File;
98+
import java.io.FileOutputStream;
9899
import java.io.IOException;
99-
import java.io.InputStream;
100100
import java.net.InetSocketAddress;
101101
import java.net.Socket;
102102
import java.net.SocketAddress;
@@ -114,6 +114,8 @@
114114
import java.util.concurrent.Executors;
115115
import java.util.concurrent.TimeUnit;
116116
import java.util.concurrent.TimeoutException;
117+
import java.util.jar.JarOutputStream;
118+
import java.util.jar.Manifest;
117119
import java.util.stream.Collectors;
118120

119121
import static org.apache.flink.kubernetes.operator.config.FlinkConfigBuilder.FLINK_VERSION;
@@ -126,13 +128,13 @@
126128
public abstract class AbstractFlinkService implements FlinkService {
127129

128130
private static final Logger LOG = LoggerFactory.getLogger(AbstractFlinkService.class);
129-
private static final String NOOP_JAR_FILENAME = "noop.jar";
131+
private static final String EMPTY_JAR_FILENAME = "empty.jar";
130132

131133
protected final KubernetesClient kubernetesClient;
132134
protected final FlinkConfigManager configManager;
133135
private final ExecutorService executorService;
134136
protected final ArtifactManager artifactManager;
135-
private final String noopJarPath;
137+
private final String emptyJar;
136138

137139
public AbstractFlinkService(
138140
KubernetesClient kubernetesClient, FlinkConfigManager configManager) {
@@ -142,7 +144,7 @@ public AbstractFlinkService(
142144
this.executorService =
143145
Executors.newFixedThreadPool(
144146
4, new ExecutorThreadFactory("Flink-RestClusterClient-IO"));
145-
this.noopJarPath = copyNoopJar();
147+
this.emptyJar = createEmptyJar();
146148
}
147149

148150
protected abstract PodList getJmPodList(String namespace, String clusterId);
@@ -717,7 +719,7 @@ private String findJarURI(JobSpec jobSpec) {
717719
if (jobSpec.getJarURI() != null) {
718720
return jobSpec.getJarURI();
719721
} else {
720-
return noopJarPath;
722+
return emptyJar;
721723
}
722724
}
723725

@@ -836,22 +838,19 @@ private void validateHaMetadataExists(Configuration conf) {
836838
}
837839
}
838840

839-
private String copyNoopJar() {
841+
private String createEmptyJar() {
840842
try {
841-
InputStream noopJarSource =
842-
AbstractFlinkService.class
843-
.getClassLoader()
844-
.getResourceAsStream(NOOP_JAR_FILENAME);
843+
String emptyJarPath =
844+
Files.createTempDirectory("flink").toString() + "/" + EMPTY_JAR_FILENAME;
845845

846-
String noopJarDestination =
847-
Files.createTempDirectory("flink").toString() + "/" + NOOP_JAR_FILENAME;
846+
LOG.debug("Creating empty jar to {}", emptyJarPath);
847+
JarOutputStream target =
848+
new JarOutputStream(new FileOutputStream(emptyJarPath), new Manifest());
849+
target.close();
848850

849-
LOG.debug("Copying noop jar to {}", noopJarDestination);
850-
org.apache.commons.io.FileUtils.copyToFile(noopJarSource, new File(noopJarDestination));
851-
852-
return noopJarDestination;
851+
return emptyJarPath;
853852
} catch (Exception e) {
854-
throw new RuntimeException("Failed to copy noop jar", e);
853+
throw new RuntimeException("Failed to create empty jar", e);
855854
}
856855
}
857856
}
Binary file not shown.

0 commit comments

Comments
 (0)