Skip to content

Commit

Permalink
Enabled real time logging on execute command (#75)
Browse files Browse the repository at this point in the history
* enabled real time logging on execute command

* have logging through event

* dummy commit to re process build

* enforce pester version.

* dummy commit

* Bump version to 3.4.0.0

* Code review

* Raise logevent implementation to main functions

* Small fixes

* Small fixes

Co-authored-by: Pedro Nunes <[email protected]>
  • Loading branch information
DuarteCoelhoOutsystems and pintonunes authored Jun 5, 2020
1 parent caea6f8 commit 9ecc440
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 63 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Outsystems.SetupTools Release History

## 3.4.0.0

- ExecuteCommand: Enabled real time logging for all executed processes. This impacts the execution of PlatformInstaller, ConfigTool, Scinstall

## 3.3.3.0

- PlatformSetup: Now all expected files are using canonical names and code improvement
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 3.3.3.{build}
version: 3.4.0.{build}

only_commits:
files:
Expand All @@ -8,7 +8,7 @@ only_commits:
install:
- ps: |
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module Pester -MinimumVersion 3.4.0 -Scope CurrentUser -Force
Install-Module Pester -RequiredVersion 4.10.1 -Scope CurrentUser -Force
Install-Module psake -Scope CurrentUser -Force -RequiredVersion 4.7.4
Install-Module PSScriptAnalyzer -Scope CurrentUser -Force
Install-Module platyPS -Scope CurrentUser -Force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ function Get-OSPlatformDeploymentZone
$configToolArguments = "/getdeploymentzones"

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Running the configuration tool. This can take a while..."

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = RunConfigTool -Arguments $configToolArguments
$result = RunConfigTool -Arguments $configToolArguments -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -76,11 +82,6 @@ function Get-OSPlatformDeploymentZone

if ($result.ExitCode -ne 0)
{
$confToolOutputLog = $($result.Output) -Split ("`r`n")
foreach ($logline in $confToolOutputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration Tool: $logline"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration tool exit code: $($result.ExitCode)"

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 3 -Message "Error getting the deployment zones. Exit code: $($result.ExitCode)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ function Install-OSPlatformLicense
}

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Installing outsytems license"

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = RunConfigTool -Arguments $("/UploadLicense " + [char]34 + $Path + [char]34)
$result = RunConfigTool -Arguments $("/UploadLicense " + [char]34 + $Path + [char]34) -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -101,11 +107,6 @@ function Install-OSPlatformLicense
return
}

$confToolOutputLog = $($result.Output) -Split ("`r`n")
foreach ($logline in $confToolOutputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "CONFTOOL: $logline"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration tool exit code: $($result.ExitCode)"

if ($result.ExitCode -ne 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,15 @@ function Install-OSPlatformServiceCenter
}

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Installing Outsystems Service Center. This can take a while..."

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = RunSCInstaller -Arguments $scInstallerArguments
$result = RunSCInstaller -Arguments $scInstallerArguments -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -122,11 +128,6 @@ function Install-OSPlatformServiceCenter
return $installResult
}

$outputLog = $($result.Output) -Split ("`r`n")
foreach ($logLine in $outputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "SCINSTALLER: $logLine"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "SCInstaller exit code: $($result.ExitCode)"

if ( $result.ExitCode -ne 0 )
Expand Down
7 changes: 6 additions & 1 deletion src/Outsystems.SetupTools/Functions/New-OSServerConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ function New-OSServerConfig
#region generate templates
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Generating new configuration for database provider $DatabaseProvider"

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = RunConfigTool -Arguments "/GenerateTemplates"
$result = RunConfigTool -Arguments "/GenerateTemplates" -OnLogEvent $onLogEvent
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,14 @@ function Publish-OSPlatformLifetime

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Installing Lifetime. This can take a while..."

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = PublishSolution -Solution "$osInstallDir\Lifetime.osp" -SCUser $ServiceCenterUser -SCPass $ServiceCenterPass
$result = PublishSolution -Solution "$osInstallDir\Lifetime.osp" -SCUser $ServiceCenterUser -SCPass $ServiceCenterPass -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -163,11 +168,6 @@ function Publish-OSPlatformLifetime
return $installResult
}

$outputLog = $($result.Output) -Split ("`r`n")
foreach ($logLine in $outputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "OSPTOOL: $logLine"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "OSPTool exit code: $($result.ExitCode)"

if ($result.ExitCode -ne 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,15 @@ function Publish-OSPlatformSolutionPack
}

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Installing Outsystems solution. This can take a while..."

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = PublishSolution -Solution $solution -SCUser $ServiceCenterUser -SCPass $ServiceCenterPass
$result = PublishSolution -Solution $solution -SCUser $ServiceCenterUser -SCPass $ServiceCenterPass -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -112,11 +118,6 @@ function Publish-OSPlatformSolutionPack
return $publishResult
}

$outputLog = $($result.Output) -Split ("`r`n")
foreach ($logline in $outputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "OSPTOOL: $logline"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "OSPTool exit code: $($result.ExitCode)"

if ( $result.ExitCode -ne 0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,15 @@ function Publish-OSPlatformSystemComponents
}

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Installing Outsystems System Components. This can take a while..."

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = PublishSolution -Solution "$osInstallDir\System_Components.osp" -SCUser $ServiceCenterUser -SCPass $ServiceCenterPass
$result = PublishSolution -Solution "$osInstallDir\System_Components.osp" -SCUser $ServiceCenterUser -SCPass $ServiceCenterPass -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -150,11 +156,6 @@ function Publish-OSPlatformSystemComponents
return $installResult
}

$outputLog = $($result.Output) -Split ("`r`n")
foreach ($logline in $outputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "OSPTOOL: $logline"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "OSPTool exit code: $($result.ExitCode)"

if ( $result.ExitCode -ne 0 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ function Set-OSPlatformDeploymentZone

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration tool parameters are: $configToolArguments"
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Running the configuration tool. This can take a while..."

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = RunConfigTool -Arguments $configToolArguments
$result = RunConfigTool -Arguments $configToolArguments -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -102,11 +108,6 @@ function Set-OSPlatformDeploymentZone
return
}

$confToolOutputLog = $($result.Output) -Split ("`r`n")
foreach ($logline in $confToolOutputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration Tool: $logline"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration tool exit code: $($result.ExitCode)"

if ($result.ExitCode -ne 0)
Expand Down
13 changes: 7 additions & 6 deletions src/Outsystems.SetupTools/Functions/Set-OSServerConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,15 @@ function Set-OSServerConfig
}

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuring the platform. This can take a while..."

$onLogEvent = {
param($logLine)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message $logLine
}

try
{
$result = RunConfigTool -Arguments $configToolArguments
$result = RunConfigTool -Arguments $configToolArguments -OnLogEvent $onLogEvent
}
catch
{
Expand All @@ -378,11 +384,6 @@ function Set-OSServerConfig
return $null
}

$confToolOutputLog = $($result.Output) -Split ("`r`n")
foreach ($logline in $confToolOutputLog)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration Tool: $logline"
}
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 0 -Message "Configuration tool exit code: $($result.ExitCode)"

if ($result.ExitCode -ne 0)
Expand Down
33 changes: 22 additions & 11 deletions src/Outsystems.SetupTools/Lib/PlatformSetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ function GetOperatingSystemProductType()
return $osProductType
}

Function RunConfigTool([string]$Arguments)
Function RunConfigTool([string]$Arguments, [scriptblock]$OnLogEvent)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Getting server install directory"
$InstallDir = GetServerInstallDir
Expand All @@ -590,37 +590,39 @@ Function RunConfigTool([string]$Arguments)
}

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Running the config tool..."
$Result = ExecuteCommand -CommandPath "$InstallDir\ConfigurationTool.com" -WorkingDirectory $InstallDir -CommandArguments "$Arguments"

$Result = ExecuteCommand -CommandPath "$InstallDir\ConfigurationTool.com" -WorkingDirectory $InstallDir -CommandArguments "$Arguments" -OnLogEvent $OnLogEvent
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Exit code: $($Result.ExitCode)"

Return $Result
}

function RunSCInstaller([string]$Arguments)
function RunSCInstaller([string]$Arguments, [scriptblock] $OnLogEvent)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Getting server install directory"
$installDir = GetServerInstallDir

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Running SCInstaller..."

#SCInstaller needs to run inside a CMD or will not return an exit code
$result = ExecuteCommand -CommandPath "$env:comspec" -WorkingDirectory $installDir -CommandArguments "/c SCInstaller.exe $Arguments && exit /b %ERRORLEVEL%" -ErrorAction Stop
$result = ExecuteCommand -CommandPath "$env:comspec" -WorkingDirectory $installDir -CommandArguments "/c SCInstaller.exe $Arguments && exit /b %ERRORLEVEL%" -OnLogEvent $OnLogEvent -ErrorAction Stop

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Exit code: $($result.ExitCode)"

return $result
}

function PublishSolution([string]$Solution, [string]$SCUser, [string]$SCPass)
function PublishSolution([string]$Solution, [string]$SCUser, [string]$SCPass, [scriptblock]$OnLogEvent)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Solution path: $Solution"
$result = RunOSPTool -Arguments $("/publish " + [char]34 + $("$Solution") + [char]34 + " $ENV:ComputerName $SCUser $SCPass")
$result = RunOSPTool -Arguments $("/publish " + [char]34 + $("$Solution") + [char]34 + " $ENV:ComputerName $SCUser $SCPass") -OnLogEvent $OnLogEvent

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Exit code: $($result.ExitCode)"

return $result
}

function RunOSPTool([string]$Arguments)
function RunOSPTool([string]$Arguments, [scriptblock]$OnLogEvent)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Getting server install directory"
$installDir = GetServerInstallDir
Expand All @@ -642,7 +644,8 @@ function RunOSPTool([string]$Arguments)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "OSPTool path is $ospToolPath"

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Running the OSPTool..."
$result = ExecuteCommand -CommandPath "$ospToolPath\OSPTool.com" -WorkingDirectory $installDir -CommandArgument $Arguments

$result = ExecuteCommand -CommandPath "$ospToolPath\OSPTool.com" -WorkingDirectory $installDir -CommandArgument $Arguments -OnLogEvent $OnLogEvent

LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Return code: $($result.ExitCode)"

Expand Down Expand Up @@ -724,7 +727,7 @@ function DownloadOSSources([string]$URL, [string]$SavePath)
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "File successfully downloaded!"
}

Function ExecuteCommand([string]$CommandPath, [string]$WorkingDirectory, [string]$CommandArguments)
Function ExecuteCommand([string]$CommandPath, [string]$WorkingDirectory, [string]$CommandArguments, [scriptblock]$OnLogEvent)
{
LogMessage -Function $($MyInvocation.Mycommand) -Phase 1 -Stream 2 -Message "Launching the process $CommandPath with the arguments $CommandArguments"

Expand All @@ -742,12 +745,20 @@ Function ExecuteCommand([string]$CommandPath, [string]$WorkingDirectory, [string
$Process.StartInfo = $ProcessInfo
$Process.Start() | Out-Null
$Process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::Idle
$Output = $Process.StandardOutput.ReadToEnd()

if ($OnLogEvent)
{
do
{
# Keep redirecting output until process exits
$OnLogEvent.Invoke($process.StandardOutput.ReadLine());

} until ($process.HasExited)
}

$Process.WaitForExit()

Return [PSCustomObject]@{
Output = $Output
ExitCode = $Process.ExitCode
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Outsystems.SetupTools/OutSystems.SetupTools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'OutSystems.SetupTools.psm1'

# Version number of this module.
ModuleVersion = '3.3.3.0'
ModuleVersion = '3.4.0.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down

0 comments on commit 9ecc440

Please sign in to comment.