Create TDI RMI based service with a script
Contents |
[edit] What is this
This is a set of windows batch scripts that can create and modify manual adapter profiles based on a provided template. Once you've created the profile you can import it by running
"F:\Program Files\ibm\itim\bin\win\config_remote_services.cmd" -profile %1 -jar %1.jar
This code is also a useful example of how cumbersome a Windows batch processing is.
[edit] Setting up
- Get the Template and unzip it.
- Get the batch files one by one from below or in one zip file unzip on the same level as the template.
You'll need a windows version of SED in your path to get it all running.
[edit] How to update all app profiles
Create the file you want to replace. You can do this by copying a file from _Skeleton and modifying it with the needed mods.
_Skeleton_mods\ITIM$1UserProfile
Attn: Due to the way batch files are structured interrupting them with Ctrl-C or Ctrl-Break is not advisable and often not possible. Make sure you have correct parameters before running the scripts.
As a last step after modifying remember to move files from _mod to _Skeleton so that the changes are not reapplied (in fact the change application will fail since there will be differences between _Skeleton and all profiles) run modifySkeleton.bat
[edit] Files
Make a profile based on a given name an a profile class. Use 'User' for the profile class. Download buildITIMProfile.bat.
@echo off rem Generic builder for an application profile to be imported into ITIM rem v1 2008(c) Alex Ivkin if "%1" == "" goto usage if not exist "..\Deployment" goto missing if not exist "..\ITIM%1%2Profile\%1%2*.xml" goto missing if not exist "..\ITIM%1%2Profile\ITIM%1%2*.xml" goto missing if not exist "..\ITIM%1%2Profile\CustomLabels.properties" goto missing if not exist "..\ITIM%1%2Profile\schema.dsml" goto missing if not exist "..\ITIM%1%2Profile\service.def" goto missing echo Building ITIM%1%2Profile if not exist "ITIM%1%2Profile\" mkdir ITIM%1%2Profile rem cd Deployment del /q "ITIM%1%2Profile\*.*" del /q "ITIM%1%2Profile.jar" copy "..\ITIM%1%2Profile\%1%2*.xml" .\ITIM%1%2Profile > nul copy "..\ITIM%1%2Profile\ITIM%1%2*.xml" .\ITIM%1%2Profile > nul copy "..\ITIM%1%2Profile\CustomLabels.properties" .\ITIM%1%2Profile > nul copy "..\ITIM%1%2Profile\schema.dsml" .\ITIM%1%2Profile > nul copy "..\ITIM%1%2Profile\service.def" .\ITIM%1%2Profile > nul "f:\Program Files\IBM\TDI\V6.1.1\AppServer\java\bin\jar" -cf ITIM%1%2Profile.jar ITIM%1%2Profile pause goto :eof :missing echo missing some of the files required for an ITIM Profile goto :eof :usage echo call from the app deployment folder as following: echo %0 {AppName} {Class}
Create a new application profile, build and test harnesses based on a skeleton. Download createApplication.bat.
@echo off rem Create a new application profile, build and test harnesses based on a skeleton. rem Replaces "$1" and "$2" in file names and file contents of the skeleton with the app name and profile type, respectively. rem v1 2008(c) Alex Ivkin rem GNU sed must be in the same folder as the batch file. The batch must be executed from the folder that it is in. if .%1.==.. goto usage if .%2.==.-f. goto run if .%3.==.-f. goto run if .%2.==.-np. set passwordless=true if .%3.==.-np. set passwordless=true if exist ..\%1 goto exists :run rem ---- Create deployment structure ---- mkdir ..\%1 mkdir ..\%1\Logs mkdir ..\%1\Deployment rem ---- Create development structure ---- rem Rob Boime 5/13/09 Do not create a custom Staff profile. rem call createApplicationSubProfile.bat %1 Staff call createApplicationSubProfile.bat %1 User %passwordless% goto :eof :exists echo ..\%1 exists. Will not overwrite existing profile, unless run with -f goto :eof :usage echo Run as %0 [AppName] [-np] [-f] echo -f will force an existing profile overwrite. No files are deleted from the old profile echo -np indicates a passwordless service
Creates an actual profile by mass search and replace of $1 in file names and contents. Download createApplicationSubProfile.bat.
@echo off rem Creates actual profile by mass search and replace of $1 in file names and contents rem Replaces "$1" in file names and file contents of the skeleton with the app name. rem v1 2008(c) Alex Ivkin rem GNU sed must be in the same folder as the batch file. The batch must be executed from the folder that it is in. if .%1.==.. goto usage if .%2.==.. goto usage <nul (set/p z=Creating %1 %2 profile.) rem ---- Create deployment structure ---- mkdir ..\%1\Deployment\ITIM%1%2Profile sed -rT s/\$1/%1/g "..\_Skeleton\Deployment\build$1%2Profile.bat" > ..\%1\Deployment\build%1%2Profile.bat <nul (set/p z=.) rem ---- Create development structure ---- mkdir ..\%1\ITIM%1%2Profile pushd ..\_Skeleton\ITIM$1%2Profile for %%a in (*) do ( rem Do search and replace in both file name and file contents rem Do not even dare to understand how it works. Its magic. Microsoft sort of way. <nul (set/p z=..\..\_AppToolkit\sed -rT s/\$1/%1/g "%%a" ^> ) > tmp$.bat echo ..\..\%1\ITIM%1%2Profile\%%a | ..\..\_AppToolkit\sed -r s/\$1/%1/g >> tmp$.bat call tmp$.bat <nul (set/p z=.) ) del tmp$.bat if not .%2. == .User. goto ignorepassword if not .%3. == .true. goto ignorepassword rem Remove erPassword attribute from the user account class ..\..\_AppToolkit\sed -T "/ITIM%1UserAccount/,/\/class/ {/erPassword/d}" ../../%1/ITIM%1%2Profile/schema.dsml > ../../%1/ITIM%1%2Profile/schema.dsml.fixed move ../../%1/ITIM%1%2Profile/schema.dsml.fixed ../../%1/ITIM%1%2Profile/schema.dsml rem add password commands to the end on service.def ..\..\_AppToolkit\sed -T "/<\/properties>/i\ <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_REQUIRED_ON_RESTORE\"><value>true</value></property>\n <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_ALLOWED_ON_RESTORE\"><value>true</value></property>" ../../%1/ITIM%1%2Profile/service.def > ../../%1/ITIM%1%2Profile/service.def.fixed move ../../%1/ITIM%1%2Profile/service.def.fixed ../../%1/ITIM%1%2Profile/service.def :ignorepassword popd echo ok goto :eof :usage echo Do not call this file directly unless you know what you are doing.
Shows a list of differences in the profile compared to the skeleton. Download diffApplication.bat.
@echo off rem Shows a list of differences in the profile compared to the skeleton rem Replaces "$1" in file names and file contents of the skeleton with the app name. rem v1 2008(c) Alex Ivkin rem GNU sed must be in the same folder as the batch file. The batch must be executed from the folder that it is in. if .%1.==.. goto usage set leavefile=false set passwordless=false if .%2.==.-x. set leavefile=true if .%3.==.-x. set leavefile=true if .%2.==.-np. set passwordless=true if .%3.==.-np. set passwordless=true if not exist ..\%1 goto notexists :run call diffApplicationSubProfile.bat %1 User %leavefile% %passwordless% goto :eof :notexists echo ..\%1 does not exists. goto :eof :usage echo Run as %0 [AppName] [-np][-x] echo -x instructs the diff routine to leave the copy of the file from the skeleton in an app folder if it is different echo -np indicates a passwordless service
Check the differences in the profile compared to the skeleton. Leaves the file generated from skeleton in the app folder. Download diffApplicationSubProfile.bat.
@echo off rem Check the differences in the profile compared to the skeleton. Leaves the file generated from skeleton in the app folder rem Replaces "$1" in file names and file contents of the skeleton with the app name. rem v1 2008(c) Alex Ivkin rem GNU sed must be in the same folder as the batch file. The batch must be executed from the folder that it is in. if .%1.==.. goto usage if .%2.==.. goto usage if .%3.==.true. set dontdelete=true if not exist ..\%1\PGE%1%2Profile goto missing <nul (set/p z=Checking %1 %2 profile.) rem ---- Check deployment structure ---- sed -rT s/\$1/%1/g "..\_Skeleton\Deployment\build$1%2Profile.bat" > ..\%1\Deployment\build%1%2Profile.bat.fromskeleton fc ..\%1\Deployment\build%1%2Profile.bat ..\%1\Deployment\build%1%2Profile.bat.fromskeleton | find "FC: no diff" > nul IF ERRORLEVEL 1 ( echo. <nul (set/p z=Found differences in ..\%1\Deployment\build%1%2Profile.bat...) IF NOT .%dontdelete%.==.true. del ..\%1\Deployment\build%1%2Profile.bat.fromskeleton ) ELSE (del ..\%1\Deployment\build%1%2Profile.bat.fromskeleton) <nul (set/p z=.) rem ---- Check development structure ---- setlocal EnableDelayedExpansion pushd ..\_Skeleton\PGE$1%2Profile for %%a in (*) do ( rem Do search and replace in both file name and file contents. Then diff that. rem Do not even dare to understand how it works. Its magic. Microsoft sort of way. <nul (set/p z=set filename=) > filename$.bat echo %%a| ..\..\_AppToolkit\sed -r s/\$1/%1/g >> filename$.bat call filename$.bat ..\..\_AppToolkit\sed -rT s/\$1/%1/g "%%a" > ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton if .%2. == .User. ( if .%4. == .true. ( if %%a == schema.dsml ( rem Remove erPassword attribute from the user account class ..\..\_AppToolkit\sed -T "/pge%1UserAccount/,/\/class/ {/erPassword/d}" ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton > ..\..\%1\PGE%1%2Profile\!filename!.fromskeletonfix move ..\..\%1\PGE%1%2Profile\!filename!.fromskeletonfix ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton > nul ) if %%a == service.def ( rem add password commands to the end on service.def ..\..\_AppToolkit\sed -T "/<\/properties>/i\ <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_REQUIRED_ON_RESTORE\"><value>true</value></property>\n <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_ALLOWED_ON_RESTORE\"><value>true</value></property>" ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton > ..\..\%1\PGE%1%2Profile\!filename!.fromskeletonfix move ..\..\%1\PGE%1%2Profile\!filename!.fromskeletonfix ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton > nul ) ) ) fc ..\..\%1\PGE%1%2Profile\!filename! ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton | find "FC: no diff" > nul IF ERRORLEVEL 1 ( echo. <nul (set/p z=Found differences in !filename!...) IF NOT .%dontdelete%.==.true. del ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton ) ELSE (del ..\..\%1\PGE%1%2Profile\!filename!.fromskeleton) <nul (set/p z=.) ) del filename$.bat popd echo ok goto :eof :missing echo Missing ..\%1\PGE%1%2Profile goto :eof :usage echo Do not call this file directly unless you know what you are doing.
Augments an existing application with changes from skeleton. Download modifyApplication.bat.
@echo off rem Augments an existing application with changes from skeleton rem Replaces "$1" in file names and file contents of the skeleton with the app name. rem v1 2008(c) Alex Ivkin rem GNU sed must be in the same folder as the batch file. The batch must be executed from the folder that it is in. if .%1.==.. goto usage set leavefile=false set passwordless=false if .%2.==.-x. set leavefile=true if .%3.==.-x. set leavefile=true if .%2.==.-np. set passwordless=true if .%3.==.-np. set passwordless=true if not exist ..\%1 goto notexists :run rem ---- Create development structure ---- call modifyApplicationSubProfile.bat %1 User %leavefile% %passwordless% goto :eof :notexists echo ..\%1 does not exists. goto :eof :usage echo Run as %0 [AppName] [-np] echo -x instructs the diff routine to leave the copy of the file from the skeleton in an app folder if it is different echo -np indicates a passwordless service
Augments an existing application with changes from skeleton. Download modifyApplicationSubProfile.bat.
@echo off rem Augments an existing application with changes from skeleton rem Replaces "$1" in file names and file contents of the skeleton with the app name. rem v1 2008(c) Alex Ivkin rem GNU sed must be in the same folder as the batch file. The batch must be executed from the folder that it is in. if .%1.==.. goto usage if .%2.==.. goto usage if not exist ..\%1\ITIM%1%2Profile goto missing echo Checking and modifying %1 %2 profile... rem ---- Check deployment structure ---- if exist "..\_Skeleton_mods\Deployment\build$1%2Profile.bat" ( sed -rT s/\$1/%1/g "..\_Skeleton\Deployment\build$1%2Profile.bat" > ..\%1\Deployment\build%1%2Profile.bat.fromskeleton fc ..\%1\Deployment\build%1%2Profile.bat ..\%1\Deployment\build%1%2Profile.bat.fromskeleton | find "FC: no diff" > nul IF ERRORLEVEL 1 ( echo - File Deployment\build%1%2Profile.bat has been already modified. Will not update. IF NOT .%dontdelete%.==.true. del ..\%1\Deployment\build%1%2Profile.bat.fromskeleton ) ELSE ( echo Updating Deployment\build%1%2Profile.bat sed -rT s/\$1/%1/g "..\_Skeleton_mods\Deployment\build$1%2Profile.bat" > ..\%1\Deployment\build%1%2Profile.bat del ..\%1\Deployment\build%1%2Profile.bat.fromskeleton ) ) rem ---- Check development structure ---- setlocal EnableDelayedExpansion pushd ..\_Skeleton_mods\ITIM$1%2Profile for %%a in (*) do ( rem Do search and replace in both file name and file contents. Then diff that. <nul (set/p z=set filename=) > filename$.bat echo %%a| ..\..\_AppToolkit\sed -r s/\$1/%1/g >> filename$.bat call filename$.bat ..\..\_AppToolkit\sed -rT s/\$1/%1/g "..\..\_Skeleton\ITIM$1%2Profile\%%a" > ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton if .%2. == .User. ( if .%4. == .true. ( if %%a == schema.dsml ( rem Remove erPassword attribute from the user account class ..\..\_AppToolkit\sed -T "/ITIM%1UserAccount/,/\/class/ {/erPassword/d}" ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton > ..\..\%1\ITIM%1%2Profile\!filename!.fromskeletonfix move ..\..\%1\ITIM%1%2Profile\!filename!.fromskeletonfix ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton > nul ) if %%a == service.def ( rem add password commands to the end on service.def ..\..\_AppToolkit\sed -T "/<\/properties>/i\ <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_REQUIRED_ON_RESTORE\"><value>true</value></property>\n <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_ALLOWED_ON_RESTORE\"><value>true</value></property>" ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton > ..\..\%1\ITIM%1%2Profile\!filename!.fromskeletonfix move ..\..\%1\ITIM%1%2Profile\!filename!.fromskeletonfix ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton > nul ) ) ) fc ..\..\%1\ITIM%1%2Profile\!filename! ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton | find "FC: no diff" > nul IF ERRORLEVEL 1 ( echo - File !filename! has been already modified. Will not update. IF NOT .%3.==.true. del ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton ) ELSE ( echo Updating !filename! ..\..\_AppToolkit\sed -rT s/\$1/%1/g "%%a" > ..\..\%1\ITIM%1%2Profile\!filename! if .%2. == .User. ( if .%4. == .true. ( if %%a == schema.dsml ( rem Remove erPassword attribute from the user account class ..\..\_AppToolkit\sed -T "/ITIM%1UserAccount/,/\/class/ {/erPassword/d}" ..\..\%1\ITIM%1%2Profile\!filename! > ..\..\%1\ITIM%1%2Profile\!filename!.fix move ..\..\%1\ITIM%1%2Profile\!filename!.fix ..\..\%1\ITIM%1%2Profile\!filename! > nul ) if %%a == service.def ( rem add password commands to the end on service.def ..\..\_AppToolkit\sed -T "/<\/properties>/i\ <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_REQUIRED_ON_RESTORE\"><value>true</value></property>\n <property name=\"com.ibm.itim.remoteservices.ResourceProperties.PASSWORD_NOT_ALLOWED_ON_RESTORE\"><value>true</value></property>" ..\..\%1\ITIM%1%2Profile\!filename! > ..\..\%1\ITIM%1%2Profile\!filename!.fix move ..\..\%1\ITIM%1%2Profile\!filename!.fix ..\..\%1\ITIM%1%2Profile\!filename! > nul ) ) ) del ..\..\%1\ITIM%1%2Profile\!filename!.fromskeleton ) del filename$.bat ) popd goto :eof :missing echo Missing ..\%1\ITIM%1%2Profile goto :eof :usage echo Do not call this file directly unless you know what you are doing.
Augments the skeleton with changes. Run this file ONLY after a successful completion of profile modifications for all services. Run like this:
call modifySkeletonProfile.bat User
Augments the skeleton with changes. Download modifySkeletonProfile.bat.
@echo off rem Augments the skeleton with changes rem Run this file ONLY after a successful completion of profile modifications for all services if .%1.==.. goto usage pushd ..\_Skeleton_mods echo Updating %1 Skeleton... if exist "Deployment\build$1%1Profile.bat" move "Deployment\build$1%1Profile.bat" "..\_Skeleton\Deployment\build$1%1Profile.bat" > nul for %%a in (ITIM$1%1Profile\*) do ( move %%a ..\_Skeleton\%%a > nul ) popd goto :eof :usage echo Do not call this file directly unless you know what you are doing.