Saturday, May 9, 2015

How to Auto start Weblogic Domain through WLST

 

The Following Script checks the health of Weblogic Domain when configured as corn job, it connected to domain admin servers if its up if adminserver is down it will start the admin server before proceeding further. Expectation of this script is Nodemanager is running in all the machines hosting the domain.

 

We need two files one is the environment Properties file and one python script.

<evn>.<properties> file will have following information need to update according to the environment.

# Environment Specific Values need to updated below

LOGS=/home/oracle/logs
WLS_HOME=/u01/app/oracle/product/fmw/wlserver_10.3
DOMAIN_BASE=/u03/app/oracle
JAVA_HOME=/u01/app/oracle/product/fmw/java/jrockit-jdk1.6.0_33-R28.2.4-4.1.0
MW_HOME=/u01/app/oracle/product/fmw
ORACLE_COMMON_HOME=/u01/app/oracle/product/fmw/oracle_common

# Credentials to connect to Domain

admin.url=t3://hostname:port
admin.userName=xxxxxx
admin.password=xxxxx

#NodeManager Details.

NM_user=xxxxxx
NM_pass=xxxxxx
NM_host=localhost
NM_port=5556
NM_type=plain
verboseModeValue=false
Domain_Name=WLSDomain
Domain_Directory=/u03/app/oracle/admin/WLSDomain

# Defining the UserKey values if we need to use the encrypted user and password

UserKeyFile=/u02/oraScripts/Automation/Env/UserKeyFile

UserConfigFile=/u02/oraScripts/Automation/Env/UserConfigFile

# List of Servers in Domain separated by comma

Serverlist=

# Order to Start/Stop Servers

StartServersOrder=

StopServersOrder=

# List of Clusters in the domain

ClusterList=

# Order to Start the servers on VM restart/crash

ClusterStartOrder=

# Order to stop the cluster in the Domain

ClusterStopOrder=

------------------------------

# Script to AutoStart All the instances of the Domain.

from java.io import FileInputStream
import sys
import os
from java.util import Date
import string


Environment = sys.argv[1]
Domain = sys.argv[2]
env = Environment + '.' + Domain + '.properties'
logfile = Environment + '.' + Domain
propInputStream = FileInputStream(env)

#propInputStream = FileInputStream("env.properties")
configProps = Properties()
configProps.load(propInputStream)

adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")
Serverlist=configProps.get("ServerList")
StartServersOrder=configProps.get("StartServersOrder")
StopServersOrder=configProps.get("StopServersOrder")
ClusterList=configProps.get("ClusterList")
ClusterStartOrder=configProps.get("ClusterStartOrder")
ClusterStopOrder=configProps.get("ClusterStopOrder")

UserKeyFile=configProps.get("UserKeyFile")
UserConfigFile=configProps.get("UserConfigFile")

NM_user=configProps.get("NM_user")
NM_pass=configProps.get("NM_pass")
NM_type=configProps.get("NM_type")
NM_port=configProps.get("NM_port")
NM_host=configProps.get("NM_host")
verboseModeValue=configProps.get("verboseModeValue")
Domain_Name=configProps.get("Domain_Name")
Domain_Directory=configProps.get("Domain_Directory")
serverValue='AdminServer'

print 'AutoStart of Domain Script Starting....';
print 'Connecting to Nodemanager ..';

# Function to Connecting to NodeManager

def NMconn():
    try:
        nmConnect(NM_user,NM_pass,NM_host,NM_port,Domain_Name,Domain_Directory,NM_type)
#        nmConnect(UserConfigFile,UserKeyFile,NM_host,NM_port,Domain_Name,Domain_Directory,NM_type)
    except ConnectionException, e:
        print ' Unable to Connect to Node Manager ...'
        exit()

# Function to Autostart the AdminServer

def AdminAutoStart():
    serverStatus = nmServerStatus(serverValue)
    print ' Current ', serverValue ,'Server Status is : ', serverStatus;
    if serverStatus != 'RUNNING' :
        print ' Starting', serverValue ,'Now ..'
        nmStart(serverValue)
        CurrentStatus = nmServerStatus(serverValue)
        print ' Current ', serverValue , 'Status ', CurrentStatus;
    nmDisconnect()
    #exit()


# Function to Connect to Domain

def conn():
    try:
        connect(adminUserName, adminPassword, adminURL)
#        connect(UserConfigFile,UserKeyFile,adminURL)
    except ConnectionException,e:
        print ' Unable to Find Admin Server ...'
        exit()

# Function to Check server state and Initiate Managed Server Start

def ServerAutoStart():
    for server in StartServersOrder.split(','):
        if server != 'AdminServer' :
            ServerState = serverStatus(server)
            if ServerState != "RUNNING" :
                start(server,'Server')
#    disconnect()
#    stopRedirect()
#    exit()

# Function to Check the server status of Managed Server

# Function to Auto Start the Cluster

def ClusterAutoStart():
    for clustername in ClusterStartOrder.split(','):
        clusterstate = printClusterState(clustername)
        if clusterstate != "RUNNING" :
            startCluster(clustername)

# Alert Funciton

def AlertMe():
        for server in StartServersOrder.split(','):
                serverstate = serverStatus(server)
                if serverstate != 'RUNNING':
                        today = Date()
                        stateMessage = 'The Follwoing Server is not Running please check ... ' + server
                        cmd = "echo " + stateMessage + " >> serverState_file"
                        os.system(cmd)
                        sendMail()
                        cmd = "rm -f serverState_file"
                        os.system(cmd)
        disconnect()
        stopRedirect()
        exit()

   
def serverStatus(server):
    cd("/ServerLifeCycleRuntimes/"+ server)
    return cmo.getState()

#Fetch the state of the every cluster in the Domain.
   
def ClusterStatus():
    for clustername in ClusterList.split(','):
        ClusterState = printClusterState(clustername)
    disconnect()
    stopRedirect()
    exit()

# Start the clusters in the Domain.

def StartClusters():
    for clustername in ClusterStartOrder.split(','):
        startcluster =startCluster(clustername)
        clusterstate = printClusterState(clustername)
    disconnect()
    stopRedirect()
    exit()

# Stop the Clusters in the Domain

def StopCluster():
    for clustername in ClusterStopOrder.split(','):
        stopcluster =shutdownCluster(clustername)
        clusterstate = printClusterState(clustername)
    disconnect()
    stopRedirect()
    exit()


       
# Print state of cluster

def printClusterState(clustername):
    try:
       state(clustername,"Cluster")
    except Exception, e:
       print 'Error while printing cluster state ',e
       dumpStack()


# Start the Cluster

def startCluster(clustername):
    try:
       start(clustername,"Cluster")
    except Exception, e:
       print 'Error while starting cluster ',e
       dumpStack()

# Stop the Cluster

def shutdownCluster(clustername):
    try:
       shutdown(clustername,"Cluster")
    except Exception, e:
       print 'Error while shutting down cluster ',e
       dumpStack()

# Function to send email.

def sendMail():
    os.system('/bin/mailx -s " ALERT : Check the Server it May not be RUNNING !!! Please Check .." mohanmurali_kandra@optum.com < serverstate_file')
    print ' '
   
# Function to Quit

def quit():
    print '\033{1;35mRe-Run the Script Hit any key ..\033[0m'
    Ans = raw_input("Are you sure Quit from WLST ...(y/n) ")
    if (Ans == 'y'):
        disconnect()
        stopRedirect()
        exit()
    else:
        printClusterState()

# Main Function to declared the flow

if __name__== "main":
    redirect('./logs/'+ logfile +'.Autostart.log', 'false')
    NMconn()
    AdminAutoStart()
    conn()
    serverNames = cmo.getServers()
    domainRuntime()
#    ServerAutoStart()
    ClusterAutoStart()
    ClusterStatus()   
#    AlertMe()   

 

----------------------------------------------------------------

How to deploy multiple SOA composites using WLST

Following post describes the process to deploy multiple soa composites .

Step1 . Create a file with list of soa composites that are needed to deploy.

Stpe2 . Create env.properties file with environment details

env.properties

soa.soa_server = http://<SOA Server Address>:<Port>
soa.jar_location = <Path to SAR Files>/sar/
soa.xml_location = <Path to Config Plan>/configPlan/
soa.username = weblogic
soa.password = <weblogic password>

Step 3. Create soadeploy.py

from java.io import FileInputStream

propInputStream = FileInputStream("env.properties")
configProps = Properties()
configProps.load(propInputStream)
soa_server = configProps.get("soa.soa_server")
jar_location = configProps.get("soa.jar_location")
config_location = configProps.get("soa.xml_location")
username = configProps.get("soa.username")
password = configProps.get("soa.password")
composites = [line.strip() for line in open('soa_list')]
configpath = config_location + "soa_cfgplan.xml"
error_occurred = False
failed_composites = []
for composite in composites:
    print "----------------------------------------------------------------------------------------"
    print 'Attempting to deploy: ' + composite
    try:
        sca_deployComposite(soa_server,jar_location + composite,true,username,password,true,configpath)

    except:
        print 'Failed to deploy: ' + composite
        print "Exeception info: ", sys.exc_info()[0]
        error_occurred = True
        failed_composites.append(composite)
    print "----------------------------------------------------------------------------------------"
if error_occurred:
    print "\nThe following soa composites failed to deploy:"
    for failure in failed_composites:
        print failure
else:
    print "\nAll soa composites deployed successfully!"
print "\nDone."
exit()

------------------------------------------------------------------------------------

How to check the files existing in particular directory in bash script (UNIX)

 

In order to verify list of file names are existing  in particular location in Unix  we can use the if function to verify if the file is exists in the given path or not.

We need to read the list files which we need to verify . To just read the file names only on a given location we can use the ls command with additional option like below.

ls --file-type –1 <path location> | grep -v '/' >file_list

when the above command is executed the file_list will have all the filenames on the path location mentioned on the command

Once we read the list of file names we can verify those files exists in particular location or not by using below function

for filename in `cat file_list`
do
    if [ -a ${path}/$filename ];
        then   
                echo “ File exists in the $path”
        else        
                echo " File is NOT  found "
    fi
done

--------------------------------------------------------------------------------------------------------------------------------

How to use Xming/XLaunch to invoke the GUI on Linux servers

 

In order to invoke the GUI Interface for any application installation in oracle/ibm stacks or any other GUI mode of installation is easy .

There are variety of tools available to invoke the gui from Linux servers like vncserver . In this post I will brief about xming which is one of tools used to invoke the GUI.

Download the xming from http://sourceforge.net/projects/xming/   or any other location from web.

Install the xming binaries, once you install you can see XLaunch on your applications/Desktop. click on XLaunch

 

  image

On the Display number you can choose to give any number here in example I have given 20 and then click next

image

click next

image

click next

image

click Finish

once we configured the XLaunch we need to update x11 on the putty to use the XLaunch. open the putty

image

under the X11 forwarding check the box for Enable X11 forwarding and in X display location provide the following.

localhost:20 ( which we have chosen as Display Number)

image

Now connect to the server

image

once login to the servers please execute the following commands.

xauth list    ( this command will list the xauth listeners running on the server) copy the latest one and execute below command

xauth add <>  ( you need to paste the line you have copied in above step)

Now you can invoke xclock from your console which will open the clock on your desktop for testing the connectivity.

 

---------------------------------------------------------------------------------------------------------------------------------------------