Script to create transformers cubes

A good solution for transformer cube creation i found on the web! :slight_smile:

http://blogs.captechconsulting.com/

This is a technique for building cubes on a regular basis, preferably after hours. It uses three shared folders on each server that runs Transformer in each environment (Dev, Test, and Prod). The folders are referenced within Cognos by their UNC name. Cognos Administrators should have access to these folders.

Share Name Purpose
\cubes Cubes are accessed here
\cubes\build Cubes are built here
\cubes\model Batch (other than cogconfig.bat) and PYJ files

To enable Transformer to log into the server to build the cube, you must create an OS Signon in the model, store the user ID and password (using the local environment’s service credentials), then set it as an auto logon.

When you build the model in Development, you create the data source(s) using saved Query or Report Studio reports, or you can select items directly from a package. Remember that the reports and package must exist in the same location in each environment, or you will need to adjust the data source to find them. The first time you build a cube in an environment, you need to create a data source for cube access within Cognos Connection by the studios.

CAUTION – When creating an export, or performing an import, be careful NOT TO INCLUDE data sources. If you do, ALL data source connections in the target environment (not just the one for the package you are exporting / importing) will be replaced with the connections from the source environment. In other words, all Test data sources will suddenly point to Dev databases, as will Production data sources. Also, do not include Cognos Roles, as it will have the same effect on security.

Since the model contains environment-specific signons and build targets, you will need to modify it as you promote it.

* create the model with the cube build target location set as
  \\servername\cubes\build\cubename.mdc
* as you promote the model, you will need to change servername in the target location entry, and the OS signon, to match the new environment
* the model data source (reports feeding the model) properties should not need changing as long as their name and location does not change as you promote from Dev to Test to Prod.
* Copy the model to \\servername\cubes\model\. Transformer models are not handled within Cognos Connection. They must be manually copied from environment to environment, just like the deployment package for your model data source. 

You will need two system environment variables on each server used to build cubes. One is cog8_drive, who’s value is the drive letter where the \Cube share is located (e.g. “D:”). The other is cog8_root, which points to the bin folder of the Cognos install (e.g. “d:\program files\cognos\c8\bin”.

There are four batch files you will use. One is a Cognos-provided file: \Program Files\cognos\c8\bin\cogconfig.bat. You will need to edit this file, adding an EXIT command as the last line to return control to the calling batch job. Be sure to save a backup first.

The second is cubebuild.bat, which will run transformer to build the enabled cubes in a model. You will need to call this for each model you want to run. This file stays the same in each environment, as it gets the drive letter and Cognos\bin location from environment variables and the model name is passed as a parameter when it is called.

Blat (used below in a commented example for error trapping) is a Win32 command line utility that sends email using SMTP or posts to Usenet using NNTP. (www.blat.net). Be sure to change the settings below to match your configuration, if you use it.

@ECHO OFF
::
:: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
:: = CubeBuild.bat
:: = John Anderson, CapTech Ventures
:: = This is the batch file for automating Transformer Cube Builds
:: = It uses environment system variables %cog8_root% and %cog8_drive%
:: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
::
:: Bug in 8.3, requires changing to Bin before running Transformer -
::
CD %cog8_root%
::
:: Build the cube using the argument passed in the calling command
:: (from scheduler), save model when done
::
cogtr -n2 -p"%cog8_drive%\cubes\model%1" -s"%cog8_drive%\cubes\model%1"
::
:: Check return code for error indication
::
if %errorlevel% == 0 goto noerror
::
:error
::
:: Errors were encountered, so send email advising same
:: this example uses BLAT installed on the server
::
:: set BLAT variables
::
::set eMailTo=janderson@sample.com
::set eMailFrom=janderson@sample.com
::set subj=-s “! Transformer Encountered An Error !”
::set note=Please check the model %1 for errors
::set server=-server Emailserver:25
::set debug=-debug -log c:\ja\blat.log -timestamp
::
:: run Blat
::
::blat - -to %eMailTo% -f %eMailFrom% %subj% -body “%note%” %server% %debug%
::
:noerror
::
:: No errors were encountered, so exit this batch job
::
Exit

The third batch file is run once nightly, and will stop Cognos, wait for the file locks to be released, call the copy_cubes batch job, and restart Cognos.

@ECHO OFF
::
:: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
:: = restart_cognos.bat
:: = John Anderson, CapTech Ventures
:: = This is the batch file for stopping Cognos, copying new cubes
:: = to the cubes folder, and restarting Cognos
:: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
::
:: Change to the bin folder
::
cd %cog8_root%
::
:: Stop Cognos, wait for job to finish
::
start /w cogconfig -stop
::
:: Use PING to delay execution of copy step for 20 seconds
:: while system drops file locks
::
PING 1.0.0.0 -n 20 -w 1000 >NUL
::
:: Call the job to copy all cubes from staging up to cubes,
:: verifying the write and suppressing prompts,
:: ` wait for copy to finish
::
start /w %cog8_drive%\cubes\model\copy_cubes
::
:: Start Cognos, saving current configuration in UTF-8 format,
:: wait for job to finish
::
start /w cogconfig -s -utf8
::
:: Exit this batch job
::
exit

The fourth batch file is a short one called from restart_cognos.bat that copies the cubes from \cubes\build to \cubes while Cognos is stopped.

@ECHO OFF
::
:: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
:: = copy_cubes.bat
:: = John Anderson, CapTech Ventures
:: = This batch file copies new cubes to the cubes folder
:: = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
::
:: Copy all cubes from build up to cubes, verifying the write and
:: suppressing prompts, wait for copy to finish
::
copy /v /y %cog8_drive%\cubes\build*.mdc %cog8_drive%\cubes
::
:: Exit this batch job
::
exit

To put all this together, you will use Windows Scheduler. Create a scheduled task running cubebuild.bat for each model you want to automate. The command line should look like D:\cubes\model\CubeBuild.bat model.pyj where model.pyj is the name of the model to run. Remember, the models must reside in \cubes\model. Add the model name to the task name so you can keep them straight.

You will also need to schedule restart_cognos.bat to run at whatever frequency you will need to refresh the cubes. Remember, this will bring Cognos down while it runs – typically for about five minutes – test it on your server to find out the downtime you will experience. In practice, these will all be scheduled for the early hours of the morning.

Although this looks like a major hassle to maintain, it’s not. The majority of the work is in setting up the environment the first time. After that, it’s little more than the standard cube build-and-promote process. The batch files should not need to be modified once they’re in place, unless the environment (e.g. - email server address) changes. If the Cog8 install location or cube drive is changed, the environment variables will need updating.

thanks a lot.