In my previous article, Creating and scaling Dynamic Clusters in Weblogic 12c, I described the creation and scaling of Dynamic Clusters. I used the Weblogic Console to create the Dynamic Clusters and change the number of servers.
Most of the time you will use some wlst scripting to create and manage your Weblogic environments.
In this article I will show you how to create Dynamic Clusters en how you can scale them.
The example scripts from the Oracle documentation where used as base for the following script.
It is just a simple create script to show you how easy it is to create a Dynamic Cluster via wlst. So no fancy functions and exception handling in there. Yet …
createDynamicCluster.py
print '--- Set properties for dynamic Cluster creation' clusterName='dyna-cluster' serverTemplate='dyna-server-Template' serverNamePrefix='dyna-server-' listenAddress='192.168.100.4${id}' listenPort=8000 listenPortSSL=9000 maxServerCount=2 print '--- Connect to the AdminServer' try: connect('weblogic','Welcome01','t3://wls01.domain.local:7001') except err: print "--- Can't connect to AdminServer, "+err sys.exit(2) print '--- Start an edit session' edit() startEdit() print '--- Creating the server template '+serverTemplate+' for the dynamic servers and set the attributes' dynamicServerTemplate=cmo.createServerTemplate(serverTemplate) dynamicServerTemplate.setListenAddress(listenAddress) dynamicServerTemplate.setListenPort(listenPort) dynamicServerTemplateSSL=dynamicServerTemplate.getSSL() dynamicServerTemplateSSL.setListenPort(listenPortSSL) print '--- Creating the dynamic cluster '+clusterName+', set the number of dynamic servers and designate the server template to it.' dynamicCluster=cmo.createCluster(clusterName) dynamicServers=dynamicCluster.getDynamicServers() dynamicServers.setMaximumDynamicServerCount(maxServerCount) dynamicServers.setServerTemplate(dynamicServerTemplate) print '--- Designating the Cluster to the ServerTemplate' dynamicServerTemplate.setCluster(dynamicCluster) print '--- Set the servername prefix to '+serverNamePrefix dynamicServers.setServerNamePrefix(serverNamePrefix) print '--- Set Calculate Listen Port and Machinename based on server template' dynamicServers.setCalculatedMachineNames(true) dynamicServers.setCalculatedListenPorts(true) print '--- Save and activate the changes' save() activate() serverConfig()
Running the script with wlst will produce the following output and will create a Dynamic Cluster with two Dynamic Servers.
[oracle@wls01 ~]$ ${WL_HOME}/common/bin/wlst.sh createDynamicCluster.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands --- Set properties for dynamic Cluster creation --- Connect to the AdminServer Connecting to t3://wls01.domain.local:7001 with userid weblogic ... Successfully connected to Admin Server "AdminServer" that belongs to domain "demo_domain". Warning: An insecure protocol was used to connect to the server. To ensure on-the-wire security, the SSL port or Admin port should be used instead. Start an edit session Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit(). For more help, use help('edit') Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. --- Creating the server template dyna-server-Template for the dynamic servers and set the attributes --- Creating the dynamic cluster dyna-cluster, set the number of dynamic servers and designate the server template to it. --- Designating the Cluster to the ServerTemplate --- Set the servername prefix to dyna-server- --- Set Calculate Listen Port and Machinename based on server template --- Save and activate the changes Saving all your changes ... Saved all your changes successfully. Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. Activation completed
As you might expect, it is way faster than clicking through the Weblogic Console.
Next step will be to scale the Dynamic Cluster up to four Dynamic Servers.
scaleDynamicCluster.py
print '--- Set properties for dynamic Cluster creation' clusterName='dyna-cluster' maxServerCount=4 print '--- Connect to the AdminServer' try: connect('weblogic','Welcome01','t3://wls01.domain.local:7001') except err: print "Can't connect to AdminServer, "+err sys.exit(2) print '--- Start an edit session' edit() startEdit() print '--- Change the maximum number of dynamic servers' cd('/Clusters/%s' % clusterName ) dynamicServers=cmo.getDynamicServers() dynamicServers.setMaximumDynamicServerCount(maxServerCount) print '--- Save and activate the changes' save() activate() serverConfig()
Running the script with wlst will produce the following output and will scale up to four Dynamic Servers.
[oracle@wls01 ~]$ ${WL_HOME}/common/bin/wlst.sh scaleDynamicCluster.py Initializing WebLogic Scripting Tool (WLST) ... Welcome to WebLogic Server Administration Scripting Shell Type help() for help on available commands --- Set properties for dynamic Cluster creation --- Connect to the AdminServer Connecting to t3://wls01.domain.local:7001 with userid weblogic ... Successfully connected to Admin Server "AdminServer" that belongs to domain "demo_domain". Warning: An insecure protocol was used to connect to the server. To ensure on-the-wire security, the SSL port or Admin port should be used instead. --- Start an edit session Location changed to edit tree. This is a writable tree with DomainMBean as the root. To make changes you will need to start an edit session via startEdit(). For more help, use help('edit') Starting an edit session ... Started edit session, please be sure to save and activate your changes once you are done. --- Change the maximum number of dynamic servers --- Save and activate the changes Saving all your changes ... Saved all your changes successfully. Activating all your changes, this may take a while ... The edit lock associated with this edit session is released once the activation is completed. Activation completed
As mentioned before, the scripts are very limited and just show you how easy it is to create Dynamic Clusters using wlst. The scripts can be made as comprehensive as you need (want) them to be.
I will create some more examples and post them as I get them ready.
Imagine the possibilities when you create scripts you can connect to your monitoring system. Capacity on demand!