Thursday, 31 May 2012 09:07

Custom BizTalk Deployment - Part 3 - Final

Written by 
Rate this item
(1 Vote)

Final Scripts

 

It's been the time of my last Post, but not so this is a topic I have left behind.

Remember my previous Posts, in which we were using the PowerShell Provider to BizTalk

Based on the possibilities offered by the cmdlets included in PowerShell provider to BizTalk, we have developed a set of scripts. Each one of them performs specific functions, so it can be executed separately in the environment providing the necessary parameters.

The main process starts with the execution of the Deploy.ps1.The syntax used to run the same is as follows (in the PowerShell console)

 

Deploy.ps1 <Server Instance> <Deploy File> <Import bindings> <Start orch/Instances>

Where

<Server Instance>: Is the Database of the BizTlak server Group

<Deploy File>: Full Path of the Deploy File as discussed in ________

<Import Bindings>: YES/NO Switch to import bindings defined in a Bindings Section of the Deploy File

<Start orch/Instances>: YES/NO Switch to enlist/start orchestrations defined in Orchestrations section of Deploy File and/or restart hosts instances

The beginning of the script establishes the remote execution policy to run PowerShell commands

 

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

 

If it has not been loaded previously as the user profile the SnapIn (my case) runs the instruction set

      Add-PSSnapIn BizTalkFactory.PowerShell.Extensions

      Write-Host "Creating BizTalk Drives"

      New-PSDrive -Name BizTalk -PSProvider BizTalk -Root BizTalk:\ -Instance $Server -Database BizTalkMgmtDb

 

Based on the XML Deploy file defined in previous posts, we can isolate the different components to install getting the set of XML nodes associated with them

      

      $Node = $xml.SelectSingleNode("Deploy/Resources")

      $App = $Node.Application

      $Orchestrations = $xml.SelectSingleNode("Deploy/Orchestrations")

      $Bindings = $xml.SelectSingleNode("Deploy/Bindings")

 

With this information, we start executing the corresponding scripts, as shown in the following fragment

       ./DeployAssemblies.ps1 "Assembly"

       Set-location -Path $CurrentLocation

      ./DeployAssemblies.ps1 "AppAssembly"

       Set-location -Path $CurrentLocation

        ./DeployAssemblies.ps1 "BizTalkAssembly"

 

Orchestration Management

As a previous step to update an orchestration, we must take it down , for which we use the following code snippet

Set-location -Path BizTalk:Applications\$Args\Orchestrations

foreach ($Orch in Get-ChildItem )

{

            if ($Orch.Status -EQ "Started")

            {

                        $name = $Orch.Name

                        Write-host $Name

                        $Pattern = GetOrchPattern($Name)

                        cscript.exe ./ManageOrchestrations.vbs Unenlist $Pattern%

            }

}

 

For this task we’ve used the script ManageOrchestrations.vbs, extracted from here.

The reason for using this scripts instead of the cmdlets of the BizTalk PowerShell Provider is that with this cmdlets, we cannot gain control of dependent/called orchestrations via Start Orchestration or Call Orchestration shape. This script developed by Paul Green fits perfectly to this scenario.

The addition of artifacts or resources to the application is performed using the command

Add-ApplicationResource -Path $App -Type System.BizTalk:BizTalkAssembly -ResourcePath $Destination –Overwrite

 

As you’ll see on the script, there is a set of additional commands commented

             $resource = (Get-Item -Path "$App\Resources\$ResourceFullName")

             $resource.GACOnAdd = $true

             $resource.GACOnImport = $true

             $resource.GACOnInstall = $true

 

But according to this discussion , this functionality is not fully supported.

To ensure correct GAC’ing of the assemblies we’ve used the following code snippet

Set-location -Path $CurrentLocation

Get-Item $Destination | ./GACINSTALL.ps1

The steps contained on GACINSTALL.ps1 has been described in Custom BizTalk Deployment - Part 2.

Now it’s time to start orchestrations. If the Deploy file contains the Orchestrations Section using this syntax

<Orchestrations>

                        <Orchestration name="MyApp.Orchestration1" version="2.2.0.0" action="start"/>

Then the enlist/start Orchestration task is performed using the following snippet

$OrchNodes =$Orchestrations.SelectNodes("Orchestration[@action='start']")

 foreach ($Orchestration in $OrchNodes)

{

            $Name = $Orchestration.Name

            $Version = $Orchestration.Version

            cscript.exe ./ManageOrchestrations.vbs start $Name $Version

}

Now we are almost completed. It only remains restart Host instances. For this we use the following code

Get-ChildItem "biztalk:\Platform settings\Host Instances\" | where {$_.HostType -eq "InProcess"} | where { $_.ServiceState -eq "Running"} | restart-hostinstance |select Hostname

 

That’s all!!! Deploy completed!!!

On attached ZIP file you will find all the scripts used.

I encourage you to try to make deployments with these scripts. I have benefited them the most from more than one year ago.

Still a lot to develop and improve, but that will be another entry in a while

I hope your comments and suggestions

Read 2664 times Last modified on Thursday, 31 May 2012 09:57
Ernesto Tellez

Ernesto is currently a Microsoft solutions architect,  focusing on developing BizTalk solutions for banking. He has managed to combine the power the BizTalk platform with the power of programming in.NET Farmework towards applications easily scalable and maintainable, high availability environments.

Currently resides in Barcelona, Spain

linkedin

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.