################################################################################
# Jython script to configurate server and deploy applications
# application.py
################################################################################
from org.w3c.dom import Node
from common import Common
from destination import Destination
from resource import PropertySet
from resource import Property
import sys
import java
class Apps:
elements = []
def __init__(self, node):
childNodes = node.getChildNodes()
idx = 0
while idx < childNodes.getLength():
childNode = childNodes.item(idx)
if childNode.getNodeType() == Node.ELEMENT_NODE:
nodeName = childNode.getNodeName()
if nodeName == 'app':
app = App(childNode)
self.elements.append(app)
else:
print 'ERROR: <'+nodeName+'> is an invalid element.'
#end if
#end if
idx += 1
#end while
#end def
def deploy(self):
for elem in self.elements:
elem.deploy()
#end for
#end def
#end class
class App:
name = None
ear = None
mapTo = None
startWeight = None
classloader = None
classloaderPolicy = None
ejbs = []
wars = []
rars = []
roles = []
connFactory = None
def __init__(self, node):
self.name = node.getAttribute('name')
self.ear = node.getAttribute('ear')
self.mapTo = node.getAttribute('map-to')
self.startWeight = node.getAttribute('start-weight')
self.classloader = node.getAttribute('classloader')
self.classloaderPolicy = node.getAttribute('classloader-policy')
print ''
print 'app.name='+self.name
print 'app.ear='+self.ear
print 'app.map-to='+self.mapTo
print 'app.start-weight='+self.startWeight
print 'app.classloader='+self.classloader
print 'app.classloader-policy='+self.classloaderPolicy
childNodes = node.getChildNodes()
idx = 0
while idx < childNodes.getLength():
childNode = childNodes.item(idx)
if childNode.getNodeType() == Node.ELEMENT_NODE:
nodeName = childNode.getNodeName()
if nodeName == 'ejb':
ejb = EJB(self, childNode)
self.ejbs.append(ejb)
elif nodeName == 'war':
war = War(self, childNode)
self.wars.append(war)
elif nodeName == 'rar':
rar = Rar(self, childNode)
self.rars.append(rar)
elif nodeName == 'role-mapping':
role = RoleMapping(self, childNode)
self.roles.append(role)
elif nodeName == 'conn-factory':
print "conn-factory inited"
self.connFactory = AppConnectionFactory(childNode)
else:
print 'ERROR: <'+nodeName+'> is an invalid element.'
#end if
#end if
idx += 1
#end while
#end def
def deploy(self):
print "***********************************************************************************"
print 'Deploying application '+self.name+'...'
if self.isAppInstalled() == 'true':
self.stopApp()
self.updateEar()
else:
self.installApp()
#end if
if len(self.roles) > 0:
print "***********************************************************************************"
print "Mapping roles..."
for roleMap in self.roles:
roleMap.deploy()
#end for
print "Success."
#end if
#self.mapModulesToServers()
self.changeClassLoader()
if len(self.wars) > 0:
for war in self.wars:
war.changeClassloaderMode()
#end for
#end if
if len(self.ejbs) > 0:
for ejb in self.ejbs:
ejb.changeClassloaderMode()
#end for
#end if
self.mapResourceToEJB()
if self.connFactory != None:
self.connFactory.deploy()
#end if
#save adminConfig before start application
#Common.AdminConfig.save()
self.startApp()
#end def
def updateEar(self):
AdminApp = Common.AdminApp
# Update the existing application
print "***********************************************************************************"
print "Updating application: " + self.name+"..."
AdminApp.update(self.name, "app", "-operation update -contents "+self.ear )
print "Success."
#end update()
def stopApp(self):
lineSeparator = java.lang.System.getProperty('line.separator')
AdminConfig = Common.AdminConfig
AdminControl = Common.AdminControl
cellName = Destination.cellName
servers = Destination.servers
#Query all application managers
print "***********************************************************************************"
for server in servers:
appMgrs = AdminControl.queryNames("type=ApplicationManager,cell=" + cellName + ",node=" + server.nodeName + ",process=" + server.serverName + ",*")
appMgrList = appMgrs.split(lineSeparator)
for appMgr in appMgrList:
if(len(appMgr.strip()) > 0):
try:
print "Stopping application " + self.name + " on node " + server.nodeName + "..."
AdminControl.invoke(appMgr, "stopApplication", self.name)
except:
print "WARNING: ", sys.exc_info()
print "Failed to stop application " + self.name + " on node " + server.nodeName
pass
#end try
#end if
#end for
#end for
print "Success."
#end stopApp()
def startApp(self):
lineSeparator = java.lang.System.getProperty('line.separator')
AdminControl = Common.AdminControl
cellName = Destination.cellName
servers = Destination.servers
appName = self.name
#Query all application managers
print "***********************************************************************************"
for server in servers:
appMgrs = AdminControl.queryNames("type=ApplicationManager,cell=" + cellName + ",node=" + server.nodeName + ",process=" + server.serverName + ",*")
appMgrList = appMgrs.split(lineSeparator)
for appMgr in appMgrList:
if(len(appMgr.strip()) > 0):
print "Starting application " + appName + " on node " + server.nodeName + "..."
AdminControl.invoke(appMgr, "startApplication", appName)
#end if
#end for
#end for
print "Success."
#end startApp()
def isAppInstalled(self):
AdminApp = Common.AdminApp
lineSeparator = java.lang.System.getProperty('line.separator')
installedApps = AdminApp.list()
if len(installedApps) > 0:
for installedApp in installedApps.split(lineSeparator):
if installedApp == self.name:
return 'true'
#end if
#end for
#end if
#end def
def installApp(self):
print "***********************************************************************************"
print 'Installing application '+self.name+'...'
AdminApp = Common.AdminApp
servers = Destination.servers
wsadmin自动部署的jython脚本
5星 · 超过95%的资源 需积分: 17 147 浏览量
2012-02-29
11:12:18
上传
评论 1
收藏 28KB RAR 举报
aqbbsxiao2
- 粉丝: 2
- 资源: 9
最新资源
- 基于去中心化联邦学习的货运速度预测时空模型-A decentralized federated learning-based s
- 适合新手的 OpenAI Sora 详细使用教程
- 驱动总裁离线安装包01
- NT98336 SDK 114版本
- torch-1.8.1+cu111-cp38-cp38-linux-x86-64.whl +torchvision
- 智能提取字幕-intel
- 计算机设计 - VB+ACCESS网络计时管理系统设计(源代码+系统),保证可靠运行,毕业生可参考,免费资源下载
- 信号处理,通信原理,数字通信信号处理与系统分析
- 计算机设计 - vb+ACCESS身份证管理系统设计(LW+源代码),保证可靠运行,毕业生可参考,免费资源下载
- 智能提取字幕-win10
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页