Script to target/untarget multiple datasource to/from the cluster
Hello to Viewers,
This script will help in performing the target and untarget operation on multiple datasource in one go. You don't need to go to the console and do the same task manually which is of-course time taking and error prone.
FLOW:
shell script ---> python --> wlst command.
Here shell script will call python script and in python we have mentioned few relevant wlst command that perform the actual task.
This script will help in performing the target and untarget operation on multiple datasource in one go. You don't need to go to the console and do the same task manually which is of-course time taking and error prone.
FLOW:
shell script ---> python --> wlst command.
Here shell script will call python script and in python we have mentioned few relevant wlst command that perform the actual task.
Follow the below steps:
1) Create a shell script under below directory: QueueOperation.sh
I have taken the directory structure as below:
/opt/soauser/automation/SOADataSourceOperation/
DataSourceOperation.sh
1) Create a shell script under below directory: QueueOperation.sh
I have taken the directory structure as below:
/opt/soauser/automation/SOADataSourceOperation/
DataSourceOperation.sh
----------------------------------------------------------------------------------------------
#!/bin/sh
export LOGFILE="/opt/soauser/automation/SOADataSourceOperation/DataSource.log"
if [ -f $LOGFILE ]; then
rm -f $LOGFILE
fi
rm -rf /opt/soauser/automation/SOADataSourceOperation/DataSource.log
WL_HOME="/xxxxxx/xxxx/xxx/wlserver_10.3"
export WL_HOME
echo "Please enter target to Target and untarget to Untarget the Datasources:"
read PARAMETER1
cd /opt/soauser/automation/SOADataSourceOperation/
sh ${WL_HOME}/common/bin/wlst.sh /opt/soauser/automation/SOADataSourceOperation/DataSourceOperation.py $PARAMETER1 $1 >> /opt/soauser/automation/SOADataSourceOperation/DataSource.log
exit
------------------------------------------------------------------------------------------------
2) Create a text file in same directory that contains the datasource name:
Suppose you need to untarget the datasource related to SAP then name it as SAPdsList.txt(targetdsList.txt)
here target could be SAP or any end system to which datasources are related.
SAPdsList.txt
-----------------------------------------------------------------------------------------------------
DSNAME1
DSNAME2
------------------------------------------------------------------------------------------------------
DSNAME2
------------------------------------------------------------------------------------------------------
3) Create a python file under the same directory: DataSourceOperation.py
Here i am assuming that
datasources are targeted to only weblogic cluster.
DataSourceOperation.py
------------------------------------------------------------------------------------------------------
from java.io import FileInputStream
import java.lang
import os
import string
import sys , traceback
operation=sys.argv[1]
target=sys.argv[2]
def connectToServer():
USERNAME = 'username'
PASSWORD = 'password'
URL='t3://AdminServerhost:AdminServerport'
#Connect to the AdminServer
print 'starting the script ....'
connect(USERNAME,PASSWORD,URL)
def disconnectFromServer():
print "Disconnecting from the Admin Server"
disconnect()
print "Exiting from the Admin Server"
exit()
print "Mission Accomplished"
def Target(DSName):
try:
print 'Entry point1...'
edit()
tgName = 'CLUSTER_NAME'
startEdit()
DSName = DSName.strip()
print 'test0'
cd ('/JDBCSystemResources/'+ DSName)
print 'test1'
set('Targets',jarray.array([ObjectName('com.bea:Name='+tgName+',Type=Cluster')], ObjectName))
activate()
print 'DataSource: "', DSName ,'" has been TARGETED TO CLUSTER Successfully'
except :
print 'Something went wrong...'
exit()
def Untarget(DSName):
try:
print 'Entry point1...'
edit()
tgName = 'CLUSTER_NAME'
startEdit()
DSName = DSName.strip()
print 'test0'
cd ('/JDBCSystemResources/'+ DSName)
print 'test1'
set('Targets',jarray.array([], ObjectName))
activate()
print 'DataSource: "', DSName ,'" has been UNTARGETED FROM CLUSTER Successfully'
except :
print 'Something went wrong...'
exit()
############### Main Script #####################################
#Conditionally import wlstModule only when script is executed with jython
if __name__ == '__main__':
from wlstModule import *#@UnusedWildImport
print('This will enable you to perform operation on datasource')
listName = target+'dsList.txt'
if operation=='target':
f = open(listName,'r')
out = f.readlines()
for DSName in out:
DSName.strip()
print 'Trying to target '+DSName
connectToServer()
Target(DSName)
disconnect()
print 'Target the '+DSName
else:
f = open(listName,'r')
out = f.readlines()
for DSName in out:
DSName.strip()
print 'Trying to untarget '+DSName
connectToServer()
Untarget(DSName)
disconnect()
print 'Untargeted the '+DSName
disconnectFromServer()
-------------------------------------------------------------------------------------------------------
HOW TO RUN:
Simply run the shell script and provide the target system name as a parameter for ex:
cd /opt/soauser/automation/SOADataSourceOperation/
sh DataSourceOperation.sh SAP
(here SAP is the target so python file will look for SAPdsList.txt)
then it will ask for the operation to be performed : Please enter target to Target and untarget to Untarget the Datasources
type the operation name and press "enter" and then verify the log file(DataSource.log) and queue status from console.
Thanks a lot for your patience !!!!
Regards
-Ashish
Regards
-Ashish