In them, replace the actual environment-dependent values with tokens like ${DOMAIN_NAME}
the tokens are:
tokens=DOMAIN_NAME,FTP_HOST,FTP_PASSWORD,FTP_USER
The JNDI names of all your DataSources will not change from environment to environment, so there is no point in replacing them.
create a adapters.properties file like this:
plan1=/opt/oracle/domains/${DOMAIN_NAME}/shared/apps/dbadapter/plan/DBAdapterPlan.xml
plan2=/opt/oracle/domains/${DOMAIN_NAME}/shared/apps/fileadapter/plan/FileAdapterPlan.xml
plan3=/opt/oracle/domains/${DOMAIN_NAME}/shared/apps/ftpadapter/plan/FTPAdapterPlan.xml
plans=plan1,plan2,plan3
adapter1=/opt/oracle/fmw11_1_1_5/osb/soa/connectors/DbAdapter.rar
adapter2=/opt/oracle/fmw11_1_1_5/osb/soa/connectors/FileAdapter.rar
adapter3=/opt/oracle/fmw11_1_1_5/osb/soa/connectors/FtpAdapter.rar
adapters=adapter1,adapter2,adapter3
username=weblogic
password=welcome1
url=t3://myhost.acme.com:7001
tokens=DOMAIN_NAME,FTP_HOST,FTP_PASSWORD,FTP_USER
DOMAIN_NAME=osbpl1do
FTP_HOST=myfthost.acme.com
FTP_PASSWORD=pippopassword
FTP_USER=pippouser
create a WLST script like this:
#############################################################################
#
# Configure a new environment with the Plans.xml from SVN
# uses adapters.properties file.
#
#############################################################################
from java.io import FileInputStream
from shutil import copyfile
import os, sys
import re
#not used, keep only as a reference
def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to file-like object fdst"""
while 1:
buf = fsrc.read(length)
if not buf:
break
fdst.write(buf)
def copyfileWithTokenSubstitution(filein, fileout, properties):
input = open(filein)
output = open(fileout, 'w')
for s in input:
rep = s
for tokenname in properties.get("tokens").split(','):
rep = rep.replace("${" + tokenname + "}", properties.get(tokenname))
output.write(rep)
input.close()
output.close()
#not used, keep only as a reference
def copyfile(src, dst):
"""Copy data from src to dst"""
fsrc = None
fdst = None
try:
fsrc = open(src, 'rb')
fdst = open(dst, 'wb')
copyfileobj(fsrc, fdst)
finally:
if fdst:
fdst.close()
if fsrc:
fsrc.close()
propertyFileName = 'adapters.properties'
#loading properties
print 'Loading properties from ', propertyFileName
propInputStream = FileInputStream(propertyFileName)
configProps = Properties()
configProps.load(propInputStream)
domainName = configProps.get('DOMAIN_NAME')
plans=configProps.get("plans")
adapters=configProps.get("adapters")
planArray = []
adapterArray = []
#create needed directories where to put *Plan.xml
for plan in plans.split(','):
planFullPath = configProps.get(plan).replace("${DOMAIN_NAME}", domainName)
planArray.append(planFullPath)
#create array of adapters
for adapter in adapters.split(','):
adapterName = configProps.get(adapter)
adapterArray.append(adapterName)
#create dir if doesn't exist - fail if unable to create it
for planFullPath in planArray:
dirName = os.path.dirname(planFullPath)
print "creating directory " + dirName
if not os.path.exists(dirName):
os.makedirs(dirName)
#check for directory existence
for planFullPath in planArray:
dirName = os.path.dirname(planFullPath)
print "testing directory " + dirName
if not os.path.exists(dirName):
message = "directory " + dirName + " does not exist"
print message
raise Exception(message)
#copy all Plan.xml files to their final destination, with token substitution
for planFullPath in planArray:
fileName = os.path.basename(planFullPath)
print "copying " + fileName + " to " + planFullPath
copyfileWithTokenSubstitution(fileName, planFullPath, configProps)
#Connect to Admin Server
connect(configProps.get("username"),configProps.get("password"),configProps.get("url"))
#applying changes to the Adapters
edit()
try:
for index in range(len(planArray)):
startEdit()
plan = planArray[index]
adapter = adapterArray[index]
adapterType = os.path.basename(adapter).split('.')[0]
print 'Applying plan ' + plan + " to adapter " + adapter + " (adapter type is " + adapterType + ")"
myPlan = loadApplication(adapter, plan)
myPlan.save()
save()
activate(block='true')
cd('/AppDeployments/' + adapterType + '/Targets')
#updateApplication(appName, planPath);
redeploy(adapterType, plan, targets = cmo.getTargets())
except:
dumpStack()
stopEdit('y')
message="unable to finish job"
raise Exception(message)
disconnect()
print "job finished successfully"