You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by gr...@apache.org on 2014/10/06 13:56:36 UTC
[04/14] git commit: Tidy up copyResource and copyTemplate methods
Tidy up copyResource and copyTemplate methods
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/2edd90b4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/2edd90b4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/2edd90b4
Branch: refs/heads/master
Commit: 2edd90b4bdc1558c4980236422ca3c8f41bf8c3f
Parents: dd95f95
Author: Andrew Kennedy <gr...@apache.org>
Authored: Mon Sep 29 14:56:50 2014 +0100
Committer: Andrew Kennedy <gr...@apache.org>
Committed: Sun Oct 5 23:46:59 2014 +0100
----------------------------------------------------------------------
.../brooklyn/config/BrooklynServerConfig.java | 1 -
.../basic/AbstractSoftwareProcessSshDriver.java | 116 ++++++++-----------
.../entity/messaging/qpid/QpidSshDriver.java | 6 -
.../entity/monitoring/monit/MonitSshDriver.java | 2 +-
4 files changed, 47 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2edd90b4/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/BrooklynServerConfig.java b/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
index 92abd73..13e4c5d 100644
--- a/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
+++ b/core/src/main/java/brooklyn/config/BrooklynServerConfig.java
@@ -21,7 +21,6 @@ package brooklyn.config;
import static brooklyn.entity.basic.ConfigKeys.newStringConfigKey;
import brooklyn.catalog.CatalogLoadMode;
-import brooklyn.entity.rebind.persister.PersistMode;
import io.brooklyn.camp.CampPlatform;
import java.io.File;
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2edd90b4/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
index b49062c..baa95e3 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessSshDriver.java
@@ -284,6 +284,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
return getMachine().execScript(flags, summaryForLogging, script, environment);
}
+ // Will be prefixed with the entity's {@link #getInstallDir() install directory} if relative.
@Override
public void installResources() {
try {
@@ -296,16 +297,16 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
for (String source : installFiles.keySet()) {
String target = installFiles.get(source);
String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getInstallDir(), target);
- copyResource(source, destination);
+ copyResource(source, destination, true);
}
}
Map<String, String> installTemplates = entity.getConfig(SoftwareProcess.INSTALL_TEMPLATES);
if (installTemplates != null && installTemplates.size() > 0) {
- for (String source : installFiles.keySet()) {
- String target = installFiles.get(source);
+ for (String source : installTemplates.keySet()) {
+ String target = installTemplates.get(source);
String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getInstallDir(), target);
- copyTemplate(source, destination);
+ copyTemplate(source, destination, true, MutableMap.<String, Object>of());
}
}
} catch (Exception e) {
@@ -315,6 +316,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
}
}
+ // Will be prefixed with the entity's {@link #getRunDir() run directory} if relative.
@Override
public void runtimeResources() {
try {
@@ -322,12 +324,20 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
Map<String, String> runtimeFiles = entity.getConfig(SoftwareProcess.RUNTIME_FILES);
if (runtimeFiles != null && runtimeFiles.size() > 0) {
- copyResources(runtimeFiles);
+ for (String source : runtimeFiles.keySet()) {
+ String target = runtimeFiles.get(source);
+ String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getRunDir(), target);
+ copyResource(source, destination, true);
+ }
}
Map<String, String> runtimeTemplates = entity.getConfig(SoftwareProcess.RUNTIME_TEMPLATES);
if (runtimeTemplates != null && runtimeTemplates.size() > 0) {
- copyTemplates(runtimeTemplates);
+ for (String source : runtimeTemplates.keySet()) {
+ String target = runtimeTemplates.get(source);
+ String destination = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getRunDir(), target);
+ copyTemplate(source, destination, true, MutableMap.<String, Object>of());
+ }
}
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
@@ -364,8 +374,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
/**
* @param template File to template and copy.
- * @param target Destination on server. Will be prefixed with the entity's
- * {@link #getRunDir() run directory} if relative.
+ * @param target Destination on server.
* @return The exit code the SSH command run.
*/
public int copyTemplate(File template, String target) {
@@ -374,65 +383,28 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
/**
* @param template URI of file to template and copy, e.g. file://.., http://.., classpath://..
- * @param target Destination on server. Will be prefixed with the entity's
- * {@link #getRunDir() run directory} if relative.
+ * @param target Destination on server.
* @return The exit code of the SSH command run.
*/
public int copyTemplate(String template, String target) {
- return copyTemplate(template, target, ImmutableMap.<String, String>of());
+ return copyTemplate(template, target, false, ImmutableMap.<String, String>of());
}
/**
* @param template URI of file to template and copy, e.g. file://.., http://.., classpath://..
- * @param target Destination on server. Will be prefixed with the entity's
- * {@link #getRunDir() run directory} if relative.
+ * @param target Destination on server.
* @param extraSubstitutions Extra substitutions for the templater to use, for example
* "foo" -> "bar", and in a template ${foo}.
* @return The exit code of the SSH command run.
*/
- public int copyTemplate(String template, String target, Map<String, ?> extraSubstitutions) {
+ public int copyTemplate(String template, String target, boolean createParent, Map<String, ?> extraSubstitutions) {
String data = processTemplate(template, extraSubstitutions);
- return copyResource(new StringReader(data), target);
- }
-
- /**
- * Templates all resources in the given map, then copies them to the driver's {@link #getMachine() machine}.
- * @param templates A mapping of resource URI to server destination.
- * @see #copyTemplate(String, String)
- */
- public void copyTemplates(Map<String, String> templates) {
- if (templates != null && templates.size() > 0) {
- log.info("Customising {} with templates: {}", entity, templates);
-
- for (Map.Entry<String, String> entry : templates.entrySet()) {
- String source = entry.getValue();
- String dest = entry.getKey();
- copyTemplate(source, dest);
- }
- }
- }
-
- /**
- * Copies all resources in the given map to the driver's {@link #getMachine() machine}.
- * @param resources A mapping of resource URI to server destination.
- * @see #copyResource(String, String)
- */
- public void copyResources(Map<String, String> resources) {
- if (resources != null && resources.size() > 0) {
- log.info("Customising {} with resources: {}", entity, resources);
-
- for (Map.Entry<String, String> entry : resources.entrySet()) {
- String source = entry.getValue();
- String dest = entry.getKey();
- copyResource(source, dest);
- }
- }
+ return copyResource(MutableMap.<Object,Object>of(), new StringReader(data), target, createParent);
}
/**
* @param file File to copy.
- * @param target Destination on server. Will be prefixed with the entity's
- * {@link #getRunDir() run directory} if relative.
+ * @param target Destination on server.
* @return The exit code the SSH command run.
*/
public int copyResource(File file, String target) {
@@ -441,8 +413,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
/**
* @param resource URI of file to copy, e.g. file://.., http://.., classpath://..
- * @param target Destination on server. Will be prefixed with the entity's
- * {@link #getRunDir() run directory} if relative.
+ * @param target Destination on server.
* @return The exit code of the SSH command run
*/
public int copyResource(String resource, String target) {
@@ -463,35 +434,31 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
* given flags are used. Otherwise, the given flags are combined with (and take
* precendence over) the flags returned by {@link #getSshFlags()}.
* @param source URI of file to copy, e.g. file://.., http://.., classpath://..
- * @param target Destination on server. Will be prefixed with the entity's
- * {@link #getRunDir() run directory} if relative.
+ * @param target Destination on server
* @param createParentDir Whether to create the parent target directory, if it doesn't already exist
* @return The exit code of the SSH command run
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
- public int copyResource(Map sshFlags, String source, String target, boolean createParentDir) {
+ public int copyResource(Map<Object,Object> sshFlags, String source, String target, boolean createParentDir) {
Map flags = Maps.newLinkedHashMap();
if (!sshFlags.containsKey(IGNORE_ENTITY_SSH_FLAGS)) {
flags.putAll(getSshFlags());
}
flags.putAll(sshFlags);
- // prefix with runDir if relative target
- String dest = Os.isAbsolutish(target) ? target : Os.mergePathsUnix(getRunDir(), target);
-
if (createParentDir) {
// don't use File.separator because it's remote machine's format, rather than local machine's
- int lastSlashIndex = dest.lastIndexOf("/");
- String parent = (lastSlashIndex > 0) ? dest.substring(0, lastSlashIndex) : null;
+ int lastSlashIndex = target.lastIndexOf("/");
+ String parent = (lastSlashIndex > 0) ? target.substring(0, lastSlashIndex) : null;
if (parent != null) {
getMachine().execCommands("createParentDir", ImmutableList.of("mkdir -p "+parent));
}
}
-
- int result = getMachine().installTo(resource, flags, source, dest);
+
+ int result = getMachine().installTo(resource, flags, source, target);
if (result == 0) {
if (log.isDebugEnabled()) {
- log.debug("Copied file for {}: {} to {} - result {}", new Object[] { entity, source, dest, result });
+ log.debug("Copied file for {}: {} to {} - result {}", new Object[] { entity, source, target, result });
}
}
return result;
@@ -501,21 +468,21 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
* @see #copyResource(Map, InputStream, String)
*/
public int copyResource(Reader source, String target) {
- return copyResource(MutableMap.of(), source, target);
+ return copyResource(MutableMap.of(), source, target, false);
}
/**
* @see #copyResource(Map, InputStream, String)
*/
- public int copyResource(InputStream source, String target) {
- return copyResource(MutableMap.of(), source, target);
+ public int copyResource(Map<Object,Object> sshFlags, Reader source, String target, boolean createParent) {
+ return copyResource(sshFlags, new ReaderInputStream(source), target, createParent);
}
/**
* @see #copyResource(Map, InputStream, String)
*/
- public int copyResource(Map<?,?> sshFlags, Reader source, String target) {
- return copyResource(sshFlags, new ReaderInputStream(source), target);
+ public int copyResource(InputStream source, String target) {
+ return copyResource(MutableMap.of(), source, target, false);
}
/**
@@ -527,7 +494,7 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
* @see #copyResource(Map, String, String) for parameter descriptions.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
- public int copyResource(Map<?,?> sshFlags, InputStream source, String target) {
+ public int copyResource(Map<Object,Object> sshFlags, InputStream source, String target, boolean createParentDir) {
Map flags = Maps.newLinkedHashMap();
if (!sshFlags.containsKey(IGNORE_ENTITY_SSH_FLAGS)) {
flags.putAll(getSshFlags());
@@ -536,6 +503,15 @@ public abstract class AbstractSoftwareProcessSshDriver extends AbstractSoftwareP
// prefix with runDir if relative target
String dest = Os.isAbsolutish(target) ? target : Urls.mergePaths(getRunDir(), target);
+
+ if (createParentDir) {
+ // don't use File.separator because it's remote machine's format, rather than local machine's
+ int lastSlashIndex = dest.lastIndexOf("/");
+ String parent = (lastSlashIndex > 0) ? dest.substring(0, lastSlashIndex) : null;
+ if (parent != null) {
+ getMachine().execCommands("createParentDir", ImmutableList.of("mkdir -p "+parent));
+ }
+ }
// TODO SshMachineLocation.copyTo currently doesn't log warn on non-zero or set blocking details
// (because delegated to by installTo, for multiple calls). So do it here for now.
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2edd90b4/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidSshDriver.java
----------------------------------------------------------------------
diff --git a/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidSshDriver.java b/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidSshDriver.java
index 2ad68be..25d34df 100644
--- a/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidSshDriver.java
+++ b/software/messaging/src/main/java/brooklyn/entity/messaging/qpid/QpidSshDriver.java
@@ -86,12 +86,6 @@ public class QpidSshDriver extends JavaSoftwareProcessSshDriver implements QpidD
"mkdir lib/opt"
)
.execute();
-
- Map runtimeFiles = entity.getConfig(QpidBroker.RUNTIME_FILES);
- copyResources(runtimeFiles);
-
- Map runtimeTemplates = entity.getConfig(QpidBroker.RUNTIME_TEMPLATES);
- copyTemplates(runtimeTemplates);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2edd90b4/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitSshDriver.java
----------------------------------------------------------------------
diff --git a/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitSshDriver.java b/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitSshDriver.java
index 5fd5749..36be869 100644
--- a/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitSshDriver.java
+++ b/software/monitoring/src/main/java/brooklyn/entity/monitoring/monit/MonitSshDriver.java
@@ -76,7 +76,7 @@ public class MonitSshDriver extends AbstractSoftwareProcessSshDriver implements
.execute(); //create the directory
String controlFileUrl = getEntity().getConfig(MonitNode.CONTROL_FILE_URL);
remoteControlFilePath = getRunDir() + "/monit.monitrc";
- copyTemplate(controlFileUrl, remoteControlFilePath, getEntity().getConfig(MonitNode.CONTROL_FILE_SUBSTITUTIONS));
+ copyTemplate(controlFileUrl, remoteControlFilePath, false, getEntity().getConfig(MonitNode.CONTROL_FILE_SUBSTITUTIONS));
// Monit demands the control file has permissions <= 0700
newScript(CUSTOMIZING)
.body.append("chmod 600 " + remoteControlFilePath)