Saturday, 11 January 2014

ANT and Message broker

What is the use of ANT?
  1. If you want to automate the complete build: build, jar,  code analysis, run the unit tests, generate the documentation, copy to some directory, tune some properties depending on the environment, etc.
  2. Any repititive tasks can be automated using ANT
  3. Once it's automated, you can use a continuous integration system which builds the application at each change or every hour to make sure everything still builds and the tests still pass...
Bar file contains broker.xml and compiled message flows and message sets.This broker.xml file contains the deployment descriptions. To modify any of its contents,in earlier versions of broker we had to use WMB toolkit or by manuall extracting broker.xml.
In later versions of 6 ,we got mqsiapplybaroverride command tool to modify broker.xml.
ANT is one of the automatic  build tools which helps in build,test,deploy of bar file automatically.


ANT uses XML as the configuration file.
Root element is Project.
Under project there are multiple TARGET  elements..TARGETs are logical units of work.
For eg:Compiling java program is one unit of work.
Within Target,there are tasks(ANT provides;Custom tasks also possible).
Good example of Custom tasks :- JUNIT tasks
Some targets may depend on other targets as well.

Ant looks for Build.xml file.
Broker.xml file
  • broker.xml file. This file is called the broker deployment descriptor. You can have only one of these files within your BAR file. This file, in XML format, is contained in the META-INF folder of the compressed file and can be modified by using a text editor or shell script.

Opening Broker.xml file :
 Change .bar file as .zip file.Then open the .zip file and open META-INF file.And then,open broker.xml (Deployment Descriptor file) inside that.




Mqsicreatebar
Used to create deployable bar file.
If you use a repository to store your message flows and dictionaries, you can write scripts that use themqsicreatebar command and the repository's command-line tools to deploy your message flow applications.
The following example creates a BAR file called myflow.bar. The application Application1 is added to the BAR file and the trace function is activated.
mqsicreatebar -data C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New -b C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test_command.bar -a Ant_Test -trace

When executing this command ,we need to make sure that there should not be any errors in the workspace.If there are any errors,then the mqsicreatebar will not work.
[2013/12/14/15:53:00] [ERROR]  { Workspace has errors on it after the build. In
order to create bar there should be no errors on the workspace. }  - com.ibm.eto
ols.mft.bar.cmdline.MqsiCreateBarException: Workspace has errors on it after the
 build. In order to create bar there should be no errors on the workspace.
BIP0965E Error compiling files in mqsicreatebar.
To find the build errors,during mqsicreatebar(Note : mqsicreatebar is part of Toolkit installed path  “C:\Program Files\IBM\WMBT800” ;Hence it is related to toolkit)
The build error logs is in the path “C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments\.metadata”  ,where C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments\ is the workspace name.
If the command is successfully completed,then BIP0986I Command completed successfully. Should come.Else,then if the errors are due to current workspace,take the Project to new workspace and use mqsicreatebar.

ANT initial setup :
1)First download apache ant  from http://ant.apache.org/bindownload.cgi
2)Then setup the below variables.So,you can run ANT from any path,
set ANT_HOME= E:\Softwares\apache-ant-1.9.21
set JAVA_HOME= C:\Program Files\Java\jdk1.6.0
set PATH= E:\Softwares\apache-ant-1.9.2\bin

C:\Users\Radha>echo %JAVA_HOME%
C:\Program Files\Java\jre7\bin;C:\Program Files\Java\jdk1.6.0;
Troubleshooting tip
The installer for 1.6 dropped java.exe, javaw.exe, and javaws.exe into my Windows/System32 folder (Windows 7).
I solved it by renaming those files to java_wrong.exe, javaw_wrong.exe, and javaws_wrong.exe. Only after doing that does it pick up the correct version of java as defined in JAVA_HOME and PATH.

Running simple Ant project :-
In E:\Techie\Ant , a build.xml file is created with the following content.Make sure that the file is really build.xml and not build.xml.txt
<project name="Ant" default="target1">
 <target name="target1">
  <echo>This is my first project</echo>
</target>
</project>
Output:


Simple build.xml for creating bar file
<?xml version="1.0"?>
<project name="Ant_WMB_First" default="run">

 <target name="run" description="">
  <property name="toolkit.home" value="C:\Program Files\IBM\WMBT800"/>
<property name="workspaces.dir" value="C:\Users\Radha\IBM\wmbt80\Workspace
\Rad_Experiments_New" />
<property name="bar.name" value="${workspaces.dir}\Ant_Test_command.bar"/>
 
<antcall target="mqsicreatebar.buildbar"/>
</target>

<target name="mqsicreatebar.buildbar">
 <echo message="Building broker archive file : ${bar.name} "/>
 <exec executable="${toolkit.home}\mqsicreatebar.exe" spawn="false">
 <arg value="-data" />
<arg value="${workspaces.dir}" />

<arg value="-b" />
<arg value="${bar.name}" />

<arg value="-a" />
<arg value="Ant_Test" />
</exec>
<echo message="completed building broker archive file :- ${bar.name}" />
</target>
</project>

Mqsiapplybaroverride :
The below extract taken from broker.xml file which is present inside the bar file created by the execution of above ANT command.
<ConfigurableProperty override="IN1" uri="Ant_Test#MQ Input.queueName"/>

Command sample :
mqsiapplybaroverride -b C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test_command.bar  -p C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test.properties.txt

mqsiapplybaroverride –b C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test_command.bar  –m Ant_Test#MQInput.queueName=IN_Test

Now to override the Input Queue IN1 by IN_Test.Have the below content in properties file.
#If want to replace a specific URI override value within the broker.xml
#URI_<uri with # escaped with a backslash \>=<new override value>
URI_PostcardFlow\#additionalInstances=2
 
#Replace all places in broker.xml that have IQ as a override value with
<old override value>=<new override value>
Q1=TEST_QUEUE

URI_ Ant_Test\# MQ Input.queueName= IN_Test
The correct command for application applybaroverride .This has to be applied in WMB toolkit version 8.0.0.3.
 mqsiapplybaroverride -b C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test_command.bar  -k  Ant_Test -o C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test_command_changed.bar   -p  C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test.properties.txt

Execution of the command:
C:\Program Files\IBM\MQSI\8.0.0.3> mqsiapplybaroverride -b C:\Workspace\Ant_Test_command.bar -k Ant_Test -o C:\Workspace\Ant_Test_command_changed.bar - 
p C:\Workspace\Ant_Test.properties 
BIP1138I: Applying overrides using runtime mqsiapplybaroverride... 
BIP1140I: Overriding property Ant_Test#additionalInstances with '10' in 'Ant_Tes 
t.appzip/META-INF/broker.xml' ... 
BIP1143I: Saving Bar file C:\Workspace\Ant_Test_command_changed.bar... 

BIP8071I: Successful command completion. 
To override a property use the same structure as that of the output of mqsireadbar :
mqsireadbar -b C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test_command.bar –r

Now,in build.xml I am giving the content for mqsiapplybaroverride as :-
<?xml version="1.0"?>
<project name="project" default="run">
  <target name="run" description="">
    <property name="toolkit.home" value="C:\Program Files\IBM\WMBT800" />
    <property name="ant.bars.basedir" value="C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New" />
    <property name="bar.name" value="${ant.bars.basedir}\Ant_Test_command.bar" />
    <property name="app.name" value="Ant_Test" />
    <property name="bar.properties.name"
                                             value="${ant.bars.basedir}\Ant_Test.properties" />

    <antcall target="mqsiapplybaroverride.modifybar" />
  </target>

  <!--
    Target to build the broker archive using mqsiapplybaroverride
  -->
  <target name="mqsiapplybaroverride.modifybar">
    <echo message="Applying overrides in Broker Archive file - ${bar.name} " />
    <echo
      message="${toolkit.home}\mqsiapplybaroverride.exe
                                               -b  ${bar.name} -p ${bar.properties.name}" />
    <exec executable="${toolkit.home}\mqsiapplybaroverride.exe" spawn="false">
      <arg value="-b" />
      <arg value="${bar.name}" />
      <arg value="-k" />
      <arg value="${app.name}" />
      <arg value="-p" />
      <arg value="${bar.properties.name}" />
    </exec>
    <echo message="Completed apply overrides in Broker Archive file - ${bar.name}" />
  </target>
</project>

Properties file contain:
Ant_Test#additionalInstances=10
Ant_Test#MQ Input.queueName = IN_Test

Mqsideploy
Deploying:
mqsideploy RadBroker1  -e default -a C:\Users\Radha\IBM\wmbt80\Workspace\Rad_Experiments_New\Ant_Test_command.bar  -w 600 

Undeploying :
mqsideploy RadBroker1  -e default -d Ant_Test -w 600 

Hint on mqsiprofile
If you try to run a command like ‘mqsireportproperties'and got the error below you need to run mqsiprofile BEFORE you run your command.
The user environment was not adequately prepared to continue execution. Locate and run the profile supplied with the product. This file is called mqsiprofile, and is located in the bin subdirectory for the product.
1
2
3
4
SET "BROKER_HOME=C:\Program Files\IBM\MBroker\7.0"
SET "path=%path%;%BROKER_HOME%\bin"
mqsiprofile
mqsireportproperties MB7BROKER -e EXECUTIONGROUP-o HTTPConnector -r

To run mqsi commands,mqsiprofile command has to be initially run to get some broker Environment variables.When WMB software is installed,and broker is started using mqsistart command,it tries to inherit the environment from where we issue the mqsistartcommand.

Therefore ,we need to initialise the environment before we start a component. the command mqsiprofile located in the directoryinstall_dir/bin, performs this initialization. 

Mqsideploy-Ant
<?xml version="1.0"?>
<project name="project" default="run">
  <target name="run" description="">
    <property name="toolkit.home" value="C:\Program Files\IBM\WMBT800" />
     <property name="mqsi.home" value="C:\Program Files\IBM\MQSI\8.0.0.3\bin" />
    <property name="ant.bars.basedir" value="C:\Users\Radha\IBM\wmbt80\Workspace
\Rad_Experiments_New" />
    <property name="bar.name" value="${ant.bars.basedir}\Ant_Test_command.bar" />
    <property name="app.name" value="Ant_Test" />
  <property name="broker.name"
                                    value="RadBroker1" />
<property name="EG.name" value="default" />
    <antcall target="mqsideploy.bar" />
  </target>

  <!--
    Target to deploy using mqsideploy
  -->
  <target name="mqsideploy.bar">
    <echo message="Deploying  - ${bar.name} " />
    <echo
      message="${mqsi.home}\mqsideploy  ${broker.name} -e ${EG.name}
                                      -a  ${bar.name} -w 600" />
    <exec executable="${mqsi.home}\mqsideploy.exe" spawn="false">
      <arg value="${broker.name}" />
     
      <arg value="-e" />
       <arg value="${EG.name}" />


      <arg value="-a" />
      <arg value="${bar.name}" />

      <arg value="-w" />
      <arg value="600" />
     
    </exec>
    <echo message="Completed deploy - ${bar.name}" />
  </target>
</project>

Mqsipackagebar
Use the mqsipackagebar command to create deployable broker archive (BAR) files. You can use this command to create BAR files on machines that do not have the WebSphere  Message Broker Toolkitinstalled.

Resources that you add to a BAR file by using the mqsipackagebar command are not compiled when they are added. To deploy a BAR file that you create by using this command, you must add deployable resources to the BAR file. For example, if you want to include Java code or message sets in your BAR file, you must first compile these files before you use the mqsipackagebar command to add them to your BAR file. You cannot include both the compiled (.cmf) and source (.msgflow) versions of a message flow in a BAR file.

I had an application with a JCN node.Hence the application has project reference with a java project.
I have first compiled the JCN’s java project and it got converted to .jar file.

Then I executed  mqsipackagebar for the entire application.

5 comments:

  1. Hi,

    I'm using the IIB 10.0.0.10.
    I set the PATH and BROKER_HOME as discussed above.
    As it is IIB v10, I set the PATH to PATH = PATH + BROKER_HOME/server/bin
    When I tried running the ant script I still the get the message.

    "The user environment was not adequately prepared to continue .....product."

    Can you tell me where I'm missing..

    ReplyDelete
    Replies
    1. BROKER_HOME="C:\Program Files\IBM\IIB\10.0.0.10"

      Delete
  2. This blog is really great. The information here will surely be of some help to me. Thanks!. south african brokerage firms

    ReplyDelete
  3. Revolut is currently reputable in Europe. On its residence soil, it allows individuals to buy and sell Bitcoin (BTC), Ethereum (ETH), Litecoin (LTC), Bitcoin Cash Money (BCH) and also (XRP) for among 29 fiat money. Revolut anticipates to begin using the very same service to its clients in all 50 UNITED STATE states. Crypto bot

    ReplyDelete
  4. Even just thirty years ago, most financial services offerings were dominated by a select group of traditional banks. While change has not been an easy or a smooth process, today the financial landscape looks completely different. In particular, the Payment Service has undergone some drastic transformations even in the last ten years.

    ReplyDelete