Saturday, March 22, 2014

How to use NodeManager to control WebLogic Servers

In my previous post, you have seen how we can start a WebLogic admin and multiple managed servers. One downside with that instruction is that those processes will start in foreground and the STDOUT are printed on terminal. If you intended to run these severs as background services, you might want to try the WebLogic node manager wlscontrol.sh tool. I will show you how you can get Node Manager started here.

The easiest way is still to create the domain directory with the admin server running temporary and then create all your servers through the /console application as described in last post. Once you have these created, then you may shut down all these processes and start it with Node Manager.

1. cd $WL_HOME/server/bin && startNodeManager.sh &
3. $WL_HOME/common/bin/wlscontrol.sh -d mydomain -r $HOME/domains/mydomain -c -f startWebLogic.sh -s myserver START
4. $WL_HOME/common/bin/wlscontrol.sh -d mydomain -r $HOME/domains/mydomain -c -f startManagedWebLogic.sh -s appserver1 START

The first step above is to start and run your Node Manager. It is recommended you run this as full daemon service so even OS reboot can restart itself. But for this demo purpose, you can just run it and send to background. Using the Node Manager we can then start the admin in step 2, and then to start the managed server on step 3.

The NodeManager can start not only just the WebLogic server for you, but it can also monitor them and automatically restart them if they were terminated for any reasons. If you want to shutdown the server manually, you may use this command using Node Manager as well:

$WL_HOME/common/bin/wlscontrol.sh -d mydomain -s appserver1 KILL

The Node Manager can also be used to start servers remotely through SSH on multiple machines. Using this tool effectively can help managing your servers across your network. You may read more details here:
http://docs.oracle.com/cd/E23943_01/web.1111/e13740/toc.htm

TIPS1: If there is problem when starting server, you may wnat to look into the log files. One log file is the <domain>/servers/<server>/logs/<server>.out of the server you trying to start. Or you can look into the Node Manager log itself at $WL_HOME/common/nodemanager/nodemanager.log

TIPS2: You add startup JVM arguments to each server starting with Node Manager. You need to create a file under <domain>/servers/<server>/data/nodemanager/startup.properties and add this key value pair: Arguments = -Dmyapp=/foo/bar

TIPS3: If you want to explore Windows version of NodeManager, you may want to start NodeManager without native library to save yourself some trouble. Try adding NativeVersionEnabled=false to $WL_HOME/common/nodemanager/nodemanager.properties
file.


Thursday, March 20, 2014

Java 8 is out!

You can watch webcast on March 25 here: http://eventreg.oracle.com/profile/web/index.cfm?PKWebId=0x637279c68

but you may download it now!
http://www.oracle.com/technetwork/java/javase/downloads/index.html

How exicting!

A simple Java8 test
---
import org.junit.Test;

public class LamdaTest {
    @Test
    public void lamdaExpression() {
//        Runnable r = new Runnable() {
//            public void run() {
//                System.out.println("test");               
//            }           
//        };
        //new Thread(r).start();

        //new Thread(() -> System.out.println("test")).start();

        //Runnable r = () -> System.out.println("test");
        Runnable r = () -> {
            System.out.println("test1");
            System.out.println("test2");
            System.out.println("test3");
        };
        System.out.println("result=" + r);
        new Thread(r).start();
    }
}


You can learn more from here: http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html

Wednesday, March 19, 2014

How to workaround WebLogic terminalio not found error

In some PC environments, you may have encounter error like following when trying to create and start a WebLogic Server domain admin server

<Mar 10, 2014 9:40:58 AM EDT> <Error> <Security> <BEA-090783> <Server is Running in Development Mode and Native Library(terminalio) to read the password securely from commandline is not found.><Mar 10, 2014 9:40:58 AM EDT> <Notice> <WebLogicServer> <BEA-000388> <JVM called WLS shutdown hook. The server will force shutdown now>
<Mar 10, 2014 9:40:58 AM EDT> <Notice> <WebLogicServer> <BEA-000365> <Server state changed to FORCE_SHUTTING_DOWN>

After this unfriendly message, your process will just exit and won't start at all! One quick fix for this is to try add this sys props -Dweblogic.management.allowPasswordEcho=true This will force the password prompt to echo out on console though, but at least it will start your server. And once the domain is created, you may restart it again without prompting password.

Ref: https://community.oracle.com/thread/934173

Sunday, March 16, 2014

How to monitor multiple JVM's on a server with VisualVM

In the last article I have shown you how to start WebLogic Server with single admin and mulitiple managed servers. After those are started, how do you go check their health status? You can use the admin's /console webapp. But there  is also another tool that comes with all the default Oracle/Open JDK 6+: the VisualVM. I will show you how to get that up and running to monitor multiple JVM's.

On the server where you run your JVM servers, do this:

1. cd into $HOME and create a file named "jstatd.all.policy" with the following:
    grant codebase "file:${java.home}/../lib/tools.jar" {
       permission java.security.AllPermission;
    };

2. Run this command:
    jstatd -J-Djava.security.policy=jstatd.all.policy &
3. Now go back to your PC and open a terminal and run the following:
    jvisualvm&
4. Inside ViaualVM, add a Remote host of your server and you should see all the JVM that started there.

Here is an example of how it looks like:

Wednesday, March 12, 2014

How to start multiple WebLogic managed servers

The WebLogic Server docs recommand you to create a dedicated admin server and then sepearate managed servers for application deployment. Here I will show you how to create one or more managed server in the same host as the admin server.

I assume you already have WLS installed with your own domain created and running. If you haven't done this before, you may refer to my previous blog on how to create and start WLS. After you started your domain (that's the default admin server), then follow these steps.

1. Login into your http://localhost:7001/console webapp.
2. On the right menu tree, click Environment > Servers. You should see "myserver(admin)" already listed.
3. Click "New" button, enter Server Name: appserver and set Server Listen Port: 7002
4. Click "Next" and then "Finish"
5. Now open a new terminal and run these commands:
    cd mydomain
    bin/startManagedWeblogic.sh appserver1 localhost:7001

You would need to enter the username and password, same as for your /console webapp. After this managed server is up and running you may send the process in the background by pressing CTRL+Z and then run bg command. Or you may use the servers/appserver/security/boot.properties file to bypass the user/password prompt on every restart of this managed server.

Now you have one managed server started along with your admin server. After this you may start deploying application onto this managed server. All the webapp deployed would now accessable by its assigned port such as http://localhost:7002/yourwebapp url. You may repeat the same for however number of managed server you like to run on the same host. Try to name your server name and port number unique.

Sunday, March 9, 2014

How to create MySQL DataSource in WebLogic Server

One cool thing about using an application server is that it allows you to create DataSource outside of your application and it can manage it along with connections pool and transaction manager etc. With WebLogic Server, it comes with quite a few built in JDBC drivers such as Oracle Database and MySQL etc ready for your use. Here I will show you how to create a MySQL DataSource.

1. Login into http://localhost:7001/console
2. On the left menu click Services > Data Sources
3. On the right, click "New" button
4. Enter Name: mysql_ds ; You may optionally give it an JNDI Name: jdbc/mysql_ds; And then select Database Type: MySQL
5. Click "Next" button and then accept default with another two "Next" buttons.
6. Now enter Database Name: test; Host Name: localhost; Database User Name: root; and then the password.
7. Click "Next" and you may optionally test your connection here.
8. Click "Next" and you MUST select an sever as target!
9. Click "Finish"


Now you have a DataSource ready to be used by your application on this server. You may access this by either JNDI lookup, or JPA configuration with entity manager injection.

TIPS: If you do not pick a server Target in step 8, then your applicatoin will NOT able to access this Data Source! So ensure you have done this step as it's the easy step to miss.

Wednesday, March 5, 2014

Quick project sharing with hg over ssh

Mercurial is an awesome source control system! If you got a project in your PC and would like to share with your team. An easy and practical way is to put it in a common server (eg: linux) with ssh enabled.

1. Copy your existing project source into your server $HOME/repo/myproject
2. ssh into your server and cd into $HOME/repo/myproject
3. Run # hg init && hg commit -m 'Init added'
5. Exit your server and get your project in your PC terminal and run:
    # hg clone ssh://user_id@myserver/repo/myproject

That's it. You don't even need a web server to host it! Just tell all your teammates to do the last step on their own PC terminal. Now eveyone can make changes to your project then commit and push or pull!

TIPS: If you do not place your "repo/myproject" directory under your $HOME, then you would need the double slashes when cloning! For example:
    # hg clone ssh://user_id@myserver//usr/local/repo/myproject