Thursday, May 29, 2014

Linux Directory Tree

Problem Statement
Print a tree structure showing all the files and directories under the current directory.

Solution
 find ./ | sed -e 's/[^-][^\/]*\//--/g;s/--/ |-/'

CRONTAB - Quick Reference

Crontab Commands
crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l Display your crontab file.
crontab -r Remove your crontab file.

Crontab syntax
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
  
Crontab Example
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.

     30     18     *     *     *         rm /home/someuser/tmp/*
  
Disable Email
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line.

 
    >/dev/null 2>&1

Generate log file
To collect the cron execution execution log in a file :
 
    30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

Wednesday, May 28, 2014

Adhoc Service Call in IBM BPM 7.5

Problem Statement 

You want to call a service residing outside of your toolkit/process-app. You know the name of the service, the process-app/toolkit acronym and possibly the snapshot name as well. You want to discover the service and execute it without having to go through the process of creating dependencies within your toolkit/process-app. Traditionally this is not possible, IBM BPM 7.5 provides API to call any service from JavaScript (Using tw.system.executeServiceByName()), but this can only execute the services that directly belong to the process-app/toolkit or any dependent toolkit(s). We want to break free of this limitation and execute any service on the environment.

Solution
Create a new Server-JS file and copy the following functions into it.
function findSnapshotForProcessApp(processApp, snapshotName) {
    var processAppObj = null;
    if(typeof processApp == 'string')
        processAppObj = tw.system.model.findProcessAppByAcronym(processApp);

    try {
        if(snapshotName) {
            return processAppObj.findSnapshotByName(snapshotName);
        }
        else {
            var snaps = processAppObj.snapshots;
            if(snaps && snaps.length > 0)
                return snaps[snaps.length -1];
            else
                return null;
        }
    }
    catch (e) {
      throw 'Error in findSnapshotForProcessApp : Required parameter "processApp" not provided or an invalid process-app acronym was provided.';
    }
}
function executeServiceByNameAdHoc(serviceName, inputParams, processApp, snapshotName) {
    var snapshot = findSnapshotForProcessApp(processApp, snapshotName);
   
    if(snapshot) {
        var serv = snapshot.findServiceByName(serviceName);
        if(serv) {
            return serv.execute(inputParams);
        }
        else // Service not found
           throw 'Error in executeServiceByNameAdHoc : No service found. Parameters provided : processApp=' + processApp + ", snapshotName=" + snapshotName + ", serviceName=" + serviceName;
       
    }
    else // Snapshot not found
        throw 'Error in executeServiceByNameAdHoc : No snapshot found. Parameters provided : processApp=' + processApp + ", snapshotName=" + snapshotName;
}

Call the function executeServiceByNameAdHoc with the following parameters to execute any adhoc service.

* @param {String} serviceName The name of the service to execute
* @param {Map} inputValues the input values for the service
* @param {String} processApp : The Acronym for the process app in which the service resides.
* @param {String} (OPTIONAL) snapshotName : Name of the specific snapshot version to execute the service from.
*
* @return A map of output values
* @type Map

Issues

If you get a "ConcurrentModificationException" while trying to execute a service with multiple parameters, the go ahead and deploy the IBM APAR JR49178. This fixes a bug related to HashMap in the method com.lombardisoftware.core.script.js. TWServiceScriptable.jsFunction_execute(Object)

Monday, May 19, 2014

Update group membership of a user

Use the following steps to synchronize group membership of any user, connected to external directory services (LDAP, eDirectory) :

var sec = Packages.com.lombardisoftware.client.delegate.SecurityDelegateFactory.getInstance().newInstance();
sec.updateGroupMembership(tw.local.userId);

Friday, April 25, 2014

Use SAR to Monitor CPU Utilization

SAR (System Activity Reporting) is a common *nix utiliy that can be used to track cpu utilization, memory utilization etc.
 
A common scenario is the need capture cpu statistics during some kind of load testing and then later report on those.  To capture cpu statistics with SAR you can do the following:
 
  1. Logon to the host in question and make sure that sar is installed (run sar from the command line).
  2. To capture statistics every 2 seconds to a file called "mystats.sar" in your home directory, you would execute the following command: sar -o ~/mystats.sar -u 2 0 >/dev/null 2>&1.  Note that this will keep gathering statistics until you kill it using ctrl-c.
  3. To run that same command in the background add an "&" to the end.  You can also "nohup" it so that it keeps running after you logoff - but don't forget to turn it off.  If you background it, then you can find it by typing in "jobs" and it will show you all processes you have put in the background.  You can then kill it with "kill %<jobnum>".  Or you can put it in the foreground "fg %<jobnum>" and then kill it with ctrl-c.
  4. Now you have a file that contains sar statistics, you can retrieve the contents of the file using something like: sar -f ~/mystats.sar.  If you want to just take a timeslice from the file, then you can use the -s hh:mm:ss and -e hh:mm:ss parameters.
See the sar manual page (man sar) for more details.
On Production, SAR are being generated under this directory: /var/log/sa/

Wednesday, April 16, 2014

No edit privilege on a newly imported toolkit

Problem Statement

No edit privilege on a newly imported toolkit. Even though I have listed myself to have read-write permission, I'm not able to edit any artifact in the toolkit. The toolkit was imported recently into the process-center.

Solution

For any toolkit imported into the a process-center, from another process-center, the option "Allow users to update toolkit" is disabled by default. This check-box can be found in the "Manage" tab for the toolkit. This option is only available to the "Admins" of the toolkit. Check that option and restart your process-designer, you will be able to modify toolkit artifacts now.

Tuesday, April 8, 2014

Configuring Apache Load balancer URL

Problem Statement :

You have a clustered environment with 2 or more nodes or you have an Apache layer between the user and your application servers. The users access your application interfaces through the Apache layer, which is responsible for load-balancing, SSO, etc. But when you load the portal or admin console you find that some resources are directly referenced from the application server nodes instead of going through Apache.

Resolution :

Put the following into a file (101CustomLoadBalancer.xml) and place it at

/app/websphere/<DMGR_PROFILE>/config/cells/<CELL>/nodes/<NODE>/servers/<APP_TARGET_JVM>/process-<center/server>/config

<properties>
    <authoring-environment merge="mergeChildren">
        <images-prefix merge="replace">https://<APACHE URL>/teamworks</images-prefix>
        <portal-prefix merge="replace">https://<APACHE URL>/portal</portal-prefix>
        <servlet-prefix merge="replace">https://<APACHE URL>/teamworks</servlet-prefix>
        <webapi-prefix merge="replace">https://<APACHE URL>/webapi</webapi-prefix>
        <repository-prefix merge="replace">https://<APACHE URL>/ProcessCenter</repository-prefix>
        <process-help-wiki-url-view merge="replace">https://<APACHE URL>/processhelp/en/%TITLE%?teamworksTitle=%TEAMWORKS_TITLE%</process-help-wiki-url-view>
        <process-help-wiki-url-edit merge="replace">https://<APACHE URL>/processhelp/en/Special:Edit?topic=%TITLE%&amp;teamworksTitle=%TEAMWORKS_TITLE%</process-help-wiki-url-edit>
    </authoring-environment>
    <common merge="mergeChildren">
        <portal-prefix merge="replace">https://<APACHE URL>/portal</portal-prefix>
        <process-admin-prefix merge="replace">https://<APACHE URL>/ProcessAdmin</process-admin-prefix>
        <!-- Disable for Process Center -->
        <teamworks-webapp-prefix merge="replace">https://<APACHE URL>/teamworks</teamworks-webapp-prefix>
        <coach-designer-xsl-url merge="replace">https://<APACHE URL>/teamworks/coachdesigner/transform/CoachDesigner.xsl</coach-designer-xsl-url>
       
        <webservices merge="mergeChildren">
            <base-url merge="replace">https://<APACHE URL>/teamworks/webservices</base-url>
        </webservices>
        <xml-serialization merge="mergeChildren">
            <default-namespace-uri merge="replace">https://<APACHE URL>/schema/</default-namespace-uri>
        </xml-serialization>
    </common>
    <server merge="mergeChildren">
        <repository-server-url merge="replace">https://<APACHE URL>/ProcessCenter</repository-server-url>
        <email merge="mergeChildren">
            <mail-template merge="mergeChildren">
                <client-link merge="replace">https://<APACHE URL>/teamworks</client-link>
            </mail-template>
        </email>
    </server>
</properties>