import sys,java
from java.util import Properties
from org.python.modules import time
from java.io import FileInputStream
lineSep = java.lang.System.getProperty('line.separator')
def variable(node,varname1,varvalue1):
global AdminApp
global AdminConfig
global AdminControl
print " ----------------------------------------------------------------------------------------- "
cell = AdminControl.getCell()
cellid = AdminConfig.getid('/Cell:'+ cell)
nodeid= AdminConfig.getid('/Cell:'+ cell +'/Node:'+ node +'/')
varMapserver = AdminConfig.getid('/Cell:'+ cell +'/Node:'+ node +'/VariableMap:/')
if len(varMapserver) > 0:
print " Variable Map exists on node ........... "
variables = AdminConfig.list("VariableSubstitutionEntry", varMapserver).split(lineSeparator)
for variable in variables[:]:
vname = AdminConfig.showAttribute(variable, "symbolicName")
if (vname == varname1) :
print "Removing old variable " + vname + " from variables.xml..."
AdminConfig.remove(variable)
nameattr1 = ['symbolicName', varname1]
valattr1 = ['value', varvalue1]
desc1 = ["description", varname1]
attr1 = [nameattr1, valattr1, desc1]
attrs1 = [attr1]
entries1 = ['entries', attrs1 ]
print "creating new variable " + varname1
AdminConfig.modify(varMapserver, [entries1] )
AdminConfig.save()
print " Node Level Variable Configured ................ "
print " ------------------------------------------------------------------------------------------------------------------------ "
else:
print " Variable Map doesn't exists on node ........... "
varMapserver = AdminConfig.create('VariableMap', nodeid, [])
print " Variable Map created on node ........... "
nameattr1 = ['symbolicName', varname1]
valattr1 = ['value', varvalue1]
desc1 = ["description", varname1]
attr1 = [nameattr1, valattr1, desc1]
attrs1 = [attr1]
entries1 = ['entries', attrs1 ]
print "creating new variable " + varname1
AdminConfig.modify(varMapserver, [entries1] )
AdminConfig.save()
print " Node Level Variable Configured ................ "
print " ------------------------------------------------------------------------------------------------------------------------ "
######################################################### Full Resyncronization #########################################################
print " Fully Resyncronizing nodes ........... "
nodelist = AdminTask.listManagedNodes().split(lineSep)
for nodename in nodelist :
####################Identifying the ConfigRepository MBean and assign it to variable######################
repo = AdminControl.completeObjectName('type=ConfigRepository,process=nodeagent,node='+ nodename +',*')
print AdminControl.invoke(repo, 'refreshRepositoryEpoch')
sync = AdminControl.completeObjectName('cell='+ cell +',node='+ nodename +',type=NodeSync,*')
print AdminControl.invoke(sync , 'sync')
print " ----------------------------------------------------------------------------------------- "
print " Full Resyncronization completed "
print " ----------------------------------------------------------------------------------------- "
########################################################## Main Program #############################################################
arglen=len(sys.argv)
num_exp_args=2
if (arglen != num_exp_args):
print "Two arguments are required."
print " ----------------------------------------------------------------------------------------- "
sys.exit(-1)
propFile=sys.argv[0]
properties=Properties();
try:
properties.load(FileInputStream(propFile))
print " ----------------------------------------------------------------------------------------- "
print "Succesfully read property file "+propFile
print " ----------------------------------------------------------------------------------------- "
except:
print "Cannot read property file "+propFile
sys.exit(-1)
print " ----------------------------------------------------------------------------------------- "
node = sys.argv[1]
varname1=str(properties.getProperty("VARIABLE_NAME"))
varvalue1=str(properties.getProperty("VARIABLE_VALUE"))
variable(node,varname1,varvalue1)
Excellent post..your blog provides the most fascinating information... SAP Services
ReplyDelete