ranger-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From v..@apache.org
Subject [1/2] incubator-ranger git commit: RANGER-1173: Improve Ranger database schema import logic and make it more robust
Date Tue, 13 Sep 2016 14:39:27 GMT
Repository: incubator-ranger
Updated Branches:
  refs/heads/master 1115ca8e9 -> 68541c92a


http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/68541c92/security-admin/scripts/db_setup.py
----------------------------------------------------------------------
diff --git a/security-admin/scripts/db_setup.py b/security-admin/scripts/db_setup.py
index a2b26f5..c1efd4a 100644
--- a/security-admin/scripts/db_setup.py
+++ b/security-admin/scripts/db_setup.py
@@ -27,6 +27,7 @@ from datetime import date
 import time
 import datetime
 from time import gmtime, strftime
+import socket
 globalDict = {}
 
 os_name = platform.system()
@@ -41,6 +42,11 @@ if os_name == "LINUX":
 elif os_name == "WINDOWS":
 	RANGER_ADMIN_HOME = os.getenv("RANGER_ADMIN_HOME")
 
+if socket.getfqdn().find('.')>=0:
+	client_host=socket.getfqdn()
+else:
+	client_host=socket.gethostbyaddr(socket.gethostname())[0]
+
 def check_output(query):
 	if os_name == "LINUX":
 		p = subprocess.Popen(shlex.split(query), stdout=subprocess.PIPE)
@@ -105,11 +111,10 @@ class BaseDB(object):
 		log("[I] ---------- Verifying table ----------", "info")
 
 	def import_db_file(self, db_name, db_user, db_password, file_name):
-		log("[I] ---------- Importing db schema ----------", "info")
+		log("[I] Importing DB file :"+file_name, "info")
 
-	def upgrade_db(self, db_name, db_user, db_password, DBVERSION_CATALOG_CREATION):
-		self.import_db_file(db_name, db_user, db_password, DBVERSION_CATALOG_CREATION)
-		log("[I] Baseline DB upgraded successfully", "info")
+	def create_version_history_table(self, db_name, db_user, db_password, DBVERSION_CATALOG_CREATION,TABLE_NAME):
+		log("[I] Creating version and patch history info table", "info")
 
 	def apply_patches(self, db_name, db_user, db_password, PATCHES_PATH):
 		#first get all patches and then apply each patch
@@ -153,6 +158,9 @@ class BaseDB(object):
 	def change_admin_default_password(xa_db_host, db_user, db_password, db_name,userName,oldPassword,newPassword):
 		log("[I] ----------------- Changing Ranger admin default password  ------------", "info")
 
+	def import_core_db_schema(self, db_name, db_user, db_password, file_name,first_table,last_table):
+		log("[I] ---------- Importing Core DB Schema ----------", "info")
+
 class MysqlConf(BaseDB):
 	# Constructor
 	def __init__(self, host,SQL_CONNECTOR_JAR,JAVA_BIN):
@@ -207,6 +215,7 @@ class MysqlConf(BaseDB):
 				sys.exit(1)
 
 	def import_db_file(self, db_name, db_user, db_password, file_name):
+		isImported=False
 		name = basename(file_name)
 		if os.path.isfile(file_name):
 			log("[I] Importing db schema to database " + db_name + " from file: " + name,"info")
@@ -220,13 +229,14 @@ class MysqlConf(BaseDB):
 				jisql_log(query, db_password)
 				ret = subprocess.call(query)
 			if ret == 0:
-				log("[I] "+name + " DB schema imported successfully","info")
+				log("[I] "+name + " file imported successfully","info")
+				isImported=True
 			else:
-				log("[E] "+name + " DB schema import failed!","error")
-				sys.exit(1)
+				log("[E] "+name + " file import failed!","error")
 		else:
 			log("[E] DB schema file " + name+ " not found","error")
 			sys.exit(1)
+		return isImported
 
 	def import_db_patches(self, db_name, db_user, db_password, file_name):
 		name = basename(file_name)
@@ -257,11 +267,11 @@ class MysqlConf(BaseDB):
 						output = check_output(query)
 				else:
 					if os_name == "LINUX":
-						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), user(), now(), user(),'N') ;\"" %(version)
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\"" %(version,client_host,client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(shlex.split(query))
 					elif os_name == "WINDOWS":
-						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), user(), now(), user(),'N') ;\" -c ;" %(version)
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(query)
 					if ret == 0:
@@ -280,25 +290,33 @@ class MysqlConf(BaseDB):
 					if ret == 0:
 						log("[I] "+name + " patch applied","info")
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
 							log("[I] Patch version updated", "info")
 						else:
+							if os_name == "LINUX":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(shlex.split(query))
+							elif os_name == "WINDOWS":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(query)
 							log("[E] Updating patch version failed", "error")
 							sys.exit(1)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						log("[E] "+name + " import failed!","error")
@@ -336,11 +354,11 @@ class MysqlConf(BaseDB):
 							output = check_output(query)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), user(), now(), user(),'N') ;\"" %(version)
+							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\"" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), user(), now(), user(),'N') ;\" -c ;" %(version)
+							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -360,25 +378,33 @@ class MysqlConf(BaseDB):
 						if ret == 0:
 							log("[I] "+name + " patch applied","info")
 							if os_name == "LINUX":
-								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log("[I] Patch version updated", "info")
 							else:
+								if os_name == "LINUX":
+									query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(shlex.split(query))
+								elif os_name == "WINDOWS":
+									query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(query)
 								log("[E] Updating patch version failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] "+name + " import failed!","error")
@@ -466,11 +492,11 @@ class MysqlConf(BaseDB):
 								output = check_output(query)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', now(), user(), now(), user(),'N') ;\"" %(version)
+								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', now(), '%s', now(), '%s','N') ;\"" %(version,client_host,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', now(), user(), now(), user(),'N') ;\" -c ;" %(version)
+								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', now(), '%s', now(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
@@ -489,33 +515,33 @@ class MysqlConf(BaseDB):
 								ret = subprocess.call(get_java_cmd)
 							if ret == 0:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\"" %(version)
+									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								if ret == 0:
 									log ("[I] java patch "+ className +" is applied..","info")
 								else:
 									if os_name == "LINUX":
-										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\"" %(version)
+										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(shlex.split(query))
 									elif os_name == "WINDOWS":
-										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(query)
 									log("[E] java patch "+ className +" failed", "error")
 									sys.exit(1)
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\"" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] applying java patch "+ className +" failed", "error")
@@ -555,11 +581,11 @@ class MysqlConf(BaseDB):
 							output = check_output(query)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), user(), now(), user(),'N') ;\"" %(version)
+							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\"" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), user(), now(), user(),'N') ;\" -c ;" %(version)
+							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -578,38 +604,154 @@ class MysqlConf(BaseDB):
 							ret = subprocess.call(get_java_cmd)
 						if ret == 0:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log ("[I] Ranger admin default password change request processed successfully..","info")
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] Ranger admin default password change request failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] Ranger admin default password change request failed", "error")
 							sys.exit(1)
 
+	def create_version_history_table(self, db_name, db_user, db_password, file_name,table_name):
+		name = basename(file_name)
+		if os.path.isfile(file_name):
+			isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+			if isTableExist==False:
+				log("[I] Importing "+table_name+" table schema to database " + db_name + " from file: " + name,"info")
+			while(isTableExist==False):
+				get_cmd = self.get_jisql_cmd(db_user, db_password, db_name)
+				if os_name == "LINUX":
+					query = get_cmd + " -input %s" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(shlex.split(query))
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -input %s -c ;" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(query)
+				if ret == 0:
+					log("[I] "+name + " file imported successfully","info")
+				else:
+					log("[E] "+name + " file import failed!","error")
+					time.sleep(30)
+				isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+		else:
+			log("[E] Table schema file " + name+ " not found","error")
+			sys.exit(1)
+
+	def import_core_db_schema(self, db_name, db_user, db_password, file_name,first_table,last_table):
+		version = 'CORE_DB_SCHEMA'
+		if os.path.isfile(file_name):
+			get_cmd = self.get_jisql_cmd(db_user, db_password, db_name)
+			if os_name == "LINUX":
+				query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\"" %(version)
+			elif os_name == "WINDOWS":
+				query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\" -c ;" %(version)
+			jisql_log(query, db_password)
+			output = check_output(query)
+			if output.strip(version + " |"):
+				log("[I] "+version+" is already imported" ,"info")
+			else:
+				if os_name == "LINUX":
+					query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'N';\"" %(version)
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'N';\" -c ;" %(version)
+				jisql_log(query, db_password)
+				output = check_output(query)
+				if output.strip(version + " |"):
+					while(output.strip(version + " |")):
+						log("[I] "+ version  +" is being imported by some other process" ,"info")
+						time.sleep(300)
+						jisql_log(query, db_password)
+						output = check_output(query)
+				else:
+					if os_name == "LINUX":
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\"" %(version,client_host,client_host)
+						jisql_log(query, db_password)
+						ret = subprocess.call(shlex.split(query))
+					elif os_name == "WINDOWS":
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
+						jisql_log(query, db_password)
+						ret = subprocess.call(query)
+					if ret != 0:
+						log("[E] "+ version +" import failed", "error")
+						sys.exit(1)
+					isFirstTableExist = self.check_table(db_name, db_user, db_password, first_table)
+					isLastTableExist = self.check_table(db_name, db_user, db_password, last_table)
+					isSchemaCreated=False
+					if isFirstTableExist == True and isLastTableExist == True :
+						isSchemaCreated=True
+					elif isFirstTableExist == True and isLastTableExist == False :
+						while(isLastTableExist==False):
+							log("[I] "+ version  +" is being imported by some other process" ,"info")
+							time.sleep(300)
+							isLastTableExist=self.check_table(db_name, db_user, db_password, last_table)
+							if(isLastTableExist==True):
+								isSchemaCreated=True
+					elif isFirstTableExist == False and isLastTableExist == False :
+						isImported=self.import_db_file(db_name, db_user, db_password, file_name)
+						if(isImported==False):
+							log("[I] "+ version  +" might being imported by some other process" ,"info")
+							time.sleep(300)
+						isLastTableExist=self.check_table(db_name, db_user, db_password, last_table)
+						if(isLastTableExist==True):
+							isSchemaCreated=True
+					if isSchemaCreated == True:
+						if os_name == "LINUX":
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(shlex.split(query))
+						elif os_name == "WINDOWS":
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(query)
+						if ret == 0:
+							log("[I] "+version +" import status has been updated", "info")
+						else:
+							if os_name == "LINUX":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(shlex.split(query))
+							elif os_name == "WINDOWS":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(query)
+							log("[E] Updating "+version +" import status failed", "error")
+							sys.exit(1)
+					else:
+						if os_name == "LINUX":
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(shlex.split(query))
+						elif os_name == "WINDOWS":
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(query)
+						log("[E] "+version + " import failed!","error")
+						sys.exit(1)
 
 class OracleConf(BaseDB):
 	# Constructor
@@ -679,6 +821,7 @@ class OracleConf(BaseDB):
 			sys.exit(1)
 
 	def import_db_file(self, db_name, db_user, db_password, file_name):
+		isImported=False
 		name = basename(file_name)
 		if os.path.isfile(file_name):
 			log("[I] Importing script " + db_name + " from file: " + name,"info")
@@ -693,9 +836,13 @@ class OracleConf(BaseDB):
 				ret = subprocess.call(query)
 			if ret == 0:
 				log("[I] "+name + " imported successfully","info")
+				isImported=True
 			else:
 				log("[E] "+name + " import failed!","error")
-				sys.exit(1)
+		else:
+			log("[E] DB schema file " + name+ " not found","error")
+			sys.exit(1)
+		return isImported
 
 	def create_synonym(self,db_name, db_user, db_password,audit_db_user):
 		log("[I] ----------------- Creating Synonym ------------", "info")
@@ -750,11 +897,11 @@ class OracleConf(BaseDB):
 						output = check_output(query)
 				else:
 					if os_name == "LINUX":
-						query = get_cmd + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\"" %(version, db_user, db_user)
+						query = get_cmd + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\"" %(version, client_host, client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(shlex.split(query))
 					elif os_name == "WINDOWS":
-						query = get_cmd + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\" -c ;" %(version, db_user, db_user)
+						query = get_cmd + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\" -c ;" %(version, client_host, client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(query)
 					if ret == 0:
@@ -772,25 +919,33 @@ class OracleConf(BaseDB):
 					if ret == 0:
 						log("[I] "+name + " patch applied","info")
 						if os_name == "LINUX":
-							query = get_cmd + " -c \; -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+							query = get_cmd + " -c \; -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
 							log("[I] Patch version updated", "info")
 						else:
+							if os_name == "LINUX":
+								query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(shlex.split(query))
+							elif os_name == "WINDOWS":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(query)
 							log("[E] Updating patch version failed", "error")
 							sys.exit(1)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+							query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						log("[E] "+name + " Import failed!","error")
@@ -828,11 +983,11 @@ class OracleConf(BaseDB):
 							output = check_output(query)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd1 + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\"" %(version, db_user, db_user)
+							query = get_cmd1 + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\"" %(version, client_host, client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd1 + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\" -c ;" %(version, db_user, db_user)
+							query = get_cmd1 + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\" -c ;" %(version, client_host, client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -851,25 +1006,33 @@ class OracleConf(BaseDB):
 						if ret == 0:
 							log("[I] "+name + " patch applied","info")
 							if os_name == "LINUX":
-								query = get_cmd1 + " -c \; -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+								query = get_cmd1 + " -c \; -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version, client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version, client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log("[I] Patch version updated", "info")
 							else:
+								if os_name == "LINUX":
+									query = get_cmd1 + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version, client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(shlex.split(query))
+								elif os_name == "WINDOWS":
+									query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version, client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(query)
 								log("[E] Updating patch version failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd1 + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+								query = get_cmd1 + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version, client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version, client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] "+name + " Import failed!","error")
@@ -976,11 +1139,11 @@ class OracleConf(BaseDB):
 								output = check_output(query)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by) values ( X_DB_VERSION_H_SEQ.nextval,'J%s', sysdate, '%s', sysdate, '%s');\"" %(version, db_user, db_user)
+								query = get_cmd + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'J%s', sysdate, '%s', sysdate, '%s','N');\"" %(version, client_host, client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by) values ( X_DB_VERSION_H_SEQ.nextval,'J%s', sysdate, '%s', sysdate, '%s');\" -c ;" %(version, db_user, db_user)
+								query = get_cmd + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'J%s', sysdate, '%s', sysdate, '%s','N');\" -c ;" %(version, client_host, client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
@@ -999,33 +1162,33 @@ class OracleConf(BaseDB):
 								ret = subprocess.call(get_cmd)
 							if ret == 0:
 								if os_name == "LINUX":
-									query = get_cmd + " -c \; -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\"" %(version)
+									query = get_cmd + " -c \; -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\"" %(version, client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version, client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								if ret == 0:
 									log ("[I] java patch "+ className +" is applied..","info")
 								else:
 									if os_name == "LINUX":
-										query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='J%s' and active='N';\"" %(version)
+										query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\"" %(version, client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(shlex.split(query))
 									elif os_name == "WINDOWS":
-										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version, client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(query)
 									log("[E] java patch "+ className +" failed", "error")
 									sys.exit(1)
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='J%s' and active='N';\"" %(version)
+									query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] applying java patch "+ className +" failed", "error")
@@ -1065,11 +1228,11 @@ class OracleConf(BaseDB):
 							output = check_output(query)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s');\"" %(version, db_user, db_user)
+							query = get_cmd + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\"" %(version, client_host, client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s');\" -c ;" %(version, db_user, db_user)
+							query = get_cmd + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\" -c ;" %(version, client_host, client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -1088,38 +1251,155 @@ class OracleConf(BaseDB):
 							ret = subprocess.call(get_java_cmd)
 						if ret == 0:
 							if os_name == "LINUX":
-								query = get_cmd + " -c \; -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+								query = get_cmd + " -c \; -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log ("[I] Ranger admin default password change request processed successfully..","info")
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+									query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] Ranger admin default password change request failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+								query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] Ranger admin default password change request failed", "error")
 							sys.exit(1)
 
+	def create_version_history_table(self, db_name, db_user, db_password, file_name,table_name):
+		name = basename(file_name)
+		if os.path.isfile(file_name):
+			isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+			if isTableExist==False:
+				log("[I] Importing "+table_name+" table schema from file: " + name,"info")
+			while(isTableExist==False):
+				get_cmd = self.get_jisql_cmd(db_user, db_password)
+				if os_name == "LINUX":
+					query = get_cmd + " -input %s -c \;" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(shlex.split(query))
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -input %s -c ;" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(query)
+				if ret == 0:
+					log("[I] "+name + " file imported successfully","info")
+				else:
+					log("[E] "+name + " file import failed!","error")
+					time.sleep(30)
+				isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+		else:
+			log("[E] Table schema file " + name+ " not found","error")
+			sys.exit(1)
+
+	def import_core_db_schema(self, db_name, db_user, db_password, file_name,first_table,last_table):
+		version = 'CORE_DB_SCHEMA'
+		if os.path.isfile(file_name):
+			get_cmd = self.get_jisql_cmd(db_user, db_password)
+			if os_name == "LINUX":
+				query = get_cmd + " -c \; -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\"" %(version)
+			elif os_name == "WINDOWS":
+				query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\" -c ;" %(version)
+			jisql_log(query, db_password)
+			output = check_output(query)
+			if output.strip(version + " |"):
+				log("[I] "+version+" is already imported" ,"info")
+			else:
+				if os_name == "LINUX":
+					query = get_cmd + " -c \; -query \"select version from x_db_version_h where version = '%s' and active = 'N';\"" %(version)
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'N';\" -c ;" %(version)
+				jisql_log(query, db_password)
+				output = check_output(query)
+				if output.strip(version + " |"):
+					while(output.strip(version + " |")):
+						log("[I] "+ version  +" is being imported by some other process" ,"info")
+						time.sleep(300)
+						jisql_log(query, db_password)
+						output = check_output(query)
+				else:
+					if os_name == "LINUX":
+						query = get_cmd + " -c \; -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\"" %(version, client_host, client_host)
+						jisql_log(query, db_password)
+						ret = subprocess.call(shlex.split(query))
+					elif os_name == "WINDOWS":
+						query = get_cmd + " -query \"insert into x_db_version_h (id,version, inst_at, inst_by, updated_at, updated_by,active) values ( X_DB_VERSION_H_SEQ.nextval,'%s', sysdate, '%s', sysdate, '%s','N');\" -c ;" %(version, client_host, client_host)
+						jisql_log(query, db_password)
+						ret = subprocess.call(query)
+					if ret != 0:
+						log("[E] "+ version +" import failed", "error")
+						sys.exit(1)
+					isFirstTableExist = self.check_table(db_name, db_user, db_password, first_table)
+					isLastTableExist = self.check_table(db_name, db_user, db_password, last_table)
+					isSchemaCreated=False
+					if isFirstTableExist == True and isLastTableExist == True :
+						isSchemaCreated=True
+					elif isFirstTableExist == True and isLastTableExist == False :
+						while(isLastTableExist==False):
+							log("[I] "+ version  +" is being imported by some other process" ,"info")
+							time.sleep(300)
+							isLastTableExist=self.check_table(db_name, db_user, db_password, last_table)
+							if(isLastTableExist==True):
+								isSchemaCreated=True
+					elif isFirstTableExist == False and isLastTableExist == False :
+						isImported=self.import_db_file(db_name, db_user, db_password, file_name)
+						if(isImported==False):
+							log("[I] "+ version  +" might being imported by some other process" ,"info")
+							time.sleep(300)
+						isLastTableExist=self.check_table(db_name, db_user, db_password, last_table)
+						if(isLastTableExist==True):
+							isSchemaCreated=True
+					if isSchemaCreated == True:
+						if os_name == "LINUX":
+							query = get_cmd + " -c \; -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(shlex.split(query))
+						elif os_name == "WINDOWS":
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(query)
+						if ret == 0:
+							log("[I] "+version +" import status has been updated", "info")
+						else:
+							if os_name == "LINUX":
+								query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(shlex.split(query))
+							elif os_name == "WINDOWS":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(query)
+							log("[E] Updating "+version +" import status failed", "error")
+							sys.exit(1)
+					else:
+						if os_name == "LINUX":
+							query = get_cmd + " -c \; -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(shlex.split(query))
+						elif os_name == "WINDOWS":
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(query)
+						log("[E] "+version + " import failed!","error")
+						sys.exit(1)
+
 class PostgresConf(BaseDB):
 	# Constructor
 	def __init__(self, host, SQL_CONNECTOR_JAR, JAVA_BIN):
@@ -1154,6 +1434,7 @@ class PostgresConf(BaseDB):
 			sys.exit(1)
 
 	def import_db_file(self, db_name, db_user, db_password, file_name):
+		isImported=False
 		name = basename(file_name)
 		if os.path.isfile(file_name):
 			log("[I] Importing db schema to database " + db_name + " from file: " + name,"info")
@@ -1168,9 +1449,13 @@ class PostgresConf(BaseDB):
 				ret = subprocess.call(query)
 			if ret == 0:
 				log("[I] "+name + " DB schema imported successfully","info")
+				isImported=True
 			else:
 				log("[E] "+name + " DB schema import failed!","error")
-				sys.exit(1)
+		else:
+			log("[E] DB schema file " + name+ " not found","error")
+			sys.exit(1)
+		return isImported
 
 	def grant_audit_db_user(self, audit_db_name , db_user, audit_db_user, db_password, audit_db_password):
 		log("[I] Granting permission to " + audit_db_user, "info")
@@ -1254,11 +1539,11 @@ class PostgresConf(BaseDB):
 						output = check_output(query)
 				else:
 					if os_name == "LINUX":
-						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,db_user,db_user)
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,client_host,client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(shlex.split(query))
 					elif os_name == "WINDOWS":
-						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,db_user,db_user)
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,client_host,client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(query)
 					if ret == 0:
@@ -1276,25 +1561,33 @@ class PostgresConf(BaseDB):
 					if ret == 0:
 						log("[I] "+name + " patch applied","info")
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
 							log("[I] Patch version updated", "info")
 						else:
+							if os_name == "LINUX":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(shlex.split(query))
+							elif os_name == "WINDOWS":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(query)
 							log("[E] Updating patch version failed", "error")
 							sys.exit(1)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						log("[E] "+name + " import failed!","error")
@@ -1333,11 +1626,11 @@ class PostgresConf(BaseDB):
 							output = check_output(query)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,db_user,db_user)
+							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,db_user,db_user)
+							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -1356,25 +1649,33 @@ class PostgresConf(BaseDB):
 						if ret == 0:
 							log("[I] "+name + " patch applied","info")
 							if os_name == "LINUX":
-								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log("[I] Patch version updated", "info")
 							else:
+								if os_name == "LINUX":
+									query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(shlex.split(query))
+								elif os_name == "WINDOWS":
+									query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(query)
 								log("[E] Updating patch version failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] "+name + " import failed!","error")
@@ -1465,11 +1766,11 @@ class PostgresConf(BaseDB):
 								output = check_output(query)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,db_user,db_user)
+								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,client_host,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,db_user,db_user)
+								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,client_host,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
@@ -1488,33 +1789,33 @@ class PostgresConf(BaseDB):
 								ret = subprocess.call(get_java_cmd)
 							if ret == 0:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\"" %(version)
+									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								if ret == 0:
 									log ("[I] java patch "+ className +" is applied..","info")
 								else:
 									if os_name == "LINUX":
-										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\"" %(version)
+										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(shlex.split(query))
 									elif os_name == "WINDOWS":
-										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(query)
 									log("[E] java patch "+ className +" failed", "error")
 									sys.exit(1)
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\"" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] applying java patch "+ className +" failed", "error")
@@ -1554,11 +1855,11 @@ class PostgresConf(BaseDB):
 							output = check_output(query)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,db_user,db_user)
+							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,db_user,db_user)
+							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\" -c ;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -1577,38 +1878,155 @@ class PostgresConf(BaseDB):
 							ret = subprocess.call(get_java_cmd)
 						if ret == 0:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\"" %(version)
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log ("[I] Ranger admin default password change request processed successfully..","info")
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] Ranger admin default password change request failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\"" %(version)
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] Ranger admin default password change request failed", "error")
 							sys.exit(1)
 
+	def create_version_history_table(self, db_name, db_user, db_password, file_name,table_name):
+		name = basename(file_name)
+		if os.path.isfile(file_name):
+			isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+			if isTableExist==False:
+				log("[I] Importing "+table_name+" table schema to database " + db_name + " from file: " + name,"info")
+			while(isTableExist==False):
+				get_cmd = self.get_jisql_cmd(db_user, db_password, db_name)
+				if os_name == "LINUX":
+					query = get_cmd + " -input %s" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(shlex.split(query))
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -input %s -c ;" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(query)
+				if ret == 0:
+					log("[I] "+name + " file imported successfully","info")
+				else:
+					log("[E] "+name + " file import failed!","error")
+					time.sleep(30)
+				isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+		else:
+			log("[E] Table schema file " + name+ " not found","error")
+			sys.exit(1)
+
+	def import_core_db_schema(self, db_name, db_user, db_password, file_name,first_table,last_table):
+		version = 'CORE_DB_SCHEMA'
+		if os.path.isfile(file_name):
+			get_cmd = self.get_jisql_cmd(db_user, db_password, db_name)
+			if os_name == "LINUX":
+				query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\"" %(version)
+			elif os_name == "WINDOWS":
+				query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\" -c ;" %(version)
+			jisql_log(query, db_password)
+			output = check_output(query)
+			if output.strip(version + " |"):
+				log("[I] "+version+" is already imported" ,"info")
+			else:
+				if os_name == "LINUX":
+					query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'N';\"" %(version)
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'N';\" -c ;" %(version)
+				jisql_log(query, db_password)
+				output = check_output(query)
+				if output.strip(version + " |"):
+					while(output.strip(version + " |")):
+						log("[I] "+ version  +" is being imported by some other process" ,"info")
+						time.sleep(300)
+						jisql_log(query, db_password)
+						output = check_output(query)
+				else:
+					if os_name == "LINUX":
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', current_timestamp, '%s', current_timestamp, '%s','N') ;\"" %(version,client_host,client_host)
+						jisql_log(query, db_password)
+						ret = subprocess.call(shlex.split(query))
+					elif os_name == "WINDOWS":
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', now(), '%s', now(), '%s','N') ;\" -c ;" %(version)
+						jisql_log(query, db_password)
+						ret = subprocess.call(query)
+					if ret != 0:
+						log("[E] "+ version +" import failed", "error")
+						sys.exit(1)
+					isFirstTableExist = self.check_table(db_name, db_user, db_password, first_table)
+					isLastTableExist = self.check_table(db_name, db_user, db_password, last_table)
+					isSchemaCreated=False
+					if isFirstTableExist == True and isLastTableExist == True :
+						isSchemaCreated=True
+					elif isFirstTableExist == True and isLastTableExist == False :
+						while(isLastTableExist==False):
+							log("[I] "+ version  +" is being imported by some other process" ,"info")
+							time.sleep(300)
+							isLastTableExist=self.check_table(db_name, db_user, db_password, last_table)
+							if(isLastTableExist==True):
+								isSchemaCreated=True
+					elif isFirstTableExist == False and isLastTableExist == False :
+						isImported=self.import_db_file(db_name, db_user, db_password, file_name)
+						if(isImported==False):
+							log("[I] "+ version  +" might being imported by some other process" ,"info")
+							time.sleep(300)
+						isLastTableExist=self.check_table(db_name, db_user, db_password, last_table)
+						if(isLastTableExist==True):
+							isSchemaCreated=True
+					if isSchemaCreated == True:
+						if os_name == "LINUX":
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(shlex.split(query))
+						elif os_name == "WINDOWS":
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(query)
+						if ret == 0:
+							log("[I] "+version +" import status has been updated", "info")
+						else:
+							if os_name == "LINUX":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(shlex.split(query))
+							elif os_name == "WINDOWS":
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(query)
+							log("[E] Updating "+version +" import status failed", "error")
+							sys.exit(1)
+					else:
+						if os_name == "LINUX":
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\"" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(shlex.split(query))
+						elif os_name == "WINDOWS":
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+							jisql_log(query, db_password)
+							ret = subprocess.call(query)
+						log("[E] "+version + " import failed!","error")
+						sys.exit(1)
+
 class SqlServerConf(BaseDB):
 	# Constructor
 	def __init__(self, host, SQL_CONNECTOR_JAR, JAVA_BIN):
@@ -1643,6 +2061,7 @@ class SqlServerConf(BaseDB):
 			sys.exit(1)
 
 	def import_db_file(self, db_name, db_user, db_password, file_name):
+		isImported=False
 		name = basename(file_name)
 		if os.path.isfile(file_name):
 			log("[I] Importing db schema to database " + db_name + " from file: " + name,"info")
@@ -1657,9 +2076,13 @@ class SqlServerConf(BaseDB):
 				ret = subprocess.call(query)
 			if ret == 0:
 				log("[I] "+name + " DB schema imported successfully","info")
+				isImported=True
 			else:
 				log("[E] "+name + " DB Schema import failed!","error")
-				sys.exit(1)
+		else:
+			log("[E] DB schema file " + name+ " not found","error")
+			sys.exit(1)
+		return isImported
 
 	def check_table(self, db_name, db_user, db_password, TABLE_NAME):
 		get_cmd = self.get_jisql_cmd(db_user, db_password, db_name)
@@ -1721,11 +2144,11 @@ class SqlServerConf(BaseDB):
 						output = check_output(query)
 				else:
 					if os_name == "LINUX":
-						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,db_user,db_user)
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,client_host,client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(shlex.split(query))
 					elif os_name == "WINDOWS":
-						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,db_user,db_user)
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 						jisql_log(query, db_password)
 						ret = subprocess.call(query)
 					if ret == 0:
@@ -1743,25 +2166,33 @@ class SqlServerConf(BaseDB):
 					if ret == 0:
 						log("[I] "+name + " patch applied","info")
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c \;"  %(version)
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
 							log("[I] Patch version updated", "info")
 						else:
+							if os_name == "LINUX":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(shlex.split(query))
+							elif os_name == "WINDOWS":
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+								jisql_log(query, db_password)
+								ret = subprocess.call(query)
 							log("[E] Updating patch version failed", "error")
 							sys.exit(1)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c \;"  %(version)
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+							query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						log("[E] "+name + " import failed!","error")
@@ -1800,11 +2231,11 @@ class SqlServerConf(BaseDB):
 					else:
 						get_cmd2 = self.get_jisql_cmd(db_user, db_password, audit_db_name)
 						if os_name == "LINUX":
-							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,db_user,db_user)
+							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,db_user,db_user)
+							query = get_cmd1 + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -1822,25 +2253,33 @@ class SqlServerConf(BaseDB):
 						if ret == 0:
 							log("[I] "+name + " patch applied","info")
 							if os_name == "LINUX":
-								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c \;"  %(version)
+								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log("[I] Patch version updated", "info")
 							else:
+								if os_name == "LINUX":
+									query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(shlex.split(query))
+								elif os_name == "WINDOWS":
+									query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
+									jisql_log(query, db_password)
+									ret = subprocess.call(query)
 								log("[E] Updating patch version failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c \;"  %(version)
+								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd1 + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] "+name + " import failed!","error")
@@ -1915,11 +2354,11 @@ class SqlServerConf(BaseDB):
 								output = check_output(query)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,db_user,db_user)
+								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,client_host,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,db_user,db_user)
+								query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('J%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
@@ -1938,33 +2377,33 @@ class SqlServerConf(BaseDB):
 								ret = subprocess.call(get_java_cmd)
 							if ret == 0:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\" -c \;"  %(version)
+									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								if ret == 0:
 									log ("[I] java patch "+ className +" is applied..","info")
 								else:
 									if os_name == "LINUX":
-										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c \;"  %(version)
+										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(shlex.split(query))
 									elif os_name == "WINDOWS":
-										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+										query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 										jisql_log(query, db_password)
 										ret = subprocess.call(query)
 									log("[E] java patch "+ className +" failed", "error")
 									sys.exit(1)
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c \;"  %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='J%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] applying java patch "+ className +" failed", "error")
@@ -2004,11 +2443,11 @@ class SqlServerConf(BaseDB):
 							output = check_output(query)
 					else:
 						if os_name == "LINUX":
-							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,db_user,db_user)
+							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(shlex.split(query))
 						elif os_name == "WINDOWS":
-							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,db_user,db_user)
+							query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c ;" %(version,client_host,client_host)
 							jisql_log(query, db_password)
 							ret = subprocess.call(query)
 						if ret == 0:
@@ -2027,38 +2466,155 @@ class SqlServerConf(BaseDB):
 							ret = subprocess.call(get_java_cmd)
 						if ret == 0:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c \;"  %(version)
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"update x_db_version_h set active='Y' where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							if ret == 0:
 								log ("[I] Ranger admin default password change request processed successfully..","info")
 							else:
 								if os_name == "LINUX":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c \;"  %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(shlex.split(query))
 								elif os_name == "WINDOWS":
-									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+									query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 									jisql_log(query, db_password)
 									ret = subprocess.call(query)
 								log("[E] Ranger admin default password change request failed", "error")
 								sys.exit(1)
 						else:
 							if os_name == "LINUX":
-								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c \;"  %(version)
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c \;"  %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(shlex.split(query))
 							elif os_name == "WINDOWS":
-								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N';\" -c ;" %(version)
+								query = get_cmd + " -query \"delete from x_db_version_h where version='%s' and active='N' and updated_by='%s';\" -c ;" %(version,client_host)
 								jisql_log(query, db_password)
 								ret = subprocess.call(query)
 							log("[E] Ranger admin default password change request failed", "error")
 							sys.exit(1)
 
+	def create_version_history_table(self, db_name, db_user, db_password, file_name,table_name):
+		name = basename(file_name)
+		if os.path.isfile(file_name):
+			isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+			if isTableExist==False:
+				log("[I] Importing "+table_name+" table schema to database " + db_name + " from file: " + name,"info")
+			while(isTableExist==False):
+				get_cmd = self.get_jisql_cmd(db_user, db_password, db_name)
+				if os_name == "LINUX":
+					query = get_cmd + " -input %s" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(shlex.split(query))
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -input %s" %file_name
+					jisql_log(query, db_password)
+					ret = subprocess.call(query)
+				if ret == 0:
+					log("[I] "+name + " file imported successfully","info")
+				else:
+					log("[E] "+name + " file import failed!","error")
+					time.sleep(30)
+				isTableExist=self.check_table(db_name, db_user, db_password, table_name)
+		else:
+			log("[E] Table schema file " + name+ " not found","error")
+			sys.exit(1)
+
+	def import_core_db_schema(self, db_name, db_user, db_password, file_name,first_table,last_table):
+		version = 'CORE_DB_SCHEMA'
+		if os.path.isfile(file_name):
+			get_cmd = self.get_jisql_cmd(db_user, db_password, db_name)
+			if os_name == "LINUX":
+				query = get_cmd + " -c \; -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\"" %(version)
+			elif os_name == "WINDOWS":
+				query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'Y';\" -c ;" %(version)
+			jisql_log(query, db_password)
+			output = check_output(query)
+			if output.strip(version + " |"):
+				log("[I] "+version+" is already imported" ,"info")
+			else:
+				if os_name == "LINUX":
+					query = get_cmd + " -c \; -query \"select version from x_db_version_h where version = '%s' and active = 'N';\"" %(version)
+				elif os_name == "WINDOWS":
+					query = get_cmd + " -query \"select version from x_db_version_h where version = '%s' and active = 'N';\" -c ;" %(version)
+				jisql_log(query, db_password)
+				output = check_output(query)
+				if output.strip(version + " |"):
+					while(output.strip(version + " |")):
+						log("[I] "+ version  +" is being imported by some other process" ,"info")
+						time.sleep(300)
+						jisql_log(query, db_password)
+						output = check_output(query)
+				else:
+					if os_name == "LINUX":
+						query = get_cmd + " -query \"insert into x_db_version_h (version, inst_at, inst_by, updated_at, updated_by,active) values ('%s', GETDATE(), '%s', GETDATE(), '%s','N') ;\" -c \;" %(version,client_host,client_host)
+						jisql_log(query, db_password)
+						ret = subprocess.call(shlex.split(query))
+					elif os_name == "WINDOWS":
+						query = get_cmd + " -query \"insert

<TRUNCATED>


Mime
View raw message