Tag: WLST

How to Move Messages From One Queue To Another Queue Using WLST

Ravish Mody

Two days back one of our subscribers Pavan had asked us by using comment , that is it possible to move the messages from one queue to another queue that to using WLST and the answer to that question is YES. It is possible to do the same using WLST and we have created the WLST script.

This is a very simple script which would just collect the target/destination queue where the messages has to be moved to (i.e. new.queue.name) and then would just go to the queue where the messages has to be moved from(i.e. old.queue.name). All this can be done using the same script just give the domain and there servers details in the domain.properties files and you are good to go.

Steps to Move Messages From One Queue To Another Queue Using WLST

Step1). Create a Directory somewhere in your file system like : “C:WLSTMove_Messages”

Step2). Write a Properties filedomain.properties inside “C:WLSTMove_Messages” like following:

server.url=t3://localhost:8001
username=weblogic
password=weblogic

system.module.name=MySystemModule

old.server.name=AdminServer
old.jms.server.name=Admin_JMSServer
old.queue.name=Admin_Queue

new.tragated.server.name=AdminServer
new.jms.server.name=MyJMSServer
new.queue.name=MyTestQueue

Step2). Now in the same directory write the following WLST Script “move_messages.py” like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)

serverUrl = configProps.get("server.url")
Username = configProps.get("username")
Password = configProps.get("password")

systemModuleName = configProps.get("system.module.name")

oldServerName = configProps.get("old.server.name")
oldJmsServerName = configProps.get("old.jms.server.name")
oldQueueName = configProps.get("old.queue.name")

newTragatedServerName = configProps.get("new.tragated.server.name")
newJmsServerName = configProps.get("new.jms.server.name")
newQueueName = configProps.get("new.queue.name")

connect(Username,Password,serverUrl)

serverRuntime()

print 'Getting the traget...'
cd('/JMSRuntime/'+newTragatedServerName+'.jms/JMSServers/'+newJmsServerName+'/Destinations/'+systemModuleName +'!'+ newQueueName)
target = cmo.getDestinationInfo()
print 'Got the traget...'

cd('/JMSRuntime/'+oldServerName+'.jms/JMSServers/'+oldJmsServerName+'/Destinations/'+systemModuleName +'!'+ oldQueueName)

print 'Moving the messages to the new traget...'
cmo.moveMessages('',target)
print 'Messages have been moved to the traget Successfully !!!'

print '======================================='
print 'Messages from queue: "'+oldQueueName+'" have been moved to the new queue: "'+newQueueName+'" Successfully !!!'
print '======================================='

Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh

Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Run the Above WLST Script like following:

java weblogic.WLST move_messages.py

Following would be the Output

java weblogic.WLST move_messages.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:8001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_8001'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

Getting the traget...
Got the traget...
Moving the messages to the new traget...
Messages have been moved to the traget Successfully !!!
=======================================
Messages from queue: "Admin_Queue" have been moved to the new queue: "MyTestQueue" Successfully !!!
=======================================

Note:

Only for Pava you would have to do the following changes
– Instead for line number – 34
cd('/JMSRuntime/'+oldServerName+'.jms/JMSServers/'+oldJmsServerName+'/Destinations/'+systemModuleName +'!'+newJmsServerName+'@'+ newQueueName)
- Instead for line number - 38
cd('/JMSRuntime/'+oldServerName+'.jms/JMSServers/'+oldJmsServerName+'/Destinations/'+systemModuleName +'!'+oldJmsServerName+'@'+ oldQueueName)

Regards, Ravish Mody


How to get the Users List from Security Realm using WLST

Ravish Mody

Today one of our subscribers Sai using comment asked how to list out users which are in default Authenticator only, hence we have just created a script which would do the same and would also show you all the Authenticator’s list of users if you want by just setting one flag as true (show.all.authenticator.userlist) inside your “details.properties” file. This way everyone can get what they want.

As every time we have again used a properties file in which you can give the required details and can get your required output, hence just by giving the details in the details.properties files and you are good to go.

An article written by Jay  WebLogic SQLAuthenticator Demo With FormBased Authentication helped me alot in testing this script, so others can also take the advantage from it.

Steps to get the Users List from Security Realm using WLST

Step1). Create a Directory somewhere in your file system like : “C:WLST_log”

Step2). Write a Properties filedetails.properties inside “C:WLSTUserList” like following:

admin.url=t3://localhost:7001
admin.userName=weblogic
admin.password=weblogic

########## User Name which wants to get listed (where, * = all users name) ################
user.name.wildcard=*

########## Maximum Numbers of List you want to see (where, 0 = all the number of users) ###############
maximum.to.return=0

########## If "true" will show all the Authenticator's Users List, if "false" then would only show Default Authenticators Uers List ################
show.all.authenticator.userlist=false

Step2). Now in the same directory write the following WLST Script “usersList.py” like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################

from java.io import FileInputStream
from weblogic.management.security.authentication import UserReaderMBean

propInputStream = FileInputStream("details.properties")
configProps = Properties()
configProps.load(propInputStream)

adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")
userNameWildcard=configProps.get("user.name.wildcard")
maximumToReturn=configProps.get("maximum.to.return")
showAllAuthenticatorUserList=configProps.get("show.all.authenticator.userlist")

connect(adminUserName, adminPassword, adminURL)

realmName=cmo.getSecurityConfiguration().getDefaultRealm()
authProvider = realmName.getAuthenticationProviders()

for i in authProvider:
	if isinstance(i,UserReaderMBean):
		userName = i
		authName= i.getName()

		if showAllAuthenticatorUserList == 'true':
			userList = i.listUsers(str(userNameWildcard),int(maximumToReturn))
			print '======================================================================'
			print 'Below are the List of USERS which are in the: "'+authName+'"'
			print '======================================================================'
			num=1
			while userName.haveCurrent(userList):
				print num,'- '+ userName.getCurrentName(userList)
				userName.advance(userList)
				num=num+1
			print '======================================================================'
			userName.close(userList)

		else:
			if authName == 'DefaultAuthenticator':
				userList = i.listUsers(str(userNameWildcard),int(maximumToReturn))
				print '======================================================================'
				print 'Below are the List of USERS which are in the: "'+authName+'"'
				print '======================================================================'
				num=1
				while userName.haveCurrent(userList):
					print num,'- '+ userName.getCurrentName(userList)
					userName.advance(userList)
					num=num+1
				print '======================================================================'
				userName.close(userList)

Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh

Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Run the Above WLST Script like following:

java weblogic.WLST usersList.py

Following would be the Output when

show.all.authenticator.userlist=true

java weblogic.WLST usersList.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_7001'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

======================================================================
Below are the List of USERS which are in the: "DefaultAuthenticator"
======================================================================
1 - weblogic
2 - TestUserOne
3 - TestUserTwo
4 - TestUserThree
5 - TestUserFour
6 - TestUserFive
======================================================================
======================================================================
Below are the List of USERS which are in the: "RavishAuth"
======================================================================
1 - DB-weblogic-1
2 - DB-weblogic-2
3 - DB-weblogic-3
4 - weblogic
======================================================================

Following would be the Output when

show.all.authenticator.userlist= false

java weblogic.WLST usersList.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://localhost:7001 with userid weblogic ...
Successfully connected to Admin Server 'AdminServer' that belongs to domain 'Domain_7001'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

======================================================================
Below are the List of USERS which are in the: "DefaultAuthenticator"
======================================================================
1 - weblogic
2 - TestUserOne
3 - TestUserTwo
4 - TestUserThree
5 - TestUserFour
6 - TestUserFive
======================================================================

Regards,
Ravish Mody


How To Pause and Resume A Queue Using WLST

Ravish Mody

Today one of our subscribers Pavan had asked us by using comment , Here based on the query of Pavan we are writing the following article, which would Pause the Queue at Runtime even when the AdminServer/AdminConsole  is unavailable, thus we took out sometime and just now created a WLST script which would do the same job very easily.

In this script you can choose from which end do you want Queue to get paused, say if you want to pause the messages to be inserted then you can use pauseProduction , if you need that the consumption from the queue should stop then use pauseConsumtion and if you want that Queue should not insert or consume then use both. This way you can pause the queue as per your requirement, also with this you can resume the queue too by using resumeProduction, resumeConsumption or both of them. All this can be done using the same script just give the domain and there servers details in the domain.properties files and you are good to go.

Steps to Pause and Resume A Queue Using WLST

Step1). Create a Directory somewhere in your file system like : “C:WLSTPause_Queue”

Step2). Write a Properties filedomain.properties inside “C:WLSTPause_Queue” like following:

server.url=t3://10.10.10.10:7003
username=weblogic
password=weblogic
tragated.server.name=MS-1
jms.server.name=JMSServer-1
system.module.name=SystemModule-1
queue.name=Q-1

Step2). Now in the same directory write the following WLST Script “pause_queue.py” like following:

#############################################################################
#
# @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved.
#
#############################################################################
from java.io import FileInputStream
import java.lang
import os
import string

propInputStream = FileInputStream("domain.properties")
configProps = Properties()
configProps.load(propInputStream)

serverUrl = configProps.get("server.url")
Username = configProps.get("username")
Password = configProps.get("password")

tragatedServerName = configProps.get("tragated.server.name")
jmsServerName = configProps.get("jms.server.name")
systemModuleName = configProps.get("system.module.name")
queueName = configProps.get("queue.name")

connect(Username,Password,serverUrl)
serverRuntime()
cd('JMSRuntime/'+tragatedServerName+'.jms/JMSServers/'+jmsServerName+'/Destinations/'+systemModuleName +'!'+ queueName)

##################
# To PAUSE A Queue
##################

######## This would NOT let the messages Insert in the queue but it would let the messages get Consumed  ###########
cmo.pauseProduction()
print 'Queue: "', queueName ,'" has been PRODUCTION Paused Successfully'

######## This would let the messages Insert in the queue but it would NOT let the messages get Consumed  ###########
cmo.pauseConsumption()
print 'Queue: "', queueName ,'" has been CONSUMPTION Paused Successfully'

###################
# To RESUME A Queue
###################

#cmo.resumeProduction()
#print 'Queue: "', queueName ,'" has been PRODUCTION Resumed Successfully'

#cmo.resumeConsumption()
#print 'Queue: "', queueName ,'" has been CONSUMPTION Resumed Successfully'

Step3). Now Open a Command/Shell Prompt and then run the “setWLSEnv.sh” script to set the CLASSPATH and PATH environment variables. Run the “. ./setWLSEnv.sh” by adding two DOTs separated by a single space …..before the actual script like following : (use ‘cd’ command to move inside the <BEA_HOME>/wlserver_10.3/server/bin) then run the following command….
. ./setWLSEnv.sh

Note: Here The first DOT represents that set the Environment in the current Shell, AND the second ./ represents execute the script from the current directory.

Step4). Run the Above WLST Script like following:

java weblogic.WLST pause_queue.py

Following would be the Output

java weblogic.WLST pause_queue.py

Initializing WebLogic Scripting Tool (WLST) ...

Welcome to WebLogic Server Administration Scripting Shell

Type help() for help on available commands

Connecting to t3://10.10.10.10:7003 with userid weblogic ...
Successfully connected to managed Server 'MS-1' that belongs to domain 'Domain_7001'.

Warning: An insecure protocol was used to connect to the
server. To ensure on-the-wire security, the SSL port or
Admin port should be used instead.

Location changed to serverRuntime tree. This is a read-only tree with ServerRuntimeMBean as the root.
For more help, use help(serverRuntime)

Queue: " Q-1 " has been PRODUCTION Paused Successfully
Queue: " Q-1 " has been CONSUMPTION Paused Successfully

Regards,
Ravish Mody


Copyright © 2010-2012 Middleware Magic. All rights reserved. |