Fixes destruction of WinRmMachineLocation on stop

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

Branch: refs/heads/master
Commit: 0e50fcf616f6f1b3ddf7b48f84d8de8ace81ee7d
Parents: 7e2d618
Author: Martin Harris <[email protected]>
Authored: Mon Apr 27 22:56:56 2015 +0530
Committer: Richard Downer <[email protected]>
Committed: Thu May 28 17:27:34 2015 +0100

----------------------------------------------------------------------
 .../entity/group/DynamicClusterImpl.java        | 22 +++++++++++------
 .../location/basic/WinRmMachineLocation.java    | 15 ++++++++++-
 .../location/jclouds/JcloudsLocation.java       |  3 ++-
 .../basic/VanillaWindowsProcessWinRmDriver.java |  1 +
 .../software/MachineLifecycleEffectorTasks.java |  6 ++---
 .../brooklyn/entity/software/StaticSensor.java  | 26 ++++++++++++++++++++
 6 files changed, 60 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0e50fcf6/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java 
b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
index ab2a21e..7d82e2e 100644
--- a/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
+++ b/core/src/main/java/brooklyn/entity/group/DynamicClusterImpl.java
@@ -588,16 +588,22 @@ public class DynamicClusterImpl extends AbstractGroupImpl 
implements DynamicClus
 
         // choose locations to be deployed to
         List<Location> chosenLocations;
-        if (isAvailabilityZoneEnabled()) {
-            List<Location> subLocations = getNonFailedSubLocations();
-            Multimap<Location, Entity> membersByLocation = 
getMembersByLocation();
-            chosenLocations = 
getZonePlacementStrategy().locationsForAdditions(membersByLocation, 
subLocations, delta);
-            if (chosenLocations.size() != delta) {
-                throw new IllegalStateException("Node placement strategy chose 
" + Iterables.size(chosenLocations)
-                        + ", when expected delta " + delta + " in " + this);
+        chosenLocations = getMemberSpec().getLocations();
+        if (chosenLocations == null) {
+            if (isAvailabilityZoneEnabled()) {
+                List<Location> subLocations = getNonFailedSubLocations();
+                Multimap<Location, Entity> membersByLocation = 
getMembersByLocation();
+                chosenLocations = 
getZonePlacementStrategy().locationsForAdditions(membersByLocation, 
subLocations, delta);
+                if (chosenLocations.size() != delta) {
+                    throw new IllegalStateException("Node placement strategy 
chose " + Iterables.size(chosenLocations)
+                            + ", when expected delta " + delta + " in " + 
this);
+                }
+            } else {
+                chosenLocations = Collections.nCopies(delta, getLocation());
             }
         } else {
-            chosenLocations = Collections.nCopies(delta, getLocation());
+            // FIXME: Tidy this up!
+            chosenLocations = Collections.nCopies(delta, 
chosenLocations.get(0));
         }
 
         // create and start the entities

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0e50fcf6/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 33421af..d527121 100644
--- a/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
@@ -157,12 +157,25 @@ public class WinRmMachineLocation extends 
AbstractLocation implements MachineLoc
         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";
+                "Set-ExecutionPolicy Unrestricted\r\n" +
+                "Set-Item WSMan:\\localhost\\Shell\\MaxConcurrentUsers 
100\r\n" +
+                "Set-Item WSMan:\\localhost\\Shell\\MaxMemoryPerShellMB 0\r\n" 
+
+                "Set-Item WSMan:\\localhost\\Shell\\MaxProcessesPerShell 
0\r\n" +
+                "Set-Item WSMan:\\localhost\\Shell\\MaxShellsPerUser 0\r\n" +
+                "New-ItemProperty 
\"HKLM:\\System\\CurrentControlSet\\Control\\LSA\" -Name 
\"SuppressExtendedProtection\" -Value 1 -PropertyType \"DWord\"";
+//                "New-ItemProperty 
\"HKLM:\\System\\CurrentControlSet\\Control\\LSA\" -Name 
\"LmCompatibilityLevel\" -Value 3 -PropertyType \"DWord\" \r\n";
+
         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/service/auth @{CredSSP=\"true\"} & " +
+                "winrm set winrm/config/client/auth @{CredSSP=\"true\"} & " +
                 "winrm set winrm/config/client @{AllowUnencrypted=\"true\"} & 
" +
                 "winrm set winrm/config/service @{AllowUnencrypted=\"true\"} & 
" +
+                "winrm set winrm/config/winrs @{MaxConcurrentUsers=\"100\"} & 
" +
+                "winrm set winrm/config/winrs @{MaxMemoryPerShellMB=\"0\"} & " 
+
+                "winrm set winrm/config/winrs @{MaxProcessesPerShell=\"0\"} & 
" +
+                "winrm set winrm/config/winrs @{MaxShellsPerUser=\"0\"} & " +
                 "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 & " +
                 "powershell -EncodedCommand " + encoded;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0e50fcf6/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git 
a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
 
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index e793bb1..3aeaf13 100644
--- 
a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ 
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -2017,7 +2017,8 @@ public class JcloudsLocation extends 
AbstractCloudMachineProvisioningLocation im
         }
 
         try {
-            if (!machine.getMachineDetails().getOsDetails().isWindows()) {
+            // FIXME: Needs to release port forwarding for 
WinRmMachineLocations
+            if (machine.getMachineDetails().getOsDetails() != null && 
!machine.getMachineDetails().getOsDetails().isWindows()) {
                 releasePortForwarding((SshMachineLocation)machine);
             }
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0e50fcf6/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcessWinRmDriver.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcessWinRmDriver.java
 
b/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcessWinRmDriver.java
index 768da6f..a5c91db 100644
--- 
a/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcessWinRmDriver.java
+++ 
b/software/base/src/main/java/brooklyn/entity/basic/VanillaWindowsProcessWinRmDriver.java
@@ -19,6 +19,7 @@
 package brooklyn.entity.basic;
 
 import brooklyn.location.basic.WinRmMachineLocation;
+import brooklyn.util.time.Duration;
 
 public class VanillaWindowsProcessWinRmDriver extends 
AbstractSoftwareProcessWinRmDriver implements VanillaWindowsProcessDriver {
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0e50fcf6/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
 
b/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
index 6ccfc38..9c929bb 100644
--- 
a/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
+++ 
b/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
@@ -567,7 +567,7 @@ public abstract class MachineLifecycleEffectorTasks {
             return null;
         }});
 
-        Maybe<SshMachineLocation> sshMachine = 
Machines.findUniqueSshMachineLocation(entity().getLocations());
+        Maybe<MachineLocation> machine = 
Machines.findUniqueMachineLocation(entity().getLocations());
         Task<String> stoppingProcess = null;
         if (canStop(stopProcessMode, entity())) {
             stoppingProcess = DynamicTasks.queue("stopping (process)", new 
Callable<String>() { public String call() {
@@ -579,7 +579,7 @@ public abstract class MachineLifecycleEffectorTasks {
         }
 
         Task<StopMachineDetails<Integer>> stoppingMachine = null;
-        if (canStop(stopMachineMode, sshMachine.isAbsent())) {
+        if (canStop(stopMachineMode, machine.isAbsent())) {
             // Release this machine (even if error trying to stop process - we 
rethrow that after)
             stoppingMachine = DynamicTasks.queue("stopping (machine)", new 
Callable<StopMachineDetails<Integer>>() {
                 public StopMachineDetails<Integer> call() {
@@ -615,7 +615,7 @@ public abstract class MachineLifecycleEffectorTasks {
             if (checkStopProcesses) {
                 // TODO we should test for destruction above, not merely 
successful "stop", as things like localhost and ssh won't be destroyed
                 DynamicTasks.waitForLast();
-                if (sshMachine.isPresent()) {
+                if (machine.isPresent()) {
                     // throw early errors *only if* there is a machine and we 
have not destroyed it
                     stoppingProcess.get();
                 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/0e50fcf6/software/base/src/main/java/brooklyn/entity/software/StaticSensor.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/software/StaticSensor.java 
b/software/base/src/main/java/brooklyn/entity/software/StaticSensor.java
new file mode 100644
index 0000000..deaac70
--- /dev/null
+++ b/software/base/src/main/java/brooklyn/entity/software/StaticSensor.java
@@ -0,0 +1,26 @@
+package brooklyn.entity.software;
+
+import brooklyn.config.ConfigKey;
+import brooklyn.entity.basic.ConfigKeys;
+import brooklyn.entity.basic.EntityLocal;
+import brooklyn.entity.effector.AddSensor;
+import brooklyn.event.basic.Sensors;
+import brooklyn.util.config.ConfigBag;
+
+public class StaticSensor<T> extends AddSensor<Integer> {
+
+    public static final ConfigKey<Integer> STATIC_VALUE = 
ConfigKeys.newConfigKey(Integer.class, "static.value");
+
+    private final Integer value;
+
+    public StaticSensor(ConfigBag params) {
+        super(params);
+        value = params.get(STATIC_VALUE);
+    }
+
+    @Override
+    public void apply(EntityLocal entity) {
+        super.apply(entity);
+        entity.setAttribute(Sensors.newIntegerSensor(name), value);
+    }
+}

Reply via email to