brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] git commit: fix BROOKLYN-70 , allowing the new-style chef community download links
Date Wed, 01 Oct 2014 16:41:54 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master c2b56d756 -> 8a1fd77ea


fix BROOKLYN-70 , allowing the new-style chef community download links


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

Branch: refs/heads/master
Commit: 9667fa8df33dc94099188f8c1228c0595a778876
Parents: c49d7d3
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Fri Sep 26 11:39:30 2014 +0100
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Fri Sep 26 11:39:30 2014 +0100

----------------------------------------------------------------------
 .../java/brooklyn/util/file/ArchiveTasks.java   | 11 ++++++--
 .../java/brooklyn/util/file/ArchiveUtils.java   | 29 ++++++++++++++------
 .../java/brooklyn/entity/chef/ChefTasks.java    | 14 +++++++++-
 usage/camp/src/test/resources/mysql-chef.yaml   |  3 ++
 4 files changed, 45 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9667fa8d/core/src/main/java/brooklyn/util/file/ArchiveTasks.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/file/ArchiveTasks.java b/core/src/main/java/brooklyn/util/file/ArchiveTasks.java
index 57b3c9e..0f2e73d 100644
--- a/core/src/main/java/brooklyn/util/file/ArchiveTasks.java
+++ b/core/src/main/java/brooklyn/util/file/ArchiveTasks.java
@@ -34,15 +34,20 @@ public class ArchiveTasks {
         return deploy(optionalResolver, null, archiveUrl, machine, destDir, false, null,
null);
     }
     
-    /** returns a task which installs and unpacks the given archive, as per {@link ArchiveUtils#deploy(ResourceUtils,
Map, String, SshMachineLocation, String, String, String)} */
-    public static TaskFactory<?> deploy(final ResourceUtils resolver, final Map<String,
?> props, final String archiveUrl, final SshMachineLocation machine, final String destDir,
final boolean keepArchiveAfterDeploy, final String tmpDir, final String destFile) {
+    /** returns a task which installs and unpacks the given archive, as per {@link ArchiveUtils#deploy(ResourceUtils,
Map, String, SshMachineLocation, String, String, String)};
+     * if allowNonarchivesOrKeepArchiveAfterDeploy is false, this task will fail if the item
is not an archive;
+     * in cases where the download type is not clear in the URL but is known by the caller,
supply a optionalDestFile including the appropriate file extension */
+    public static TaskFactory<?> deploy(final ResourceUtils resolver, final Map<String,
?> props, final String archiveUrl, final SshMachineLocation machine, final String destDir,
final boolean allowNonarchivesOrKeepArchiveAfterDeploy, final String optionalTmpDir, final
String optionalDestFile) {
         return new TaskFactory<TaskAdaptable<?>>() {
             @Override
             public TaskAdaptable<?> newTask() {
                 return Tasks.<Void>builder().name("deploying "+Urls.getBasename(archiveUrl)).description("installing
"+archiveUrl+" and unpacking to "+destDir).body(new Runnable() {
                     @Override
                     public void run() {
-                        ArchiveUtils.deploy(resolver, props, archiveUrl, machine, destDir,
keepArchiveAfterDeploy, tmpDir, destFile);
+                        boolean unpacked = ArchiveUtils.deploy(resolver, props, archiveUrl,
machine, destDir, allowNonarchivesOrKeepArchiveAfterDeploy, optionalTmpDir, optionalDestFile);
+                        if (!unpacked && !allowNonarchivesOrKeepArchiveAfterDeploy)
{
+                            throw new IllegalStateException("Unable to unpack archive from
"+archiveUrl+"; not able to infer archive type");
+                        }
                     }
                 }).build();
             }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9667fa8d/core/src/main/java/brooklyn/util/file/ArchiveUtils.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/util/file/ArchiveUtils.java b/core/src/main/java/brooklyn/util/file/ArchiveUtils.java
index a61b2c5..be67dfe 100644
--- a/core/src/main/java/brooklyn/util/file/ArchiveUtils.java
+++ b/core/src/main/java/brooklyn/util/file/ArchiveUtils.java
@@ -163,8 +163,14 @@ public class ArchiveUtils {
                     break;
                 }
             case UNKNOWN:
-                if (!sourcePath.equals(Urls.mergePaths(targetDir, fileName)))
+                if (!sourcePath.equals(Urls.mergePaths(targetDir, fileName))) {
                     commands.add("cp " + sourcePath + " " + targetDir);
+                } else {
+                    keepOriginal = true;
+                    // else we'd just end up deleting it!
+                    // this branch will often lead to errors in any case, see the allowNonarchivesOrKeepArchiveAfterDeploy
parameter 
+                    // in ArchiveTasks which calls through to here and then fails in the
case corresponding to this code branch
+                }
                 break;
         }
         if (!keepOriginal && !commands.isEmpty())
@@ -238,18 +244,24 @@ public class ArchiveUtils {
      * Copies the archive file from the given URL to a file in a temporary directory and
extracts
      * the contents in the destination directory. For Java archives of type {@code .jar},
      * {@code .war} or {@code .ear} the file is simply copied.
+     * 
+     * @return true if the archive is downloaded AND unpacked; false if it is downloaded
but not unpacked; 
+     * throws if there was an error downloading or, for known archive types, unpacking.
      *
      * @see #deploy(String, SshMachineLocation, String)
      * @see #deploy(Map, String, SshMachineLocation, String, String, String)
      * @see #install(SshMachineLocation, String, String, int)
      */
-    public static void deploy(ResourceUtils resolver, Map<String, ?> props, String
archiveUrl, SshMachineLocation machine, String destDir, boolean keepArchiveAfterUnpacking,
String optionalTmpDir, String optionalDestFile) {
-        if (optionalDestFile==null) optionalDestFile = Urls.getBasename(Preconditions.checkNotNull(archiveUrl,
"archiveUrl"));
-        if (Strings.isBlank(optionalDestFile)) 
+    public static boolean deploy(ResourceUtils resolver, Map<String, ?> props, String
archiveUrl, SshMachineLocation machine, String destDir, boolean keepArchiveAfterUnpacking,
String optionalTmpDir, String optionalDestFile) {
+        String destFile = optionalDestFile;
+        if (destFile==null) destFile = Urls.getBasename(Preconditions.checkNotNull(archiveUrl,
"archiveUrl"));
+        if (Strings.isBlank(destFile)) 
             throw new IllegalStateException("Not given filename and cannot infer archive
type from '"+archiveUrl+"'");
-        if (optionalTmpDir==null) optionalTmpDir=Preconditions.checkNotNull(destDir, "destDir");
+        
+        String tmpDir = optionalTmpDir;
+        if (tmpDir==null) tmpDir=Preconditions.checkNotNull(destDir, "destDir");
         if (props==null) props = MutableMap.of();
-        String destPath = Os.mergePaths(optionalTmpDir, optionalDestFile);
+        String destPath = Os.mergePaths(tmpDir, destFile);
 
         // Use the location mutex to prevent package manager locking issues
         try {
@@ -260,8 +272,8 @@ public class ArchiveUtils {
             }
             
             // extract, now using task if available
-            MutableList<String> commands = MutableList.copyOf(installCommands(optionalDestFile))
-                .appendAll(extractCommands(optionalDestFile, optionalTmpDir, destDir, false,
keepArchiveAfterUnpacking));
+            MutableList<String> commands = MutableList.copyOf(installCommands(destFile))
+                .appendAll(extractCommands(destFile, tmpDir, destDir, false, keepArchiveAfterUnpacking));
             if (DynamicTasks.getTaskQueuingContext()!=null) {
                 result = DynamicTasks.queue(SshTasks.newSshExecTaskFactory(machine, commands.toArray(new
String[0])).summary("extracting archive").requiringExitCodeZero()).get();
             } else {
@@ -270,6 +282,7 @@ public class ArchiveUtils {
             if (result != 0) {
                 throw new IllegalStateException(format("Failed to expand archive %s on %s",
archiveUrl, machine));
             }
+            return ArchiveType.of(destFile)!=ArchiveType.UNKNOWN;
         } catch (InterruptedException e) {
             throw Exceptions.propagate(e);
         } finally {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9667fa8d/software/base/src/main/java/brooklyn/entity/chef/ChefTasks.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/chef/ChefTasks.java b/software/base/src/main/java/brooklyn/entity/chef/ChefTasks.java
index 96309fb..5eb5ee2 100644
--- a/software/base/src/main/java/brooklyn/entity/chef/ChefTasks.java
+++ b/software/base/src/main/java/brooklyn/entity/chef/ChefTasks.java
@@ -20,6 +20,9 @@ package brooklyn.entity.chef;
 
 import java.util.Map;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import brooklyn.entity.Entity;
 import brooklyn.entity.effector.EffectorTasks;
 import brooklyn.entity.software.SshEffectorTasks;
@@ -27,6 +30,7 @@ import brooklyn.management.TaskAdaptable;
 import brooklyn.management.TaskFactory;
 import brooklyn.util.collections.MutableMap;
 import brooklyn.util.file.ArchiveTasks;
+import brooklyn.util.file.ArchiveUtils.ArchiveType;
 import brooklyn.util.net.Urls;
 import brooklyn.util.ssh.BashCommands;
 import brooklyn.util.task.DynamicTasks;
@@ -43,6 +47,8 @@ import com.google.gson.GsonBuilder;
 @Beta
 public class ChefTasks {
 
+    private static final Logger log = LoggerFactory.getLogger(ChefTasks.class);
+    
     public static TaskFactory<?> installChef(String chefDirectory, boolean force) {
         // TODO check on entity whether it is chef _server_
         String installCmd = cdAndRun(chefDirectory, ChefBashCommands.INSTALL_FROM_OPSCODE);
@@ -81,7 +87,13 @@ public class ChefTasks {
 //                    // remove reference to 'force' below
 //                }
                 
-                tb.add(ArchiveTasks.deploy(null, cookbookArchiveUrl, EffectorTasks.findSshMachine(),
privateTmpDirContainingUnpackedCookbook).newTask());
+                String destName = null;
+                if (ArchiveType.of(cookbookArchiveUrl)==ArchiveType.UNKNOWN) {
+                    destName = cookbookName + ".tgz";
+                    log.debug("Assuming TGZ type for chef cookbook url "+cookbookArchiveUrl+";
it will be downloaded as "+destName);
+                }
+                tb.add(ArchiveTasks.deploy(null, null, cookbookArchiveUrl, EffectorTasks.findSshMachine(),
privateTmpDirContainingUnpackedCookbook,
+                    false, null, destName).newTask());
                 
                 String installCmd = BashCommands.chain(
                     "cd "+privateTmpDirContainingUnpackedCookbook,  

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9667fa8d/usage/camp/src/test/resources/mysql-chef.yaml
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/resources/mysql-chef.yaml b/usage/camp/src/test/resources/mysql-chef.yaml
index 6db7ba6..36fdeb2 100644
--- a/usage/camp/src/test/resources/mysql-chef.yaml
+++ b/usage/camp/src/test/resources/mysql-chef.yaml
@@ -26,6 +26,9 @@ services:
     mysql: https://github.com/opscode-cookbooks/mysql/archive/v4.0.12.tar.gz
     openssl: https://github.com/opscode-cookbooks/openssl/archive/v1.1.0.tar.gz
     build-essential: https://github.com/opscode-cookbooks/build-essential/archive/v1.4.4.tar.gz
+    # NB: this also supports new style community url links, assuming TGZ and directory name,
+    # (eg https://community.opscode.com/cookbooks/mysql/download) but github versioned links
+    # are recommended because they point to a specific released version and explicit archive
type
   
   launch_run_list: [ "mysql::server" ]
   launch_attributes:


Mime
View raw message