From d1efe1be6dab4931b22e0b83b9ec2549345ced86 Mon Sep 17 00:00:00 2001 From: mycFelix Date: Thu, 8 Dec 2016 15:37:08 +0800 Subject: [PATCH] Remove duplicated code in SubmitterMain and SchedulerConfig --- .../com/twitter/heron/common/basics/FileUtils.java | 13 +++++++++++++ .../com/twitter/heron/scheduler/SubmitterMain.java | 11 +---------- .../twitter/heron/spi/utils/SchedulerConfig.java | 10 +--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/heron/common/src/java/com/twitter/heron/common/basics/FileUtils.java b/heron/common/src/java/com/twitter/heron/common/basics/FileUtils.java index da8f39e9f41..c53503d352c 100644 --- a/heron/common/src/java/com/twitter/heron/common/basics/FileUtils.java +++ b/heron/common/src/java/com/twitter/heron/common/basics/FileUtils.java @@ -123,4 +123,17 @@ public static boolean isOriginalPackagePex(String packageFilename) { public static String getBaseName(String file) { return new File(file).getName(); } + + public static String getPkgType(String topologyBinaryFile) { + String pkgType; + String basename = FileUtils.getBaseName(topologyBinaryFile); + if (FileUtils.isOriginalPackagePex(basename)) { + pkgType = "pex"; + } else if (FileUtils.isOriginalPackageJar(basename)) { + pkgType = "jar"; + } else { + pkgType = "tar"; + } + return pkgType; + } } diff --git a/heron/scheduler-core/src/java/com/twitter/heron/scheduler/SubmitterMain.java b/heron/scheduler-core/src/java/com/twitter/heron/scheduler/SubmitterMain.java index 1392bd20b14..7102f81142e 100644 --- a/heron/scheduler-core/src/java/com/twitter/heron/scheduler/SubmitterMain.java +++ b/heron/scheduler-core/src/java/com/twitter/heron/scheduler/SubmitterMain.java @@ -60,16 +60,7 @@ public class SubmitterMain { protected static Config topologyConfigs( String topologyPackage, String topologyBinaryFile, String topologyDefnFile, TopologyAPI.Topology topology) { - - String pkgType; - String basename = FileUtils.getBaseName(topologyBinaryFile); - if (FileUtils.isOriginalPackagePex(basename)) { - pkgType = "pex"; - } else if (FileUtils.isOriginalPackageJar(basename)) { - pkgType = "jar"; - } else { - pkgType = "tar"; - } + String pkgType = FileUtils.getPkgType(topologyBinaryFile); Config config = Config.newBuilder() .put(Keys.topologyId(), topology.getId()) diff --git a/heron/spi/src/java/com/twitter/heron/spi/utils/SchedulerConfig.java b/heron/spi/src/java/com/twitter/heron/spi/utils/SchedulerConfig.java index 1d5c9ace47f..cbfbc5f4126 100644 --- a/heron/spi/src/java/com/twitter/heron/spi/utils/SchedulerConfig.java +++ b/heron/spi/src/java/com/twitter/heron/spi/utils/SchedulerConfig.java @@ -43,15 +43,7 @@ private SchedulerConfig() { */ protected static Config topologyConfigs(String topologyBinaryFile, String topologyDefnFile, TopologyAPI.Topology topology) { - String basename = FileUtils.getBaseName(topologyBinaryFile); - String pkgType; - if (FileUtils.isOriginalPackagePex(basename)) { - pkgType = "pex"; - } else if (FileUtils.isOriginalPackageJar(basename)) { - pkgType = "jar"; - } else { - pkgType = "tar"; - } + String pkgType = FileUtils.getPkgType(topologyBinaryFile); Config config = Config.newBuilder() .put(Keys.topologyId(), topology.getId())