Removes default launch command from VanillaWindowsProcess, adds ExecutionPolicy 
to default WinRm usermetadata


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

Branch: refs/heads/master
Commit: be1b50483a1f0e117ce562d5a32a02d32f1f5841
Parents: 176eed3
Author: Martin Harris <[email protected]>
Authored: Wed Apr 22 17:53:18 2015 +0530
Committer: Richard Downer <[email protected]>
Committed: Thu May 28 17:27:34 2015 +0100

----------------------------------------------------------------------
 .../location/basic/WinRmMachineLocation.java      | 18 +++++++++---------
 .../entity/basic/AbstractVanillaProcess.java      |  2 +-
 .../entity/basic/VanillaSoftwareProcess.java      |  3 ++-
 .../entity/basic/VanillaWindowsProcess.java       |  2 +-
 4 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/be1b5048/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 6f8ef04..33421af 100644
--- a/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
@@ -23,6 +23,7 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
 import java.net.InetAddress;
+import java.nio.charset.Charset;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
@@ -41,6 +42,7 @@ import brooklyn.util.flags.SetFromFlag;
 import io.cloudsoft.winrm4j.winrm.WinRmTool;
 import io.cloudsoft.winrm4j.winrm.WinRmToolResponse;
 
+import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
 
 public class WinRmMachineLocation extends AbstractLocation implements 
MachineLocation {
@@ -151,21 +153,19 @@ public class WinRmMachineLocation extends 
AbstractLocation implements MachineLoc
     }
 
     public static String getDefaultUserMetadataString() {
+        // Using an encoded command obviates the need to escape
+        String unencodePowershell =
+                "$RDP = Get-WmiObject -Class Win32_TerminalServiceSetting 
-ComputerName $env:computername -Namespace root\\CIMV2\\TerminalServices 
-Authentication PacketPrivacy\r\n" +
+                "$RDP.SetAllowTSConnections(1,1)\r\n" +
+                "Set-ExecutionPolicy Unrestricted";
+        String encoded = new 
String(Base64.encodeBase64(unencodePowershell.getBytes(Charsets.UTF_16LE)));
         return "winrm quickconfig -q & " +
                 "winrm set winrm/config/service/auth @{Basic=\"true\"} & " +
                 "winrm set winrm/config/client @{AllowUnencrypted=\"true\"} & 
" +
                 "winrm set winrm/config/service @{AllowUnencrypted=\"true\"} & 
" +
                 "netsh advfirewall firewall add rule name=RDP dir=in 
protocol=tcp localport=3389 action=allow profile=any & " +
                 "netsh advfirewall firewall add rule name=WinRM dir=in 
protocol=tcp localport=5985 action=allow profile=any & " +
-                // Using an encoded command necessitates the need to escape. 
The unencoded command is as follows:
-                // $RDP = Get-WmiObject -Class Win32_TerminalServiceSetting 
-ComputerName $env:computername -Namespace root\CIMV2\TerminalServices 
-Authentication PacketPrivacy
-                // $Result = $RDP.SetAllowTSConnections(1,1)
-                "powershell -EncodedCommand 
JABSAEQAUAAgAD0AIABHAGUAdAAtAFcAbQBpAE8AYgBqAGUAYwB0ACAALQBDAGwAYQBzAHMAI" +
-                        
"ABXAGkAbgAzADIAXwBUAGUAcgBtAGkAbgBhAGwAUwBlAHIAdgBpAGMAZQBTAGUAdAB0AGkAbgBnACAALQBDAG8AbQBwA"
 +
-                        
"HUAdABlAHIATgBhAG0AZQAgACQAZQBuAHYAOgBjAG8AbQBwAHUAdABlAHIAbgBhAG0AZQAgAC0ATgBhAG0AZQBzAHAAY"
 +
-                        
"QBjAGUAIAByAG8AbwB0AFwAQwBJAE0AVgAyAFwAVABlAHIAbQBpAG4AYQBsAFMAZQByAHYAaQBjAGUAcwAgAC0AQQB1A"
 +
-                        
"HQAaABlAG4AdABpAGMAYQB0AGkAbwBuACAAUABhAGMAawBlAHQAUAByAGkAdgBhAGMAeQANAAoAJABSAGUAcwB1AGwAd"
 +
-                        
"AAgAD0AIAAkAFIARABQAC4AUwBlAHQAQQBsAGwAbwB3AFQAUwBDAG8AbgBuAGUAYwB0AGkAbwBuAHMAKAAxACwAMQApAA==";
+                "powershell -EncodedCommand " + encoded;
         /* TODO: Find out why scripts with new line characters aren't working 
on AWS. The following appears as if it *should*
            work but doesn't - the script simply isn't run. By connecting to 
the machine via RDP, you can get the script
            from 'http://169.254.169.254/latest/user-data', and running it at 
the command prompt works, but for some

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/be1b5048/software/base/src/main/java/brooklyn/entity/basic/AbstractVanillaProcess.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/basic/AbstractVanillaProcess.java 
b/software/base/src/main/java/brooklyn/entity/basic/AbstractVanillaProcess.java
index 5c89f51..b7f0050 100644
--- 
a/software/base/src/main/java/brooklyn/entity/basic/AbstractVanillaProcess.java
+++ 
b/software/base/src/main/java/brooklyn/entity/basic/AbstractVanillaProcess.java
@@ -26,7 +26,7 @@ public interface AbstractVanillaProcess extends 
SoftwareProcess {
 
     ConfigKey<String> SUGGESTED_VERSION = 
ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "0.0.0");
 
-    ConfigKey<String> LAUNCH_COMMAND = 
ConfigKeys.newStringConfigKey("launch.command", "command to run to launch the 
process", "./start.sh");
+    ConfigKey<String> LAUNCH_COMMAND = 
ConfigKeys.newStringConfigKey("launch.command", "command to run to launch the 
process");
     ConfigKey<String> CHECK_RUNNING_COMMAND = 
ConfigKeys.newStringConfigKey("checkRunning.command", "command to determine 
whether the process is running");
     ConfigKey<String> STOP_COMMAND = 
ConfigKeys.newStringConfigKey("stop.command", "command to run to stop the 
process");
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/be1b5048/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java 
b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
index ff37c0a..daa112b 100644
--- 
a/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
+++ 
b/software/base/src/main/java/brooklyn/entity/basic/VanillaSoftwareProcess.java
@@ -19,6 +19,7 @@
 package brooklyn.entity.basic;
 
 import brooklyn.catalog.Catalog;
+import brooklyn.config.ConfigKey;
 import brooklyn.entity.proxying.ImplementedBy;
 
 /** 
@@ -53,5 +54,5 @@ import brooklyn.entity.proxying.ImplementedBy;
 @Catalog(name="Vanilla Software Process", description="A software process 
configured with scripts, e.g. for launch, check-running and stop")
 @ImplementedBy(VanillaSoftwareProcessImpl.class)
 public interface VanillaSoftwareProcess extends AbstractVanillaProcess {
-
+    ConfigKey<String> LAUNCH_COMMAND = 
ConfigKeys.newConfigKeyWithDefault(AbstractVanillaProcess.LAUNCH_COMMAND, 
"./start.sh");
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/be1b5048/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcess.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcess.java 
b/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcess.java
index 585f73e..532821d 100644
--- 
a/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcess.java
+++ 
b/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcess.java
@@ -24,7 +24,7 @@ import brooklyn.entity.proxying.ImplementedBy;
 @ImplementedBy(VanillaWindowsProcessImpl.class)
 public interface VanillaWindowsProcess extends AbstractVanillaProcess {
     ConfigKey<String> LAUNCH_POWERSHELL_COMMAND = 
ConfigKeys.newStringConfigKey("launch.powershell.command",
-            "command to run to launch the process", "./start.sh");
+            "command to run to launch the process");
     ConfigKey<String> CHECK_RUNNING_POWERSHELL_COMMAND = 
ConfigKeys.newStringConfigKey("checkRunning.powershell.command",
             "command to determine whether the process is running");
     ConfigKey<String> STOP_POWERSHELL_COMMAND = 
ConfigKeys.newStringConfigKey("stop.powershell.command",

Reply via email to