Saturday, 3 December 2016

Python Script - JMS File Store, JMS Server, JMS Module, JMS Subdeployment and JMS Connection Factory Creation

JMS File Store, JMS Server, JMS Module, JMS Subdeployment and JMS Connection Factory Creation


I want to create JMS File Store, JMS Server, JMS Module, JMS Subdeployment and JMS Connection Factory using Python Script.

My Server Details are,

Cluster Environment: 1 Admin Server and 2 Managed Server (wls_osb1 and wls_osb2) 
Domain Name: soa_domain


Save below weblogic.properties file as weblogic.properties

#################################################################################
# admin server url
   admin.url=t3://localhost:7001
#################################################################################

# Domain Name:
domainName=soa_domain
osbServer1=wls_osb1
osbServer2=wls_osb2

Manage Server Name:
targetServer.1=wls_osb1
targetServer.2=wls_osb2

Cluster Name:
osb_ClusterName=osb_cluster
migrateServerType=MigratableTarget
clusterServerType=Cluster
normalServerType=Server
#################################################################################

#Total how many JMS File Store needs to be create
#File Store Creation
total.filestore=2

#File Store Name
fileStore.1=OFMJMSFileStore1
fileStore.2=OFMJMSFileStore2

#File Store Path
fileStorePath.1=/u01/shared/adapters/FileStore/OFM_OSB1
fileStorePath.2=/u01/shared/adapters/FileStore/OFM_OSB2

#File Store CacheDirectory
filecachedirectory.1=/u01/shared/adapters/FileStore/OFM_OSB1/CacheDirectory
filecachedirectory.2=/u01/shared/adapters/FileStore/OFM_OSB2/CacheDirectory
#---------------------------------------------------------------------------------------
#Total how many JMS Server needs to be create
#JMS Server Creation
total.jmsServer=2

#JMS Server Name
jmsServer.1=OFMJMSServer1
jmsServer.2=OFMJMSServer2
#---------------------------------------------------------------------------------------

#JMS Module Name
jmsModuleName=OFMJMSModule

#JMS Sub-deployment Name
SubdeploymentName=OFMJMSSubDeployment
#---------------------------------------------------------------------------------------
#Total how many Connection Factory needs to be create
#ConnectionFactory Creation
total.cf=7

#Connection Factory Name/JNDI
cfName.1=US1ItemsUpdateCF
cfJNDIName.1=jms/US1ItemsUpdateCF

cfName.2=OFMCF
cfJNDIName.2=jms/OFMCF

cfName.3=MP1ItemsUpdateCF
cfJNDIName.3=jms/MP1ItemsUpdateCF

cfName.4=MK1ItemsUpdateCF
cfJNDIName.4=jms/MK1ItemsUpdateCF

cfName.5=LD1ItemsUpdateCF
cfJNDIName.5=jms/LD1ItemsUpdateCF

cfName.6=ItemsJMSConnectionFactory
cfJNDIName.6=ItemsJMSConnectionFactory

cfName.7=AT1ItemsUpdateCF
cfJNDIName.7=jms/AT1ItemsUpdateCF

#################################################################################

Now, below python script you have to save as create_JMS_Server_FS_Module_SubDeploy_CF.py

#################################################################################

#!/usr/bin/python
from java.io import FileInputStream
import time

propInputStream= FileInputStream('weblogic.properties')
configProps = Properties()
configProps.load(propInputStream)

adminURL= configProps.get('admin.url')
# Enter username and password
adminUserName= ''
adminPassword= ''

Target_Cluster=configProps.get('osb_ClusterName')
Normal_type_Migrate=configProps.get('normalServerType')
Server_type_Cluster=configProps.get('clusterServerType')

total_fileStore_to_create = configProps.get('total.filestore')
total_jms_server_to_create = configProps.get('total.jmsServer')
total_ConnectionFactory_to_create = configProps.get('total.cf')

JMSModuleName = configProps.get('jmsModuleName')
subdeploymentName = configProps.get('SubdeploymentName')
JMSServerName1 = configProps.get('jmsServer.1')
JMSServerName2 = configProps.get('jmsServer.2')

connect(adminUserName, adminPassword, adminURL)
edit()
startEdit()

try:

#################################################################################
                      #       FileStore
#################################################################################

        i=1
        while (i <= int(total_fileStore_to_create)):

            try:
                cd('/')
                FileStoreName=configProps.get('fileStore.'+ str(i))
                FileStore_SharedPath=configProps.get('fileStorePath.'+ str(i))
                FileStore_cacheDirectory=configProps.get('filecachedirectory.'+ str(i))
                TargetServer=configProps.get('targetServer.'+ str(i))
                cmo.createFileStore(FileStoreName)
                cd('/FileStores/'+ FileStoreName)
                cmo.setDirectory(FileStore_SharedPath)
                set('Targets',jarray.array([ObjectName('com.bea:Name='+ TargetServer+',Type='+Normal_type_Migrate)], ObjectName))
                cmo.setCacheDirectory(FileStore_cacheDirectory)
                cmo.setSynchronousWritePolicy('Direct-Write-With-Cache')
                cmo.setFileLockingEnabled(false)

                print 'FileStore: "', FileStoreName,'" is created'
            except:

                i = i + 1

#################################################################################
#       JMSServer
#################################################################################

        j=1
        while (j <= int(total_jms_server_to_create)):

            try:
                cd('/')
                JMSServerName=configProps.get('jmsServer.'+ str(j))
                FileStoreName=configProps.get('fileStore.'+ str(j))
                TargetServer=configProps.get('targetServer.'+ str(j))
                cmo.createJMSServer(JMSServerName)
                cd('/Deployments/'+ JMSServerName)
                cmo.setPersistentStore(getMBean('/FileStores/'+ FileStoreName))
                set('Targets',jarray.array([ObjectName('com.bea:Name='+ TargetServer+',Type='+Normal_type_Migrate)], ObjectName))

                print 'JMSServer: "', JMSServerName,'" is created'
            except:
                j=j+1

#################################################################################
#       
JMSModule
#################################################################################

        cd('/')
        cmo.createJMSSystemResource(JMSModuleName)

        cd('/SystemResources/'+ JMSModuleName)
        set('Targets',jarray.array([ObjectName('com.bea:Name='+Target_Cluster+',Type='+Server_type_Cluster)], ObjectName))

        print 'JMSModule: "', JMSModuleName,'" is created'

#################################################################################
                      #       
Subdeployment
#################################################################################

  
     cd('/SystemResources/'+ JMSModuleName)
        cmo.createSubDeployment(subdeploymentName)

        cd('/SystemResources/'+ JMSModuleName +'/SubDeployments/'+ subdeploymentName)
        set('Targets',jarray.array([ObjectName('com.bea:Name='+ JMSServerName1 +',Type=JMSServer'), ObjectName('com.bea:Name='+ JMSServerName2 +',Type=JMSServer')], ObjectName))

        print 'Subdeployment: "', subdeploymentName,'" is created'

#################################################################################
                      #       
ConnectionFactory
#################################################################################

        k=1
        while (k <= int(total_ConnectionFactory_to_create)):

            try:
                cd('/')
                CFName=configProps.get('cfName.'+ str(k))
                CFJNDIName=configProps.get('cfJNDIName.'+ str(k))
                cd('/JMSSystemResources/'+ JMSModuleName +'/JMSResource/'+ JMSModuleName)
                cmo.createConnectionFactory(CFName)
                cd('/JMSSystemResources/'+ JMSModuleName +'/JMSResource/'+ JMSModuleName +'/ConnectionFactories/'+ CFName)
                set('JNDIName',CFJNDIName)
                cd('/JMSSystemResources/'+ JMSModuleName +'/JMSResource/'+ JMSModuleName +'/ConnectionFactories/'+ CFName +'/SecurityParams/'+ CFName)
                cmo.setAttachJMSXUserId(false)
                cd('/JMSSystemResources/'+ JMSModuleName +'/JMSResource/'+ JMSModuleName +'/ConnectionFactories/'+ CFName +'/ClientParams/'+ CFName)
                cmo.setClientIdPolicy('Restricted')
                cmo.setSubscriptionSharingPolicy('Exclusive')
                cmo.setMessagesMaximum(10)
                cd('/JMSSystemResources/'+ JMSModuleName +'/JMSResource/'+ JMSModuleName +'/ConnectionFactories/'+ CFName +'/TransactionParams/'+ CFName)
                cmo.setXAConnectionFactoryEnabled(true)
                cd('/SystemResources/'+ JMSModuleName +'/SubDeployments/'+ subdeploymentName)
                set('Targets',jarray.array([ObjectName('com.bea:Name='+ JMSServerName1 +',Type=JMSServer'), ObjectName('com.bea:Name='+ JMSServerName2 +',Type=JMSServer')], ObjectName))
                cd('/JMSSystemResources/'+ JMSModuleName +'/JMSResource/'+ JMSModuleName +'/ConnectionFactories/'+ CFName)
                cmo.setSubDeploymentName(subdeploymentName)
                print 'ConnectionFactory: "', CFName,'" is created'

            except:
                k=k+1

#################################################################################

except:
print('--> something went wrong, bailing out', sys.exc_info()[0])
stopEdit('y')
raise SystemExit

save()
activate()

#################################################################################

Procedure to run above python script,

Step1: Copy your weblogic.properties and create_JMS_Server_FS_Module_SubDeploy_CF.py        
           in <Middleware_Home>/wlserver_10.3/common/bin location. Where wlst.sh or wlst.cmd present
Step2: Run ./wlst.sh (if you install middleware in UNIX) or wlst.cmd (if you install middleware in 
            windows)
Step 3: When Username and Password asked that time you have to pass weblogic console username and password.

No comments:

Post a Comment