Skip to content
June 21, 2013 / Shailendra Singh

Adding/Updating Resource Environment Provider custom properties using wsadmin

Step 1 :
Creating following directory structure

  WSAdmin (project_root)
     config
            rep       
     scripts
            rep

Step 2 :
     Copy portalDeploy.xml to WSAdmin folder.
     Copy resourceEnvProviders.cfg file to WSAdmin\config\rep folder.
     Copy resourceEnvProviders.py file to WSAdmin\scripts\rep folder.

Step 3 :
    Run following command - 
    <wp_profile>/bin>ws_ant.bat -f <WSAdmin folder path>\portalDeploy.xml crateUpdateREP


  • portalDeploy.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="portaldeploy" basedir=".">

   <!-- Project properties -->
   <property name="name" value="app" />
   <property name="build.dir" location="build" />
   <property name="userId" value="wpsadmin" />
   <property name="password" value="wpsadmin" />

   <!-- wsadmin properties -->
   <property name="lang" value="jython" />
   <pathconvert property="configPath" dirsep="" pathsep="">
      <path path="config" />
      <filtermapper>
          <replacestring from="\" to="/" />
      </filtermapper>
   </pathconvert>

   <!-- WAS Ant task definitions -->
   <taskdef name="wsAdmin" classname="com.ibm.websphere.ant.tasks.WsAdmin" />

   <target name="crateUpdateREP">
     <wsAdmin user="${userId}" password="${password}" lang="${lang}" script="${basedir}/scripts/rep/resourceEnvProviders.py">
        <arg value="${configPath}/rep/resourceEnvProviders.cfg" />
     </wsAdmin>
   </target>

</project>


  • resourceEnvProviders.cfg
##############################################
# Format for updating/adding a property
# Existing property
# <name>: <value>
# New proeprty
# <name>: <value>|<type>|<description>
##############################################
[WP ConfigService]
com.ibm.wps.resourceaggregator.cache.info.0.max-age: 5
com.ibm.wps.resourceaggregator.cache.info.1.max-age: 5
filestore.cache.expiration.0.seconds: 5
filestore.cache.expiration.1.seconds: 5
filestore.cache.expiration.2.seconds: 5
filestore.cache.expiration.3.seconds: 5


  • resourceEnvProviders.py
import sys
import ConfigParser

cfgFile = sys.argv[0]
print "Config file : " + cfgFile

config = ConfigParser.ConfigParser()
config.read(cfgFile)

def findProperty(propSet, option):
	
	propertyList = AdminConfig.list("J2EEResourceProperty", propSet).splitlines()
	
	for elem in propertyList:
		if(AdminConfig.showAttribute(elem, "name") == option):
			return elem;

print "========================= Applying configuration ============================="

for section in config.sections():

	print "Reading properties for section : " + section

	wpConfigREP = AdminConfig.getid('/ResourceEnvironmentProvider:' + section + '/')
	
	propSet = AdminConfig.showAttribute(wpConfigREP, 'propertySet')
	
	for option in config.options(section):
		property = findProperty(propSet, option)		
		
		if(property is not None):
			currentValue = AdminConfig.showAttribute(property, "value")
			currentDesc = AdminConfig.showAttribute(property, "description")
			
			newValue = config.get(section, option)
			if(newValue != currentValue):
				print "UPDATING property : '" + option + "' ====>"
				newSettings = [
								["value", config.get(section, option)],
								["description ", "Original value was " + currentValue + "."]
							  ]
							  
				AdminConfig.modify(property, newSettings)
			else:
				print "Property : '" + option + "' is already having latest value."
				
		else:
			print "ADDING property : '" + option + "' ====>"
			values = config.get(section, option).split('|')
			newSettings = [
							["name", option],
							["value", values[0]],
							["type", values[1]], 
							["description ", values[2]]
						  ]
			AdminConfig.create('J2EEResourceProperty', propSet, newSettings)
				
#Save configuration
AdminConfig.save()

print "========================= DONE ============================="

Leave a comment