Tuesday, April 30, 2013

WLST Overview


http://jianmingli.com/wp/?p=2132


Overview


* A command line scripting tools for WebLogic domain management:

- create

- manage

- monitor

* Based on Jython



WSLT Online

* Is a JMX client

* Equivalent to Admin Console

- needs running Admin Server and active WebLogic domain

* Can

- view performance data

- manage security data

* Can NOT

- modify config data for managed servers



WSLT Offline

* Provides read/write access to config data

* Should NOT be used on active WebLogic domain (ignored/overwritten otherwise)

* Can

- create domain templates

- create a new domain based on existing templates

- extend an existing, inactive domain

* Can NOT

- view performance data

- modify security data



Command Modes

Interactice Mode

Script Mode

* Script needs .py file extension

* Can

- automate server config and application deployment

- apply same config setings across multiple nodes of a topology

- script scheduling

- automate complex procedures

- config an application in a hands free data center



Embedded Mode

* WLST interpreter is instantiated in Java code.

* WLST commands and scripts are then run from within Java code.



Secure WLST Connection

Admin Port

* WLST connects to a server instance via admin port.

* Default to 9002

* SSL enabled



Secure Access from WLST Online

* Use user name and password as defined in the active WebLogic security realm.

- From command line





connect('weblogic', 'welcome1', 'localhost:7001')

- From password file





# Prepare password files

connect('weblogic', 'welcome1', 'localhost:7001')

storeUserConfig('c:/myFiles/myuserconfigfile.secure',

'c:/myFiles/myuserkeyfile.secure')



# Use password files

connect(userConfigFile='c:/myfiles/myuserconfigfile.secure',

userKeyFile='c:/myfiles/myuserkeyfile.secure')

- Use boot.properties file





# boot.properties file in current directory

connect()

Main Steps for Using WLST in Interactive or Script Mode

Invoking WLST

* Execute the appropriate shell script for your environment.

- UNIX





cd WL_HOME/common/bin

./wlst.sh

- Windows





cd WL_HOME\common\bin

wlst.cmd

* Execute the java weblogic.WLST command.





java

[ -Dweblogic.security.SSL.ignoreHostnameVerification=true

-Dweblogic.security.TrustKeyStore=DemoTrust ]

[ -Dweblogic.security.JavaStandardTrustKeyStorePassPhrase=password]

[ -Dweblogic.security.CustomTrustKeyStoreFileName=filename

-Dweblogic.security.TrustKeystoreType=jks

[ -Dweblogic.security.CustomTrustKeyStorePassPhrase=password]]

[ -Dweblogic.security.SSL.hostnameVerifier=classname]

weblogic.WLST

[ -loadProperties propertyFilename ]

[ -skipWLSModuleScanning ]

[ [-i] filePath.py ]

- Example:





jjava weblogic.WLST c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributeQueues.py



java -Dweblogic.security.SSL.ignoreHostnameVerification=true

-Dweblogic.security.TrustKeyStore=DemoTrust weblogic.WLST

c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributeQueues.py

* Run a WLST script.

- Use Java command line:





java weblogic.WLST c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributedQueues.py

- From WLST interactive mode:





wls:offline> execfile('c:/Oracle/Middleware/wlserver/templates/scripts/wlst/distributedQueues.py')

* Execute the WebLogic Scripting Tool command from the Start menu (Windows only).



* Running WLST from Ant.

- Set env:

WL_HOME\server\bin\setWLSEnv.cmd (or setWLSEnv.sh on UNIX)

- Import task:






classname="weblogic.ant.taskdefs.management.WLSTTask" />

- Examples








fileName="./myscript.py">

























fileName="./myscript.py" failOnError="true">

























Exiting WLST



wls:/mydomain/serverConfig> exit()

Exiting WebLogic Scripting Tool ...

Syntax for WLST Commands

* Case sensitive.

* Enclose arguments in single or double quotes.

* Escape character: \

* String as is: r

- Example: readTemplate(r'c:\userdomains\mytemplates\mytemplate.jar')

* If you need to cd to a management object whose name includes a forward slash (/), surround the object name in parentheses.

- For example:cd('JMSQueue/(jms/REGISTRATION_MDB_QUEUE)')



Redirecting Error and Debug Output to a File

* To redirect stdout, stderr to a file:



redirect(outputFile,[toStdOutAsWell])

* Stop redirect:



stopRedirect()

* Example:



wls:/mydomain/serverConfig> redirect('./logs/wlst.log')

Getting Help

help

help('online')

help('offline')

help('get*')

Importing WLST as a Jython Module

* Invoke WLST:



c:\>java weblogic.WLST

wls:/(offline)>



* Use the writeIniFile command to convert WLST definitions and method declarations to a .py file:



wls:/(offline)> writeIniFile("wl.py")

The Ini file is successfully written to wl.py



* Open a new command shell and invoke Jython directly by entering the following command:



c:\>java org.python.util.jython



* Import the WLST module into your Jython module using the Jython import command.



>>>import wl



*Now you can use WLST methods in the module. For example, to connect WLST to a server instance:



wl.connect('username','password')

....



Customizing WLST

*



Adding Integrated Help for Custom Commands

* Define help text entries:



_ShortDescription

_Description

_Example

_Syntax

* Example:



navigate_ShortDescription=\

Lists commands for navigating the hierarchy of beans.

navigate_Description=\

\n Navigates the hierarchy of beans and controls the prompt display. \n

*



*



*



Monday, April 29, 2013

This script is used the check the health of the heap in weblogic server 11g

There are two script

1. Shell script whihc will call a python
2. Python Script


1. Shell Script : heap_status.sh

#!/bin/bash


#Author Mohammed Ashraf TP

#Date APRIL 08 2013

# ************* Setting the Environment ***********************

PAR_SLICE=`whoami `

echo $PAR_SLICE

SLICE=`echo $PAR_SLICE
cut -c4-8`

echo $SLICE

SOA_USER=soa_"$SLICE"

echo $SOA_USER

SOA_DOMAIN_NAME=soa_"$SLICE"_Domain

echo $S0A_DOMAIN_NAME







DOMAIN_HOME="/var/domain/"$SOA_USER"/"$SOA_DOMAIN_NAME"/"

echo $DOMAIN_HOME

. ${DOMAIN_HOME}/bin/setDomainEnv.sh $*



export CLASSPATH=/var/domain/"$PAR_SLICE"/WEBLOGIC_HOME/server/lib/weblogic.jar



echo "Environment has been set....."



# ************* Changing the directory where all the related files are needed ***********************



echo "Calling the PYTHON script....."



# ************* Calling the WLST script *****************



export CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=CustomTrust -Dweblogic.security.CustomTrustKeyStoreFileName=/var/domain/"$SOA_USER"/keystore/WebLogicTrustKeyStore.jks -Dweblogic.security.CustomTrustKeyStorePassPhrase=password -Dweblogic.security.CustomTrustKeyStoreType=JKS -Dweblogic.security.SSL.allowSmallRSAExponent=true"



echo $CONFIG_JVM_ARGS

/opt/Oracle/Middleware/Oracle_SOA1/common/bin/wlst.sh /home/"$PAR_SLICE"/WLST_TP/Health_Check/heap_status.py

    ++++++++++++++++++++++++++++++++++++++++++++++++++ 2.Python Script :heap_status.py   #Definition for connecting to a server

#!/usr/bin/python

from java.io import FileInputStream

from java.util import *

from javax.management import *

import sys

import re

import os

import pdb



def connectToServer():

username = 'weblogic'

password = 'password'

url = 't3s://mlx555:7777'

connect(username, password, url)



#Definition to print a running servers heap details

def printHeapDetails(server_name):

domainRuntime()

cd('/')

cd('ServerRuntimes/'+server_name+'/JVMRuntime/'+server_name)

hf = float(get('HeapFreeCurrent'))/1024

hs = float(get('HeapSizeCurrent'))/1024

hf = hf/1024

hs = hs/1024

print 'HeapFreeCurrent - ' + `hf` + 'MB'

print 'HeapSizeCurrent - ' + `hs` + 'MB'



#Definition to disconnect from a server

def disconnectFromServer():

disconnect()

exit()



#Calling connectToServer definition with no arguments

connectToServer()



#Calling printHeapDetails with arguments

printHeapDetails('soa_dev04_AdminServer01')

printHeapDetails('soa_dev04_BusinessServer01')

#printHeapDetails('mgds2')



#Calling disconnectFromServer definition with no arguments

disconnectFromServer()

Monday, April 15, 2013

command to delete control m character

sed -i -e 's/^/rm -rf /' toDelete.sh

cut command ...

Write a script called mycut.sh
And invoke the script using mycut.sh android


Snippets of mycut.sh is given below
===================
PAR_SLICE=$1


SLICE=`echo $PAR_SLICE
cut -c4-7`

echo $SLICE

SOA_USER=soa_"$SLICE"

echo $SOA_USER

SOA_DOMAIN_NAME=soa_"$SLICE"_Domain

echo $S0A_DOMAIN_NAME

================ Execute :   ./mycut.sh android   =============== Output roid soa-roid soa_roid_Domain    

Friday, April 5, 2013

Auomation of "Mapping of Logical Role to BPM Roles"

Script to automate "Logical group to BPM Access role mapping" is working succesfully .




Please find the below location of the script name and the syntax to execute the script



Location : /home/soast01/WLST_TP/Create_AccessRoles

Script Name : Create_AccessRoles_BPM.sh





Note:



Please modify the property file /home/soast01/WLST_TP/Create_AccessRoles/Access_Role.properties, according to the requirement ..







To test I am trying to add 2 groups

1. gr gg  usr eur Level 2_DIT ,

2. gr gg usr eur Level 3_DIT

to the BPM Process Role -> CreateTelephoneApplication.CustomerService



So in this case we have to modify the property file Access_Role.properties, with the above 2 groups and the BPM Process Role

groups gr gg usr eur Level 2_DIT , gr gg usr eur Level 3_DIT to the BPM Process Role , CreateTelephoneApplication.CustomerService .

Also Admin URL,username , password and total number of groups should be mentioned .





Syntax :



Create_AccessRoles_BPM.sh



1. cat //WLST_TP/Create_AccessRoles/Access_Role.properties

admin.url=t3s://mlx123:25454

admin.userName=weblogic

admin.password=pwd



total.GROUPS=3



group.name.1 = gr gg usr eur Level 2_DIT



user.soarole.1 = CreateApplication.CustomerService





user.soarole.2 = CreateApplication.CustomerService

group.name.2 = gr gg usr eur Level 3_DIT



#Comma seperated roles

2.  cat Create_AccessRoles_BPM.sh

#!/bin/bash

#Author Mohammed Ashraf TP

#Date MARCH 18 2013

# ************* Setting the Environment ***********************

DOMAIN_HOME="/var/domain/soa_st01/soa_st01_Domain/"

. ${DOMAIN_HOME}/bin/setDomainEnv.sh $*



export CLASSPATH=/var/domain/soa_st01/WEBLOGIC_HOME/server/lib/weblogic.jar



echo "Environment has been set....."



# ************* Changing the directory where all the related files are needed ***********************

cd /home/soa01/WLST_TP/Create_AccessRoles



echo "Calling the PYTHON script....."



# ************* Calling the WLST script *****************



export CONFIG_JVM_ARGS="-Dweblogic.security.SSL.ignoreHostnameVerification=true -Dweblogic.security.TrustKeyStore=CustomTrust -Dweblogic.security.CustomTrustKeyStoreFileName=/var/domain/soa_01/keystore/TrustKeyStore.jks -Dweblogic.security.CustomTrustKeyStorePassPhrase=wpwd -Dweblogic.security.CustomTrustKeyStoreType=JKS -Dweblogic.security.SSL.allowSmallRSAExponent=true"



/opt/Oracle/Middleware/Oracle_SOA1/common/bin/wlst.sh /home/soa/WLST_TP/Create_AccessRoles/AccessRoles_BPM.py $1 $2 $3


3.
[soast01@ngmlx476 Create_AccessRoles]$ cat AccessRoles_BPM.py


#!/usr/bin/python



from java.io import FileInputStream



from java.util import *



from javax.management import *



import sys



import re



import os



import pdb



propInputStream = FileInputStream("/home/soast01/WLST_TP/Create_AccessRoles/Access_Role.properties")



configProps = Properties()



configProps.load(propInputStream)



adminURL=configProps.get("admin.url")



adminUserName=configProps.get("admin.userName")



adminPassword=configProps.get("admin.password")



totalnumberofGROUPS=configProps.get("total.GROUPS")



connect(adminUserName, adminPassword, adminURL)



domainRuntime()



print 'Adding SOA Roles Membership of the Users:'



counter = 1



print counter



print totalnumberofGROUPS



print adminURL

print adminUserName

print adminPassword



count = 1

while count < int(totalnumberofGROUPS):

roleName = configProps.get("user.soarole." + str(count))

#groupName = configProps.get("group.name." + str(count)).split(",")

groupName = configProps.get("group.name." + str(count))

count = count + 1

print roleName

print groupName

grantAppRole(appStripe="OracleBPMProcessRolesApp",appRoleName=roleName ,principalClass="weblogic.security.principal.WLSGroupImpl",principalName=groupName)





disconnect()



exit()

How to display only Permissions and file names using ls command?

find /path -printf "%f:%p:%u:%g:%m\n"


Purging old instance data from SOA/BPM 11g

Purging old instance data from SOA/BPM 11g



When you are running a lot of instances of your composites through SOA/BPM 11g in your testing/development environment, you will start to fill up the available space in your database with the logging and auditing information for these instances. From time to time, you will want to clean up your database by purging the old instance data.



Starting from version 11.1.1.2, we provide a set of SQL scripts in the following location that can be used for just this purpose.



\Oracle_SOA1\rcu\integration\soainfra\sql\purgeIf you want to get a feeling for how much free space you have, you might like to use the query in this post, which will produce results like those shown below.







If you are running an earlier version, you can download the scripts as a patch by looking up Oracle Support document number 815896.1. This document also provides details about how to define a filter so that the scripts will only remove certain instance data, and leave other data untouched.



To remove all old instance data, you can just invoke the scripts like this:



sqlplus dev_soainfra/welcome1 @purge_soainfra_oracle.sql   http://redstack.wordpress.com/2010/10/06/purging-old-instance-data-from-soabpm-11g/