Friday, December 22, 2006

BizTalk 2006 - BTSTask

This Post is obtained from Matt Hall. Thanks Matt !!!

BizTalk 2006 comes with a handy new tool named BTSTask. This utility facilitates the execution of deployment tasks that you are able to perform from the BizTalk Administration console from the command line. This supercedes BizTalk 2004’s BTSDeploy and should be used in new scripts, as BTSDeploy may be removed in subsequent versions of BizTalk Server, although it is still supported in 2006.


BTSTask includes more functionality than BTSDeploy, adding support for the new functionality such as resources and MSI files:
Installing an application to the BizTalk Management database.
Adding resources to the application.
Exporting an application to an MSI file.
Export binding information to a file.
Import an application from an MSI file.
Import binding information from a file.
List resources for an application.
List all applications in the BizTalk Management database.
List the resources in an MSI file.
Remove an application from the BizTalk Management database.
Remove a resource from an application

The following example steps through a few commands used to provide a deployment using BTSTask. These have been consolidated into a single batch file which executes all the steps. Being a batch file you may therefore also call it from any automated deployment mechanisms you may have in place.

Step 1 – Set variables
set LOG_LOCATION=.\Logs\LogFile.txt
This step simply sets the location of where we will log the installation script results


Step 2 – Attempt to install the Application
BTSTask AddApp -ApplicationName:EAISolution >> %LOG_LOCATION%if %errorlevel%==1 ( echo Error Creating Application >> %LOG_LOCATION% goto :delete)goto :install
The next step attempts to create a new BizTalk application to the BizTalk Management database. This is the new container found in BizTalk 2006 that is used to reduce the management effort for applications. At this point we also include some error checking. If there is an error it is generally due to an application already existing with the same name, so we attempt to remove the existing application. This is handled at another step in the batch file.
Note that it would be unlikely for you to want to delete an existing application in a production environment, as you would probably manage any upgrades through versioning and the side-by-side capabilities available within BizTalk.


Step 3 – Attempt to Remove Existing Application
:delete
.\scripts\StopApp.vbs >> %LOG_LOCATION%
BTSTask RemoveApp -ApplicationName:EAISolution >> %LOG_LOCATION%if %errorlevel%==1 ( echo Error Deleting Application >> %LOG_LOCATION% goto :end)BTSTask AddApp -ApplicationName:EAISolution >> %LOG_LOCATION%
This section of the batch file only gets called if there is an existing application to remove. See the notes above. A custom WMI script written in
VBScript is called that attempts to get the application into a state whereby it can be successfully removed.
The BTSTask RemoveApp is then executed to remove the application specified. If we receive an error at this point then log it and simply go to the end. Otherwise the existing application has been removed successfully so create the application again.


Step 4 – Add Assemblies
BTSTask AddResource -Source:.\Assemblies\EAISchemas.dll -ApplicationName:EAISolution -Type:BizTalkAssembly -Options:GacNow,GACUtil >> %LOG_LOCATION%
BTSTask AddResource -Source:.\Assemblies\EAIOrchestrations.dll -ApplicationName:EAISolution -Type:BizTalkAssembly -Options:GacNow,GACUtil >> %LOG_LOCATION%
The next two lines use the AddResource command to add the two assemblies into the BizTalk application. Using the Type parameter we have specified we are adding an assembly resource rather than other resources such as BAM Definitions, Certificates, and Policies etc.
This will simply add the assembly to the BizTalk Management database, so notice the use of the GACNow and GACUtil options to handle GACing of these assemblies. Also as usual you must make sure you are installing the assemblies in dependency order, so that if one assembly depends on another then it must be installed after the assembly it depends on.


Step 5 – Add PostProcessingScript
BTSTask AddResource -Source:.\Scripts\StartOrch.vbs -Destination:.\StartOrch.bat -ApplicationName:EAISolution -Type:PostProcessingScript >> %LOG_LOCATION%
This next step adds a post processing script to application, the type being specified as with adding assemblies by utilising the Type parameter. You may now include pre and post processing scripts with your installation packages in BizTalk 2006 that get executed during deployment. This facilitates the execution of additional installation tasks, thereby making the process extremely flexible.


Step 6 – Import Bindings
BTSTask ImportBindings -Source:.\Bindings\EAISolution.xml -ApplicationName:EAISolution >> %LOG_LOCATION%
We then simply import our previously exported bindings. Exporting binding files from your BizTalk applications can now be achieved through the BizTalk Administration console and can be set at various levels within the hierarchy such as all bindings from a selected application, all bindings from a selected group or bindings for the selected assembly.


Step 7 – Create Manifest
BTSTask ListApp -ApplicationName:EAISolution -ResourceSpec:.\Logs\AppManifest.xml
For record logging purposes we then create a manifest of the deployed application. This is achieved through the ListApp command which lists all the artefacts in the application, along with the unique identifier (LUID) and type of each artefact. We use the ResourceSpec parameter to export this to an XML file.


Step 8 – Create MSI
BTSTask ExportApp -ApplicationName:EAISolution -Package:.\MSI\EAISolution.msi >> %LOG_LOCATION%
The final step is to create a complete MSI of the application. It is possible to export specific artefacts from an application into an MSI by using the ResourceSpec parameter, but in this case we simply export everything.
Don’t forget this is merely a very simple example of how the scripts are used and only used as a taster; you would take the commands and use them according to your environment and solution.

No comments: