Pages

Showing posts with label WLST. Show all posts
Showing posts with label WLST. Show all posts

Thursday, August 7, 2014

Create with WLST a SOA Suite, Service Bus 12.1.3 Domain

When you want to create a 12.1.3 SOA Suite, Service Bus Domain, you have to use the WebLogic config.sh utility.  The 12.1.3 config utility is a big improvement when you compare this to WebLogic 11g. With this I can create some complex cluster configuration without any after configuration.
But if you want to automate the domain creation and use it in your own (provisioning) tool/script then you can use the following scripts to create a normal SOA Suite, Service Bus domain together with BPM, BAM & the Enterprise scheduler options.

Off course!!! use this script only for development, do some intensive testing on this domain and don't use this script in production or acceptance ( use the supported config.sh utility).

The second part of this blog we will create a cluster configuration with a WLST offline script.

Before we can start we need to have a FMW database repository.  You can use the RCU utility ( MDW_HOME/oracle_common/bin/rcu) to create one.

Enable the following options



Here you can also see the improvements in the 12c FMW domain creation like

  • ServerGroups, an easy way of assigning libraries,  applications and datasources to managed servers and clusters. It will auto-detect if a managed server is part of a cluster :-)
  • Service Table Datasource together with the getDatabaseDefaults() function, no need to change all the datasources. It will re-use the RCU configuration data.


Use this to start the creation of our domain.
MDW_HOME/oracle_common/common/bin/wlst.sh soa_domain_1213.py

Here we need to do some extra configuration like

  • Change a few datasources so they will use the Oracle XA driver

With this as output.



When you want to create a cluster configuration you can use the following script.



Tuesday, April 30, 2013

Offline Oracle Service Bus Configuration export

With Oracle Service Bus PS6 or 11.1.1.7 we finally have an new offline build tool with does not require Eclipse (OEPE).  With this OSB configjar tool ( located in the OSB home /tools/configjar/ folder ) you can make OSB export sbconfig jar based on 1 or more OSB projects or even with more then one OSB Configuration projects. Plus have total control what to include or exclude.

In this blogpost I will show you first, how to do this in a shell script with I run on a linux server and the second part how to do the same with maven.

all demo code is available at github and contains a demo OSB workspace.

First step is to create an configuration setting xml with will be used by the configjar utility

here is an example of a OSB workspace configuration file with all its project and resources

<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
    <source>
        <project dir="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/source/ReliableMessageWS"/>
        <project dir="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/source/XSDvalidation"/>
        <system  dir="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/source/OSB Configuration"/>
    </source>

    <configjar jar="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/export/sbconfig-resources.jar">
         <projectLevel includeSystem="true"/>
    </configjar>
    
</configjarSettings>


and in this case only one project and an separate export for particular system resource

<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
    <source>
        <project dir="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/source/ReliableMessageWS"/>
        <system  dir="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/source/OSB Configuration"/>
    </source>
    <configjar jar="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/export/sbconfig-rel.jar">
        <projectLevel includeSystem="false"/>
    </configjar>
    <configjar jar="/home/oracle/projects/soa_tools/maven_osb_ps6_tool/export/sbconfig-rel-system.jar">
         <resourceLevel>
            <resources>
                <include name="**/*.jndi"/>
            </resources>
        </resourceLevel>
    </configjar>
</configjarSettings>


To see all the possible options see this Oracle document page

Next step is to use this setting xml in our shell script.


That's all, this will generate the sbconfig jars but we can also do the same with maven.

The rest of the blog will describe the maven build and deploy.

First we also need to have a setting xml which will be used by maven. The OSB setting file does not support environment variables so I need to use the com.google.code.maven-replacer-plugin maven plugin to replace the tokens.

This is the workspace setting xml ( located in the OSB workspace folder)

<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
    <source>
        <project dir="$WORKSPACE_HOME$/ReliableMessageWS"/>
        <project dir="$WORKSPACE_HOME$/XSDvalidation"/>
        <system  dir="$WORKSPACE_HOME$/OSB Configuration"/>
    </source>

    <configjar jar="$BUILDDIR$/$ARTIFACTID$-$VERSION$.jar">
         <projectLevel includeSystem="$OSBINCLUDESYSTEM$"/>
    </configjar>
    
</configjarSettings>


This is de project setting xml ( located in the OSB project folder)

<configjarSettings xmlns="http://www.bea.com/alsb/tools/configjar/config">
    <source>
        <project dir="$WORKSPACE_HOME$/ReliableMessageWS"/>
        <system  dir="$WORKSPACE_HOME$/OSB Configuration"/>
    </source>
    <configjar jar="$BUILDDIR$/$ARTIFACTID$-$VERSION$.jar">
         <projectLevel includeSystem="$OSBINCLUDESYSTEM$"/>
    </configjar>
</configjarSettings>

The workspace pom  ( located in the OSB workspace folder) , where the path to parent pom is different and the target folder

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>biemond.core.osb</groupId>
    <artifactId>tool</artifactId>
    <version>1.0</version>
    <relativePath>../parent/pom.xml</relativePath>
  </parent>
  <groupId>biemond</groupId>
  <artifactId>osb.source</artifactId>
  <version>1.5.1-SNAPSHOT</version>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>    
    <buildDirectory>${project.basedir}/../target</buildDirectory>
    <buildOsbBase>${project.basedir}/../</buildOsbBase>
    <osbProjectBase>${project.basedir}</osbProjectBase>
    <osbIncludeSystem>true</osbIncludeSystem>
  </properties>
  <scm>
    <connection>scm:git:git@github.com:biemond/soa_tools.git</connection>
    <developerConnection>scm:git:git@github.com:biemond/soa_tools.git</developerConnection>
    <url>https://github.com/biemond/soa_tools/tree/master/maven_osb_ps6_tool</url>
    <tag>osb.source-1.3.3</tag>
  </scm>  
</project>

The OSB project pom ( located in the OSB project folder) , this one is level deeper then the workspace pom.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>biemond.core.osb</groupId>
    <artifactId>tool</artifactId>
    <version>1.0</version>
    <relativePath>../../parent/pom.xml</relativePath>
  </parent>
  <groupId>biemond</groupId>
  <artifactId>osb.source.reliablemessagews</artifactId>
  <version>1.4.0-SNAPSHOT</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>    
    <buildDirectory>${project.basedir}/../../target</buildDirectory>
    <buildOsbBase>${project.basedir}/../../</buildOsbBase>
    <osbProjectBase>${project.basedir}/../</osbProjectBase>
    <osbIncludeSystem>true</osbIncludeSystem>
  </properties>

  <scm>
    <connection>scm:git:git@github.com:biemond/soa_tools.git</connection>
    <developerConnection>scm:git:git@github.com:biemond/soa_tools.git</developerConnection>
    <url>https://github.com/biemond/soa_tools/tree/master/maven_osb_ps6_tool</url>
    <tag>HEAD</tag>
  </scm>  

</project>


Here is the parent pom with the prepare package phase to replace the tokens in the osb setting file, package for making a sbconfig jar and the deploy phase which use the WLST import.py script to deploy it to the server.


Last step is to add some variables to the maven settings.xml, which contains all the WebLogic and OSB variables




At last we can generate some artifacts.

. osb.sh ( sets maven, java environment variables )

mvn package, builds all or 1 project depends on the location in the source folder ( OEPE Workspace )

mvn deploy -Dtarget-env=dev-osb, deploy to the dev OSB server

mvn release:prepare, prepare a release

mvn release:perform -Dtarget-env=dev-osb -DconnectionUrl=scm:git:git@github.com:biemond/soa_tools.git

Here is the url of the demo workspace on github

Sunday, October 7, 2012

Build and Deploy OSB projects with Maven

2 years ago I already did the same with ANT and now I migrated these scripts to Maven. These Maven poms can still do the same like my ANT scripts.
  • Build and deploy an OSB OEPE workplace
  • Build one OSB project.
  • Export OSB projects from an OSB server and generate a customization plan.
Here you can find my code https://github.com/biemond/soa_tools/tree/master/maven_osb_ps5 or the PS6 version https://github.com/biemond/soa_tools/tree/master/maven_osb_ps6
or with the new PS6 configjar tool which can create offline OSB exports without OEPE http://biemond.blogspot.nl/2013/04/offline-oracle-service-bus.html 

Also the readme contains some examples how to this from Java without the help of Maven or Ant.

I based my scripts on the following software and folders

My Environment Oracle OSB PS5 or 11.1.1.6 with Maven 3.0.4

JVM                         = JDK 1.7_07 x64
Middleware home      = /opt/oracle/wls/wls11g
OSB & Oracle home = /opt/oracle/wls/wls11g/Oracle_OSB1
WebLogic home       = /opt/oracle/wls/wls11g/wlserver_10.3
Oepe home               = /opt/oracle/wls/wls11g/oepe11.1.1.8

My Maven settings.xml


run . osb.sh to set all the Maven, Java variables.

To build a project or the whole OEPE workspace use this
mvn package

To deploy or export an existing OSB server use this target-env=dev so it uses the right Maven profile for the WebLogic Settings
mvn deploy -Dtarget-env=dev

Prepare a release
mvn release:prepare

Perform a release
mvn release:perform -Dtarget-env=dev 
-DconnectionUrl=scm:git:git@github.com:biemond/soa_tools.git



the pom.xml in the Maven_osb_ps5 folder build the whole source folder workspace, this generates a jar in the export folder with the same name as your pom definition.

the pom.xml in the Maven_osb_ps5/source/ReliableMessageWS and Maven_osb_ps5/source/XSDvalidation folder build only this project and generate a jar in the export folder with the same name as your pom definition.

the pom.xml in the Maven_osb_ps5/export folder export everything from the OSB server and puts the jar in the import folder.

Here is an example of a pom which build and deploys the whole OSB OEPE workspace.
This pom has the following plugins

  • exec-maven-plugin for building the OSB jar and deploy the jar to the OSB server, 
  • maven-assembly-plugin for adding the OSB jar as maven artifact 
  • maven-release-plugin for OSB releases. 

And here the assembly to add the generated OSB jar to Maven artifact

Tuesday, July 3, 2012

Do WebLogic configuration from ANT

With WebLogic WLST you can script the creation of all your Application DataSources or SOA Integration artifacts( like JMS etc). This is necessary if your domain contains many WebLogic artifacts or you have more then one WebLogic environment. If so, you want to script this so you can configure a  new WebLogic domain in minutes and you can repeat this task with always the same result.

I started a new project on Github https://github.com/biemond/soa_tools/tree/master/ant_wls which can do this from ANT, for this I created some WLST ANT macrodefs. These ANT targets can be invoked many times ( great for Continuous Integration ) and if the object already exists it rollbacks the edit action and give a BeanAlreadyExists exception. Great way to keep all your environments in sync.

These ANT scripts can do the following configuration.

  • Create users and roles
  • Reset or create JDBC DataSources 
  • File or JDBC persistence stores
  • JMS servers
  • JMS modules
  •    Sub Deployments
  •    Foreign Servers
  •       Foreign Server Destinations
  •       Foreign Server Connection Factories
  •    Connection Factories
  •    Queues ( Distributed )
  •    Topics ( Distributed )
  •    SAF Remote Contexts
  •    SAF Imported Destinations 
  • SAF agents 

Still to do  is the creation of SAF Imported Destinations.   

An example of an ANT macrodef with the WLST code for the creation of a Queue or a Topic on a WebLogic server or cluster, also supports distributed Queue or Topics plus re-directing to an other Queue.



Snippet of the ANT build.xml with the ANT target which calls this Macrodef and uses the build.properties for all the JMS objects definitions. The foreach is provided by the ANT Contrib library, this is not part of ANT and need to downloaded separately .


Snippet of the build.properties with all the weblogic environments. Just change wls.environment to acc or   some other value.

wls.environment=dev

# dev deployment server weblogic
dev.serverURL=t3://localhost:7001
dev.user=weblogic
dev.password=weblogic1
dev.target=AdminServer

# acceptance deployment server weblogic
acc.serverURL=t3://soaps3:7001
acc.user=weblogic
acc.password=weblogic1
acc.target=soa_server1



# All jms objects entries like Queue, Topic or distributed
queuesOrTopics=error1,queue1

# JMS module name
error1.jmsModule=JMSModule1
# JMS module subdeployment.
error1.subDeployment=JmsServer
error1.jmsName=ErrorQueue      
error1.jmsJNDIName=jms/ErrorQueue
# queue, topic
error1.jmsType=queue
# distributed true ,false
error1.distributed=false
error1.balancingPolicy=xxxxx
# redirect to an error Queue
error1.redirect=false
error1.limit=xxxxx
error1.policy=xxxxx      
error1.errorObject=xxxxx

queue1.jmsModule=JMSModule1
queue1.subDeployment=JmsServer
queue1.jmsName=Queue1      
queue1.jmsJNDIName=jms/Queue1
queue1.jmsType=queue
queue1.distributed=false
queue1.balancingPolicy=xxxxx
queue1.redirect=true
queue1.limit=3
queue1.policy=Redirect
queue1.errorObject=ErrorQueue

And we can run the ANT target when we execute the following command.

ant -f build.xml createCreateJMSQueuesOrTopics


https://github.com/biemond/soa_tools/tree/master/ant_wls

Wednesday, April 20, 2011

Easy way to start your WebLogic Servers with the NodeManager in the background

When you work with Fusion Middleware you probably know you need to start the WebLogic Servers with the scripts located in the bin folder of your WebLogic domain and you need to start these servers in the background else these processes will be killed when you log out. On unix you can start these scripts in the background and on Windows you can try to make some Windows services with the service utility of WebLogic, but you need to update the path, classpath and java parameters of this service ( in the registry)  so it matches with the startup script. ( easy to make mistakes and memory changes can't be done from the WebLogic Console )

In this blogpost I will show you how you can start a WebLogic server from WLST in combination with a NodeManager which is started in the background of the server.

The first step is starting the Nodemanager once so the nodemanager.properties file is created. After this you can stop the nodemanager by killing the process
Go to XXX\wlserver_10.3\server\bin and start startNodeManager.cmd

Open the nodemanager.properties in a editor ( located in XXX\wlserver_10.3\common\nodemanager )
For FMW you need to change the StopScriptEnabled property to true, do the same for StartScriptEnabled 


On windows there is a utility to make a service for this nodemanager.
Go to XXX\wlserver_10.3\server\bin and start installNodeMgrSvc.cmd


Start the service

To automatically start a WebLogic Server and not prompted for a username / password  you need to create a boot.properties with username and password and put this in every server folder.

Start startWebLogic.cmd , located in the bin folder of your domain and when it is started then you can shut it down. Do the same for all the Managed Servers. start startManagedWebLogic.cmd xxxx, where xxxx is the name of the managed servers.

Go to XXX\domains\soa_domain\servers and create in every server folder a new folder called security
and create a boot.properties file and with the following content
username=weblogic
password=yourpassword

put this file in every security folder.

Next step is to set the nodemanager username and password
Start your WebLogic AdminServer
Go to the WebLogic Console, Domain and then open the Security tab

 Click on the Advanced link and set the nodemanager username and password

Activate the changes and shutdown the AdminServer

Now you try to start the AdminServer with WLST which connects to the NodeManager


Start XXX\wlserver_10.3\common\bin\wlst.cmd
you will see wls:/offline>

Connect to the NodeManager by using nmConnect
nmConnect('weblogic','yourpassword','localhost','5556','your_domain','C:/XXX/user_projects/domains/your_domain','ssl')
You need to see the  following Successfully Connected to Node Manager.

start the AdminServer
nmStart('AdminServer')

Ask the status of the AdminServer
nmServerStatus('AdminServer')

Stop the AdminServer
nmKill('AdminServer')

disconnect from the nodemanager
nmDisconnect()

Now you can make some cmd and WLST scripts

first create a start WLST script, called startDomain.wlst with the following content
nmConnect('weblogic','yourpassword','localhost','5556','wls_domain','C:/XXX/user_projects/domains/wls_domain','ssl')
nmStart('AdminServer')

nmStart('soa_server1')
nmDisconnect()


and a cmd script startDomain.cmd
call XXX\wlserver_10.3\common\bin\wlst.cmd startDomain.wlst


Now you have a script what you can add to windows task schedular or an other utility

Wednesday, August 4, 2010

WLST Scripting with Oracle Enterprise Pack for Eclipse (OEPE)

With the new OEPE 11.1.1.6 you can create and run all your WLST scripts from Eclipse. This blogpost will give you a WLST jumpstart in the Eclipse IDE. The WLST / Phyton support for the Eclipse IDE is one of the many new OEPE features. For more info read the Markus Eisele great blogpost about all the new and cool features of OEPE.

Let's do some WLST scripting. Before you can start you need to download and install WebLogic. Off course you also need to download OEPE 11.1.1.6

Start Eclipse and provide the workspace folder. 

Click on Workbench
You need to create a new Project where WebLogic can be targeted. Choose for example Dynamic Web Project. ( You don't need to create a Web Application for WLST scripting )
Provide the name of the Project and click on New Runtime.

Open the Bea or Oracle Node and select a WebLogic release. The latest WLS release is 11gR1 PatchSet 2
Browse to the WebLogic Home this is the wlserver_10.3 folder in the FMW Home.
Click on Finish.
Select your just created web project and open the project options. Go to the Project Facets and enable the Oracle WebLogic Scripting Tools support.
This enables the WLST scripting for this project.

Select the wlst folder and create a new WLST Script.
Choose for a default template or make a empty wlst file. In this case we will use "Create Basic WebLogic Domain"
This will always create a file called newWlst.py in the wlst folder.
Change the domain folder in /user_project/domains/...
Rename this wlst file else it will be overwritten by a other WLST script creation.
Select your Domain script and in Run As, choose for WLST Run.
This will create the WebLogic Domain.
Next step is to start this WebLogic Domain. Select New and go to the Server node and click on Next.
Choose for Oracle WebLogic Server 11gR1 PatchSet 2 in the Oracle node.
Browse to the new WLS Domain folder.
In the server window you can start this WebLogic server.
After the WebLogic is started, you can open the MBean Browser. Go to the Window Menu , Show View and choose Other.
Select WebLogic MBean Explorer in the WebLogic node.
This will give you an overview of all the MBeans. You can drag and drop a MBean to your WLST script.
To this WLS Domain we can add some JMS messaging by creating a new WLST Script.
Select the "Configure JMS System Resource" Template.
Rename this script.
And when you run this script you will see the output in the console window.
That's all for the jumpstart.

Thursday, July 15, 2010

OSB 11g ANT deployment scripts

For Oracle Service Bus 10.3 & 11g you can use the ANT / WLST deployment scripts provided by Oracle. With these scripts you can make an export 1 or more OSB projects from sbconsole, make a deployment / configuration plan and you can import a project jar to the sbconsole.

I made some changes to these scripts so it only needs one property file (build.properties ), you don't need to use the import or export.properties files. The second change I made, is support for making an export jar from the OSB workspace ( OEPE environment ). Very important! Do this on a copy of your workspace or use subversion because maybe you need to delete the .metadata folder for a successful export. ( you will loose all your workspace settings )

When you want to do this with Maven instead of ANT you can use these scripts and poms https://github.com/biemond/soa_tools/tree/master/maven_osb_ps5
or for PS6
https://github.com/biemond/soa_tools/tree/master/maven_osb_ps6
or with the new PS6 configjar tool which can create offline OSB exports without OEPE http://biemond.blogspot.nl/2013/04/offline-oracle-service-bus.html 

Here is the build.properties.
The ANT build.xml
When you want to run the ANT task from CMD then you need these environment variables
You can use these ANT tasks
ant exportFromWorkspace ( do this on a copy of your OEPE workspace )
ant importToOSB
ant exportFromOSB

Or you can run these task in JDeveloper, then you need to update these classpath entries for ANT


And run your ANT task from JDeveloper.

Download the PS5 or PS6 source code on my github https://github.com/biemond/soa_tools

Tuesday, April 13, 2010

Resetting Weblogic datasources with ANT

When you are working with Weblogic JDBC Datasources for example in a Web Application, EJB or in an AQ or Database resource adapter then there is a possibility that the database sessions are in an invalid state when you change something like a package or object type in the database. This can be solved by restarting all the managed servers, reset all the Datasources in the Weblogic console or use this ANT or WLST script. This script is an ANT file where I use the WLST ANT task to fire some wlst and phyton commandos.
This ANT target works fast and can be easily integrated in your deployed script.

the reset.xml ANT build file.
<?xml version="1.0" encoding="iso-8859-1"?>
<project name="resetAllDatasources" default="resetJDBC">

  <target name="resetJDBC">
   <property name="admin.User" value="weblogic"/>
   <property name="admin.Password" value="weblogic1"/>
   <property name="admin.Url" value="localhost"/>
   <property name="admin.Port" value="7101"/>
   <property name="admin.ServerTarget" value="DefaultServer"/>

   <property name="datasources" value="hrDS,scottDS"/>

    <wlResetDatasource adminUser="${admin.User}" 
            adminPassword="${admin.Password}" 
            adminUrl="${admin.Url}" 
            adminPort="${admin.Port}" 
            serverTarget="${admin.ServerTarget}" 
            datasourceNames="${datasources}"/>

  </target>

 <macrodef name="wlResetDatasource">
  <attribute name="adminUser"/>
  <attribute name="adminPassword"/>
  <attribute name="adminUrl"/>
  <attribute name="adminPort"/>
  <attribute name="serverTarget"/>
  <attribute name="datasourceNames"/>
  <sequential>
    <wlst failonerror="true" debug="true" arguments="@{adminUser} @{adminPassword} @{adminUrl} @{adminPort} @{serverTarget} @{datasourceNames}">
      <script>
          adminUser=sys.argv[0]
          adminPassword=sys.argv[1]
          adminUrl="t3://"+sys.argv[2]+":"+sys.argv[3]
          serverTarget=sys.argv[4]
          datasourceNames=String(sys.argv[5]).split(",")
          connect(adminUser,adminPassword,adminUrl)
          print 'all datasource: '+sys.argv[5]
          domainRuntime()
          for datasourceName in datasourceNames:
           print 'resetting datasource: '+datasourceName
           cd('/')
           cd('ServerRuntimes/'+serverTarget+'/JDBCServiceRuntime/'+serverTarget+'/JDBCDataSourceRuntimeMBeans/'+datasourceName)
           objs = jarray.array([], java.lang.Object)
           strs = jarray.array([], java.lang.String)
           invoke('reset', objs, strs)
      </script>
    </wlst>
  </sequential>
 </macrodef>

</project>
And the windows bat file to startup the ANT target. I only need a ANT home and the weblogic.jar
set ORACLE_HOME=C:\oracle\MiddlewareJdev11gR1PS1
set ANT_HOME=%ORACLE_HOME%\jdeveloper\ant
set PATH=%ANT_HOME%\bin;%PATH%
set JAVA_HOME=%ORACLE_HOME%\jdk160_14_R27.6.5-32
set ANT_OPTS=%ANT_OPTS% -XX:MaxPermSize=128m

set CLASSPATH=%CLASSPATH%;%ORACLE_HOME%\wlserver_10.3\server\lib\weblogic.jar

ant -f reset.xml
I also made a WLST script which automatically finds the managed servers in the connected domains and resets the user created datasources ( I skipped the Soa datasource )
domainRuntime()

drs = ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean"); 
domainconfig =  mbs.getAttribute(drs, "DomainConfiguration");
servers = mbs.getAttribute(domainconfig, "Servers"); 
for server in servers:
  serverName = mbs.getAttribute(server,'Name')
  print 'server: '+serverName
  if serverName == "AdminServer":
    print 'server skipped'
  else:
    dsBean = ObjectName('com.bea:ServerRuntime='+serverName+',Name='+serverName+',Location='+serverName+',Type=JDBCServiceRuntime')
    if dsBean is None:
      print 'not found'
    else:
      datasourceObjects = mbs.getAttribute(dsBean, 'JDBCDataSourceRuntimeMBeans')  
      for datasourceObject in datasourceObjects:
        if datasourceObject is None:
          print 'datasource not found'
        else:
          Name = mbs.getAttribute(datasourceObject,'Name')
          x = Name.find("SRA",0,3 )
          if ( Name.find("SOA",0,3 ) == -1 and Name.find("mds",0,3 ) == -1 and Name.find("EDN",0,3 ) == -1 and Name.find("BAM",0,3 ) == -1 and Name.find("Ora",0,3 ) == -1):  
            mbs.invoke(datasourceObject, 'reset',None,None)  
            print 'reset: '+Name

Thursday, February 4, 2010

Invoking FMW Application MBeans in Weblogic

In the Fusion Middleware 11g Oracle added a lot of ADF, MDS and Soa Suite Application MBeans. These MBeans have attributes and operations which you can set , get or invoke. So with these MBeans you can control ADF, MDS or a Soa composite. Off course you do the same in the FMW Enterprise Manager(EM) application but sometimes it can be better to script actions so you can garantee that your Acceptance or Production Weblogic are the same. So lets take a look add these FMW MBeans and play with these FMW Mbeans. First we need to go the EM application to get an overview. The EM has a nice MBeans Browser.
Here you get a list of the Application Defined MBeans. These MBeans can't be invoked with a specific WLST command.
For example we can select a Soa composite application.
Here we can see or change the attributes of this Composite Mbean, We can retrieve these attributes and some of them we can change when the Access of the attribute = RW

In the operation tab we can see the operation methods of this MBean. You also can invoke the operation in this EM application just by selecting the operation.
Now lets invoke these operations from WLST or rettrieve an attribute
We need to start WLST
cd FMW_HOME\wlserver_10.3\common\bin
wlst.cmd
connect('weblogic','weblogic1','t3://localhost:7001')

To stop WLST we can use
disconnect()
exit()

In the WLST windows after we are connected we can go the domainRuntime where the application MBeans are located. domainRuntime()
Then we can lookup the MBean, the MBean can be seen in the MBean Browser ( above the atrributes & operations) For example mdsBean = ObjectName('oracle.mds.lcm:name=MDSDomainRuntime,type=MDSDomainRuntime')
We can invoke for example the operation listRepositories, this operation has no parameters.
Type repositories = mbs.invoke(mdsBean, 'listRepositories',None,None)
When the operation has parameters then we need to provide the parameters and the type of these parameters like this.
params = [Name]
sign = ['java.lang.String']
partitions = mbs.invoke(mdsBean, "listPartitions", params, sign)
To get an MBean attribute value we can use getAttribute
mdsObject = ObjectName(repository)
Name = mbs.getAttribute(mdsObject, 'Name')
Here is an example where I retrieve all the MDS repositories with the parttions.
domainRuntime()

mdsBean = ObjectName('oracle.mds.lcm:name=MDSDomainRuntime,type=MDSDomainRuntime')

print 'invoke listRepositories without parameters on mds bean'
repositories = mbs.invoke(mdsBean, 'listRepositories',None,None)
for repository in repositories:
mdsObject = ObjectName(repository)
Name = mbs.getAttribute(mdsObject, 'Name')
print 'mds repository object: ', Name
params = [Name]
sign = ['java.lang.String']
partitions = mbs.invoke(mdsBean, "listPartitions", params, sign)
for partition in partitions:
print 'partition: ', partition

or a Soa Suite example to get a list with all the deployed composites
domainRuntime()

soaBean = ObjectName('oracle.soa.config:Location=soa_server1,name=soa-infra,j2eeType=CompositeLifecycleConfig,Application=soa-infra')
print soaBean
composites = mbs.getAttribute(soaBean, 'DeployedComposites')
for composite in composites:
print 'composite: ',composite


Here an example to set a SOA Composite auditlevel to Development mode
# function to help locate a mbean(s)
# that match a specific name
def findMBean(prefix, name):
    # get a listing of everything in the current directory
    mydirs = ls(returnMap='true');
        
    # we're going to use a regular expression for our test
    pattern = java.util.regex.Pattern.compile(str(prefix) + str('.*name=') + str(name) + str('.*$'));
        
    # loop through the listing
    for mydir in mydirs:
        x = java.lang.String(mydir);
        matcher = pattern.matcher(x);
        # if we find a match, add it to the found list
        while matcher.find():
            return x;

print 'starting the script ....'
username = 'weblogic'
password = 'weblogic1'
url='t3://localhost:7001'

connect(username,password,url)

custom();
cd('oracle.soa.config');

composite = findMBean('oracle.soa.config:partition=default,j2eeType=SCAComposite',
                      '"CallingComposite"');
print 'bean ' + str(composite);
cd( composite );
print 'path: ' + pwd();

params = jarray.array(['auditLevel','Development'],
                       java.lang.Object)
sign   = jarray.array(['java.lang.String','java.lang.String'], 
                      java.lang.String)
invoke('setProperty', 
       params, 
       sign); 

disconnect();

The same but then in an other way
print 'starting the script ....'
username = 'weblogic'
password = 'weblogic1'
url='t3://localhost:7001'

connect(username,password,url)

domainRuntime()

helloworldComposite = ObjectName('oracle.soa.config:Location=AdminServer,partition=default,j2eeType=SCAComposite,revision=1.0,label=soa_d84546d1-22b0-496a-8b33-a5705caf19e6,Application=soa-infra,wsconfigtype=WebServicesConfig,name="Helloworld"')
print helloworldComposite
params = ['auditLevel','Development'] 
sign = ['java.lang.String','java.lang.String'] 
mbs.invoke(helloworldComposite, 'setProperty', params, sign) 
print mbs.getAttribute(helloworldComposite, 'Properties')

Tuesday, January 26, 2010

Creating Users and Groups in Weblogic with WLST

A small blogpost how you can create users and groups with WLST scripting in Weblogic. This can be handy when you have a lot of application environments for Dev, Test ...) In WLST there is no default WLST function for creating users and groups, but in the serverConfig() we can lookup the right MBean and call the createUser, createGroup and addMemberToGroup operation.
Here is an example of the user creation phyton script.

serverConfig()

print 'lookup DefaultAuthenticator'

password = 'weblogic1'

atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

print 'create group App-MHS-Users'
group = 'App-MHS-Users'
atnr.createGroup(group,group)

users = ['user1','user2']
for user in users:
print 'create user: ',user
atnr.createUser(user,password,user)
atnr.addMemberToGroup(group,user)


print 'create group App-MHS-Admin'
group = 'App-MHS-Admin'
atnr.createGroup(group,group)

users = ['admin1','admin2']
for user in users:
print 'create user: ',user
atnr.createUser(user,password,user)
atnr.addMemberToGroup(group,user)


print 'create group App-MHS-SB'
group = 'App-MHS-SB'
atnr.createGroup(group,group)

users = ['sbuser1','sbuser2']
for user in users:
print 'create user: ',user
atnr.createUser(user,password,user)
atnr.addMemberToGroup(group,user)


To run this script we need a Weblogic environment ( can be remote ) and start wlst.cmd or wlst.sh

Go to the C:\Oracle\jdevstudio111120\wlserver_10.3\common\bin folder and start wlst.cmd

connect('weblogic','weblogic1','t3://server.domainname:7001')
execfile('/oracle/wls_scripts/createDefaultUserAndGroup.py')
disconnect()
exit()

that's all.