Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 2f3e465cd -> 27cd0920d


Adds EmptyWindowsProcess

- Includes EmptyWindowsProcess.USE_WINRM_MONITORING, for disabling 
  checking of WinRM connectivity.
- Adds EmptySoftwareProcess.USE_SSH_MONITORING, for disabling checking 
  of ssh connectivity.

With EmptyWindowsProcess, one can provision an entity that will not 
execute anything on the box. That makes it usable even if there is
no direct WinRM connectivity to the box.

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

Branch: refs/heads/master
Commit: 56f9cdda95451dcf58b80e2aab44c8be34e94d0a
Parents: 7191c7b
Author: Aled Sage <aled.s...@gmail.com>
Authored: Tue Jan 19 14:57:47 2016 +0000
Committer: Aled Sage <aled.s...@gmail.com>
Committed: Wed Jan 20 10:28:51 2016 +0000

----------------------------------------------------------------------
 .../brooklyn/EmptySoftwareProcessYamlTest.java  | 22 +++++
 .../brooklyn/EmptyWindowsProcessYamlTest.java   | 51 ++++++++++
 .../software/base/EmptySoftwareProcess.java     |  4 +
 .../software/base/EmptySoftwareProcessImpl.java | 12 ++-
 .../software/base/EmptyWindowsProcess.java      | 38 ++++++++
 .../base/EmptyWindowsProcessDriver.java         | 22 +++++
 .../software/base/EmptyWindowsProcessImpl.java  | 49 ++++++++++
 .../base/EmptyWindowsProcessWinRmDriver.java    | 97 ++++++++++++++++++++
 8 files changed, 294 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java
 
b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java
index 06badd6..0554917 100644
--- 
a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java
+++ 
b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptySoftwareProcessYamlTest.java
@@ -23,15 +23,21 @@ import java.util.Map;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.core.entity.Attributes;
+import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess;
 import org.apache.brooklyn.location.ssh.SshMachineLocation;
+import org.apache.brooklyn.test.EntityTestUtils;
 import org.apache.brooklyn.util.collections.Jsonya;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
+import com.google.common.collect.Iterables;
+
 @Test
 public class EmptySoftwareProcessYamlTest extends AbstractYamlTest {
     private static final Logger log = 
LoggerFactory.getLogger(EnrichersYamlTest.class);
@@ -99,4 +105,20 @@ public class EmptySoftwareProcessYamlTest extends 
AbstractYamlTest {
         // TODO this, below, probably should be 'localhost on entity', see 
#1377
         Assert.assertEquals(actualMachine.getParent().getDisplayName(), 
"localhost on entity");
     }
+    
+    @Test(groups="Integration")
+    public void testNoSshing() throws Exception {
+        Entity app = createAndStartApplication(
+                "location: byon:(hosts=\"1.2.3.4\")",
+                "services:",
+                "- type: "+EmptySoftwareProcess.class.getName(),
+                "  brooklyn.config:",
+                "    sshMonitoring.enabled: false",
+                "    
"+BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION.getName()+": true");
+        waitForApplicationTasks(app);
+
+        EmptySoftwareProcess entity = 
Iterables.getOnlyElement(Entities.descendants(app, EmptySoftwareProcess.class));
+        EntityAsserts.assertAttributeEqualsEventually(entity, 
Attributes.SERVICE_UP, true);
+        EntityAsserts.assertAttributeEqualsContinually(entity, 
Attributes.SERVICE_UP, true);
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptyWindowsProcessYamlTest.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptyWindowsProcessYamlTest.java
 
b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptyWindowsProcessYamlTest.java
new file mode 100644
index 0000000..77043c7
--- /dev/null
+++ 
b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/EmptyWindowsProcessYamlTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.camp.brooklyn;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.core.entity.Attributes;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.entity.software.base.EmptyWindowsProcess;
+import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+
+@Test
+public class EmptyWindowsProcessYamlTest extends AbstractYamlTest {
+
+    @Test(groups="Integration")
+    public void testNoWinrm() throws Exception {
+        Entity app = createAndStartApplication(
+                "location: byon:(hosts=\"1.2.3.4\",osFamily=windows)",
+                "services:",
+                "- type: "+EmptyWindowsProcess.class.getName(),
+                "  brooklyn.config:",
+                "    winrmMonitoring.enabled: false");
+        waitForApplicationTasks(app);
+
+        EmptyWindowsProcess entity = 
Iterables.getOnlyElement(Entities.descendants(app, EmptyWindowsProcess.class));
+        EntityAsserts.assertAttributeEqualsEventually(entity, 
Attributes.SERVICE_UP, true);
+        EntityAsserts.assertAttributeEqualsContinually(entity, 
Attributes.SERVICE_UP, true);
+        
+        Iterables.find(entity.getLocations(), 
Predicates.instanceOf(WinRmMachineLocation.class));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcess.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcess.java
 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcess.java
index 98a97c0..3fd694c 100644
--- 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcess.java
+++ 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcess.java
@@ -19,10 +19,14 @@
 package org.apache.brooklyn.entity.software.base;
 
 import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
 
 @ImplementedBy(EmptySoftwareProcessImpl.class)
 public interface EmptySoftwareProcess extends SoftwareProcess {
 
+    ConfigKey<Boolean> USE_SSH_MONITORING = 
ConfigKeys.newConfigKey("sshMonitoring.enabled", "SSH monitoring enabled", 
Boolean.TRUE);
+
     public SoftwareProcessDriver getDriver();
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcessImpl.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcessImpl.java
 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcessImpl.java
index 154a08a..7330461 100644
--- 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcessImpl.java
+++ 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptySoftwareProcessImpl.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.entity.software.base;
 
+import org.apache.brooklyn.core.entity.Attributes;
+
 public class EmptySoftwareProcessImpl extends SoftwareProcessImpl implements 
EmptySoftwareProcess {
 
     @Override
@@ -28,7 +30,11 @@ public class EmptySoftwareProcessImpl extends 
SoftwareProcessImpl implements Emp
     @Override
     protected void connectSensors() {
         super.connectSensors();
-        connectServiceUpIsRunning();
+        if (isSshMonitoringEnabled()) {
+            connectServiceUpIsRunning();
+        } else {
+            sensors().set(Attributes.SERVICE_UP, true);
+        }
     }
 
     @Override
@@ -36,4 +42,8 @@ public class EmptySoftwareProcessImpl extends 
SoftwareProcessImpl implements Emp
         disconnectServiceUpIsRunning();
         super.disconnectSensors();
     }
+    
+    protected boolean isSshMonitoringEnabled() {
+        return Boolean.TRUE.equals(getConfig(USE_SSH_MONITORING));
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcess.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcess.java
 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcess.java
new file mode 100644
index 0000000..770ba0d
--- /dev/null
+++ 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcess.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.entity.software.base;
+
+import java.util.Collection;
+
+import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+
+import com.google.common.collect.ImmutableSet;
+
+@ImplementedBy(EmptyWindowsProcessImpl.class)
+public interface EmptyWindowsProcess extends SoftwareProcess {
+
+    // 3389 is RDP; 5985 is WinRM (3389 isn't used by Brooklyn, but useful for 
the end-user subsequently)
+    ConfigKey<Collection<Integer>> REQUIRED_OPEN_LOGIN_PORTS = 
ConfigKeys.newConfigKeyWithDefault(
+            SoftwareProcess.REQUIRED_OPEN_LOGIN_PORTS,
+            ImmutableSet.of(5985, 3389));
+    
+    ConfigKey<Boolean> USE_WINRM_MONITORING = 
ConfigKeys.newConfigKey("winrmMonitoring.enabled", "WinRM monitoring enabled", 
Boolean.TRUE);
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessDriver.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessDriver.java
 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessDriver.java
new file mode 100644
index 0000000..d6e1c99
--- /dev/null
+++ 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessDriver.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.entity.software.base;
+
+public interface EmptyWindowsProcessDriver extends SoftwareProcessDriver {
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessImpl.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessImpl.java
 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessImpl.java
new file mode 100644
index 0000000..ae87774
--- /dev/null
+++ 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessImpl.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.entity.software.base;
+
+import org.apache.brooklyn.core.entity.Attributes;
+
+public class EmptyWindowsProcessImpl extends SoftwareProcessImpl implements 
EmptyWindowsProcess {
+
+    @Override
+    public Class<?> getDriverInterface() {
+        return EmptyWindowsProcessDriver.class;
+    }
+
+    @Override
+    protected void connectSensors() {
+        super.connectSensors();
+        if (isWinrmMonitoringEnabled()) {
+            connectServiceUpIsRunning();
+        } else {
+            sensors().set(Attributes.SERVICE_UP, true);
+        }
+    }
+
+    @Override
+    protected void disconnectSensors() {
+        disconnectServiceUpIsRunning();
+        super.disconnectSensors();
+    }
+    
+    protected boolean isWinrmMonitoringEnabled() {
+        return Boolean.TRUE.equals(getConfig(USE_WINRM_MONITORING));
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/56f9cdda/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessWinRmDriver.java
----------------------------------------------------------------------
diff --git 
a/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessWinRmDriver.java
 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessWinRmDriver.java
new file mode 100644
index 0000000..4a9a054
--- /dev/null
+++ 
b/brooklyn-server/software/base/src/main/java/org/apache/brooklyn/entity/software/base/EmptyWindowsProcessWinRmDriver.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.entity.software.base;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.brooklyn.core.entity.Attributes;
+import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
+import org.apache.brooklyn.util.net.UserAndHostAndPort;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class EmptyWindowsProcessWinRmDriver extends 
AbstractSoftwareProcessWinRmDriver implements VanillaWindowsProcessDriver {
+    @SuppressWarnings("unused")
+    private static final Logger LOG = 
LoggerFactory.getLogger(EmptyWindowsProcessWinRmDriver.class);
+
+    private final AtomicBoolean running = new AtomicBoolean();
+
+    public EmptyWindowsProcessWinRmDriver(EmptyWindowsProcessImpl entity, 
WinRmMachineLocation machine) {
+        super(entity, machine);
+    }
+
+    @Override
+    public void start() {
+        WinRmMachineLocation machine = (WinRmMachineLocation) location;
+        UserAndHostAndPort winrmAddress = 
UserAndHostAndPort.fromParts(machine.getUser(), 
machine.getAddress().getHostName(), 
machine.config().get(WinRmMachineLocation.WINRM_PORT));
+        getEntity().sensors().set(Attributes.WINRM_ADDRESS, winrmAddress);
+
+        super.start();
+    }
+
+    @Override
+    public boolean isRunning() {
+        return running.get();
+    }
+
+    @Override
+    public void install() { }
+
+    @Override
+    public void customize() { }
+
+    @Override
+    public void copyInstallResources() { 
+        Map<String, String> installFiles = 
entity.getConfig(SoftwareProcess.INSTALL_FILES);
+        Map<String, String> installTemplates = 
entity.getConfig(SoftwareProcess.INSTALL_TEMPLATES);
+        if ((installFiles!=null && !installFiles.isEmpty()) || 
(installTemplates!=null && !installTemplates.isEmpty())) {
+            // only do this if there are files, to prevent unnecessary `mkdir`
+            super.copyInstallResources();
+        }
+    }
+
+    @Override
+    public void copyRuntimeResources() { 
+        Map<String, String> runtimeFiles = 
entity.getConfig(SoftwareProcess.RUNTIME_FILES);
+        Map<String, String> runtimeTemplates = 
entity.getConfig(SoftwareProcess.RUNTIME_TEMPLATES);
+        if ((runtimeFiles!=null && !runtimeFiles.isEmpty()) || 
(runtimeTemplates!=null && !runtimeTemplates.isEmpty())) {
+            // only do this if there are files, to prevent unnecessary `mkdir`
+            super.copyRuntimeResources();
+        }        
+    }
+
+    @Override
+    public void launch() {
+        running.set(true);
+    }
+
+    @Override
+    public void rebind() {
+        super.rebind();
+        /* TODO not necessarily, but there is not yet an easy way to persist 
state without 
+         * using config/sensors which we might not want do. */
+        running.set(true);
+    }
+
+    @Override
+    public void stop() {
+        running.set(false);
+    }
+}

Reply via email to