brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/5] git commit: SimulatedXyzImpl: add SIMULATE_ENTITY config
Date Wed, 08 Oct 2014 22:45:51 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 9acf9a4f3 -> f7d8691c4


SimulatedXyzImpl: add SIMULATE_ENTITY config

- For SimulatedJBoss7ServerImpl etc, add a SIMULATE_ENTITY config
  option.
- If set, then don’t start the real entity (instead just run `sleep`
  or skip the step entirely)
- Should we useful for setting to false, while also setting
  simulateExternalMonitoring (in situations where there is enough
  underlying resource to run many app-servers!)


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

Branch: refs/heads/master
Commit: 61b3621ebb1b3752e7c2bb02621a32a4b0fbf6ad
Parents: 066e37f
Author: Aled Sage <aled.sage@gmail.com>
Authored: Tue Oct 7 14:56:25 2014 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Oct 8 23:24:23 2014 +0100

----------------------------------------------------------------------
 .../qa/load/SimulatedJBoss7ServerImpl.java      | 64 +++++++++++++++++++-
 .../qa/load/SimulatedMySqlNodeImpl.java         | 20 +++++-
 .../qa/load/SimulatedNginxControllerImpl.java   | 21 ++++++-
 .../brooklyn/qa/load/SimulatedTheeTierApp.java  |  4 ++
 4 files changed, 103 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/61b3621e/usage/qa/src/main/java/brooklyn/qa/load/SimulatedJBoss7ServerImpl.java
----------------------------------------------------------------------
diff --git a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedJBoss7ServerImpl.java b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedJBoss7ServerImpl.java
index 7111ca2..64f7aa5 100644
--- a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedJBoss7ServerImpl.java
+++ b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedJBoss7ServerImpl.java
@@ -40,8 +40,46 @@ import brooklyn.util.os.Os;
 
 import com.google.common.net.HostAndPort;
 
+/**
+ * For simulating various aspects of the JBoss 7 app-server entity.
+ *  
+ * The use-case for this is that the desired configuration is not always available for testing.

+ * For example, there may be insufficient resources to run 100s of JBoss app-servers, or
one 
+ * may be experimenting with possible configurations such as use of an external monitoring
tool 
+ * that is not yet available.
+ * 
+ * It is then possible to simulate aspects of the behaviour, for performance and load testing
purposes. 
+ * 
+ * There is configuration for:
+ * <ul>
+ *   <li>{@code simulateEntity}
+ *     <ul>
+ *       <li>if true, no underlying entity will be started. Instead a sleep 100000
job will be run and monitored.
+ *       <li>if false, the underlying entity (i.e. a JBoss app-server) will be started
as normal.
+ *     </ul>
+ *   <li>{@code simulateExternalMonitoring}
+ *     <ul>
+ *       <li>if true, disables the default monitoring mechanism. Instead, a function
will periodically execute 
+ *           to set the entity's sensors (as though the values had been obtained from the
external monitoring tool).
+ *       <li>if false, then:
+ *         <ul>
+ *           <li>If {@code simulateEntity==true} it will execute comparable commands
(e.g. execute a command of the same 
+ *               size over ssh or do a comparable number of http GET requests).
+ *           <li>If {@code simulateEntity==false} then normal monitoring will be done.
+ *         </ul>
+ *     </ul>
+ *   <li>{@code skipSshOnStart}
+ *     <ul>
+ *       <li>If true (and if {@code simulateEntity==true}), then no ssh commands will
be executed at deploy-time. 
+ *           This is useful for speeding up load testing, to get to the desired number of
entities.
+ *           Should not be set to {@code true} if {@code simulateEntity==false}.
+ *       <li>If false, the ssh commands will be executed (based on the value of {@code
simulateEntity}.
+ *     </ul>
+ * </ul>
+ */
 public class SimulatedJBoss7ServerImpl extends JBoss7ServerImpl {
 
+    public static final ConfigKey<Boolean> SIMULATE_ENTITY = SimulatedTheeTierApp.SIMULATE_ENTITY;
     public static final ConfigKey<Boolean> SIMULATE_EXTERNAL_MONITORING = SimulatedTheeTierApp.SIMULATE_EXTERNAL_MONITORING;
     public static final ConfigKey<Boolean> SKIP_SSH_ON_START = SimulatedTheeTierApp.SKIP_SSH_ON_START;
     
@@ -55,8 +93,14 @@ public class SimulatedJBoss7ServerImpl extends JBoss7ServerImpl {
 
     @Override
     protected void connectSensors() {
+        boolean simulateEntity = getConfig(SIMULATE_ENTITY);
         boolean simulateExternalMonitoring = getConfig(SIMULATE_EXTERNAL_MONITORING);
 
+        if (!simulateEntity && !simulateExternalMonitoring) {
+            super.connectSensors();
+            return;
+        }
+        
         HostAndPort hp = BrooklynAccessUtils.getBrooklynAccessibleAddress(this,
                 getAttribute(MANAGEMENT_HTTP_PORT) + getConfig(PORT_INCREMENT));
 
@@ -68,11 +112,13 @@ public class SimulatedJBoss7ServerImpl extends JBoss7ServerImpl {
             // TODO What would set this normally, if not doing connectServiceUpIsRunning?
             setAttribute(SERVICE_PROCESS_IS_RUNNING, true);
         } else {
-            // simulate work of periodic HTTP request; TODO but not parsing JSON response
+            // if simulating entity, then simulate work of periodic HTTP request; TODO but
not parsing JSON response
+            String uriToPoll = (simulateEntity) ? "http://localhost:8081" : managementUri;
+            
             httpFeed = HttpFeed.builder()
                     .entity(this)
                     .period(200)
-                    .baseUri("http://localhost:8081")
+                    .baseUri(uriToPoll)
                     .credentials(getConfig(MANAGEMENT_USER), getConfig(MANAGEMENT_PASSWORD))
                     .poll(new HttpPollConfig<Integer>(MANAGEMENT_STATUS)
                             .onSuccess(HttpValueFunctions.responseCode()))
@@ -118,6 +164,15 @@ public class SimulatedJBoss7ServerImpl extends JBoss7ServerImpl {
         }
         
         @Override
+        public boolean isRunning() {
+            if (entity.getConfig(SKIP_SSH_ON_START)) {
+                return true;
+            } else {
+                return super.isRunning();
+            }
+        }
+
+        @Override
         public void install() {
             if (entity.getConfig(SKIP_SSH_ON_START)) {
                 // no-op
@@ -137,6 +192,11 @@ public class SimulatedJBoss7ServerImpl extends JBoss7ServerImpl {
         
         @Override
         public void launch() {
+            if (!entity.getConfig(SIMULATE_ENTITY)) {
+                super.launch();
+                return;
+            }
+            
             // We wait for evidence of JBoss running because, using
             // brooklyn.ssh.config.tool.class=brooklyn.util.internal.ssh.cli.SshCliTool,
             // we saw the ssh session return before the JBoss process was fully running

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/61b3621e/usage/qa/src/main/java/brooklyn/qa/load/SimulatedMySqlNodeImpl.java
----------------------------------------------------------------------
diff --git a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedMySqlNodeImpl.java b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedMySqlNodeImpl.java
index 4c423a9..bad437a 100644
--- a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedMySqlNodeImpl.java
+++ b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedMySqlNodeImpl.java
@@ -37,8 +37,12 @@ import brooklyn.util.task.system.ProcessTaskWrapper;
 import brooklyn.util.time.CountdownTimer;
 import brooklyn.util.time.Duration;
 
+/**
+ * @see SimulatedJBoss7ServerImpl for description of purpose and configuration options.
+ */
 public class SimulatedMySqlNodeImpl extends MySqlNodeImpl {
 
+    public static final ConfigKey<Boolean> SIMULATE_ENTITY = SimulatedTheeTierApp.SIMULATE_ENTITY;
     public static final ConfigKey<Boolean> SIMULATE_EXTERNAL_MONITORING = SimulatedTheeTierApp.SIMULATE_EXTERNAL_MONITORING;
     public static final ConfigKey<Boolean> SKIP_SSH_ON_START = SimulatedTheeTierApp.SKIP_SSH_ON_START;
     
@@ -83,7 +87,11 @@ public class SimulatedMySqlNodeImpl extends MySqlNodeImpl {
         // simulate metrics, for if using ssh polling
         @Override
         public String getStatusCmd() {
-            return "echo Uptime: 2427  Threads: 1  Questions: 581  Slow queries: 0  Opens:
53  Flush tables: 1  Open tables: 35  Queries per second avg: "+(counter++ % 100);
+            if (entity.getConfig(SIMULATE_ENTITY)) {
+                return "echo Uptime: 2427  Threads: 1  Questions: 581  Slow queries: 0  Opens:
53  Flush tables: 1  Open tables: 35  Queries per second avg: "+(counter++ % 100);
+            } else {
+                return super.getStatusCmd();
+            }
         }
 
         @Override
@@ -99,7 +107,10 @@ public class SimulatedMySqlNodeImpl extends MySqlNodeImpl {
         // This is a copy of super.customize, but with the mysqladmin-exec disabled
         @Override
         public void customize() {
-            if (entity.getConfig(SKIP_SSH_ON_START)) {
+            if (!entity.getConfig(SIMULATE_ENTITY)) {
+                super.customize();
+                return;
+            } else if (entity.getConfig(SKIP_SSH_ON_START)) {
                 // no-op
             } else {
                 copyDatabaseConfigScript();
@@ -138,6 +149,11 @@ public class SimulatedMySqlNodeImpl extends MySqlNodeImpl {
 
         @Override
         public void launch() {
+            if (!entity.getConfig(SIMULATE_ENTITY)) {
+                super.launch();
+                return;
+            }
+            
             entity.setAttribute(MySqlNode.PID_FILE, getRunDir() + "/" + AbstractSoftwareProcessSshDriver.PID_FILENAME);
             
             if (entity.getConfig(SKIP_SSH_ON_START)) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/61b3621e/usage/qa/src/main/java/brooklyn/qa/load/SimulatedNginxControllerImpl.java
----------------------------------------------------------------------
diff --git a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedNginxControllerImpl.java b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedNginxControllerImpl.java
index ec93fc5..d8fe57a 100644
--- a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedNginxControllerImpl.java
+++ b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedNginxControllerImpl.java
@@ -42,8 +42,12 @@ import brooklyn.util.net.Networking;
 
 import com.google.common.base.Functions;
 
+/**
+ * @see SimulatedJBoss7ServerImpl for description of purpose and configuration options.
+ */
 public class SimulatedNginxControllerImpl extends NginxControllerImpl {
 
+    public static final ConfigKey<Boolean> SIMULATE_ENTITY = SimulatedTheeTierApp.SIMULATE_ENTITY;
     public static final ConfigKey<Boolean> SIMULATE_EXTERNAL_MONITORING = SimulatedTheeTierApp.SIMULATE_EXTERNAL_MONITORING;
     public static final ConfigKey<Boolean> SKIP_SSH_ON_START = SimulatedTheeTierApp.SKIP_SSH_ON_START;
     
@@ -57,8 +61,14 @@ public class SimulatedNginxControllerImpl extends NginxControllerImpl {
 
     @Override
     public void connectSensors() {
+        boolean simulateEntity = getConfig(SIMULATE_ENTITY);
         boolean simulateExternalMonitoring = getConfig(SIMULATE_EXTERNAL_MONITORING);
 
+        if (!simulateEntity && !simulateExternalMonitoring) {
+            super.connectSensors();
+            return;
+        }
+
         // From AbstractController.connectSensors
         if (getUrl()==null) setAttribute(ROOT_URL, inferUrl());
         addServerPoolMemberTrackingPolicy();
@@ -67,11 +77,13 @@ public class SimulatedNginxControllerImpl extends NginxControllerImpl
{
         ConfigToAttributes.apply(this);
 
         if (!simulateExternalMonitoring) {
-            // simulate work of periodic HTTP request
+            // if simulating entity, then simulate work of periodic HTTP request; TODO but
not parsing JSON response
+            String uriToPoll = (simulateEntity) ? "http://localhost:8081" : getAttribute(ROOT_URL);
+            
             httpFeed = HttpFeed.builder()
                     .entity(this)
                     .period(getConfig(HTTP_POLL_PERIOD))
-                    .baseUri("http://localhost:8081")
+                    .baseUri(uriToPoll)
                     .poll(new HttpPollConfig<Boolean>(SERVICE_UP)
                             .onSuccess(Functions.constant(true))
                             .onFailureOrException(Functions.constant(true)))
@@ -137,6 +149,11 @@ public class SimulatedNginxControllerImpl extends NginxControllerImpl
{
         
         @Override
         public void launch() {
+            if (!entity.getConfig(SIMULATE_ENTITY)) {
+                super.launch();
+                return;
+            }
+            
             Networking.checkPortsValid(MutableMap.of("httpPort", getHttpPort()));
 
             if (entity.getConfig(SKIP_SSH_ON_START)) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/61b3621e/usage/qa/src/main/java/brooklyn/qa/load/SimulatedTheeTierApp.java
----------------------------------------------------------------------
diff --git a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedTheeTierApp.java b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedTheeTierApp.java
index 204fa67..24c0355 100644
--- a/usage/qa/src/main/java/brooklyn/qa/load/SimulatedTheeTierApp.java
+++ b/usage/qa/src/main/java/brooklyn/qa/load/SimulatedTheeTierApp.java
@@ -63,9 +63,13 @@ import com.google.common.collect.Lists;
  * rather than the ability to host many running app-servers.
  * 
  * The app is based on WebClusterDatabaseExampleApp
+ * 
+ * @see SimulatedJBoss7ServerImpl for description of purpose and configuration options.
  */
 public class SimulatedTheeTierApp extends AbstractApplication {
 
+    public static final ConfigKey<Boolean> SIMULATE_ENTITY = ConfigKeys.newBooleanConfigKey("simulateEntity",
"", true);
+    
     public static final ConfigKey<Boolean> SIMULATE_EXTERNAL_MONITORING = ConfigKeys.newBooleanConfigKey("simulateExternalMonitoring",
"", true);
 
     public static final ConfigKey<Boolean> SKIP_SSH_ON_START = ConfigKeys.newBooleanConfigKey("skipSshOnStart",
"", false);


Mime
View raw message