WebSphere – Restart enterprise applications usign Jython Script

My jython script : restartApp.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
appName = sys.argv[0]
nodeName = 'w9Node'
serverName = 'WebSphere_Portal'
 
try:
   appMgr = AdminControl.queryNames('type=ApplicationManager,node='+nodeName+',process='+serverName+',*')
   appDetails = AdminControl.completeObjectName('type=Application,name='+appName+',*')
   print ''
 
  if len(appDetails) > 0:
    print '['+appName+'] is started lets stop'
    AdminControl.invoke(appMgr, 'stopApplication', appName)
 
except:
  print("Ignoring error - %s" % sys.exc_info())
 
print 'lets start ['+appName+']'
    AdminControl.invoke(appMgr, 'startApplication', appName)

Restart multiple app using jhyton script invoked by dos script :

1
2
3
4
5
6
7
8
9
10
11
12
@echo off
 
set baseCommand=C:\ibm\portal\AppServer\bin\wsadmin.bat -conntype SOAP -host localhost -port 10033 -user <youruser> -password <yourpassword> -lang jython -f restartApp.py
set cellName=wp9Celldev
 
set appName=app001-ear 
set "MYCOMMAND=%baseCommand% %appName% %cellName%"
call %MYCOMMAND%
 
set appName=app002-ear 
set "MYCOMMAND=%baseCommand% %appName% %cellName%"
call %MYCOMMAND%

Vaadin : Use a custom converter on grid

Here a simple Vaadin converter to format dateTime in GRID.
ConvertToModel method is not implemented because converter is not associated to any field.

How to use Grid

  CustomFormatDateStringConverter dateConverter = new CustomFormatDateStringConverter();
  grid.getColumn("beanDateAttr").setConverter(dateConverter);

Converter Implementation

package com.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import com.vaadin.data.util.converter.Converter;

public class CustomFormatDateStringConverter implements Converter<String, String> {
	SimpleDateFormat dateParser = new SimpleDateFormat("ddMMyyyy");
	SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");

	@Override
	public String convertToModel(String value,
			Class<? extends String> targetType, Locale locale)
			throws com.vaadin.data.util.converter.Converter.ConversionException {
			
			// If using in a grid this part can be omitted
			
			return value;
	}

	@Override
	public String convertToPresentation(String value,
			Class<? extends String> targetType, Locale locale)
			throws com.vaadin.data.util.converter.Converter.ConversionException {
			
			if (value!=null && !value.isEmpty()) {
				try {
					Date date = dateParser.parse(value);
					value = dateFormatter.format(date);
				} catch (ParseException e) {
					e.printStackTrace();

				}
			}else{
				value="";
			}
			return value;
	}

	@Override
	public Class<String> getModelType() {
		return String.class;
	}

	@Override
	public Class<String> getPresentationType() {
		return String.class;
	}

}

Configure Jrebel with remote server

After 3 hours turning around over many examples, finally I’ve configured Jrebel with remote webpshere portal.
This is my step by step configuration guide:

-) Step 1 : download the client from this url :

Archived JRebel Releases

-) Step 2 : copy and unpack downloaded file on the remote server (I usually use: C:\IBM\jrebel\)

-) Step 3 : Activate client using a valid licence (I’ve used activate script in client’s bin directory)

-) Step 4 : Generate bootstrap file using this command (Don’t forget to use websphere portal jvm ):

cd C:\IBM\jrebel

C:\IBM\WebSphere\AppServer\java\jre\bin\java -jar jrebel.jar

-) Step 5 : Copy jrebel-bootstrap.jar from [userHome]/.jrebel to C:\IBM\jrebel\

-) Step 6 : Add jrebel parameter to websphere portal jvm (if you don’t know how visit this : http://www-01.ibm.com/support/docview.wss?uid=swg21417365) :

-Xshareclasses:none -Xbootclasspath/p:C:\IBM\jrebel\jrebel-bootstrap.jar;C:\IBM\jrebel\jrebel.jar -Drebel.remoting_plugin=true 

finally my configuration seems like this:

-Xshareclasses:none -Xbootclasspath/p:C:\IBM\jrebel\jrebel-bootstrap.jar;C:\IBM\jrebel\jrebel.jar -Drebel.remoting_plugin=true ${WPS_JVM_ARGUMENTS_EXT} -Dderby.system.home=${USER_INSTALL_ROOT}/PortalServer/derby -Dibm.stream.nio=true -Djava.io.tmpdir=${WAS_TEMP_DIR} -Xdump:stack:events=allocation,filter=#10m -Xgcpolicy:gencon -verbose:gc -Xverbosegclog:${SERVER_LOG_ROOT}/verbosegc.%Y%m%d.%H%M%S.%pid.txt,20,10000

-) Step 7 : Finally don’t foget generate password using this command:

cd C:\IBM\jrebel

C:\IBM\WebSphere\AppServer\java\jre\bin\java -jar jrebel.jar -set-remote-password password

Generate version.txt in a maven project

If you need to generate a txt with project version / timestamp in project’s root you can use an ant build like this.


<plugins>

...


<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  	<version>1.8</version>
	<executions>
  	<execution>
	<phase>prepare-package</phase>
	<configuration>
	   <tasks>
	     <tstamp>
		<format property="now" pattern="yyyy-MM-dd hh:mm:ss" locale="it" />
		  </tstamp>
		    <echo file="<path>/version.txt" append="false">
			Project Version : ${project.version} ${line.separator}Build @ ${now}
		    </echo>
            </tasks>
         </configuration>
	    <goals>
		<goal>run</goal>
	    </goals>
	</execution>
	</executions>
</plugin>

...

</plugins>