You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by el...@apache.org on 2016/06/18 23:16:09 UTC
[19/31] incubator-slider git commit: SLIDER-1133 Provide support to
accept metainfo as a JSON blob from the command line
SLIDER-1133 Provide support to accept metainfo as a JSON blob from the command line
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/eccefc1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/eccefc1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/eccefc1e
Branch: refs/heads/branches/branch-0.91
Commit: eccefc1e407ffd90ae81612c713787bf712eab9e
Parents: 44f4a54
Author: Gour Saha <go...@apache.org>
Authored: Fri May 27 11:37:14 2016 -0700
Committer: Gour Saha <go...@apache.org>
Committed: Fri May 27 11:37:14 2016 -0700
----------------------------------------------------------------------
.../AbstractClusterBuildingActionArgs.java | 6 ++-
.../apache/slider/common/params/Arguments.java | 1 +
.../core/persist/AppDefinitionPersister.java | 47 ++++++++++++++++----
.../agent/TestAppDefinitionPersister.java | 43 ++++++++++++++++--
4 files changed, 85 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/eccefc1e/slider-core/src/main/java/org/apache/slider/common/params/AbstractClusterBuildingActionArgs.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/params/AbstractClusterBuildingActionArgs.java b/slider-core/src/main/java/org/apache/slider/common/params/AbstractClusterBuildingActionArgs.java
index 1c694bd..3833394 100644
--- a/slider-core/src/main/java/org/apache/slider/common/params/AbstractClusterBuildingActionArgs.java
+++ b/slider-core/src/main/java/org/apache/slider/common/params/AbstractClusterBuildingActionArgs.java
@@ -87,9 +87,13 @@ public abstract class AbstractClusterBuildingActionArgs extends
public File template;
@Parameter(names = {ARG_METAINFO},
- description = "Application meta info")
+ description = "Application meta info file")
public File appMetaInfo;
+ @Parameter(names = {ARG_METAINFO_JSON},
+ description = "Application meta info JSON blob")
+ public String appMetaInfoJson;
+
@Parameter(names = {ARG_APPDEF},
description = "Application def (folder or a zip package)")
public File appDef;
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/eccefc1e/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java b/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java
index bac20d7..0a8388d 100644
--- a/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java
+++ b/slider-core/src/main/java/org/apache/slider/common/params/Arguments.java
@@ -87,6 +87,7 @@ public interface Arguments {
String ARG_MANAGER_SHORT = "--m";
String ARG_MESSAGE = "--message";
String ARG_METAINFO = "--metainfo";
+ String ARG_METAINFO_JSON = "--metainfojson";
String ARG_NAME = "--name";
String ARG_OPTION = "--option";
String ARG_OPTION_SHORT = "-O";
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/eccefc1e/slider-core/src/main/java/org/apache/slider/core/persist/AppDefinitionPersister.java
----------------------------------------------------------------------
diff --git a/slider-core/src/main/java/org/apache/slider/core/persist/AppDefinitionPersister.java b/slider-core/src/main/java/org/apache/slider/core/persist/AppDefinitionPersister.java
index 2448c72..8efaa5b 100644
--- a/slider-core/src/main/java/org/apache/slider/core/persist/AppDefinitionPersister.java
+++ b/slider-core/src/main/java/org/apache/slider/core/persist/AppDefinitionPersister.java
@@ -24,6 +24,7 @@ import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.fs.Path;
import org.apache.slider.common.SliderKeys;
import org.apache.slider.common.params.AbstractClusterBuildingActionArgs;
+import org.apache.slider.common.params.Arguments;
import org.apache.slider.common.tools.SliderFileSystem;
import org.apache.slider.common.tools.SliderUtils;
import org.apache.slider.core.conf.ConfTreeOperations;
@@ -35,6 +36,7 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -109,28 +111,57 @@ public class AppDefinitionPersister {
ConfTreeOperations appConf)
throws BadConfigException, IOException, BadCommandArgumentsException {
// if metainfo is provided add to the app instance
- if (buildInfo.appMetaInfo != null) {
-
- if (!buildInfo.appMetaInfo.canRead() || !buildInfo.appMetaInfo.isFile()) {
- throw new BadConfigException("--metainfo file cannot be read.");
+ if (buildInfo.appMetaInfo != null || buildInfo.appMetaInfoJson != null) {
+ if (buildInfo.appMetaInfo != null && buildInfo.appMetaInfoJson != null) {
+ throw new BadConfigException("Both %s and %s cannot be specified",
+ Arguments.ARG_METAINFO, Arguments.ARG_METAINFO_JSON);
}
+ // Now we know that only one of either file or JSON is used
+ boolean isFileUsed = buildInfo.appMetaInfo != null ? true : false;
+ String argUsed = isFileUsed ? Arguments.ARG_METAINFO
+ : Arguments.ARG_METAINFO_JSON;
+
if (buildInfo.appDef != null) {
- throw new BadConfigException("both --metainfo and --appdef may not be specified.");
+ throw new BadConfigException("Both %s and %s cannot be specified",
+ argUsed, Arguments.ARG_APPDEF);
}
if (SliderUtils.isSet(appConf.getGlobalOptions().get(AgentKeys.APP_DEF))) {
- throw new BadConfigException("application.def must not be set if --metainfo is provided.");
+ throw new BadConfigException(
+ "%s cannot not be set if %s is specified in the cmd line ",
+ AgentKeys.APP_DEF, argUsed);
+ }
+
+ if (isFileUsed) {
+ if (!buildInfo.appMetaInfo.canRead() || !buildInfo.appMetaInfo.isFile()) {
+ throw new BadConfigException(
+ "Path specified with %s either cannot be read or is not a file",
+ Arguments.ARG_METAINFO);
+ }
+ } else {
+ if (StringUtils.isEmpty(buildInfo.appMetaInfoJson.trim())) {
+ throw new BadConfigException("Empty string specified with %s",
+ Arguments.ARG_METAINFO_JSON);
+ }
}
File tempDir = Files.createTempDir();
File pkgSrcDir = new File(tempDir, "default");
pkgSrcDir.mkdirs();
- Files.copy(buildInfo.appMetaInfo, new File(pkgSrcDir, "metainfo.json"));
+ File destMetaInfo = new File(pkgSrcDir, "metainfo.json");
+ if (isFileUsed) {
+ Files.copy(buildInfo.appMetaInfo, destMetaInfo);
+ } else {
+ Files.write(
+ buildInfo.appMetaInfoJson.getBytes(Charset.forName("UTF-8")),
+ destMetaInfo);
+ }
Path appDirPath = sliderFileSystem.buildAppDefDirPath(clustername);
log.info("Using default app def path {}", appDirPath.toString());
- appDefinitions.add(new AppDefinition(appDirPath, pkgSrcDir, SliderKeys.DEFAULT_APP_PKG));
+ appDefinitions.add(new AppDefinition(appDirPath, pkgSrcDir,
+ SliderKeys.DEFAULT_APP_PKG));
Path appDefPath = new Path(appDirPath, SliderKeys.DEFAULT_APP_PKG);
appConf.getGlobalOptions().set(AgentKeys.APP_DEF, appDefPath);
log.info("Setting app package to {}.", appDefPath);
http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/eccefc1e/slider-core/src/test/java/org/apache/slider/providers/agent/TestAppDefinitionPersister.java
----------------------------------------------------------------------
diff --git a/slider-core/src/test/java/org/apache/slider/providers/agent/TestAppDefinitionPersister.java b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAppDefinitionPersister.java
index eaf496c..dedf4f6 100644
--- a/slider-core/src/test/java/org/apache/slider/providers/agent/TestAppDefinitionPersister.java
+++ b/slider-core/src/test/java/org/apache/slider/providers/agent/TestAppDefinitionPersister.java
@@ -85,7 +85,9 @@ public class TestAppDefinitionPersister {
adp.processSuppliedDefinitions(clustername, buildInfo, appConf);
} catch (BadConfigException bce) {
log.info(bce.getMessage());
- Assert.assertTrue(bce.getMessage().contains("--metainfo file cannot be read"));
+ Assert.assertTrue(bce.getMessage().contains(
+ "Path specified with "
+ + "--metainfo either cannot be read or is not a file"));
}
try (PrintWriter writer = new PrintWriter(metainfo.getAbsolutePath(), "UTF-8")) {
@@ -98,18 +100,53 @@ public class TestAppDefinitionPersister {
adp.processSuppliedDefinitions(clustername, buildInfo, appConf);
} catch (BadConfigException bce) {
log.info(bce.getMessage());
- Assert.assertTrue(bce.getMessage().contains("both --metainfo and --appdef may not be specified"));
+ Assert.assertTrue(bce.getMessage().contains(
+ "Both --metainfo and --appdef cannot be specified"));
+ }
+
+ // both --metainfojson and --appdef cannot be specified
+ buildInfo.appMetaInfo = null;
+ buildInfo.appMetaInfoJson = "{}";
+ try {
+ adp.processSuppliedDefinitions(clustername, buildInfo, appConf);
+ } catch (BadConfigException bce) {
+ log.info(bce.getMessage());
+ Assert.assertTrue(bce.getMessage().contains(
+ "Both --metainfojson and --appdef cannot be specified"));
}
buildInfo.appDef = null;
+ buildInfo.appMetaInfoJson = "";
+ try {
+ adp.processSuppliedDefinitions(clustername, buildInfo, appConf);
+ } catch (BadConfigException bce) {
+ log.info(bce.getMessage());
+ Assert.assertTrue(bce.getMessage().contains(
+ "Empty string specified with --metainfojson"));
+ }
+ buildInfo.appMetaInfo = metainfo;
+
+ // both --metainfo and --metainfojson cannot be specified
+ buildInfo.appMetaInfoJson = "{}";
+ try {
+ adp.processSuppliedDefinitions(clustername, buildInfo, appConf);
+ } catch (BadConfigException bce) {
+ log.info(bce.getMessage());
+ Assert.assertTrue(bce.getMessage().contains(
+ "Both --metainfo and --metainfojson cannot be specified"));
+ }
+ buildInfo.appMetaInfoJson = null;
+
appConf.getGlobalOptions().set(AgentKeys.APP_DEF, metainfo.getAbsolutePath());
try {
adp.processSuppliedDefinitions(clustername, buildInfo, appConf);
} catch (BadConfigException bce) {
log.info(bce.getMessage());
- Assert.assertTrue(bce.getMessage().contains("application.def must not be set if --metainfo is provided"));
+ Assert.assertTrue(bce.getMessage().contains(
+ "application.def cannot "
+ + "not be set if --metainfo is specified in the cmd line"));
}
appConf.getGlobalOptions().remove(AgentKeys.APP_DEF);