brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [21/29] git commit: use more rules to infer the subpath inside a brooklyn archive
Date Mon, 03 Nov 2014 15:52:05 GMT
use more rules to infer the subpath inside a brooklyn archive


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/6dfd1789
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/6dfd1789
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/6dfd1789

Branch: refs/heads/master
Commit: 6dfd17894739dc24e0198932e49218ec7dfcf8c9
Parents: d768efa
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Oct 30 21:18:07 2014 -0500
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Oct 31 09:39:51 2014 -0500

----------------------------------------------------------------------
 .../entity/brooklynnode/BrooklynNode.java       |  3 +-
 .../brooklynnode/BrooklynNodeSshDriver.java     | 35 ++++++++++++++++++--
 2 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6dfd1789/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
index a0f0032..20626f9 100644
--- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
+++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNode.java
@@ -87,7 +87,8 @@ public interface BrooklynNode extends SoftwareProcess, UsesJava {
     ConfigKey<String> SUBPATH_IN_ARCHIVE = ConfigKeys.newStringConfigKey("brooklynnode.download.archive.subpath",
         "Path to the main directory in the archive being supplied for installation; "
         + "to use the root of an archive, specify '.'; "
-        + "default value if left blank is the appropriate value for brooklyn,"
+        + "default value taken based on download URL (e.g. 'name' for 'http://path/name.tgz'
or 'http://path/name-dist.tgz') "
+        + "falling back to an appropriate value for brooklyn, "
         + "e.g. 'brooklyn-"+BrooklynVersion.INSTANCE.getVersion()+"'", null);
 
     @SetFromFlag("managementUser")

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/6dfd1789/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
index bd33b88..add3f8f 100644
--- a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeSshDriver.java
@@ -31,6 +31,7 @@ import java.util.Map;
 
 import brooklyn.entity.basic.Entities;
 import brooklyn.entity.brooklynnode.BrooklynNode.ExistingFileBehaviour;
+import brooklyn.entity.drivers.downloads.DownloadSubstituters;
 import brooklyn.entity.java.JavaSoftwareProcessSshDriver;
 import brooklyn.entity.software.SshEffectorTasks;
 import brooklyn.location.basic.SshMachineLocation;
@@ -76,14 +77,44 @@ public class BrooklynNodeSshDriver extends JavaSoftwareProcessSshDriver
implemen
     
     @Override
     protected String getInstallLabelExtraSalt() {
-        return Identifiers.makeIdFromHash(Objects.hashCode(entity.getConfig(BrooklynNode.DOWNLOAD_URL),
entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL)));
+        String downloadUrl = entity.getConfig(BrooklynNode.DOWNLOAD_URL);
+        String uploadUrl = entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL);
+        if (Objects.equal(downloadUrl, BrooklynNode.DOWNLOAD_URL.getConfigKey().getDefaultValue())
&&
+                Objects.equal(uploadUrl, BrooklynNode.DISTRO_UPLOAD_URL.getDefaultValue()))
{
+            // if both are at the default value, then no salt
+            return null;
+        }
+        return Identifiers.makeIdFromHash(Objects.hashCode(downloadUrl, uploadUrl));
     }
 
     @Override
     public void preInstall() {
         resolver = Entities.newDownloader(this);
         String subpath = entity.getConfig(BrooklynNode.SUBPATH_IN_ARCHIVE);
-        if (Strings.isBlank(subpath)) subpath = format("brooklyn-%s", getVersion());
+        if (subpath==null) {
+            // assume the dir name is `basename-VERSION` where download link is `basename-VERSION-dist.tar.gz`
+            String uploadUrl = entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL);
+            String origDownloadName = uploadUrl;
+            if (origDownloadName==null) { 
+                String downloadUrlTemplate = entity.getAttribute(BrooklynNode.DOWNLOAD_URL);
+                if (downloadUrlTemplate!=null) {
+                    // BasicDownloadResolver makes it crazy hard to get the template-evaluated
value of DOWNLOAD_URL
+                    origDownloadName = DownloadSubstituters.substitute(downloadUrlTemplate,
DownloadSubstituters.getBasicEntitySubstitutions(this));
+                }
+            }
+            if (origDownloadName!=null) {
+                origDownloadName = Urls.getBasename(origDownloadName);
+                String downloadName = origDownloadName;
+                downloadName = Strings.removeFromEnd(downloadName, ".tar.gz");
+                downloadName = Strings.removeFromEnd(downloadName, ".tgz");
+                downloadName = Strings.removeFromEnd(downloadName, ".zip");
+                if (!downloadName.equals(origDownloadName)) {
+                    downloadName = Strings.removeFromEnd(downloadName, "-dist");
+                    subpath = downloadName;
+                }
+            }
+        }
+        if (subpath==null) subpath = format("brooklyn-%s", getVersion());
         setExpandedInstallDir(Os.mergePaths(getInstallDir(), resolver.getUnpackedDirectoryName(subpath)));
     }
 


Mime
View raw message