JavaBlog.fr / Java.lu DEVELOPMENT,Documentum,Java,powershell,Tools Documentum : Execution CMD/PowerShell Via Job/Method

Documentum : Execution CMD/PowerShell Via Job/Method

Hello,

Sometimes, the execution of a job/method Documentum via Java Method Server (JMS) can generate a Core dump error for various reasons : content file protected, document corrupted, …etc…especially when using IRM protection which produces the stopping of DCTM job.

Here, an example of error:

1    EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000111b9d09, pid=3684, tid=7584
2#
3# JRE version: 7.0_17-b02
4# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode windows-amd64 compressed oops)
5# Problematic frame:
6# C  [libemcdctmirm.dll+0x1f9d09]  PVS_TemplateListFree+0x7069
7#
8# Core dump written. Default location: D:\App\Workspaces\....\hs_err_pid3684.mdmp

So, I will try to expose a simple solution in order to avoid the stopping of JMS by by-passing the use of JMS:
DCTM JOB => DCTM METHOD => Script BATCH CMD => Script POWERSHELL => JAVA DFC/JVM

  • Creation of a DCTM job My_Method_PowershellScript :
    In Documentum Administrator, in the section Administration/Job Management/Methods, create a method My_Method_PowershellScript:

    01***** in tab "Method Info"
    02* Name = My_Method_PowershellScript
    03* Verb = D:\App\MyFolder4DCTM\My_ScriptProcess.cmd
    04* Method Type = program
    05* Timeout Minimum = 30
    06* Timeout Default = 172800
    07* Timeout Maximum = 345600
    08* Launch Direct = [X] Use the exec call to execute the procedure
    09* Launch Asynchronously = [X] Launch as a separate process
    10* Run As Owner = [X] Run as the installation owner

  • Creation of a DCTM method My_Job_BatchScript :
    In Documentum Administrator, in the section Administration/Job Management/Jobs, create a method My_Job_BatchScript:

    01***** in tab "Info"
    02* Name = My_Job_BatchScript
    03* Trace Level = 0 (no trace)
    04* Designated Server = Any Running Server
    05* State = "Inactive"
    06 
    07***** in tab "Method"
    08* Method Name = My_Method_PowershellScript
    09 
    10***** in tab "SysObject Info"
    11* Title = My_Job_BatchScript

  • Creation of folder containing the scripts and librairies D:\App\MyFolder4DCTM on DCTM server

  • Creation of BATCH CMD script My_ScriptProcess.cmd in the folder D:\App\MyFolder4DCTM calling the POWERSHELL script:
    01@echo off
    02SET "DOCUMENTIDS="
    03:parse
    04IF "%~1"=="" GOTO endparse
    05if "%DOCUMENTIDS%"=="" (
    06SET DOCUMENTIDS=-DocumentIds %~1
    07) ELSE (
    08SET DOCUMENTIDS=%DOCUMENTIDS%,%~1
    09)
    10SHIFT
    11GOTO parse
    12 
    13:endparse
    14 
    15CD "D:\App\MyFolder4DCTM"
    16D:
    17 
    18SET CurrentDirectory=%CD%
    19SET JavaHome=D:\Documentum\java64\1.7.0_17
    20SET DctmDirectory=D:\Documentum
    21SET DctmConfigDirectory=%DctmDirectory%\config
    22SET DctmIrmDirectory=%DctmDirectory%\irm
    23 
    24powershell .\My_ScriptProcess.ps1 "%DOCUMENTIDS%" -DctmEnv ALL -CurrentDirectory "%CurrentDirectory%" -JavaHome "%JavaHome%" -DctmConfigDirectory "%DctmConfigDirectory%" -DctmIrmDirectory "%DctmIrmDirectory%"

  • Creation of POWERSHELL script My_ScriptProcess.ps1 in the folder D:\App\MyFolder4DCTM calling the JAVA com.java.lu.business.service.ecm.utils.main.CreateListToProcess:
    001param(
    002[Int32[]] $DocumentIds,
    003[String] $CurrentDirectory,
    004[String] $JavaHome,
    005[String] $DctmConfigDirectory,
    006[String] $DctmIrmDirectory,
    007[String] $DctmEnv
    008)
    009 
    010function CreateIdList
    011{
    012param(
    013[String] $DocumentIds,
    014[String] $CurrentDirectory,
    015[String] $JavaHome,
    016[String] $DctmConfigDirectory,
    017[String] $DctmIrmDirectory,
    018[String] $DctmEnv,
    019[String] $IdsToProcessFile
    020)
    021 
    022Write-Host "Calling CreateIdList with parameters:"
    023Write-Host " * DocumentIds: $DocumentIds"
    024Write-Host " * CurrentDirectory: $CurrentDirectory"
    025Write-Host " * JavaHome: $JavaHome"
    026Write-Host " * DctmConfigDirectory: $DctmConfigDirectory"
    027Write-Host " * DctmIrmDirectory: $DctmIrmDirectory"
    028Write-Host " * DctmEnv: $DctmEnv"
    029Write-Host " * IdsToProcessFile: $IdsToProcessFile"
    030 
    031$ClassPath = $DctmConfigDirectory;
    032 
    033foreach($Jar IN Get-ChildItem "$CurrentDirectory\dfc" -filter "*.jar" -Name){
    034$ClassPath += ";$CurrentDirectory\dfc\$Jar"
    035}
    036 
    037foreach($Jar IN Get-ChildItem "$CurrentDirectory\lib" -filter "*.jar" -Name){
    038$ClassPath += ";$CurrentDirectory\lib\$Jar"
    039}
    040 
    041$ClassPath += ";$DctmIrmDirectory\emcdctmirm.jar"
    042$ClassPath += ";$CurrentDirectory\IRMisationDocs4ArchivedDeliverable.jar"
    043 
    044$JavaLibraryPath = "$DctmIrmDirectory"
    045$JavaLibraryPath += ";$DctmIrmDirectory\Common"
    046$JavaLibraryPath += ";$env:path"
    047$JavaLibraryPath = $JavaLibraryPath -replace "\\", "/"
    048 
    049$pInfo = New-Object System.Diagnostics.ProcessStartInfo
    050$pInfo.FileName = "$JavaHome\bin\java.exe"
    051 
    052$LogFile = "$CurrentDirectory\log\My_ScriptProcess_log_$((Get-Date).ToString("yyyyMMdd_HHmmss")).log"
    053$pInfo.Arguments = @(
    054#"-Xrunjdwp:transport=dt_socket,address=9797,server=y,suspend=y",
    055#"-XX:-DumpOnCrash",
    056#"-XX:-CoreOnCrash",
    057"-Xmx1g",
    058"-Doracle.net.tns_admin=""$env:TNS_ADMIN""",
    059"-Djava.library.path=""$JavaLibraryPath""",
    060"-cp", """$ClassPath""",
    061"com.java.lu.business.service.ecm.utils.main.CreateListToProcess",
    062$DctmEnv,
    063"""$LogFile""",
    064"""$IdsToProcessFile""",
    065$DocumentIds)
    066 
    067$p = New-Object System.Diagnostics.Process
    068$p.StartInfo = $pInfo
    069 
    070$p.Start() | Out-Null
    071 
    072$p.WaitForExit()
    073 
    074Write-Host "Content of $($IdsToProcessFile):"
    075Get-Content -Path $IdsToProcessFile | Foreach-Object { Write-Host $_ }
    076Write-Host "End of Content"
    077}
    078 
    079function LaunchSensitiveProcess
    080{
    081param(
    082[String] $ObjectIds,
    083[String] $CurrentDirectory,
    084[String] $JavaHome,
    085[String] $DctmConfigDirectory,
    086[String] $DctmIrmDirectory,
    087[String] $DctmEnv
    088)
    089 
    090# ....
    091# ....
    092# ....
    093# ....
    094# ....
    095 
    096}
    097 
    098function MyProcess{
    099param(
    100[Int32[]] $DocumentIds,
    101[String] $CurrentDirectory,
    102[String] $JavaHome,
    103[String] $DctmConfigDirectory,
    104[String] $DctmIrmDirectory,
    105[String] $DctmEnv
    106)
    107$DocumentIdsToProcess=$DocumentIds -join ','
    108 
    109$IdsToProcessFile = "$CurrentDirectory\My_ScriptProcess_$((Get-Date).ToString("yyyyMMdd_HHmmss")).txt"
    110 
    111CreateIdList -DocumentIds $DocumentIdsToProcess -CurrentDirectory $CurrentDirectory -JavaHome $JavaHome -DctmConfigDirectory $DctmConfigDirectory -DctmIrmDirectory $DctmIrmDirectory -DctmEnv $DctmEnv -IdsToProcessFile $IdsToProcessFile
    112 
    113foreach ($IdsToProcess in Get-Content -Path $IdsToProcessFile) {
    114LaunchSensitiveProcess -ObjectIds $IdsToProcess -CurrentDirectory $CurrentDirectory -JavaHome $JavaHome -DctmConfigDirectory $DctmConfigDirectory -DctmIrmDirectory $DctmIrmDirectory -DctmEnv $DctmEnv
    115}
    116 
    117#Remove-Item -Path $IdsToProcessFile
    118}
    119 
    120$MaxNbOfDocumentIds = 150
    121 
    122if ($DocumentIds.Count -gt $MaxNbOfDocumentIds){
    123while($DocumentIds.Count -gt 0){
    124$NewDocumentIds = New-Object System.Collections.ArrayList
    125while(($NewDocumentIds.Count -le $MaxNbOfDocumentIds) -and ($DocumentIds.Count -gt 0)){
    126$DocumentId = $DocumentIds[0]
    127if ($DocumentIds.Count -gt 1){
    128$DocumentIds = $DocumentIds[1..($DocumentIds.Count -1)]
    129}else{
    130$DocumentIds = @()
    131}
    132$NewDocumentIds.Add($DocumentId) > $null
    133}
    134 
    135MyProcess -DocumentIds $NewDocumentIds -CurrentDirectory $CurrentDirectory -JavaHome $JavaHome -DctmConfigDirectory $DctmConfigDirectory -DctmIrmDirectory $DctmIrmDirectory -DctmEnv $DctmEnv
    136}
    137}else{
    138MyProcess -DocumentIds $DocumentIds -CurrentDirectory $CurrentDirectory -JavaHome $JavaHome -DctmConfigDirectory $DctmConfigDirectory -DctmIrmDirectory $DctmIrmDirectory -DctmEnv $DctmEnv
    139}

  • Creation of java class com.java.lu.business.service.ecm.utils.main.CreateListToProcess:
    001package com.java.lu.business.service.ecm.utils.main;
    002 
    003import java.io.File;
    004import java.io.PrintWriter;
    005import java.text.MessageFormat;
    006import java.util.ArrayList;
    007import java.util.HashSet;
    008import java.util.List;
    009import java.util.Properties;
    010import java.util.Set;
    011 
    012import javax.naming.spi.NamingManager;
    013import javax.sql.DataSource;
    014 
    015import org.apache.commons.configuration.PropertiesConfiguration;
    016import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
    017import org.apache.commons.lang.StringUtils;
    018 
    019import com.documentum.com.DfClientX;
    020import com.documentum.com.IDfClientX;
    021import com.documentum.fc.client.DfQuery;
    022import com.documentum.fc.client.IDfClient;
    023import com.documentum.fc.client.IDfCollection;
    024import com.documentum.fc.client.IDfQuery;
    025import com.documentum.fc.client.IDfSession;
    026import com.documentum.fc.client.IDfSessionManager;
    027import com.documentum.fc.client.IDfUser;
    028import com.documentum.fc.common.DfException;
    029import com.documentum.fc.common.DfLoginInfo;
    030import com.documentum.fc.common.IDfId;
    031 
    032public class CreateListToProcess {
    033public static void main(String[] args) {
    034try {
    035String myRepository = "MY_DOCBASE";
    036String adminLogin = "adminuser";
    037String adminPassword = "pwd4adminuser";
    038 
    039IDfClientX clientx = new DfClientX();
    040IDfClient client = clientx.getLocalClient();
    041final IDfSessionManager sMgr = client.newSessionManager();
    042sMgr.setIdentity(IDfSessionManager.ALL_DOCBASES, new DfLoginInfo(adminLogin, adminPassword));
    043IDfSession dfSession = sMgr.getSession(myRepository);
    044 
    045try {
    046if (dfSession.getUser(null).getUserPrivileges() != IDfUser.DF_PRIVILEGE_SUPERUSER) {
    047throw new DfException(MessageFormat.format("{0} is not a superuser.", dfSession.getUser(null).getUserName()));
    048}
    049 
    050PrintWriter printWriterLog = new PrintWriter(new File(args[1])) {
    051@Override
    052public void println(String x) {
    053super.println(x);
    054super.flush();
    055System.out.println(x);
    056}
    057};
    058 
    059HashSet<String> docsIdsSet = new HashSet<String>();
    060File fileToCreate = null;
    061 
    062for (int i = 2; i < args.length; i++) {
    063if (i == 2) {
    064fileToCreate = new File(args[i]);
    065} else {
    066docsIdsSet.add(args[i]);
    067}
    068}
    069 
    070int cpt = 0;
    071 
    072PrintWriter printWriterIdsFile = new PrintWriter(fileToCreate);
    073try {
    074final int lineSize = 100;
    075 
    076IDfCollection dfCollection = getDocumentIdsToProcess(dfSession);
    077try {
    078List<String> list = new ArrayList<String>();
    079while (dfCollection.next()) {
    080cpt++;
    081IDfId dfId = dfCollection.getId("r_object_id");
    082list.add(dfId.getId());
    083if (list.size() == lineSize) {
    084printWriterIdsFile.println(StringUtils.join(list, ','));
    085printWriterIdsFile.flush();
    086list.clear();
    087}
    088}
    089if (list.size() > 0) {
    090printWriterIdsFile.println(StringUtils.join(list, ','));
    091printWriterIdsFile.flush();
    092list.clear();
    093}
    094} finally {
    095dfCollection.close();
    096}
    097 
    098} finally {
    099printWriterLog.write(MessageFormat.format("There {0,choice,0#are no documents|1#is one document|1<are {0,number,integer} documents} to process.", cpt));
    100printWriterLog.close();
    101}
    102 
    103} finally {
    104sMgr.release(dfSession);
    105}
    106} catch (Throwable e) {
    107e.printStackTrace();
    108}
    109}
    110 
    111/**
    112* Get the documents for the scope's current execution
    113* @param session
    114* @return
    115* @throws Throwable
    116*/
    117public static IDfCollection getDocumentIdsToProcess(IDfSession session) throws Throwable {
    118IDfCollection collection = null;
    119 
    120StringBuilder sb = new StringBuilder();
    121sb.append(" SELECT DISTINCT docsall.r_object_id FROM my_document (ALL) docsall WHERE docsall.i_chronicle_id  ");
    122sb.append("     IN ( SELECT docs.i_chronicle_id  from my_document docs ");
    123sb.append("         WHERE ANY docs.r_aspect_name = 'my_aspect' and docs.my_aspect.is_ok=1  ");
    124sb.append("         AND docs.r_content_size>0 ");
    125//....
    126sb.append("     ) ");
    127 
    128System.out.println(MessageFormat.format("Building and execution of query: {0}", sb.toString()));
    129IDfQuery dfQuery = new DfQuery(sb.toString());
    130collection = dfQuery.execute(session, IDfQuery.DF_READ_QUERY);
    131return collection;
    132}
    133 
    134}

  • So, on the DCTM server, in the folder D:\App\MyFolder4DCTM, there will be:
    o My_ScriptProcess.cmd
    o My_ScriptProcess.ps1
    o MyJavaLuLib.jar : containing all needed classes
    o \lib : commons-collections-3.2.jar + commons-configuration-1.5.jar + commons-io-1.2.jar + commons-logging-1.1.1.jar + ojdbc6.jar + commons-csv-1.1.jar …etc.
    o \dfc : all JARs and DLLs of DFC (dfc.jar,Dfc.dll, …etc).
    o \log : log files

Just a last point, in the POWERSHELL script the below command allows debugging of remote server execution from local IDE (Composer) via the port 9797:
“-Xrunjdwp:transport=dt_socket,address=9797,server=y,suspend=y”
however, if this instruction is uncommented, the execution is put on hold until the launch of the IDE on the port.

Best regards,

Huseyin OZVEREN

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

Related Post