Guest User

Untitled

a guest
Feb 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. #This script is to create multiple Active grid link DS
  2.  
  3. def file_parse():
  4. global _dict
  5. _dict={}
  6. dsprop = "/mypath/ds.properties"
  7. if os.path.exists(dsprop):
  8. fo = open(dsprop,'r+')
  9. lines = fo.readlines()
  10. for line in lines:
  11. if "=" in line:
  12. line = line.rstrip()
  13. key = line.split('=')[0]
  14. value = line.split('=')[1]
  15. _dict[key]=value
  16. else:
  17. print(dsprop+" property file is missing !")
  18.  
  19. def connect_domain():
  20. try:
  21. AdmSvr = _dict.get('AdminServer')
  22. AdmPort = _dict.get('AdminPort')
  23. AdmURL = "t3://"+AdmSvr+":"+AdmPort
  24. AdmCfg = _dict.get('AdminConfig')
  25. AdmKey = _dict.get('AdminKey')
  26. print("Connecting to Admin server")
  27. if os.path.exists(AdmCfg) and os.path.exists(AdmKey):
  28. connect(userConfigFile=AdmCfg, userKeyFile=AdmKey, url=AdmURL)
  29. print("connection successfull")
  30. except Exception, error:
  31. print ("\nUnable to connect to admin server")
  32. print ("Please verify the URL (or) check if Admin server is stopped")
  33. print ("Error description as follows:\n")
  34. print(error)
  35. print dumpStack()
  36. exit()
  37.  
  38. def create_agl_ds(DSN,DSJ,DSU,DSP,DSC):
  39. db_host = _dict.get('dbHostName')
  40. db_port = _dict.get('dbPort')
  41. db_name = _dict.get('dbServiceName')
  42. jdbcURL = 'jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST='+db_host+')(PORT='+db_port+')))(CONNECT_DATA=(SERVICE_NAME='+db_name+')))'
  43. db_driver = _dict.get('dbDriver')
  44. ons_node1 = _dict.get('onsNode1')
  45. ons_node2 = _dict.get('onsNode2')
  46. ons_port = _dict.get('onsPort')
  47.  
  48. try:
  49. edit()
  50. startEdit()
  51. print("\nCreating "+DSN+" datasource")
  52. cd('/')
  53. cmo.createJDBCSystemResource(DSN)
  54. cd('/JDBCSystemResources/'+DSN+'/JDBCResource/'+DSN)
  55. cmo.setName(DSN)
  56. cd('JDBCDataSourceParams/'+DSN)
  57. set('JNDINames',jarray.array([String(DSJ)], String))
  58. cd('/JDBCSystemResources/'+DSN+'/JDBCResource/'+DSN+'/JDBCDriverParams/'+DSN)
  59. cmo.setUrl(jdbcURL)
  60. cmo.setDriverName('oracle.jdbc.OracleDriver')
  61. enpwd = encrypt(DSP)
  62. set('PasswordEncrypted',enpwd)
  63. cd('/JDBCSystemResources/'+DSN+'/JDBCResource/'+DSN+'/JDBCConnectionPoolParams/'+DSN)
  64. cmo.setTestTableName('SQL ISVALID\r\n\r\n')
  65. cd('/JDBCSystemResources/'+DSN+'/JDBCResource/'+DSN+'/JDBCDriverParams/'+DSN+'/Properties/'+DSN)
  66. cmo.createProperty('user')
  67. cd('/JDBCSystemResources/'+DSN+'/JDBCResource/'+DSN+'/JDBCDriverParams/'+DSN+'/Properties/'+DSN+'/Properties/user')
  68. cmo.setValue(DSU)
  69. cd('/JDBCSystemResources/'+DSN+'/JDBCResource/'+DSN+'/JDBCDataSourceParams/'+DSN)
  70. cmo.setGlobalTransactionsProtocol('OnePhaseCommit')
  71. cd('/JDBCSystemResources/'+DSN+'/JDBCResource/'+DSN+'/JDBCOracleParams/'+DSN)
  72. cmo.setFanEnabled(true)
  73. cmo.setOnsWalletFile('')
  74. cmo.setActiveGridlink(true)
  75. cmo.unSet('OnsWalletPasswordEncrypted')
  76. cmo.setOnsNodeList(ons_node1+':'+ons_port+','+ons_node2+':'+ons_port)
  77. cmo.setFanEnabled(true)
  78. cmo.setOnsWalletFile('')
  79. cmo.setActiveGridlink(true)
  80. cmo.unSet('OnsWalletPasswordEncrypted')
  81. cmo.setOnsNodeList(ons_node1+':'+ons_port+','+ons_node2+':'+ons_port)
  82. cd('/JDBCSystemResources/'+DSN)
  83. set('Targets',jarray.array([ObjectName('com.bea:Name='+DSC+',Type=Cluster')], ObjectName))
  84. save()
  85. activate()
  86. print(DSN+" datasource has been created successfully\n")
  87. except Exception, error:
  88. print"------------------------------------------------------------"
  89. print("\nUnable to create "+DSN+" datasource")
  90. print(error)
  91. print dumpStack()
  92. print("proceeding to create the next datasource\n")
  93. print"------------------------------------------------------------"
  94. undo(defaultAnswer='y')
  95. stopEdit(defaultAnswer='y')
  96.  
  97. def duplicate_ds_validation(DSN):
  98. cd('/')
  99. cd('JDBCSystemResources')
  100. oldDS = ls(returnMap='true')
  101. if DSN in oldDS:
  102. return true
  103. else:
  104. return false
  105.  
  106. def db_credential_validation(DSU,DSP):
  107. db_typ = _dict.get('dbType')
  108. db_host = _dict.get('dbHostName')
  109. db_port = _dict.get('dbPort')
  110. db_name = _dict.get('dbServiceName')
  111. dbTest = "java utils.dbping "+db_typ+" "+DSU+" "+DSP+" "+db_host+":"+db_port+"/"+db_name+">/dev/null 2>&1"
  112. dbResult = os.system(dbTest)
  113. if dbResult == 0:
  114. return true
  115. else:
  116. return false
  117.  
  118. if __name__ != "__main__":
  119. import os
  120. import sys
  121.  
  122. redirect("/dev/null",'false')
  123.  
  124. file_parse()
  125. print"\n\n------------------------------------------------------------"
  126. connect_domain()
  127. print"------------------------------------------------------------"
  128.  
  129. ds = _dict.get('DataSource').split(',')
  130. for each_ds in ds:
  131. DS_N = _dict.get(each_ds+'.Name')
  132. DS_J = _dict.get(each_ds+'.jndiName')
  133. DS_U = _dict.get(each_ds+'.dbUName')
  134. DS_P = _dict.get(each_ds+'.dbPasswd')
  135. DS_C = _dict.get(each_ds+'.Cluster')
  136.  
  137. if db_credential_validation(DS_U,DS_P):
  138. if not duplicate_ds_validation(DS_N):
  139. create_agl_ds(DS_N,DS_J,DS_U,DS_P,DS_C)
  140. else:
  141. print"\n------------------- Duplicate DS found ! -------------------"
  142. print("\nThere is already a ds with the name: "+DS_N)
  143. print("skipping "+DS_N+" ds creation\n")
  144. print"------------------------------------------------------------\n"
  145. else:
  146. print"\n---------------- DB connectivity failure ! -----------------"
  147. print("\nUnable to connect the database with "+DS_U+" user")
  148. print("skipping "+DS_N+" ds creation\n")
  149. print"------------------------------------------------------------\n"
  150. print"\n\n------------------------------------------------------------"
  151. print" cheers for using WLST ! "
  152. print"------------------------------------------------------------\n\n"
  153.  
  154. if __name__ == "__main__":
  155. print('Please execute the script via WLST')
Add Comment
Please, Sign In to add comment