2 Replies Latest reply: Dec 12, 2012 1:08 PM by 948568 RSS

    WLST & ALSB AttributeError: 'None' object has no attribute 'exportProjects'

    655092
      I have the following WLST script that exports an ALSB 2.6 project and a Customization file for that project. The script was downloaded from the BEA website sometime ago, and I had it working fine. A recent change broke it, and I'm not sure why. I'm hoping someone can help me out here...

      The script is below:
      <blockquote>
           <p>
           from java.io import FileInputStream
           from java.io import FileOutputStream
           from java.util import ArrayList
           from java.util import Collections
           </p>
           <p>
           from com.bea.wli.sb.util import EnvValueTypes
           from com.bea.wli.config.env import EnvValueQuery;
           from com.bea.wli.config import Ref
           from com.bea.wli.config.customization import Customization
           from com.bea.wli.config.customization import FindAndReplaceCustomization
           </p>
           <p>
           import sys
           </p>
           <p>
           #=======================================================================================
           # Utility function to load properties from a config file
           #=======================================================================================
           def exportAll(exportConfigFile):
           try:
           print "Loading export config from :", exportConfigFile
           exportConfigProp = loadProps(exportConfigFile)
           adminUrl = exportConfigProp.get("adminUrl")
           exportUser = exportConfigProp.get("exportUser")
           exportPasswd = exportConfigProp.get("exportPassword")
           </p>
           <p>
           exportJar = exportConfigProp.get("exportJar")
           customFile = exportConfigProp.get("customizationFile")
           </p>
           <p>
           passphrase = exportConfigProp.get("passphrase")
           project = exportConfigProp.get("project")
           </p>
           <p>
           <strong># connectToServer(exportUser, exportPasswd, adminUrl)
           connect(userConfigFile='connect.properties', userKeyFile='key.properties', url='t3://patten:30001')
           </strong> ALSBConfigurationMBean = findService("ALSBConfiguration", "com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
           print "ALSBConfiguration MBean found"
           </p>
           <p>
           print project
           if project == None :
           ref = Ref.DOMAIN
           collection = Collections.singleton(ref)
           if passphrase == None :
           print "Export the config"
           theBytes = ALSBConfigurationMBean.export(collection, true, None)
           else :
           print "Export and encrypt the config"
           theBytes = ALSBConfigurationMBean.export(collection, true, passphrase)
           else :
           ref = Ref.makeProjectRef(project);
           print "Export the project", project
           collection = Collections.singleton(ref)
           print "MADE IT HERE", project
           <strong> theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
           </strong> print "MADE IT HERE 2", project
           </p>
           <p>
           aFile = File(exportJar)
           out = FileOutputStream(aFile)
           out.write(theBytes)
           out.close()
           print "ALSB Configuration JAR file: "+ exportJar + " has been exported"
           </p>
           <p>
           if customFile != None:
           print collection
           customList = ArrayList()
           query = EnvValueQuery(None, Collections.singleton(EnvValueTypes.WORK_MANAGER), collection, false, None, false)
           customEnv = FindAndReplaceCustomization('Set the right Work Manager', query, 'Production System Work Manager')
           customList.add(customEnv)
           query = EnvValueQuery(None, Collections.singleton(EnvValueTypes.SERVICE_URI), collection, false, 'winthrop.namerica.idexxi.com:50002', false)
           customEnv = FindAndReplaceCustomization('Update To the Correct Server and Port Number', query, 'wesley.namerica.idexxi.com:50005')
           print 'EnvValueCustomization created'
           customList.add(customEnv)
           print customList
           aFile = File(customFile)
           out = FileOutputStream(aFile)
           Customization.toXML(customList, out)
           out.close()
           </p>
           <p>
           print "ALSB Dummy Customization file: "+ customFile + " has been exported"
           except:
           raise
           dumpStack()
           #=======================================================================================
           # Utility function to load properties from a config file
           #=======================================================================================
           </p>
           <p>
           def loadProps(configPropFile):
           propInputStream = FileInputStream(configPropFile)
           configProps = Properties()
           configProps.load(propInputStream)
           return configProps
           </p>
           <p>
           #=======================================================================================
           # Connect to the Admin Server
           #=======================================================================================
           </p>
           <p>
           def connectToServer(username, password, url):
           connect(username, password, url)
           domainRuntime()
           </p>
           <p>
           
           # EXPORT script init
           try:
           exportAll(sys.argv[1])
           </p>
           except:
           print "Unexpected error: ", sys.exc_info()[0]
           dumpStack()
           raise
           
           
           
           
           
           When I connect to the admin server using the "connectToServer" command (commented out in the code above) the script works fine. When I tried to use the "connect" command, using a connect.properties file instead of a plain text userid and password, the line:
           <strong>theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)
           
           </strong>fails and I get an error that says: <strong>AttributeError: 'None' object has no attribute 'exportProjects'
           
           </strong>Can someone explain to me the difference between these two commands, and if there is anything I can do to tweak this code to get it working using 'connect' vs. 'connectToServer' syntax?
           
      </blockquote>
        • 1. Re: WLST & ALSB AttributeError: 'None' object has no attribute 'exportProjects'
          655092
          OK, I found my error. Dumb Code mistake... but at least I found it.

          connectToServer is defined as a subroutine in the code, so I needed to modify that (or take it out and put the 2 lines to connect up in the script where it was being called.
          • 2. Re: WLST & ALSB AttributeError: 'None' object has no attribute 'exportProjects'
            948568
            I'm getting the following error while doing an export from alsb2.1 env. using wlst invoked via ant:

            C:\Users\vxvm\import_export_test_ALSB21\import-export>ant export
            Buildfile: build.xml

            export:
            [echo] exportscript: export.py
            [java]
            [java] Initializing WebLogic Scripting Tool (WLST) ...
            [java]
            [java] Welcome to WebLogic Server Administration Scripting Shell
            [java]
            [java] Type help() for help on available commands
            [java]
            [java] Loading export config from : export.properties
            [java] Connecting to t3://localhost:7003 with userid weblogic ...
            [java] Successfully connected to Admin Server 'AdminServer' that belongs to
            domain 'alsb21_domain'.
            [java]
            [java] Warning: An insecure protocol was used to connect to the
            [java] server. To ensure on-the-wire security, the SSL port or
            [java] Admin port should be used instead.
            [java]
            [java] Location changed to domainRuntime tree. This is a read-only tree wit
            h DomainMBean as the root.
            [java] For more help, use help(domainRuntime)
            [java]
            [java]
            [java] ALSBConfiguration MBean found
            [java] None
            [java] Export the config
            [java] Unexpected error: exceptions.AttributeError
            [java] No stack trace available.
            [java] Problem invoking WLST - Traceback (innermost last):
            [java] File "C:\Users\vxvm\import_export_test_ALSB21\import-export\export
            .py", line 96, in ?
            [java] File "C:\Users\vxvm\import_export_test_ALSB21\import-export\export
            .py", line 42, in exportAll
            [java] AttributeError: 'NoneType' object has no attribute 'export'
            [java]
            [java] Java Result: 1

            BUILD SUCCESSFUL

            Here is my export.py:

            from java.io import FileInputStream
            from java.io import FileOutputStream
            from java.util import ArrayList
            from java.util import Collections

            from com.bea.wli.sb.util import EnvValueTypes
            from com.bea.wli.config.env import EnvValueQuery;
            from com.bea.wli.config import Ref
            from com.bea.wli.config.customization import Customization
            from com.bea.wli.config.customization import FindAndReplaceCustomization

            import sys

            #=======================================================================================
            # Utility function to load properties from a config file
            #=======================================================================================
            def exportAll(exportConfigFile):
            try:
            print "Loading export config from :", exportConfigFile
            exportConfigProp = loadProps(exportConfigFile)
            adminUrl = exportConfigProp.get("adminUrl")
            exportUser = exportConfigProp.get("exportUser")
            exportPasswd = exportConfigProp.get("exportPassword")

            exportJar = exportConfigProp.get("exportJar")
            customFile = exportConfigProp.get("customizationFile")

            passphrase = exportConfigProp.get("passphrase")
            project = exportConfigProp.get("project")

            connectToServer(exportUser, exportPasswd, adminUrl)

            ALSBConfigurationMBean = findService("ALSBConfiguration", "com.bea.wli.sb.management.configuration.ALSBConfigurationMBean")
            print "ALSBConfiguration MBean found"

            print project
            if project == None :
            ref = Ref.DOMAIN
            collection = Collections.singleton(ref)
            if passphrase == None :
            print "Export the config"
            theBytes = ALSBConfigurationMBean.export(collection, true, None)
            else :
            print "Export and encrypt the config"
            theBytes = ALSBConfigurationMBean.export(collection, true, passphrase)
            else :
            ref = Ref.makeProjectRef(project);
            print "Export the project", project
            collection = Collections.singleton(ref)
            theBytes = ALSBConfigurationMBean.exportProjects(collection, passphrase)

            aFile = File(exportJar)
            out = FileOutputStream(aFile)
            out.write(theBytes)
            out.close()
            print "ALSB Configuration file: "+ exportJar + " has been exported"

            if customFile != None:
            print collection
            query = EnvValueQuery(None, Collections.singleton(EnvValueTypes.WORK_MANAGER), collection, false, None, false)
            customEnv = FindAndReplaceCustomization('Set the right Work Manager', query, 'Production System Work Manager')
            print 'EnvValueCustomization created'
            customList = ArrayList()
            customList.add(customEnv)
            print customList
            aFile = File(customFile)
            out = FileOutputStream(aFile)
            Customization.toXML(customList, out)
            out.close()

            print "ALSB Dummy Customization file: "+ customFile + " has been created"
            except:
            raise

            #=======================================================================================
            # Utility function to load properties from a config file
            #=======================================================================================

            def loadProps(configPropFile):
            propInputStream = FileInputStream(configPropFile)
            configProps = Properties()
            configProps.load(propInputStream)
            return configProps

            #=======================================================================================
            # Connect to the Admin Server
            #=======================================================================================

            def connectToServer(username, password, url):
            connect(username, password, url)
            domainRuntime()


            # EXPORT script init
            try:
            exportAll(sys.argv[1])

            except:
            print "Unexpected error: ", sys.exc_info()[0]
            dumpStack()
            raise

            and export.properties:

            ##################################################################
            # OSB Admin Security Configuration #
            ##################################################################
            adminUrl=t3://localhost:7003
            exportUser=weblogic
            exportPassword=welcome3
            #exportConfigFile=true

            ##################################################################
            # OSB Jar to be exported #
            ##################################################################
            exportJar=sbconfig.jar
            includeDependencies=true


            ##################################################################
            # Optional passphrase and project name #
            ##################################################################
            #passphrase=123

            ##################################################################
            # Optional, create a dummy customization file #
            ##################################################################
            #customizationFile=devcustomize.xml


            Can someone help me out in resolving the above issue,Thanks!