Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master b118c1194 -> 324bb38be


Apply creation script on all nodes, including slaves, before initializing 
replication


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

Branch: refs/heads/master
Commit: ac7b9d1522026c5e26a181478fc1155e1254f8c8
Parents: e92dd1e
Author: Svetoslav Neykov <[email protected]>
Authored: Wed Sep 16 08:49:15 2015 +0300
Committer: Svetoslav Neykov <[email protected]>
Committed: Wed Sep 16 08:49:15 2015 +0300

----------------------------------------------------------------------
 .../entity/database/mysql/MySqlClusterImpl.java | 22 +++++---------------
 .../database/mysql/MySqlClusterTestHelper.java  |  3 +--
 2 files changed, 6 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac7b9d15/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterImpl.java
----------------------------------------------------------------------
diff --git 
a/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterImpl.java
 
b/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterImpl.java
index ae75254..164bac4 100644
--- 
a/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterImpl.java
+++ 
b/software/database/src/main/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterImpl.java
@@ -63,7 +63,6 @@ import com.google.common.reflect.TypeToken;
 
 // https://dev.mysql.com/doc/refman/5.7/en/replication-howto.html
 
-// TODO CREATION_SCRIPT_CONTENTS executed before replication setup so it is 
not replicated to slaves
 // TODO Bootstrap slave from dump for the case where the binary log is purged
 // TODO Promote slave to master
 // TODO SSL connection between master and slave
@@ -150,7 +149,7 @@ public class MySqlClusterImpl extends DynamicClusterImpl 
implements MySqlCluster
     protected EntitySpec<?> getFirstMemberSpec() {
         final EntitySpec<?> firstMemberSpec = super.getFirstMemberSpec();
         if (firstMemberSpec != null) {
-            return applyDefaults(firstMemberSpec, 
Suppliers.ofInstance(MASTER_SERVER_ID), MASTER_CONFIG_URL, false);
+            return applyDefaults(firstMemberSpec, 
Suppliers.ofInstance(MASTER_SERVER_ID), MASTER_CONFIG_URL);
         }
 
         final EntitySpec<?> memberSpec = super.getMemberSpec();
@@ -176,24 +175,19 @@ public class MySqlClusterImpl extends DynamicClusterImpl 
implements MySqlCluster
 
         EntitySpec<?> spec = super.getMemberSpec();
         if (spec != null) {
-            return applyDefaults(spec, serverIdSupplier, SLAVE_CONFIG_URL, 
true);
+            return applyDefaults(spec, serverIdSupplier, SLAVE_CONFIG_URL);
         }
 
         return EntitySpec.create(MySqlNode.class)
                 .displayName("MySql Slave")
                 .configure(MySqlNode.MYSQL_SERVER_ID, serverIdSupplier.get())
-                .configure(MySqlNode.TEMPLATE_CONFIGURATION_URL, 
SLAVE_CONFIG_URL)
-                // block inheritance, only master should execute the creation 
script
-                .configure(MySqlNode.CREATION_SCRIPT_URL, (String) null)
-                .configure(MySqlNode.CREATION_SCRIPT_CONTENTS, (String) null);
+                .configure(MySqlNode.TEMPLATE_CONFIGURATION_URL, 
SLAVE_CONFIG_URL);
     }
 
-    private EntitySpec<?> applyDefaults(EntitySpec<?> spec, Supplier<Integer> 
serverId, String configUrl, boolean resetCreationScript) {
+    private EntitySpec<?> applyDefaults(EntitySpec<?> spec, Supplier<Integer> 
serverId, String configUrl) {
         boolean needsServerId = !isKeyConfigured(spec, 
MySqlNode.MYSQL_SERVER_ID);
         boolean needsConfigUrl = !isKeyConfigured(spec, 
MySqlNode.TEMPLATE_CONFIGURATION_URL.getConfigKey());
-        boolean needsCreationScriptUrl = resetCreationScript && 
!isKeyConfigured(spec, MySqlNode.CREATION_SCRIPT_URL);
-        boolean needsCreationScriptContents = resetCreationScript && 
!isKeyConfigured(spec, MySqlNode.CREATION_SCRIPT_CONTENTS);
-        if (needsServerId || needsConfigUrl || needsCreationScriptUrl || 
needsCreationScriptContents) {
+        if (needsServerId || needsConfigUrl) {
             EntitySpec<?> clonedSpec = EntitySpec.create(spec);
             if (needsServerId) {
                 clonedSpec.configure(MySqlNode.MYSQL_SERVER_ID, 
serverId.get());
@@ -201,12 +195,6 @@ public class MySqlClusterImpl extends DynamicClusterImpl 
implements MySqlCluster
             if (needsConfigUrl) {
                 clonedSpec.configure(MySqlNode.TEMPLATE_CONFIGURATION_URL, 
configUrl);
             }
-            if (needsCreationScriptUrl) {
-                clonedSpec.configure(MySqlNode.CREATION_SCRIPT_URL, (String) 
null);
-            }
-            if (needsCreationScriptContents) {
-                clonedSpec.configure(MySqlNode.CREATION_SCRIPT_URL, (String) 
null);
-            }
             return clonedSpec;
         } else {
             return spec;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ac7b9d15/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java
----------------------------------------------------------------------
diff --git 
a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java
 
b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java
index 0bdf7f6..dc13546 100644
--- 
a/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java
+++ 
b/software/database/src/test/java/org/apache/brooklyn/entity/database/mysql/MySqlClusterTestHelper.java
@@ -74,12 +74,11 @@ public class MySqlClusterTestHelper {
     public static void test(TestApplication app, Location location) throws 
Exception {
         MySqlCluster mysql = 
app.createAndManageChild(EntitySpec.create(MySqlCluster.class)
                 .configure(MySqlCluster.INITIAL_SIZE, 2)
+                .configure(MySqlNode.CREATION_SCRIPT_CONTENTS, CREATION_SCRIPT)
                 .configure(MySqlNode.MYSQL_SERVER_CONF, MutableMap.<String, 
Object>of("skip-name-resolve","")));
 
         app.start(ImmutableList.of(location));
         log.info("MySQL started");
-        MySqlNode masterEntity = (MySqlNode) 
mysql.getAttribute(MySqlCluster.FIRST);
-        masterEntity.invoke(MySqlNode.EXECUTE_SCRIPT, 
ImmutableMap.of("commands", CREATION_SCRIPT)).asTask().getUnchecked();
 
         VogellaExampleAccess masterDb = new 
VogellaExampleAccess("com.mysql.jdbc.Driver", 
mysql.getAttribute(MySqlNode.DATASTORE_URL));
         VogellaExampleAccess slaveDb = new 
VogellaExampleAccess("com.mysql.jdbc.Driver", 
Iterables.getOnlyElement(mysql.getAttribute(MySqlCluster.SLAVE_DATASTORE_URL_LIST)));

Reply via email to