You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by de...@apache.org on 2019/02/18 13:12:20 UTC

svn commit: r1853796 - in /uima/uima-ducc/trunk: src/main/admin/db_util.py src/main/admin/ducc_post_install uima-ducc-database/src/main/java/org/apache/uima/ducc/database/DbCreate.java

Author: degenaro
Date: Mon Feb 18 13:12:19 2019
New Revision: 1853796

URL: http://svn.apache.org/viewvc?rev=1853796&view=rev
Log:
UIMA-5742 Reliable DUCC

> ducc_post_install should allow for specification of DB replication level

Modified:
    uima/uima-ducc/trunk/src/main/admin/db_util.py
    uima/uima-ducc/trunk/src/main/admin/ducc_post_install
    uima/uima-ducc/trunk/uima-ducc-database/src/main/java/org/apache/uima/ducc/database/DbCreate.java

Modified: uima/uima-ducc/trunk/src/main/admin/db_util.py
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/admin/db_util.py?rev=1853796&r1=1853795&r2=1853796&view=diff
==============================================================================
--- uima/uima-ducc/trunk/src/main/admin/db_util.py (original)
+++ uima/uima-ducc/trunk/src/main/admin/db_util.py Mon Feb 18 13:12:19 2019
@@ -141,7 +141,7 @@ def update_cassandra_config(DUCC_HOME, D
                 os.system(ch_head)
         
 
-def configure_database(DUCC_HOME, DUCC_HEAD, java, db_autostart=True, db_host=None, db_user=None, db_pw=None ):
+def configure_database(DUCC_HOME, DUCC_HEAD, java, db_autostart=True, db_host=None, db_user=None, db_pw=None, db_replication=None):
     # for cassandra:
     # in ducc_runtime/cassandra-server/conf we need to update cassandra.yaml to establish
     # the data directories and db connection addresses
@@ -193,6 +193,8 @@ def configure_database(DUCC_HOME, DUCC_H
 
     ret = True
     CMD = [java, '-DDUCC_HOME=' + DUCC_HOME, 'org.apache.uima.ducc.database.DbCreate', db_host, db_user, db_pw]
+    if(db_replication != None):
+        CMD.append(db_replication)
     CMD = ' '.join(CMD)
     if ( execute(CMD) == 0 ):
         print 'Database is initialized.'

Modified: uima/uima-ducc/trunk/src/main/admin/ducc_post_install
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/src/main/admin/ducc_post_install?rev=1853796&r1=1853795&r2=1853796&view=diff
==============================================================================
--- uima/uima-ducc/trunk/src/main/admin/ducc_post_install (original)
+++ uima/uima-ducc/trunk/src/main/admin/ducc_post_install Mon Feb 18 13:12:19 2019
@@ -66,6 +66,9 @@ class PostInstall():
         print "   [-a, --db-automanage] <True|False>"
         print "        Specify False if DUCC should not start/stop database."
         print ""
+        print "   [-r, --db-replication] <integer>"
+        print "        Specify database replication level (default = 1)."
+        print ""
         print "   [-m, --db-home] <path>"
         print "        The location of the database home directory, only specify when db-automanage is False and the default database directory should not be used."
         print ""
@@ -162,7 +165,7 @@ class PostInstall():
         #    self.update_property('ducc.database.host', '--disabled--', '# Database support is disabled')
         #    return True;
         
-        if ( dbu.configure_database(self.DUCC_HOME, self.ducc_head, self.path_to_java, self.database_automanage, self.database_host_list, self.database_user, db_pw) ):
+        if ( dbu.configure_database(self.DUCC_HOME, self.ducc_head, self.path_to_java, self.database_automanage, self.database_host_list, self.database_user, db_pw, self.database_replication) ):
             print 'Configuring DUCC to use the database.'
 
             self.update_property('ducc.service.persistence.impl', 'org.apache.uima.ducc.database.StateServicesDb', '# Service manager persistence')
@@ -461,6 +464,7 @@ class PostInstall():
         self.ducc_head = None
         self.keystore_pw = None
         self.database_automanage = None
+        self.database_replication = None
         self.database_home = None
         self.database_host_list = None
         self.database_user = None
@@ -469,7 +473,7 @@ class PostInstall():
         self.path_to_java = None
 
         try:
-            opts, args = getopt.getopt(argv, 'a:m:o:u:d:b:j:k:n:h?', ['db-automanage=', 'db-home=', 'db-host-list=', 'db-user=', 'db-password=', 'br-password=', 'jvm=', 'keystore=', 'head-node=', 'help'])
+            opts, args = getopt.getopt(argv, 'a:r:m:o:u:d:b:j:k:n:h?', ['db-automanage=', 'db-replication=', 'db-home=', 'db-host-list=', 'db-user=', 'db-password=', 'br-password=', 'jvm=', 'keystore=', 'head-node=', 'help'])
         except:
             self.usage("Invalid arguments " + ' '.join(argv))
 
@@ -481,6 +485,8 @@ class PostInstall():
                     self.database_automanage = True
                 else:
                     self.database_automanage = False
+            if o in ('-r', '--db-replication'):
+                self.database_replication = a
             if o in ('-m', '--db-home'):
                 self.database_home = a
             if o in ('-o', '--db-host-list'):

Modified: uima/uima-ducc/trunk/uima-ducc-database/src/main/java/org/apache/uima/ducc/database/DbCreate.java
URL: http://svn.apache.org/viewvc/uima/uima-ducc/trunk/uima-ducc-database/src/main/java/org/apache/uima/ducc/database/DbCreate.java?rev=1853796&r1=1853795&r2=1853796&view=diff
==============================================================================
--- uima/uima-ducc/trunk/uima-ducc-database/src/main/java/org/apache/uima/ducc/database/DbCreate.java (original)
+++ uima/uima-ducc/trunk/uima-ducc-database/src/main/java/org/apache/uima/ducc/database/DbCreate.java Mon Feb 18 13:12:19 2019
@@ -49,6 +49,7 @@ public class DbCreate
     String[] db_host_list;
     String adminid = null;
     String adminpw = null;
+    String replication = null;
     boolean useNewPw = false;
 
     private Cluster cluster;
@@ -70,6 +71,14 @@ public class DbCreate
         this.adminpw = adminpw;
     }
 
+    DbCreate(String db_host_list, String adminid, String adminpw, String replication)
+    {
+        this.db_host_list = toArray(db_host_list);
+        this.adminid = adminid;
+        this.adminpw = adminpw;
+        this.replication = replication;
+    }
+    
     private String toString(String[] array) {
     	StringBuffer sb = new StringBuffer();
     	if(array != null) {
@@ -263,7 +272,13 @@ public class DbCreate
     	String guest_pw = adminpw;
     	
         // A 'keyspace' is what we usually think of as a database.
-        session.execute("CREATE KEYSPACE IF NOT EXISTS ducc WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};");
+    	String strategy = "SimpleStrategy";
+		String factor = "1";
+    	if(replication != null) {
+    		//strategy = "NetworkTopologyStrategy";
+    		factor = replication;
+    	}
+        session.execute("CREATE KEYSPACE IF NOT EXISTS ducc WITH replication = {'class':'"+strategy+"', 'replication_factor':"+factor+"};");
         session.execute("CREATE USER IF NOT EXISTS guest  WITH PASSWORD '"+guest_pw+"' NOSUPERUSER");
         session.execute("GRANT SELECT ON KEYSPACE ducc TO guest");
         session.execute("REVOKE SELECT ON KEYSPACE system FROM guest");
@@ -328,14 +343,18 @@ public class DbCreate
 
     public static void main(String[] args)
     {
-        if ( args.length != 3 ) {
-            System.out.println("Usage: DbCreate database_url db_id db_pw");
-            System.exit(1);
-        }
-
         DbCreate client = null;
         try {
-            client = new DbCreate(args[0], args[1], args[2]);
+        	if ( args.length == 4 ) {
+        		client = new DbCreate(args[0], args[1], args[2], args[3]);
+        	}
+        	else if ( args.length == 3 ) {
+        		client = new DbCreate(args[0], args[1], args[2]);
+        	}
+        	else {
+                System.out.println("Usage: DbCreate database_url db_id db_pw");
+                System.exit(1);
+            }
             if ( client.connect() ) {
                 client.createSchema();
                 client.close();