Repository: incubator-brooklyn
Updated Branches:
refs/heads/master 50cd8a10f -> 0c3e7ea53
Extend brooklynnode.classpath config options
classpath can be a list of
- URLs or file names or directory names as before,
- maps specifying a URL and a filename,
e.g. { "url": "http://...", "filename": "myfile.jar" }
This feature is needed to fix incorrect filename deduction in
situations where the URL does not contain an explicit jar name
Finally, the destination directory has been changed from ./lib to
./lib/dropins
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit:
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/40ae82c8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/40ae82c8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/40ae82c8
Branch: refs/heads/master
Commit: 40ae82c85f3df9985cacb25c8d0d95059d3f576c
Parents: 7b89b66
Author: googlielmo <[email protected]>
Authored: Mon Oct 12 15:23:26 2015 +0200
Committer: googlielmo <[email protected]>
Committed: Mon Oct 12 15:23:26 2015 +0200
----------------------------------------------------------------------
.../entity/brooklynnode/BrooklynNode.java | 2 +-
.../entity/brooklynnode/BrooklynNodeImpl.java | 12 +++---
.../brooklynnode/BrooklynNodeSshDriver.java | 41 ++++++++++++++-----
.../BrooklynNodeIntegrationTest.java | 43 ++++++++++++++++++--
4 files changed, 77 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40ae82c8/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java
----------------------------------------------------------------------
diff --git
a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java
b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java
index 6399441..55c2e27 100644
---
a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java
+++
b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNode.java
@@ -218,7 +218,7 @@ public interface BrooklynNode extends SoftwareProcess,
UsesJava {
@SuppressWarnings({ "rawtypes", "unchecked" })
@SetFromFlag("classpath")
- public static final BasicAttributeSensorAndConfigKey<List<String>>
CLASSPATH = new BasicAttributeSensorAndConfigKey(
+ public static final BasicAttributeSensorAndConfigKey<List> CLASSPATH = new
BasicAttributeSensorAndConfigKey(
List.class, "brooklynnode.classpath", "classpath to use, as list
of URL entries", Lists.newArrayList());
@SuppressWarnings({ "rawtypes", "unchecked" })
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40ae82c8/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
----------------------------------------------------------------------
diff --git
a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
index 2f0d1de..e85b335 100644
---
a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
+++
b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
@@ -432,18 +432,18 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl
implements BrooklynNod
}
}
- public List<String> getClasspath() {
- List<String> classpath = getConfig(CLASSPATH);
+ public List getClasspath() {
+ List classpath = getConfig(CLASSPATH);
if (classpath == null || classpath.isEmpty()) {
classpath =
getManagementContext().getConfig().getConfig(CLASSPATH);
}
return classpath;
}
-
+
protected List<String> getEnabledHttpProtocols() {
return getAttribute(ENABLED_HTTP_PROTOCOLS);
}
-
+
protected boolean isHttpProtocolEnabled(String protocol) {
List<String> protocols = getAttribute(ENABLED_HTTP_PROTOCOLS);
for (String contender : protocols) {
@@ -457,7 +457,7 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl
implements BrooklynNod
@Override
protected void connectSensors() {
super.connectSensors();
-
+
// TODO what sensors should we poll?
ConfigToAttributes.apply(this);
@@ -512,7 +512,7 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl
implements BrooklynNod
connectServiceUpIsRunning();
}
}
-
+
@Override
protected void disconnectSensors() {
super.disconnectSensors();
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40ae82c8/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
----------------------------------------------------------------------
diff --git
a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
index 9526e94..8058d0f 100644
---
a/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
+++
b/software/base/src/main/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
@@ -175,7 +175,7 @@ public class BrooklynNodeSshDriver extends
JavaSoftwareProcessSshDriver implemen
// but that does not play nicely if installing dists
other than brooklyn
// (such as what is built by our artifact)
format("cp -R %s/* .", getExpandedInstallDir()),
- "mkdir -p ./lib/")
+ "mkdir -p ./lib/dropins/")
.execute();
SshMachineLocation machine = getMachine();
@@ -244,20 +244,33 @@ public class BrooklynNodeSshDriver extends
JavaSoftwareProcessSshDriver implemen
machine.copyTo(MutableMap.of("permissions", "0600"),
resource.getResourceFromUrl(localResource), resolvedRemotePath);
}
- for (String entry : getEntity().getClasspath()) {
- // If a local folder, then create archive from contents first
- if (Urls.isDirectory(entry)) {
- File jarFile = ArchiveBuilder.jar().addDirContentsAt(new
File(entry), "").create();
- entry = jarFile.getAbsolutePath();
+ for (Object entry : getEntity().getClasspath()) {
+ String filename = null;
+ String url = null;
+
+ if (entry instanceof String) {
+ url = (String) entry;
+ } else {
+ if (entry instanceof Map) {
+ url = (String) ((Map) entry).get("url");
+ filename = (String) ((Map) entry).get("filename");
+ }
}
+ checkNotNull(url, "url");
- // Determine filename
- String destFile = entry.contains("?") ? entry.substring(0,
entry.indexOf('?')) : entry;
- destFile = destFile.substring(destFile.lastIndexOf('/') + 1);
+ // If a local folder, then create archive from contents first
+ if (Urls.isDirectory(url)) {
+ File jarFile = ArchiveBuilder.jar().addDirContentsAt(new
File(url), "").create();
+ url = jarFile.getAbsolutePath();
+ }
- ArchiveUtils.deploy(MutableMap.<String, Object>of(), entry,
machine, getRunDir(), Os.mergePaths(getRunDir(), "lib"), destFile);
+ if (filename == null) {
+ // Determine filename
+ filename = getFilename(url);
+ }
+ ArchiveUtils.deploy(MutableMap.<String, Object>of(), url, machine,
getRunDir(), Os.mergePaths(getRunDir(), "lib", "dropins"), filename);
}
-
+
String cmd = entity.getConfig(BrooklynNode.EXTRA_CUSTOMIZATION_SCRIPT);
if (Strings.isNonBlank(cmd)) {
DynamicTasks.queueIfPossible(
SshEffectorTasks.ssh(cmd).summary("Bespoke BrooklynNode customization script")
@@ -266,6 +279,12 @@ public class BrooklynNodeSshDriver extends
JavaSoftwareProcessSshDriver implemen
}
}
+ private String getFilename(String url) {
+ String destFile = url.contains("?") ? url.substring(0,
url.indexOf('?')) : url;
+ destFile = destFile.substring(destFile.lastIndexOf('/') + 1);
+ return destFile;
+ }
+
@SuppressWarnings("deprecation")
@Override
public void launch() {
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/40ae82c8/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
----------------------------------------------------------------------
diff --git
a/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
b/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
index 5fbd5bd..32899da 100644
---
a/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
+++
b/software/base/src/test/java/org/apache/brooklyn/entity/brooklynnode/BrooklynNodeIntegrationTest.java
@@ -29,6 +29,7 @@ import java.lang.reflect.Proxy;
import java.net.URI;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.ExecutionException;
import org.apache.brooklyn.api.effector.Effector;
@@ -274,8 +275,9 @@ services:
Files.write(content, classpathEntry1, Charsets.UTF_8);
Files.write(content, classpathEntry2, Charsets.UTF_8);
File tempDir = Files.createTempDir();
- File expectedFile1 = new File(new File(tempDir, "lib"),
classpathEntry1.getName());
- File expectedFile2 = new File(new File(tempDir, "lib"),
classpathEntry2.getName());
+ File destDir = new File(new File(tempDir, "lib"), "dropins");
+ File expectedFile1 = new File(destDir, classpathEntry1.getName());
+ File expectedFile2 = new File(destDir, classpathEntry2.getName());
try {
BrooklynNode brooklynNode =
app.createAndManageChild(newBrooklynNodeSpecForTest()
@@ -297,6 +299,41 @@ services:
}
@Test(groups="Integration")
+ public void testCopiesClasspathEntriesInConfigKey2() throws Exception {
+ String content = "abc=def";
+ File classpathEntry1 = File.createTempFile("first", ".properties");
+ File classpathEntry2 = File.createTempFile("second", ".properties");
+ Files.write(content, classpathEntry1, Charsets.UTF_8);
+ Files.write(content, classpathEntry2, Charsets.UTF_8);
+ File tempDir = Files.createTempDir();
+ String testName1 = "test_" + classpathEntry1.getName();
+ File destDir = new File(new File(tempDir, "lib"), "dropins");
+ File expectedFile1 = new File(destDir, testName1);
+ String testName2 = "test_" + classpathEntry2.getName();
+ File expectedFile2 = new File(destDir, testName2);
+ Map entry1 = ImmutableMap.of("url", classpathEntry1.getAbsolutePath(),
"filename", testName1);
+ Map entry2 = ImmutableMap.of("url", classpathEntry2.getAbsolutePath(),
"filename", testName2);
+
+ try {
+ BrooklynNode brooklynNode =
app.createAndManageChild(newBrooklynNodeSpecForTest()
+ .configure(BrooklynNode.RUN_DIR,
tempDir.getAbsolutePath())
+ .configure(BrooklynNode.CLASSPATH,
ImmutableList.of(entry1, entry2))
+ );
+ app.start(locs);
+ log.info("started "+app+" containing "+brooklynNode+" for
"+JavaClassNames.niceClassAndMethod());
+
+ assertEquals(Files.readLines(expectedFile1, Charsets.UTF_8),
ImmutableList.of(content));
+ assertEquals(Files.readLines(expectedFile2, Charsets.UTF_8),
ImmutableList.of(content));
+ } finally {
+ expectedFile1.delete();
+ expectedFile2.delete();
+ tempDir.delete();
+ classpathEntry1.delete();
+ classpathEntry2.delete();
+ }
+ }
+
+ @Test(groups="Integration")
public void testCopiesClasspathEntriesInBrooklynProperties() throws
Exception {
String content = "abc=def";
File classpathEntry1 = File.createTempFile("first", ".properties");
@@ -328,7 +365,7 @@ services:
classpathEntry2.delete();
}
}
-
+
// TODO test that the classpath set above is actually used
@Test(groups="Integration")