Oracle Weblogic nodemanager STOP script Bash and Python

Everyone who is using Oracle Weblogic must had a thought like ¬†“Where the *** is the stop script to kill my nodemanager proces”…. Well, i did. So i wrote a simple stop script which can be better probally, but it does the job.

#!/bin/bash
PID=`ps -efw | grep -i "Xms128m" | grep -i nodemanager | awk '{print $2}'`
if [ ! -z $PID  ]; then
  echo "Killing nodemanager with PID: $PID"
  kill $PID
  CHECK=`ps -e -o pid | grep $PID`
  if [ -z $CHECK ]; then
    echo "Nodemanager stop success"
  fi
else
  echo "No nodemanager process running"
fi

Remember to copy this snippet into a bash file and set the correct permissions.

Some developers like to stop nodemanager programmaticly. I.E.
Note: You could use it to stop and start adminservers for example…
You could use following python definitions:

# RETURN LIST OF PROCESS IDS FROM GREPING PROCESS COMMANDS
def psgrep(str):
    pat = re.compile(str)
    cmd = "ps -e -o pid,command"
    lines = shlines("ps -e -o pid,command")
    pids = []
    for line in lines:
        cols = string.split(line)
        if cols[1] == "grep": continue
        for col in cols[1:]:
            if pat.search(col):
                pids.append(cols[0])
                continue
    return pids

def stop_process_tree(ppid):
    time.sleep(1)
    pids = get_child_processes(ppid)
    while len(pids) > 0:
        for pid in pids:
            stop_process_tree(pid)
        pids = get_child_processes(ppid)
    kill_process(ppid)
    return

def kill_process(pid):
    if pid == None or pid == '':
        return
    time.sleep(1)
    if shout("ps -o pid= --pid " + pid) != '':
        os.system("kill " + pid)
    for i in range(30):
        time.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    os.system("kill -9 " + pid)
    for i in range(30):
        time.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    error("Cannot kill " + pid)
    return

def get_child_processes(ppid):
    return string.split(shout("ps -o pid= --ppid " + ppid))

Oracle Weblogic mail sessions

Sometimes it’s handy to send mail reports from your newly created application… If we choose to do so and we have the expensive obligation of using $$ Oracle Weblogic in our project, we sure can use it ūüôā

You need two things:

  1. A J2EE java application with JavaMail
  2. A Weblogic domain which is the container for the application

1. The java snippet


public class RepportMailArchiveerder implements IRapportArchiveerder{
    private static final Logger logger = Logger.getLogger(RepportMailArchiveerder.class);

    public RepportMailArchiveerder() {
        super();
    }

    /**
     * Send email.
     */
    public void mail(Rapport rapport){

        String content = rapport.toString();

        try {
            // Lookup the WLS context
            InitialContext ic = new InitialContext();
            Session session = (Session) ic.lookup("myTestMailSetup");

            //Construct the email
            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(session.getProperty("mail.from")));
          msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(session.getProperty("mail.to"), false));
            msg.setSubject(session.getProperty("mail.subject"));
            msg.setText(content);
            Transport.send(msg);
        } catch (MessagingException mex) {
            logger.error("Send mail error: " + mex);
            } catch (NamingException ne){
                ne.getMessage();
            }
    }
}

2. The WLS configuration : SERVICES >> MAIL SESSIONS


Control Oracle HTTP server with EM

A nice feature of EM is the metric gathering and control of Oracle HTTP server. If you follow the standard installation method provided by the Oracle ‘bugy’ wizards, you could have troubles with EM and oracle HTTP server.

Most of the time the HTTP server is not registered with the EM console to gather state information.

The reason:

[wc_dev_adminserver] [NOTIFICATION:32] [] [oracle.sysman.emas.sdk.discovery.discover.WeblogicTargetDiscovery] [tid: [ACTIVE].ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: weblogic] [ecid: fe7afd919a7a61df:-1896f1d5:13739376179:-8000-0000000000000ad7,0] [APP: em] Failed to get Attributes:[[javax.management.InstanceNotFoundException: Unable to contact MBeanServer fororacle.as.management.mbeans.register:type=SystemComponent,
name=/instance1/ohs1,instance=instance1,component=ohs1,
Location=AdminServer,EMTargetType=oracle_apache at weblogic.rmi.internal.ServerRequest.sendReceive(ServerRequest.java:205)

...

As you can see, the location of the OHS is not correct defined.

Solution:
We need to delete and redeploy the system components. Make sure AdminServer is up and running at the time you do this.
Run the commands below on the OHS server. Make sure you use your correct instancename.

cd /apps/oracle/middleware/Oracle_WT1/instances/instance1/bin

echo -n unregister the OHS in EM
./opmnctl unregisterinstance -instanceName ohs1 -adminHost 145.83.73.5 -adminPort 8100

echo -n redeply to the EM adminserver
./opmnctl redeploy -adminHost 145.83.73.5 -adminPort 8100

echo -n register instance in EM
./opmnctl registerinstance -adminHost 145.83.73.5 -adminPort 8100

The Result:

WLST (Python) Factory pattern

Using a factory pattern for creating different subtypes like products of Oracle
#!/usr/local/bin/python

class Fusion(object):
  def __init__(self):
    print "This is an Oracle Fusion Middleware product"
    def createDS(self):
    print "creating fusion datasources"

class Webcenter(object):
  def __init__(self, state):
    print "This is a Oracle Webcenter product"

class Product(object):
 products = {'fusion': Fusion, 'webcenter': Webcenter}
 def __new__(self, product):
   print "creating a new product %s" % product
   return Product.products[product]()

if __name__ == '__main__':
  product = Product('fusion')
  product.createDS()

Oracle database 11g and Python cx_Oracle site-packages

Since Python and Jython  is a powerfull way to help Oracle Fusion Middleware developers, the need for database access grows. Therefore i write this installation plan to connect your Pyhton code to a Oracle 11g database using:

Instant Client Package – Basic
Instant Client Package – SQL*Plus
Instant Client Package – SDK

Follow the steps below:

  1. Download the software listed above.
  2. Extract all downloaded zips of the Oracle Instant Client to a dir which is called the ORACLE_HOME
    I used /apps/oracle/instantclient_11_2
  3. Extract the cx_Oracle dir to a tempory location, i used /apps/oracle/cx_Oracle-5.1.1
  4. Add following exports to your global Linux profile:
    </pre>
    PATH=$PATH:$HOME/bin
    ORACLE_HOME=/apps/oracle/instantclient_11_2
    PATH=$ORACLE_HOME/bin:$PATH
    PATH=$ORACLE_HOME/lib64:$PATH
    LD_LIBRARY_PATH=/apps/oracle/instantclient_11_2
    export ORACLE_HOME
    export LD_LIBRARY_PATH
    export PATH
    <pre>
  5. Go to /apps/oracle/instantclient_11_2 and generate some soft links.
    ln -s libclntsh.so.11.1 libclntsh.so
    ln -s libocci.so.11.1 libocci.so
    ln -s libocijdbc11.so libocijdbc.so
    ln -s libnnz11.so libnnz.so
    
  6. Go to the extracted cx_Oracle directory and run:
    python setup.py build
    python setup.py install
    
  7. Now start a Python shell and try:
Python 2.7.2 (default, Mar 20 2012, 03:06:10)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle

¬†If You get “missing library .so” errors:

  • Check your .bash_profile for the correct $PATH, $LD_LIBRARY_PATH and $ORACLE_HOME exports.
  • Check the permissions from the instantclient dir (/apps/oracle/instantclient_11_2)

That’s all it is to. Good luck with using your database!

Oracle SOA high availabilty documentation

Following links contain good describtions for making Oracle  SOA Suite HA.

1.  Extending the Domain for SOA Components

http://docs.oracle.com/cd/E21043_01/core.1111/e12037/extend_soa.htm#CDEDHDHA

2. A document which bundles the Oracle documentation

http://www.namredlek.nl/orasoa/InstallSOASuite11gOnCluster_v1.pdf

3. Clustering SOA suite (theorectical description)

http://blogs.oracle.com/reynolds/entry/clustering_soa_suite

4. Scripting your Oracle SOA 11g Cluster (Scripts are not complete)

http://orasoa.blogspot.com/2010/12/scripting-your-oracle-soa-11g-cluster.html

 

Android proxy-server missing settings

I think most of the Android users are disapointed because of the miss of options in proxy-server settings during WIFI set-up. Basic things that are missing:

  1. Basic authentication
  2. Ntlm authentication

I searched the net for different solutions.

With root:

http://androhacks.blogspot.com/2011/02/proxy-settings-in-android-mobiles-with.html

Without root:

I use Opera to get my webbrowser working. Hope Google will fix this problem in future releases!

https://market.android.com/details?id=com.opera.browser

Or this one :

http://duykham.blogspot.com/2009/11/setting-proxy-for-android-by-gui.html

 

Oracle SOA Suite managed server $CLASSPATH challenges

Once you installed Oracle SOA Suite en created your domain with or without scripts you will see that the installer(default) creates a separate managed server for the SOA suite, soa_server1 (default). You can start this server in two ways:

  1. Trough the admin console
  2. With the “startManagedWeblogic.sh” script

Most administrators and developers would like to start this beast with the¬†admin console. So you have to configure and start¬†the nodemanager. If¬† you start the server without setting up the correct classpath in the “server start” tab of the managed server. All the SOA suite deployments will be on status¬†“failed“. Now you have two choices:

1. Fill the tab below and figure out the classpath

2. Alter the nodemanage.properties StartScriptEnabled flag to value “true”

DomainsFile=/opt/oracle/middleware/wlserver_10.3/common/nodemanager/nodemanager.domains
LogLimit=0
PropertiesVersion=10.3
DomainsDirRemoteSharingEnabled=false
javaHome=/opt/oracle/middleware/jrockit_160_24_D1.1.2-4
AuthenticationEnabled=true
NodeManagerHome=/opt/oracle/middleware/wlserver_10.3/common/nodemanager
JavaHome=/opt/oracle/middleware/jrockit_160_24_D1.1.2-4/jre
LogLevel=INFO
DomainsFileEnabled=true
StartScriptName=startWebLogic.sh
ListenAddress=
NativeVersionEnabled=true
ListenPort=5556
LogToStderr=true
SecureListener=true
LogCount=1
DomainRegistrationEnabled=false
StopScriptEnabled=false
QuitEnabled=false
LogAppend=true
StateCheckInterval=500
CrashRecoveryEnabled=false
###########
StartScriptEnabled=true
###########
LogFile=/opt/oracle/middleware/wlserver_10.3/common/nodemanager/nodemanager.log
LogFormatter=weblogic.nodemanager.server.LogFormatter
ListenBacklog=50

The result is a beautifull “Active” state of all our SOA deployments:

Oracle Weblogc config.sh

The config.sh script from Oracle weblogic to create a domain is not compatibel with a Java version > 1.6.0_27 if you like to use X-window. Also the config_builder.sh to create domains is incompatibel with the newest (current date 10-11-2011) Java version jdk1.7.0_01.

To fix this, you have to replace the JAVA_HOME var in following Weblogic files (if you installed with jdk1.7.0_01) with your oldie jdk :

  1. commEnv.sh in WL_HOME/common/bin
  2. .product.properties in WL_HOME

To make sure before you start the config tools do this:


export JAVA_HOME=/<path>/<your new jdk>
export PATH=$JAVA_HOME/bin:$PATH
[thomas@oel5505 bin]$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b51)
Java HotSpot(TM) Server VM (build 17.0-b17, mixed mode)
[thomas@oel5505 bin]$ ./config.sh

Oracle XE: Repository creation utility (RCU) max processes

When you install the Oracle fusion middleware schema’s for development and you use Oracle XE.

You have to increase your processes in your XE installation as follow:

First login

[thomas@oel5505 software]$ sqlplus "sys as sysdba"
<pre>alter system set processes = 250 scope=spfile;

This because the RCU tool requires a minimun of 200 processes.

Note: Every proces takes an amount of memory. If you put it this parameter to high your database will be dead…’

Following system parameter could give an RCU error:  sga_max_size
You have to set this to a minimum of 159383552.

Do this by

[thomas@oel5505 software]$ sqlplus "sys as sysdba"
<pre>alter system set sga_max_size=159383552 scope=spfile;
commit;
shutdown immediate;
startup