Python [WebSphere]:项未正确附加到列表,并且正则表达式失败
我们正在尝试通过组合使用Python [WebSphere]:项未正确附加到列表,并且正则表达式失败,python,regex,jython,websphere-8,wsadmin,Python,Regex,Jython,Websphere 8,Wsadmin,我们正在尝试通过组合使用AdminApp.list()和regex来停止特定的应用程序,而无需手动干预 最终目标是:易用性。用户必须能够在不登录WAS控制台或修改脚本中的目标应用程序名称值的情况下停止应用程序。他们必须登录Jenkins并执行这个stopapp.py脚本。事情一定很简单 根据该脚本,WAS返回其DMGR中当前存在的应用程序列表。然后我们将这些项目附加到一个空列表中,然后运行一个正则表达式例程(re.match)来识别一个特定的应用程序名。然后,我们在试图停止的应用程序的URI中替
AdminApp.list()
和regex
来停止特定的应用程序,而无需手动干预
最终目标是:易用性。用户必须能够在不登录WAS控制台或修改脚本中的目标应用程序名称值的情况下停止应用程序。他们必须登录Jenkins并执行这个stopapp.py脚本。事情一定很简单
根据该脚本,WAS返回其DMGR中当前存在的应用程序列表。然后我们将这些项目附加到一个空列表中,然后运行一个正则表达式例程(re.match)来识别一个特定的应用程序名。然后,我们在试图停止的应用程序的URI中替换提取的应用程序名称值。如果成功,应用程序将被停止,状态将跨节点同步
这是我的代码:
import re
moduleName = "meap"
ctxRootOld = "/meap_old"
appList = []
appObj = AdminApp.list("WebSphere:cell=myCell,node=myNode,server=myServer")
print("These are the list of apps running in WAS DMGR: ")
print(appObj)
for apps in appObj:
appList.append(apps)
print("Now appending the apps to an empty list...Here are the values")
print(appList)
for app in appList:
appMatch = re.match("^ABC\w+$", app)
print(appMatch)
result = appMatch.group(0)
appStopName = result
print (appStopName)
appStopURI = ""+appStopName+".war,WEB-INF/web.xml"
appmanager = AdminControl.queryNames('cell=myCell,node=myNode,type=ApplicationManager,*')
AdminControl.invoke(appmanager, 'stopApplication', appStopName)
AdminApp.edit(appStopName, ['-CtxRootForWebMod', [[moduleName, appStopURI, ctxRootOld]]])
AdminConfig.save()
AdminNodeManagement.syncActiveNodes()
输出如下所示:
WASX7209I: Connected to process "dmgr" on node CellManager03 using SOAP connector; The type of process is: DeploymentManager
These are the apps running in WAS DMGR:
DefaultApp
ABCPreProd
Now appending the apps to an empty list...Here are the values
['D','e','f','a','u','l','t'.....'P','r','o','d']
None
WASX7017E: Exception received while running file "/app/was_scripts/stopapp.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
File "<string>", line 11, in ?
AttributeError: 'None' object has no attribute 'group'
WASX7209I:使用SOAP连接器连接到节点CellManager03上的进程“dmgr”;流程的类型是:DeploymentManager
以下是WAS DMGR中运行的应用程序:
DefaultApp
ABCPreProd
现在将应用程序添加到一个空列表中…以下是值
[D','e','f','a','u','l','t','P','r','o','D']
没有一个
WASX7017E:运行文件“/app/was\u scripts/stopapp.py”时收到异常;异常信息:com.ibm.bsf.BSFException:来自Jython的异常:
回溯(最里面的最后一个):
文件“”,第11行,在?
AttributeError:“无”对象没有属性“组”
虽然它正在打印一个列表(格式不太合适),但它不正确地附加到一个空列表。它获取每个应用程序名称,然后将它们拆分为单独的字母,然后附加到一个空列表中
结果,正则表达式模式匹配返回的是None
,而不是app name
请指导我,这样我就可以纠正错误并自动化这些东西。我觉得使用split方法和append可以解决这个问题。但是我不知道在split方法中放什么样的分隔符。这只是我的感觉,但每个人都可以自由地表达自己的想法
感谢和问候-KrisT:)根据您的输出,打印
appObj
会导致应用程序打印换行符。如果是这样,试试看
我们采取了以下方法。这将通过获取字符串输出并在换行符上将其拆分来创建appList
:
import re
moduleName = "meap"
ctxRootOld = "/meap_old"
appObj = AdminApp.list("WebSphere:cell=myCell,node=myNode,server=myServer")
print("These are the list of apps running in WAS DMGR: ")
print(appObj)
print("Now appending the apps to an empty list...Here are the values")
appList = str(appObj).splitlines()
print(appList)
for app in appList:
appMatch = re.match("^ABC\w+$", app)
print(appMatch)
result = appMatch.group(0)
appStopName = result
print (appStopName)
appStopURI = ""+appStopName+".war,WEB-INF/web.xml"
appmanager = AdminControl.queryNames('cell=myCell,node=myNode,type=ApplicationManager,*')
AdminControl.invoke(appmanager, 'stopApplication', appStopName)
AdminApp.edit(appStopName, ['-CtxRootForWebMod', [[moduleName, appStopURI, ctxRootOld]]])
AdminConfig.save()
这将阻止它附加每个字母。使用可以比使用
.split('\n')
更安全。如果appObj
已经是一个字符串,那么您也可以根据您的输出删除str()
,打印appObj
会导致应用程序打印换行符。如果是这样,试试看
我们采取了以下方法。这将通过获取字符串输出并在换行符上将其拆分来创建appList
:
import re
moduleName = "meap"
ctxRootOld = "/meap_old"
appObj = AdminApp.list("WebSphere:cell=myCell,node=myNode,server=myServer")
print("These are the list of apps running in WAS DMGR: ")
print(appObj)
print("Now appending the apps to an empty list...Here are the values")
appList = str(appObj).splitlines()
print(appList)
for app in appList:
appMatch = re.match("^ABC\w+$", app)
print(appMatch)
result = appMatch.group(0)
appStopName = result
print (appStopName)
appStopURI = ""+appStopName+".war,WEB-INF/web.xml"
appmanager = AdminControl.queryNames('cell=myCell,node=myNode,type=ApplicationManager,*')
AdminControl.invoke(appmanager, 'stopApplication', appStopName)
AdminApp.edit(appStopName, ['-CtxRootForWebMod', [[moduleName, appStopURI, ctxRootOld]]])
AdminConfig.save()
这将阻止它附加每个字母。使用可以比使用
.split('\n')
更安全。如果appObj
已经是一个字符串,那么您也可以删除str()
Hi@Martin Evans。很抱歉我没有及时回复。我尝试了另一种方法,它奏效了。我将split('\n')添加到AdminApp.list()命令的顶部。应用拆分后,一切都按预期进行。但我也将尝试splitlines()方法,并让您了解输出:-)Hi@Martin Evans。很抱歉我没有及时回复。我尝试了另一种方法,它奏效了。我将split('\n')添加到AdminApp.list()命令的顶部。应用拆分后,一切都按预期进行。但我也将尝试splitlines()方法,并让您了解输出:-)