【问题标题】:How to clone weblogic server in WLST (offline-mode)?如何在 WLST(离线模式)中克隆 weblogic 服务器?
【发布时间】:2011-02-21 13:13:57
【问题描述】:

我们有一个自定义 weblogic 模板,其中包含管理服务器(显然)和一个集群,其中 2 台托管服务器部署到同一台机器上。我们将该模板用于我们的开发环境。但是现在当我们转向性能测试环境时,我们需要引入更多的机器。

在 WLST(离线或在线模式)下创建新机器很容易。但是如何在 WLST 中克隆服务器(因为除了 weblogic.Name 和目标机器之外的所有设置都相同)?

这在 WebLogic 管理控制台中似乎是可能的,但我们需要自动化。

【问题讨论】:

    标签: weblogic weblogic9.x wlst


    【解决方案1】:

    我最终定义了以下函数:

    def createServer(wls, name):
      wls.cd("/")
      wls.create(name, 'Server')    
    
    
    ######################################################################
    # Checks if given bean exists
    ######################################################################
    def beanExists(wls, path, name):
      print "Checking if bean: '" + name + "' exists in path: '" + path + "'"
      wls.cd(path)
      wls.setShowLSResult(0)  
      beans = wls.ls('c', 'false', 'c')
      wls.setShowLSResult(1)  
      if (beans.find(name) != -1):
        print "Exists"  
        return 1
      else:
        print "Doesn't exist"  
        return 0
    
    
    ######################################################################
    # Copy bean properties in offline mode.
    ######################################################################
    def copyProperties(wls, originalBeanName, originalBeanPath, newBeanName, newBeanPath, ignoredProperties):
    
      wls.getCommandExceptionHandler().setMode(1)
      wls.getRuntimeEnv().set('exitonerror', 'true')
    
      srcPath = originalBeanPath + "/" + originalBeanName
      targetPath =  newBeanPath + "/" + newBeanName
    
      print "Coping properties from '" + srcPath + "' to '" + targetPath + "'"  
      wls.cd(srcPath)
    
      wls.setShowLSResult(0)
      attributes = wls.ls('a', 'true', 'a')
      children = wls.ls('c', 'true', 'c')
      wls.setShowLSResult(1)
    
      # Copy attributes.
      wls.cd(targetPath)
      for entry in attributes.entrySet(): 
        k = entry.key
        v = entry.value  
        if not(k in ignoredProperties) and not(v is None) and not(v == ''):
          print "Setting property '" + str(k) + "' = '" + str(v) + "' on '" + targetPath + "'"
          if isinstance(v, StringType):
            wls.set(k, v.replace(originalBeanName, newBeanName))
          else:
            wls.set(k, v)
    
      # Copy child bean values.
      for k in children:
        if not(k in ignoredProperties):
          srcBN = srcPath + "/" + k    
          targetBN = targetPath + "/" + k
          print "Coping bean '" + srcBN + "/" + originalBeanName + "'"
          print "Detected bean type as '" + k + "'"
          if beanExists(wls, srcBN, "NO_NAME_0"):      
            print "Changing to NO_NAME_0"
            originalBeanName = "NO_NAME_0"
            newBeanName = "NO_NAME_0"        
          wls.cd(targetPath)        
          wls.create(newBeanName, k)  
          copyProperties(wls, originalBeanName, srcBN, newBeanName, targetBN, ignoredProperties)
    

    之后只需调用:

    createServer(WLS, 'ServiceServer3')
    copyProperties(WLS, 'ServiceServer1', '/Servers', 'ServiceServer3', '/Servers', ['SSL'])
    

    更新:我在博客中写了更多关于它的内容:http://blog.aestasit.com/cloning-objects-in-wlst-offline/。该脚本还在 WebLogic 11g 上进行了测试。

    【讨论】:

      【解决方案2】:

      我不确定 WLST 的最新版本,但旧版本没有针对它的单个命令,因为 clone 在控制台端 - 它不是可以在 MBean 上调用的功能。

      您可以编写一个以 serverName 作为参数的脚本,遍历所有资源,然后创建您的新服务器。或者,也可以使用 Oracle 的 OEM。希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-25
        • 1970-01-01
        • 2016-08-29
        • 1970-01-01
        • 2011-10-24
        • 2014-04-30
        • 1970-01-01
        相关资源
        最近更新 更多