问题
I have two WLST queries. I execute it through WebLogic Scripting Tool console. These queries are:
1) List of deployed applications and status:
connect('weblogic','password','t3://localhost:7001')
cd('AppDeployments')
deplymentsList=cmo.getAppDeployments()
for app in deplymentsList:
domainConfig()
cd ('/AppDeployments/'+app.getName()+'/Targets')
mytargets = ls(returnMap='true')
domainRuntime()
cd('AppRuntimeStateRuntime')
cd('AppRuntimeStateRuntime')
for targetinst in mytargets:
curstate4=cmo.getCurrentState(app.getName(),targetinst)
print app.getApplicationName(), targetinst, curstate4;
Output example:
- WeblogicApp Cluster1 STATE_ACTIVE
- DMS Application AdminServer STATE_ACTIVE
- Benefits Cluster2 STATE_ACTIVE
2) List of hosts-machines
connect('weblogic','password','t3://localhost:7001')
svrs = cmo.getServers()
domainRuntime()
for host in svrs:
machine = host.getMachine();
print "Host: " + machine.getName()
Output example:
- Host: 192.168.200.1
- Host: 192.168.200.2
- Host: 192.168.200.3
- Host: Machine-0
- Host: Machine-1
- Host: Machine-2
I need to get both info (an application and their host or shared hosts if they have it more than one). I don't know how to solve and mix the queries to get both info in one query, or at least to get the info related about deployment application - hosts in the second query.
The output needed is something like that:
- WeblogicApp Cluster1 STATE_ACTIVE 192.168.200.2
- WeblogicApp Cluster1 STATE_ACTIVE 192.168.200.3
- DMS Application AdminServer STATE_ACTIVE 192.168.200.1
- DMS Application AdminServer STATE_ACTIVE Machine-1
- DMS Application AdminServer STATE_ACTIVE Machine-2
- Benefits Cluster1 STATE_ACTIVE Machine-0
- ..............
Thanks in advance.
回答1:
A little late to the party. But if anybody else comes by searching for answers I came up with extension of the first script to give the desired result:
connect('weblogic','password','t3://localhost:7001')
setShowLSResult(false)
cd('AppDeployments')
deplymentsList=cmo.getAppDeployments()
domainConfig()
for app in deplymentsList:
cd ('/AppDeployments/'+app.getName()+'/Targets')
mytargets = ls(returnMap='true')
for targetinst in mytargets:
domainRuntime()
cd('AppRuntimeStateRuntime')
cd('AppRuntimeStateRuntime')
curstate4 = cmo.getCurrentState(app.getName(),targetinst)
domainConfig()
cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst)
myType = cmo.getType()
if myType == 'Cluster':
myServers = cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst+'/Servers', returnMap='true')
for server in myServers:
cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst+'/Servers/'+server)
machineName = cmo.getMachine().getName()
print app.getApplicationName(), targetinst, curstate4, machineName
elif myType == 'Server':
cd('/AppDeployments/'+app.getName()+'/Targets/'+targetinst)
machineName = cmo.getMachine().getName()
print app.getApplicationName(), targetinst, curstate4, machineName
The output will be similar to the output stated in the original question.
来源:https://stackoverflow.com/questions/50037671/wlst-query-list-deployed-applications-and-hosts-together