When using the FAST Search Database Connector, updating and moving configurations between environments can be challenging. The temptation is to simply do everything by hand. This approach can be error prone and time consuming. In the interest of being as lazy (but pragmatic) as possible, an up-front investment in a good set of scripts is well worth the effort.
One of the first challenges I ran across was setting the connection string in a FAST Search Database Connector configuration file. The first step was to determine which environment the deployment was being performed on:
$computer = gc env:computername
write-host "HOST Computer is " $computer
switch ($computer.ToLower())
{
"dev-fast" { $connectionString = "jdbc:sqlserver://dev-db:1433;database=DB;integratedSecurity=true;encrypt=true;trustServerCertificate=true;"}
"test-fast" { $connectionString = "jdbc:sqlserver://test-db:1433;database=DB;integratedSecurity=true;encrypt=true;trustServerCertificate=true;" }
"prod-fast" { $connectionString = "jdbc:sqlserver://prod-db:1433;database=DB;integratedSecurity=true;encrypt=true;trustServerCertificate=true;" }
default {$connectionString = "jdbc:sqlserver://localhost:1433;database=DB;integratedSecurity=true;encrypt=true;trustServerCertificate=true;"}
}write-host "Connection string is " $connectionString
Based on the machine the deployment script is being run on, the script will select the proper connection string. With the connection string selected, the database connector configuration file can be updated:
$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$configFile = join-path $executingScriptDirectory "dbcrawl_jdbcConfig.xml"
[xml]$file = get-content $configFile
$xpath = "//group[@name='Input']/parameter[@name='JDBCURL']/value"
$node = select-xml -Xml $file -xpath $xpath | select-object -expandProperty Node
$node.FirstChild.InnerText = $connectstring
$file.Save($configFile)
The above assumes the PowerShell script is being executed from the folder containing the target configuration file. It inserts the proper connection string into the JDBCURL element and saves the change. The same approach can be used to update other elements in the configuration file.
While this function may not seem significant now, when your dealing with 10 different configuration files in 4 different environments, that’s a lot of Notepad editing to be done by hand.

0 comments:
Post a Comment