Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6C40F174C5 for ; Wed, 1 Oct 2014 16:42:16 +0000 (UTC) Received: (qmail 35796 invoked by uid 500); 1 Oct 2014 16:42:16 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 35774 invoked by uid 500); 1 Oct 2014 16:42:16 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 35764 invoked by uid 99); 1 Oct 2014 16:42:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Oct 2014 16:42:16 +0000 X-ASF-Spam-Status: No, hits=-2000.6 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 01 Oct 2014 16:42:14 +0000 Received: (qmail 34529 invoked by uid 99); 1 Oct 2014 16:41:54 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Oct 2014 16:41:54 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 21F8B925418; Wed, 1 Oct 2014 16:41:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 01 Oct 2014 16:41:54 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: fix BROOKLYN-70 , allowing the new-style chef community download links X-Virus-Checked: Checked by ClamAV on apache.org 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 Authored: Fri Sep 26 11:39:30 2014 +0100 Committer: Alex Heneveld 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 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 props, final String archiveUrl, final SshMachineLocation machine, final String destDir, final boolean allowNonarchivesOrKeepArchiveAfterDeploy, final String optionalTmpDir, final String optionalDestFile) { return new TaskFactory>() { @Override public TaskAdaptable newTask() { return Tasks.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 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 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 commands = MutableList.copyOf(installCommands(optionalDestFile)) - .appendAll(extractCommands(optionalDestFile, optionalTmpDir, destDir, false, keepArchiveAfterUnpacking)); + MutableList 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: