public static void deploy(Map<String, ?> props, String archiveUrl, SshMachineLocation machine, String destDir, String destFile) { deploy(props, archiveUrl, machine, destDir, destDir, destFile); } public static void deploy(Map<String, ?> props, String archiveUrl, SshMachineLocation machine, String tmpDir, String destDir, String destFile) {
/** * Returns the list of commands used to extract the contents of the archive with the given name. * <p> * Optionally, Java archives of type * * @see #extractCommands(String, String) */ public static List<String> extractCommands(String fileName, String sourceDir, String targetDir, boolean extractJar) { return extractCommands(fileName, sourceDir, targetDir, extractJar, true); }
/** * Installs a URL onto a remote machine. * * @see #install(SshMachineLocation, String, String) * @see SshMachineLocation#installTo(Map, String, String) */ public static int install(Map<String, ?> props, SshMachineLocation machine, String urlToInstall, String target, int numAttempts) { return install(null, props, machine, urlToInstall, target, numAttempts); }
int result = install(resolver, props, machine, archiveUrl, destPath, NUM_RETRIES_FOR_COPYING); if (result != 0) { throw new IllegalStateException(format("Unable to install archive %s to %s", archiveUrl, machine)); 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();
commands.addAll(ArchiveUtils.installCommands(downloadedFilename)); result = ArchiveUtils.install(getMachine(), urlI, Urls.mergePaths(getInstallDir(), downloadedFilename)); if (result==0) break;
@Test(groups = "Integration") public void testInstallUrlTo() throws Exception { File dest = new File(Os.tmp(), "sshMachineLocationTest_dir/"); dest.mkdir(); try { int result = host.installTo("https://raw.github.com/brooklyncentral/brooklyn/master/README.md", Urls.mergePaths(dest.getAbsolutePath(), "README.md")); assertEquals(result, 0); String contents = ArchiveUtils.readFullyString(new File(dest, "README.md")); assertTrue(contents.contains("http://brooklyncentral.github.com"), "contents missing expected phrase; contains:\n"+contents); } finally { dest.delete(); } }
private String copyResourcePathToTempPath(String resourcePath) { BundleMaker bm = new BundleMaker(ResourceUtils.create(this)); bm.setDefaultClassForLoading(CleanOrphanedLocationsIntegrationTest.class); File jar = bm.createJarFromClasspathDir(resourcePath); File output = Os.newTempDir("brooklyn-test-resouce-from-"+resourcePath); try { ArchiveUtils.extractZip(new ZipFile(jar), output.getAbsolutePath()); return output.getAbsolutePath(); } catch (Exception e) { throw Exceptions.propagate(e); } }
@Test(groups = "Integration") public void testInstallClasspathCopyTo() throws Exception { File dest = new File(Os.tmp(), "sshMachineLocationTest_dir/"); dest.mkdir(); try { int result = host.installTo("classpath://brooklyn/config/sample.properties", Urls.mergePaths(dest.getAbsolutePath(), "sample.properties")); assertEquals(result, 0); String contents = ArchiveUtils.readFullyString(new File(dest, "sample.properties")); assertTrue(contents.contains("Property 1"), "contents missing expected phrase; contains:\n"+contents); } finally { dest.delete(); } }
public static void deploy(Map<String, ?> props, String archiveUrl, SshMachineLocation machine, String tmpDir, String destDir, String destFile) { deploy(null, props, archiveUrl, machine, destDir, true, tmpDir, destFile); }
/** * Returns the list of commands used to extract the contents of the archive with the given name. * <p> * The archive will be extracted in its current directory unless it is a Java archive of type {@code .jar}, * {@code .war} or {@code .ear}, which will be left as is. * * @see #extractCommands(String, String, String, boolean) */ public static List<String> extractCommands(String fileName, String sourceDir) { return extractCommands(fileName, sourceDir, ".", false); }
/** * Installs a URL onto a remote machine. * * @see #install(Map, SshMachineLocation, String, String, int) */ public static int install(SshMachineLocation machine, String urlToInstall, String target) { return install(MutableMap.<String, Object>of(), machine, urlToInstall, target, NUM_RETRIES_FOR_COPYING); }
/** * Deploys an archive file to a remote machine and extracts the contents. */ public static void deploy(String archiveUrl, SshMachineLocation machine, String destDir) { deploy(MutableMap.<String, Object>of(), archiveUrl, machine, destDir); }
@Override public void customize() { if (downloadedFilename != null) { newScript(CUSTOMIZING) .failOnNonZeroResultCode() .environmentVariablesReset() .body.append(ArchiveUtils.extractCommands(downloadedFilename, getInstallDir())) .execute(); } String customizeCommand = getEntity().getConfig(VanillaSoftwareProcess.CUSTOMIZE_COMMAND); if (Strings.isNonBlank(customizeCommand)) { newScript(CUSTOMIZING) .failOnNonZeroResultCode() .body.append(customizeCommand) .execute(); } }
/** * Deploys an archive file to a remote machine and extracts the contents. * <p> * Copies the archive file from the given URL to a file in the destination directory and extracts * the contents. * * @see #deploy(String, SshMachineLocation, String) * @see #deploy(Map, String, SshMachineLocation, String, String, String) */ public static void deploy(String archiveUrl, SshMachineLocation machine, String destDir, String destFile) { deploy(MutableMap.<String, Object>of(), archiveUrl, machine, destDir, destDir, destFile); } public static void deploy(Map<String, ?> props, String archiveUrl, SshMachineLocation machine, String destDir, String destFile) {
/** * Deploys an archive file to a remote machine and extracts the contents. * <p> * Copies the archive file from the given URL to the destination directory and extracts * the contents. If the URL is a local directory, the contents are packaged as a Zip archive first. * * @see #deploy(String, SshMachineLocation, String, String) * @see #deploy(Map, String, SshMachineLocation, String, String, String) */ public static void deploy(Map<String, ?> props, String archiveUrl, SshMachineLocation machine, String destDir) { if (Urls.isDirectory(archiveUrl)) { File zipFile = ArchiveBuilder.zip().entry(".", Urls.toFile(archiveUrl)).create(); archiveUrl = zipFile.getAbsolutePath(); } // Determine filename String destFile = archiveUrl.contains("?") ? archiveUrl.substring(0, archiveUrl.indexOf('?')) : archiveUrl; destFile = destFile.substring(destFile.lastIndexOf('/') + 1); deploy(props, archiveUrl, machine, destDir, destFile); }
@Test(groups="Integration") public void testDeployZipDeletingArchiveAfterUnpack() throws Exception { boolean result = ArchiveUtils.deploy(resourceUtils, ImmutableMap.<String, Object>of(), origZip.getAbsolutePath(), machine, destDir.getAbsolutePath(), false, null, null); assertTrue(result); assertFalse(new File(destDir, origZip.getName()).exists()); assertSubFilesEqual(destDir, archiveContents); }
@Override public String deployArchive(String url) { String volumeId = Identifiers.makeIdFromHash(url.hashCode()); String path = Os.mergePaths(getRunDir(), volumeId); ArchiveUtils.deploy(url, getMachine(), path); return path; }
@Test(groups="Integration") public void testDeployJarNotUnpacked() throws Exception { ArchiveUtils.deploy(origJar.getAbsolutePath(), machine, destDir.getAbsolutePath()); assertFilesEqual(new File(destDir, origJar.getName()), origJar); }
@Test(groups="Integration") public void testDeployExplicitDestFile() throws Exception { String destFile = "custom-destFile.jar"; ArchiveUtils.deploy(origJar.getAbsolutePath(), machine, destDir.getAbsolutePath(), destFile); assertFilesEqual(new File(destDir, destFile), origJar); }
@Override @Effector(description="Deploys an archive of static content to the server") public void deploy(String archiveUrl) { NginxSshDriver driver = (NginxSshDriver) getDriver(); if (driver==null) { if (LOG.isDebugEnabled()) LOG.debug("No driver for {}, so not deploying archive (is entity stopping? state={})", this, getAttribute(NginxController.SERVICE_STATE_ACTUAL)); return; } // Copy to the destination machine and extract contents ArchiveUtils.deploy(archiveUrl, driver.getMachine(), driver.getRunDir()); }