brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hadr...@apache.org
Subject [3/4] incubator-brooklyn git commit: Adds ResourceExists constraint to several entities
Date Sat, 21 Nov 2015 03:27:13 GMT
Adds ResourceExists constraint to several entities


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

Branch: refs/heads/master
Commit: 2f77a52410ded545a83697248dc2f7d362df9dd8
Parents: ade3e41
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Fri Nov 20 18:37:45 2015 +0000
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Fri Nov 20 18:37:45 2015 +0000

----------------------------------------------------------------------
 .../brooklyn/util/core/ResourcePredicates.java  | 11 ++++++++
 .../nosql/elasticsearch/ElasticSearchNode.java  | 29 ++++++++++++--------
 .../nosql/mongodb/AbstractMongoDBServer.java    | 14 ++++++----
 .../brooklyn/entity/nosql/redis/RedisStore.java | 10 +++++--
 .../entity/webapp/jboss/JBoss7Server.java       | 14 ++++++----
 .../entity/webapp/tomcat/TomcatServer.java      | 19 +++++++++----
 6 files changed, 66 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f77a524/core/src/main/java/org/apache/brooklyn/util/core/ResourcePredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/ResourcePredicates.java b/core/src/main/java/org/apache/brooklyn/util/core/ResourcePredicates.java
index 8bf0309..439aaae 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/ResourcePredicates.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/ResourcePredicates.java
@@ -23,9 +23,11 @@ import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.core.objs.BrooklynObjectPredicate;
+import org.apache.brooklyn.util.text.StringPredicates;
 import org.apache.brooklyn.util.text.Strings;
 
 import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
 
 public class ResourcePredicates {
 
@@ -39,6 +41,15 @@ public class ResourcePredicates {
         return new ResourceExistsPredicate();
     }
 
+    /**
+     * @return A predicate that tests whether its input is either empty or a resource readable
by Brooklyn.
+     * @see StringPredicates#isBlank
+     * @see #urlExists
+     */
+    public static Predicate<String> urlIsBlankOrExists() {
+        return Predicates.or(StringPredicates.isBlank(), urlExists());
+    }
+
     private static class ResourceExistsPredicate implements BrooklynObjectPredicate<String>
{
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f77a524/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
index 90d8d02..1687bf1 100644
--- a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
+++ b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/elasticsearch/ElasticSearchNode.java
@@ -31,6 +31,7 @@ import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey.StringAt
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
 import org.apache.brooklyn.entity.webapp.WebAppServiceConstants;
 import org.apache.brooklyn.entity.database.DatastoreMixins;
+import org.apache.brooklyn.util.core.ResourcePredicates;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 
 /**
@@ -43,40 +44,44 @@ import org.apache.brooklyn.util.core.flags.SetFromFlag;
 public interface ElasticSearchNode extends SoftwareProcess, DatastoreMixins.HasDatastoreUrl
{
     @SetFromFlag("version")
     ConfigKey<String> SUGGESTED_VERSION = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION,
"1.2.1");
-    
+
     @SetFromFlag("downloadUrl")
     BasicAttributeSensorAndConfigKey<String> DOWNLOAD_URL = new BasicAttributeSensorAndConfigKey<String>(
             SoftwareProcess.DOWNLOAD_URL, "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${version}.tar.gz");
-    
+
     @SetFromFlag("dataDir")
     ConfigKey<String> DATA_DIR = ConfigKeys.newStringConfigKey("elasticsearch.node.data.dir",
"Directory for writing data files", null);
-    
+
     @SetFromFlag("logDir")
     ConfigKey<String> LOG_DIR = ConfigKeys.newStringConfigKey("elasticsearch.node.log.dir",
"Directory for writing log files", null);
-    
+
     @SetFromFlag("configFileUrl")
-    ConfigKey<String> TEMPLATE_CONFIGURATION_URL = ConfigKeys.newStringConfigKey(
-            "elasticsearch.node.template.configuration.url", "URL where the elasticsearch
configuration file (in freemarker format) can be found", null);
-    
+    ConfigKey<String> TEMPLATE_CONFIGURATION_URL = ConfigKeys.builder(String.class)
+            .name("elasticsearch.node.template.configuration.url")
+            .description("URL where the elasticsearch configuration file (in freemarker format)
can be found")
+            .defaultValue(null)
+            .constraint(ResourcePredicates.urlIsBlankOrExists())
+            .build();
+
     @SetFromFlag("multicastEnabled")
     ConfigKey<Boolean> MULTICAST_ENABLED = ConfigKeys.newBooleanConfigKey("elasticsearch.node.multicast.enabled",

             "Indicates whether zen discovery multicast should be enabled for a node", null);
-    
+
     @SetFromFlag("multicastEnabled")
     ConfigKey<Boolean> UNICAST_ENABLED = ConfigKeys.newBooleanConfigKey("elasticsearch.node.UNicast.enabled",

             "Indicates whether zen discovery unicast should be enabled for a node", null);
     
     @SetFromFlag("httpPort")
     PortAttributeSensorAndConfigKey HTTP_PORT = new PortAttributeSensorAndConfigKey(WebAppServiceConstants.HTTP_PORT,
PortRanges.fromString("9200+"));
-    
+
     @SetFromFlag("nodeName")
     StringAttributeSensorAndConfigKey NODE_NAME = new StringAttributeSensorAndConfigKey("elasticsearch.node.name",

             "Node name (or randomly selected if not set", null);
-    
+
     @SetFromFlag("clusterName")
     StringAttributeSensorAndConfigKey CLUSTER_NAME = new StringAttributeSensorAndConfigKey("elasticsearch.node.cluster.name",

             "Cluster name (or elasticsearch selected if not set", null);
-    
+
     AttributeSensor<String> NODE_ID = Sensors.newStringSensor("elasticsearch.node.id");
     AttributeSensor<Integer> DOCUMENT_COUNT = Sensors.newIntegerSensor("elasticsearch.node.docs.count");
     AttributeSensor<Integer> STORE_BYTES = Sensors.newIntegerSensor("elasticsearch.node.store.bytes");
@@ -84,5 +89,5 @@ public interface ElasticSearchNode extends SoftwareProcess, DatastoreMixins.HasD
     AttributeSensor<Integer> GET_TIME_IN_MILLIS = Sensors.newIntegerSensor("elasticsearch.node.get.time.in.millis");
     AttributeSensor<Integer> SEARCH_QUERY_TOTAL = Sensors.newIntegerSensor("elasticsearch.node.search.query.total");
     AttributeSensor<Integer> SEARCH_QUERY_TIME_IN_MILLIS = Sensors.newIntegerSensor("elasticsearch.node.search.query.time.in.millis");
-    
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f77a524/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/AbstractMongoDBServer.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/AbstractMongoDBServer.java
b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/AbstractMongoDBServer.java
index 5947a43..3475a7d 100644
--- a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/AbstractMongoDBServer.java
+++ b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/mongodb/AbstractMongoDBServer.java
@@ -25,6 +25,7 @@ import org.apache.brooklyn.core.sensor.AttributeSensorAndConfigKey;
 import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey;
 import org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
+import org.apache.brooklyn.util.core.ResourcePredicates;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 
 public interface AbstractMongoDBServer extends SoftwareProcess, Entity, MongoDBAuthenticationMixins
{
@@ -36,12 +37,15 @@ public interface AbstractMongoDBServer extends SoftwareProcess, Entity,
MongoDBA
     @SetFromFlag("dataDirectory")
     ConfigKey<String> DATA_DIRECTORY = ConfigKeys.newStringConfigKey(
             "mongodb.data.directory", "Data directory to store MongoDB journals");
-    
+
     @SetFromFlag("mongodbConfTemplateUrl")
-    ConfigKey<String> MONGODB_CONF_TEMPLATE_URL = ConfigKeys.newStringConfigKey(
-            "mongodb.config.url", "Template file (in freemarker format) for a MongoDB configuration
file",
-            "classpath://org/apache/brooklyn/entity/nosql/mongodb/default.conf");
-    
+    ConfigKey<String> MONGODB_CONF_TEMPLATE_URL = ConfigKeys.builder(String.class)
+            .name("mongodb.config.url")
+            .description("Template file (in freemarker format) for a MongoDB configuration
file")
+            .defaultValue("classpath://org/apache/brooklyn/entity/nosql/mongodb/default.conf")
+            .constraint(ResourcePredicates.urlIsBlankOrExists())
+            .build();
+
     @SetFromFlag("version")
     ConfigKey<String> SUGGESTED_VERSION =
             ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.SUGGESTED_VERSION, "2.6.5");

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f77a524/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/redis/RedisStore.java
----------------------------------------------------------------------
diff --git a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/redis/RedisStore.java
b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/redis/RedisStore.java
index 6b98b3b..64c0344 100644
--- a/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/redis/RedisStore.java
+++ b/software/nosql/src/main/java/org/apache/brooklyn/entity/nosql/redis/RedisStore.java
@@ -27,6 +27,7 @@ import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey;
 import org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
+import org.apache.brooklyn.util.core.ResourcePredicates;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 
 /**
@@ -48,9 +49,12 @@ public interface RedisStore extends SoftwareProcess {
     PortAttributeSensorAndConfigKey REDIS_PORT = new PortAttributeSensorAndConfigKey("redis.port",
"Redis port number", "6379+");
 
     @SetFromFlag("redisConfigTemplateUrl")
-    ConfigKey<String> REDIS_CONFIG_TEMPLATE_URL = ConfigKeys.newConfigKey(
-            "redis.config.templateUrl", "Template file (in freemarker format) for the redis.conf
config file", 
-            "classpath://org/apache/brooklyn/entity/nosql/redis/redis.conf");
+    ConfigKey<String> REDIS_CONFIG_TEMPLATE_URL = ConfigKeys.builder(String.class)
+            .name("redis.config.templateUrl")
+            .description("Template file (in freemarker format) for the redis.conf config
file")
+            .defaultValue("classpath://org/apache/brooklyn/entity/nosql/redis/redis.conf")
+            .constraint(ResourcePredicates.urlExists())
+            .build();
 
     AttributeSensor<Integer> UPTIME = Sensors.newIntegerSensor("redis.uptime", "Redis
uptime in seconds");
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f77a524/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/jboss/JBoss7Server.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/jboss/JBoss7Server.java
b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/jboss/JBoss7Server.java
index 6a67e45..0ba1b38 100644
--- a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/jboss/JBoss7Server.java
+++ b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/jboss/JBoss7Server.java
@@ -30,6 +30,7 @@ import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey.StringAttributeSensorAndConfigKey;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
 import org.apache.brooklyn.entity.webapp.JavaWebAppSoftwareProcess;
+import org.apache.brooklyn.util.core.ResourcePredicates;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 import org.apache.brooklyn.util.javalang.JavaClassNames;
 
@@ -76,10 +77,13 @@ public interface JBoss7Server extends JavaWebAppSoftwareProcess, HasShortName
{
     @SetFromFlag("deploymentTimeout")
     ConfigKey<Integer> DEPLOYMENT_TIMEOUT =
             ConfigKeys.newConfigKey("webapp.jboss.deploymentTimeout", "Deployment timeout,
in seconds", 600);
-    
-    ConfigKey<String> TEMPLATE_CONFIGURATION_URL = ConfigKeys.newConfigKey(
-            "webapp.jboss.templateConfigurationUrl", "Template file (in freemarker format)
for the standalone.xml file", 
-            JavaClassNames.resolveClasspathUrl(JBoss7Server.class, "jboss7-standalone.xml"));
+
+    ConfigKey<String> TEMPLATE_CONFIGURATION_URL = ConfigKeys.builder(String.class)
+            .name("webapp.jboss.templateConfigurationUrl")
+            .description("Template file (in freemarker format) for the standalone.xml file")
+            .defaultValue(JavaClassNames.resolveClasspathUrl(JBoss7Server.class, "jboss7-standalone.xml"))
+            .constraint(ResourcePredicates.urlExists())
+            .build();
 
     @SetFromFlag("managementUser")
     ConfigKey<String> MANAGEMENT_USER = ConfigKeys.newConfigKey("webapp.jboss.managementUser",
@@ -99,6 +103,6 @@ public interface JBoss7Server extends JavaWebAppSoftwareProcess, HasShortName
{
     AttributeSensor<Boolean> MANAGEMENT_URL_UP = 
             Sensors.newBooleanSensor("webapp.jboss.managementUp", "Management server is responding
with OK");
     
-    public static final AttributeSensor<String> PID_FILE = Sensors.newStringSensor(
"jboss.pid.file", "PID file");
+    public static final AttributeSensor<String> PID_FILE = Sensors.newStringSensor("jboss.pid.file",
"PID file");
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2f77a524/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServer.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServer.java
b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServer.java
index c16132c..cc03e65 100644
--- a/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServer.java
+++ b/software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/tomcat/TomcatServer.java
@@ -31,6 +31,7 @@ import org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey;
 import org.apache.brooklyn.entity.java.UsesJmx;
 import org.apache.brooklyn.entity.software.base.SoftwareProcess;
 import org.apache.brooklyn.entity.webapp.JavaWebAppSoftwareProcess;
+import org.apache.brooklyn.util.core.ResourcePredicates;
 import org.apache.brooklyn.util.core.flags.SetFromFlag;
 import org.apache.brooklyn.util.javalang.JavaClassNames;
 import org.apache.brooklyn.util.time.Duration;
@@ -61,14 +62,20 @@ public interface TomcatServer extends JavaWebAppSoftwareProcess, UsesJmx,
HasSho
             ConfigKeys.newPortSensorAndConfigKey("tomcat.shutdownport", "Suggested shutdown
port", PortRanges.fromString("31880+"));
 
     @SetFromFlag("server.xml")
-    ConfigKey<String> SERVER_XML_RESOURCE = ConfigKeys.newStringConfigKey(
-            "tomcat.serverxml", "The file to template and use as the Tomcat process' server.xml",
-            JavaClassNames.resolveClasspathUrl(TomcatServer.class, "server.xml"));
+    ConfigKey<String> SERVER_XML_RESOURCE = ConfigKeys.builder(String.class)
+            .name("tomcat.serverxml")
+            .description("The file to template and use as the Tomcat process' server.xml")
+            .defaultValue(JavaClassNames.resolveClasspathUrl(TomcatServer.class, "server.xml"))
+            .constraint(ResourcePredicates.urlExists())
+            .build();
 
     @SetFromFlag("web.xml")
-    ConfigKey<String> WEB_XML_RESOURCE = ConfigKeys.newStringConfigKey(
-            "tomcat.webxml", "The file to template and use as the Tomcat process' web.xml",
-            JavaClassNames.resolveClasspathUrl(TomcatServer.class, "web.xml"));
+    ConfigKey<String> WEB_XML_RESOURCE = ConfigKeys.builder(String.class)
+            .name("tomcat.webxml")
+            .description("The file to template and use as the Tomcat process' web.xml")
+            .defaultValue(JavaClassNames.resolveClasspathUrl(TomcatServer.class, "web.xml"))
+            .constraint(ResourcePredicates.urlExists())
+            .build();
 
     ConfigKey<Duration> START_TIMEOUT = ConfigKeys.newConfigKeyWithDefault(SoftwareProcess.START_TIMEOUT,
Duration.FIVE_MINUTES);
 


Mime
View raw message