Skip to content

Commit

Permalink
Merge pull request #32 from Akaizoku/30-better-error-reporting
Browse files Browse the repository at this point in the history
30 better error reporting
  • Loading branch information
Akaizoku authored Sep 17, 2024
2 parents c16917b + fcbfe7f commit 6f671e6
Show file tree
Hide file tree
Showing 17 changed files with 854 additions and 253 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Ignore log files
log
*.log

# Ignore temporary directory
tmp

# Ignore custom configuration files
custom.ini
registry.info
registry.info
*.token
88 changes: 50 additions & 38 deletions Deploy-Alteryx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
.PARAMETER Action
The action parameter corresponds to the operation to perform.
Fifteen options are available:
Sixteen options are available:
- activate: activate the Alteryx application license
- backup: backup the Alteryx application database
Expand All @@ -20,7 +20,9 @@
- download: download latest Alteryx application release
- install: install the Alteryx application
- repair: repair the Alteryx application database
- open: open the Alteryx application
- patch: patch upgrade the Alteryx application
- ping: check the status of the Alteryx application
- repair: repair the Alteryx application database
- restart: restart the Alteryx application
- restore: restore a backup of the Alteryx application database
Expand All @@ -37,7 +39,7 @@
File name: Deploy-Alteryx.ps1
Author: Florian Carrier
Creation date: 2021-06-13
Last modified: 2024-09-11
Last modified: 2024-09-16
Dependencies: - PowerShell Tool Kit (PSTK)
- Alteryx PowerShell Module (PSAYX)
Expand Down Expand Up @@ -72,7 +74,9 @@ Param (
"configure",
"deactivate",
"install",
"open",
"patch",
"ping",
"repair",
"restart",
"restore",
Expand Down Expand Up @@ -144,11 +148,13 @@ Begin {
# General
$ISOTimeStamp = Get-Date -Format "yyyyMMdd_HHmmss"

# Configuration
$LibDirectory = Join-Path -Path $PSScriptRoot -ChildPath "lib"
$ConfDirectory = Join-Path -Path $PSScriptRoot -ChildPath "conf"
$DefaultProperties = "default.ini"
$CustomProperties = "custom.ini"
# Script configuration
$ScriptProperties = [Ordered]@{
LibDirectory = (Join-Path -Path $PSScriptRoot -ChildPath "lib")
ConfDirectory = (Join-Path -Path $PSScriptRoot -ChildPath "conf")
DefaultProperties = "default.ini"
CustomProperties = "custom.ini"
}

# ----------------------------------------------------------------------------
# * Modules
Expand All @@ -162,7 +168,7 @@ Begin {
foreach ($Module in $Modules.GetEnumerator()) {
try {
# Check if package is available locally
Import-Module -Name (Join-Path -Path $LibDirectory -ChildPath $Module.Name) -MinimumVersion $Module.Value -ErrorAction "Stop" -Force
Import-Module -Name (Join-Path -Path $ScriptProperties.LibDirectory -ChildPath $Module.Name) -MinimumVersion $Module.Value -ErrorAction "Stop" -Force
$ModuleVersion = (Get-Module -Name $Module.Name).Version
Write-Log -Type "CHECK" -Object "The $($Module.Name) module (v$ModuleVersion) was successfully loaded from the library directory."
} catch {
Expand All @@ -172,7 +178,7 @@ Begin {
$ModuleVersion = (Get-Module -Name $Module.Name).Version
Write-Log -Type "CHECK" -Object "The $($Module.Name) module (v$ModuleVersion) was successfully loaded."
} catch {
Throw "The $($Module.Name) module (v$($Module.Value)) could not be loaded. Make sure it has been installed on the machine or packaged in the ""$LibDirectory"" directory"
Throw "The $($Module.Name) module (v$($Module.Value)) could not be loaded. Make sure it has been installed on the machine or packaged in the ""$($ScriptProperties.LibDirectory)"" directory"
}
}
}
Expand All @@ -181,7 +187,7 @@ Begin {
# * Script configuration
# ----------------------------------------------------------------------------
# General settings
$Properties = Get-Properties -File $DefaultProperties -Directory $ConfDirectory -Custom $CustomProperties
$Properties = Get-Properties -File $ScriptProperties.DefaultProperties -Directory $ScriptProperties.ConfDirectory -Custom $ScriptProperties.CustomProperties
# Resolve relative paths
Write-Log -Type "DEBUG" -Message "Script structure check"
$Properties = Get-Path -PathToResolve $Properties.RelativePaths -Hashtable $Properties -Root $PSScriptRoot
Expand Down Expand Up @@ -252,9 +258,10 @@ Begin {
"PredictiveTools"
"IntelligenceSuite"
"DataPackages"
)
)
$InstallationProperties = Get-Properties -File $Properties.InstallationOptions -Directory $Properties.ConfDirectory -ValidateSet $ValidateSet
$InstallationProperties.Add("Product", $Product)
$Properties.Add("Product", $Product)
# Optional parameters
if ($PSBoundParameters.ContainsKey("Version")) {
$Properties.Version = $Version
Expand All @@ -273,44 +280,49 @@ Begin {
Process {
# Check operation to perform
switch ($Action) {
"activate" { $Process = Invoke-ActivateAlteryx -Properties $Properties -Unattended:$Unattended }
"backup" { $Process = Invoke-BackupAlteryx -Properties $Properties -Unattended:$Unattended }
"configure" { $Process = Set-Configuration -Properties $Properties -Unattended:$Unattended }
"deactivate" { $Process = Invoke-DeactivateAlteryx -Properties $Properties -Unattended:$Unattended }
"download" { $Process = Invoke-DownloadAlteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
"install" { $Process = Install-Alteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
"repair" { $Process = Repair-Alteryx -Properties $Properties -Unattended:$Unattended }
"patch" { $Process = Invoke-PatchAlteryx -Properties $Properties -Unattended:$Unattended }
"repair" { $Process = Repair-Alteryx -Properties $Properties -Unattended:$Unattended }
"restart" { $Process = Invoke-RestartAlteryx -Properties $Properties -Unattended:$Unattended }
"restore" { $Process = Invoke-RestoreAlteryx -Properties $Properties -Unattended:$Unattended }
"show" { $Process = Show-Configuration -Properties $Properties -InstallationProperties $InstallationProperties }
"start" { $Process = Invoke-StartAlteryx -Properties $Properties -Unattended:$Unattended }
"stop" { $Process = Invoke-StopAlteryx -Properties $Properties -Unattended:$Unattended }
"uninstall" { $Process = Uninstall-Alteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
"upgrade" { $Process = Update-Alteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
"activate" { $Process = Invoke-ActivateAlteryx -Properties $Properties -Unattended:$Unattended }
"backup" { $Process = Invoke-BackupAlteryx -Properties $Properties -Unattended:$Unattended }
"configure" { $Process = Set-Configuration -Properties $Properties -ScriptProperties $ScriptProperties }
"deactivate" { $Process = Invoke-DeactivateAlteryx -Properties $Properties -Unattended:$Unattended }
"download" { $Process = Invoke-DownloadAlteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
"install" { $Process = Install-Alteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
"repair" { $Process = Repair-Alteryx -Properties $Properties -Unattended:$Unattended }
"open" { $Process = Open-Alteryx -Properties $Properties -Unattended:$Unattended }
"patch" { $Process = Invoke-PatchAlteryx -Properties $Properties -Unattended:$Unattended }
"ping" { $Process = Invoke-PingAlteryx -Properties $Properties -Unattended:$Unattended }
"repair" { $Process = Repair-Alteryx -Properties $Properties -Unattended:$Unattended }
"restart" { $Process = Invoke-RestartAlteryx -Properties $Properties -Unattended:$Unattended }
"restore" { $Process = Invoke-RestoreAlteryx -Properties $Properties -Unattended:$Unattended }
"show" { $Process = Show-Configuration -Properties $Properties -InstallationProperties $InstallationProperties }
"start" { $Process = Invoke-StartAlteryx -Properties $Properties -Unattended:$Unattended }
"stop" { $Process = Invoke-StopAlteryx -Properties $Properties -Unattended:$Unattended }
"uninstall" { $Process = Uninstall-Alteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
"upgrade" { $Process = Update-Alteryx -Properties $Properties -InstallationProperties $InstallationProperties -Unattended:$Unattended }
default { Write-Log -Type "ERROR" -Message """$Action"" operation is not supported" -ExitCode 1 }
}
}

End {
# Check outcome and gracefully end script
Write-Log -Type "DEBUG" -Message ($Process | Format-Table)
if ($Process.Success -And ($Process.Status -eq "Completed")) {
Write-Log -Type "CHECK" -Message "Alteryx $Action process completed successfully" -ExitCode $Process.ExitCode
$Process = $Process[0]
if ($Process.ErrorCount -gt 0) {
if ($Process.ErrorCount -gt 1) {
$Errors = "with $($Process.ErrorCount) errors"
} else {
$Errors = "with $($Process.ErrorCount) error"
}
} else {
if ($Process.ErrorCount -gt 0) {
if ($Process.ErrorCount -gt 1) {
$Errors = "with $($Process.ErrorCount) errors"
} else {
$Errors = "with $($Process.ErrorCount) error"
}
$Errors = ""
}
if ($Process.Status -eq "Completed") {
if ($Process.Success) {
Write-Log -Type "CHECK" -Message "Alteryx $Action process completed successfully" -ExitCode $Process.ExitCode
} else {
$Errors = ""
Write-Log -Type "WARN" -Message "Alteryx $Action process completed $Errors" -ExitCode $Process.ExitCode
}
} else {
switch ($Process.Status) {
"Cancelled" { $Outcome = "was cancelled" }
"Completed" { $Outcome = "completed" }
"Failed" { $Outcome = "failed" }
"Stopped" { $Outcome = "was stopped" }
default { $Outcome = "failed" }
Expand Down
22 changes: 14 additions & 8 deletions conf/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,22 @@ SrcDirectory = C:\Sources
InstallationPath = C:\Program Files\Alteryx
# Backup directory
BackupDirectory = C:\ProgramData\Alteryx\Backup
# Predictive Tools directory
RDirectory = RInstaller
# Data packages installation directory
DataPackagesPath = C:\Program Files\Alteryx\Data
# Predictive Tools directory
RDirectory = RInstaller
# 7zip application path (required for data packages)
7zipPath = C:\Program Files\7-Zip\7z.exe

[Filenames]
# Installation properties
InstallationOptions = install.ini
# License file
LicenseFile = license.key
# License API refresh token file
LicenseAPIFile = license.token
# Server admin API key & secret
ServerAdminAPI = server.token

[Misc.]
# Installation language
Expand All @@ -48,25 +54,25 @@ ActivateOnUpgrade = true
[License]
# Licensing system URL
LicensingURL = whitelist.alteryx.com
# License file
LicenseFile =
# License email
LicenseEmail =
# License Account ID
LicenseAccountID =
# License API refresh token file
LicenseAPIFile =

[SSL]
# SSL/TLS
EnableSSL = true
EnableSSL = false
# Application ID
ApplicationID = {eea9431a-a3d4-4c9b-9f9a-b83916c11c67}

[Ports]
# Gallery HTTP communication port
HTTPPort = 80
# Gallery HTTPS communication port
HTTPSPort = 443
# Embedded MongoDB database communication port
MongoDBPort = 27018

[Checks]
RelativePaths = ConfDirectory, PSDirectory, TempDirectory, LogDirectory, ResDirectory
# Script internal structure
RelativePaths = ConfDirectory, PSDirectory, TempDirectory, LogDirectory, ResDirectory
2 changes: 1 addition & 1 deletion powershell/Install-Alteryx.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Install-Alteryx {
# Get global preference variables
Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState
# Log function call
Write-Log -Type "DEBUG" -Message $MyInvocation.ScriptName
Write-Log -Type "DEBUG" -Message $MyInvocation.MyCommand.Name
# Variables
$ISOTimeStamp = Get-Date -Format "yyyyMMdd_HHmmss"
$Tags = [Ordered]@{"Version" = $Properties.Version}
Expand Down
Loading

0 comments on commit 6f671e6

Please sign in to comment.