|
|
|
|
|
Instapp
Action : was.instapp (Category : was, Name : instapp, By : kikonf)
Complete Name : was.instapp.by.kikonf Version : 5.0 License : Modified BSD License Purpose of the was category : Easy to customize. This category use in background the wsadmin command in jython mode (through AdminConfig, AdminControl and AdminTask), to drive WebSphere Application Server ® configuration. You can use it to manage the whole WebSphere ® architecture. Purpose of this instapp plugin : Install one Application The following shows the main Source Code File for the Action : was.instapp Toggle lines
## Copyright (c) 2008, Patrick Germain Placidoux
## All rights reserved.
##
## This file is part of Kikonf Public Software.
##
## Kikonf Public Software is released under the modified BSD License,
## which should accompany it or any part of it in the file "COPYING".
## If you do not have this file you can access the license
## through the WWW at http://www.kikonf.org/license/bsd/license.txt.
##
## Home: http://www.kikonf.org
## Contact: kikonf@gmx.com
from actions.was.tools import *
class Instapp(wasAction):
def extract(self, name=None, **keywords):
self_funct='extract'
self.verbose(name)
indent=self.getIndent() + 3*' '
application=name
verbose('deployedObject retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
dep=AdminConfig.getid("/Deployment:" + application +"/")
if dep=='':raise xception.kikonfActionSystemException(self, self_funct, 'Application:' + application + ' not Found !')
deps=getShowAsDict(AdminConfig.show(AdminConfig.showAttribute(dep, "deployedObject")))
verbose('DeployedObject retreived.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
ear_install_path=deps['binariesURL']
#-- check vhost
vhost=None
verbose('Application view retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
mods = getViewTaskInfoAsDict(AdminApp.view(application, ["-MapWebModToVH"]))
for module in mods.keys():
if vhost==None:vhost=mods[module]['vhost']
if mods[module]['vhost']!=vhost:raise xception.kikonfActionSystemException(self, self_funct, 'Application:' + application + ', Found multiple Virtual host ! InstApp can only manage single virtual host mapping !')
if vhost!=None and vhost.find(',')>=0:raise xception.kikonfActionSystemException(self, self_funct, 'Application:' + application + ', Found multiple Virtual host ! InstApp can only manage single virtual host mapping !')
if vhost==None:vhost=''
#-- sharedlibs
sharedlibs=[]
verbose('classloader retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
classldr=deps['classloader']
ls=split(AdminConfig.showAttribute(classldr, 'libraries'))
for library in ls:
if library=='':continue
sharedlibs.append(AdminConfig.showAttribute(library, 'libraryName'))
if len(sharedlibs)!=0:sharedlibs=','.join(sharedlibs)
else:sharedlibs=''
app_node = self.newTop() # Tag: instapp
attrs={'name':application, 'ear_path':'', 'ear_install_path':ear_install_path, 'vhost':vhost, 'sharedlibs':sharedlibs}
app_node.setAttrs(**attrs)
list_scope_attrs=rtvAppTargets(application) # Tag: scope
mkNodeScope(app_node, list_scope_attrs, isUnique=False)
def remove(self, no_name, no_name_no_prefix):
self_funct='remove'
app_node = self.getTop()
app_attrs = app_node.getAttrs()
scopes=self.getScopes(parent_node=app_node, list_scope_attrs=None) #-- Retreives scope
self.verbose(app_attrs.name)
indent=self.getIndent() + 3*' '
self.rmvApp(app_attrs.name, indent=indent)
def inject(self):
self_funct='inject'
app_node = self.getTop()
app_attrs = app_node.getAttrs()
scopes=self.getScopes(parent_node=app_node, list_scope_attrs=None) #-- Retreives scope
self.verbose(app_attrs.name)
indent=self.getIndent() + 3*' '
self.rmvApp(app_attrs.name, indent=indent) #-- Removing first
verbose('TaskInfo retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
modules = getInstTaskInfoAsDict(AdminApp.taskInfo(app_attrs.ear_path, 'MapModulesToServers'))
cmdvalues=[]
cmdvalues.append(['appname', app_attrs.name])
cmdvalues.append(['installed.ear.destination', app_attrs.ear_install_path])
cmdvalues.append(['noprocessEmbeddedConfig'])
ms=[]
mh=[]
# Check vhost existence !
if app_attrs.vhost!=None:
vh=AdminConfig.getid('/VirtualHost:' + app_attrs.vhost + '/')
if vh=='':raise xception.kikonfActionSystemException(self, self_funct, 'Inexistant vhost:' + app_attrs.vhost + '. Advice change the xml Attribute "vhost" to an existant Virtual Host !')
for module in modules.keys():
uri, server, typ=modules[module]['uri'], modules[module]['server'], modules[module]['type']
# ms.append(['-WebModule', 'DefaultWebApplication.war,WEB-INF/web.xml', srv2 + '+' + srv3 + '+' + ihs1])
if typ=='web':
ms.append(['+"' + module + '" ' + uri + ' ' + self.getScopesON()])
if app_attrs.vhost!=None:mh.append(['+"' + module + '" ' + uri + ' ' + app_attrs.vhost])
elif typ=='ejb':ms.append(['+"' + module + '" ' + uri + ' ' + self.getScopesON(doIhs=False)])
else:raise xception.kikonfActionSystemException(self, self_funct, 'UnManaged Module type:' + typ + ' !')
if len(ms)!=0:cmdvalues.append(['MapModulesToServers', ms])
if len(mh)!=0:cmdvalues.append(['MapWebModToVH', mh])
verbose('Application installing.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
cmdvalues=trsToAdminTask(cmdvalues)
AdminApp.install(app_attrs.ear_path, cmdvalues)
verbose('Application:' + app_attrs.name + ' deployed.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
if app_attrs.sharedlibs!=None:self.runSharedLib(app_attrs.name, app_attrs.sharedlibs.split(','), indent=indent)
if app_attrs.post_script!=None:
import java
verbose('Running post_script:' + app_attrs.post_script + '.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
java.lang.Runtime.getRuntime().exec(app_attrs.post_script)
def rmvApp(self, name, indent=None):
scopes=self.getScopes()
dep = AdminConfig.getid('/Deployment:' + name + '/')
if dep not in ('', None):
verbose('Application uninstaling.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminApp.uninstall(name)
verbose('Application:' + name + ' uninstalled.', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def runSharedLib(self, application, sharedlibs, indent=None):
verbose('classloader retreiving.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
classldr=AdminConfig.showAttribute(AdminConfig.showAttribute(AdminConfig.getid('/Deployment:' + application +'/'), 'deployedObject'), 'classloader')
for sh in sharedlibs:
verbose('LibraryRef creating.', level=self.getVerbose(), ifLevel=4, indent=indent, logFile=self.getLogFile())
AdminConfig.create('LibraryRef', classldr, 'libraryName', sh], ['sharedClassloader', 'true')
verbose('SharedClassloader for SharedLib:' + sh + ' created', level=self.getVerbose(), ifLevel=3, indent=indent, logFile=self.getLogFile())
def verbose(self, name):
verbose('Application:' + name + '.', level=self.getVerbose(), ifLevel=2, indent=self.getIndent())
Trademarks :
|