python - 处理 python 脚本中的 wlst 异常

标签 python maven weblogic wlst

我正在维护一个在尝试删除丢失的 MDS 分区时中断的构建。

当有东西要删除时没关系。

我对这个主题不太熟悉,我也想了解

  • 删除前检查分区是否存在
  • 处理错误并继续 maven 生命周期

有问题的pom部分是

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.1</version>
        <executions>
          <execution>
            <id>delete-MDS</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>${oracle.wlst}</executable>
              <arguments>
                <argument>${predeploy.script.deletemds}</argument>
                <argument>weblogic</argument>
                <argument>${adminServerPassword}</argument>
                <argument>${adminServerUrl}</argument>
                <argument>${mds.repository}</argument>
                <argument>${mds.partition}</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>

${predeploy.script.deletemds}内容是

print '\nStarting deleteMDSOnDomain.py'

#skipped mapping input to variables here

try:
  connect(username,password,url)

  print "Deleting MDS configuration"
  #fails if partition already removed
  deleteMetadataPartition( repository=mdsRepository, partition=mdsPartition)

except Exception, e:
  print e
  print "Error while trying to delete MDS configuration"
  dumpStack()
  #raise

print 'Finished deleteMDSOnDomain.py\n'

运行时得到

...
[INFO] Deleting MDS configuration
[INFO] Location changed to domainRuntime tree. This is a read-only tree with DomainMBean as the root.
[INFO] For more help, use help(domainRuntime)
[INFO]
[INFO]
[INFO] Problem invoking WLST - Traceback (innermost last):
[INFO]   File "C:\Dev\trunk\<App>\<Project>\scripts\deleteMDSOnDomain.py", line 24, in ?
[INFO]   File "C:\Dev\Oracle\MIDDLE~1\ORACLE~1\common\wlst\mdsWLSTCommands.py", line 471, in deleteMetadataPartition
[INFO]   File "C:\Dev\Oracle\MIDDLE~1\ORACLE~1\common\wlst\mdsWLSTCommands.py", line 836, in executeDomainRuntimeMBeanOperation
[INFO]   File "C:\Dev\Oracle\MIDDLE~1\ORACLE~1\common\wlst\mdsWLSTCommands.py", line 1097, in saveStackAndRaiseException
[INFO] WLSTException: MDS-00555: The partitionName <App> is invalid.
[INFO] ORA-01403: no data found
[INFO] ORA-06512: at "<env>_MDS.MDS_INTERNAL_SHREDDED", line 580
[INFO] ORA-06512: at line 1
[INFO]  MDS-91009: Operation "deleteMetadataPartition" failure. Use dumpStack() to view the full stacktrace.
[INFO]
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Result of cmd.exe /X /C "C:\Dev\Oracle\Middleware\oracle_common\common\bin\wlst.cmd scripts/deleteMDSOnDomain.py weblogic <pass> <url> mds-CustomPortalDS <App>" execution is: '1'.
[INFO] ------------------------------------------------------------------------

似乎 wlst 结果“1”被传播到 Maven,例如我的 py catch 没有完全处理这个问题——我可以在那里手动将它更改为“0,好的”吗?

编辑:拼写错误

一切都很好。该错误是由另一个尝试接下来取消部署应用程序的插件引发的。注意到后才明白

[INFO] [Deployer:149001]No application named '<app>' exists for operation undeploy.

我可以发誓它以前不存在......无论如何我也得到了一些代码来检查下面的答案中是否存在分区。

最佳答案

我更像是一个Look Before You Leap某种程序员所以下面是我在删除 MDS 分区时使用的一些 WLST,以首先检查它们是否存在。不幸的是,您不得不求助于直接访问 MDSDomainRuntime mBean,因为有人忘记在 WLST 中公开 listPartitions 方法。

from org.python.modules import jarray
from javax.management import ObjectName, Attribute

#skipped mapping input to variables here

connect(username, password, url)

domainRuntime()

mdsName = ObjectName('oracle.mds.lcm:name=MDSDomainRuntime,type=MDSDomainRuntime')
beans = mbs.queryMBeans(mdsName, None)

if (beans.size() == 0):
    # This _should_ be impossible
    raise Exception("Could not find mbean '%s' in the current tree '%s'." % (mdsName, pwd()))

beanName = beans.iterator().next().getObjectName()
params = jarray.array([mdsRepository], java.lang.Object) 
signature = ['java.lang.String']  
partitions = mbs.invoke(beanName, "listPartitions", params, signature)  

if (mdsPartition not in partitions):  
    print("Partition '%s' does not exist in repository '%s'." % (mdsPartition, mdsRepository))
else:
    params = jarray.array([mdsRepository, mdsPartition], java.lang.Object)
    signature = jarray.array(['java.lang.String','java.lang.String'], java.lang.String)
    mbs.invoke(beanName, 'deleteMetadataPartition', params, signature)
    print("Partition '%s' deleted from repository '%s'." % (mdsPartition, mdsRepository))

关于python - 处理 python 脚本中的 wlst 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28852346/

相关文章:

java - Maven项目中如何处理CLASSPATH?

JAVA:ThreadGroup.getParent() 上的 SecurityException

css - WebLogic和Webapp Combo崩溃后不显示图片

python - 如何对 Python 对象进行排序

python - 将 python 文件夹添加到系统变量不起作用

java - 启动SpringBoot 2.0.3.RELEASE时出错

java - weblogic中如何配置集群地址

python - django-rest-framework:在 ViewSet 更新方法中添加额外的权限

python - int.to_bytes() 的行为不一致

java - Maven 找不到编译类型的依赖项