brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [09/27] incubator-brooklyn git commit: Avoids unnecessary Arrays.copyOf in WinRmMachineLocation.copyTo
Date Fri, 29 May 2015 17:22:02 GMT
Avoids unnecessary Arrays.copyOf in WinRmMachineLocation.copyTo


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

Branch: refs/heads/master
Commit: f5664860d7249a0caea95dad071c6935946a54c2
Parents: 2b07bed
Author: Martin Harris <github@nakomis.com>
Authored: Mon Apr 13 13:14:47 2015 +0100
Committer: Richard Downer <richard@apache.org>
Committed: Thu May 28 17:27:34 2015 +0100

----------------------------------------------------------------------
 .../location/basic/WinRmMachineLocation.java      | 18 +++++++++++-------
 .../basic/AbstractSoftwareProcessDriver.java      |  6 +-----
 2 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f5664860/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java b/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
index 186fc4f..6f8ef04 100644
--- a/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
@@ -122,14 +122,18 @@ public class WinRmMachineLocation extends AbstractLocation implements
MachineLoc
     public int copyTo(InputStream source, File destination) {
         executePsScript(ImmutableList.of("rm -ErrorAction SilentlyContinue " + destination.getPath()));
         try {
-            byte[] inputData = new byte[getConfig(COPY_FILE_CHUNK_SIZE_BYTES)];
-            int bytesRead = source.read(inputData);
-            while (bytesRead > 0) {
-                byte[] chunk = Arrays.copyOf(inputData, bytesRead);
-                String encoded = new String(Base64.encodeBase64(chunk));
+            int chunkSize = getConfig(COPY_FILE_CHUNK_SIZE_BYTES);
+            byte[] inputData = new byte[chunkSize];
+            int bytesRead;
+            while ((bytesRead = source.read(inputData)) > 0) {
+                byte[] chunk;
+                if (bytesRead == chunkSize) {
+                    chunk = inputData;
+                } else {
+                    chunk = Arrays.copyOf(inputData, bytesRead);
+                }
                 executePsScript(ImmutableList.of("Add-Content -Encoding Byte -path " + destination.getPath()
+
-                        " -value ([System.Convert]::FromBase64String(\"" + encoded + "\"))"));
-                bytesRead = source.read(inputData);
+                        " -value ([System.Convert]::FromBase64String(\"" + new String(Base64.encodeBase64(chunk))
+ "\"))"));
             }
 
             return 0;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f5664860/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
index 9762c4f..061cd12 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/AbstractSoftwareProcessDriver.java
@@ -314,11 +314,7 @@ public abstract class AbstractSoftwareProcessDriver implements SoftwareProcessDr
      */
     public void copyRuntimeResources() {
         try {
-            // Ensure environment variables are not looked up here, otherwise sub-classes
might
-            // lookup port numbers and fail with ugly error if port is not set. It could
also
-            // cause us to block for attribute ready earlier than we need.
-            DynamicTasks.queue(SshEffectorTasks.ssh("mkdir -p " + getRunDir()).summary("create
run directory")
-                    .requiringExitCodeZero()).get();
+            createDirectory(getRunDir(), "create run directory");
 
             Map<String, String> runtimeFiles = entity.getConfig(SoftwareProcess.RUNTIME_FILES);
             if (runtimeFiles != null && runtimeFiles.size() > 0) {


Mime
View raw message