Obs/bin/ObsDep/content/Powershell/ObservabilityConfig.psm1

<###################################################
# #
# Copyright (c) Microsoft. All rights reserved. #
# #
##################################################>


class ObservabilityConfig
{
    static RegisterObservabilityEventSource([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        $eventSources = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.EventSources.EventSource

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        foreach ($eventSource in $eventSources)
        {
            $eventSourceRootName = $eventSource.EventSourceRootName
            $eventSourceLogName = $eventSource.EventSourceLogName
            $eventSourceLogSizeInBytes = $eventSource.EventSourceLogSizeInBytes
            $eventSourcePublisher = $eventSource.EventSourcePublisher

            Trace-Execution "Registering Observability EventSource $eventSourceLogName with Windows EventLog"
            try
            {
                # Register eventsource on hosts
                Invoke-Command `
                    -ComputerName $hostIps `
                    -Credential $localAdminCredential `
                    -Authentication Credssp `
                    -ScriptBlock {
                        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                        $manifestDllPath = "$observabilityNugetPath\lib\net472\$Using:eventSourceRootName.dll"
                        $manifestPath = "$observabilityNugetPath\lib\net472\$Using:eventSourceRootName.man"

                        # Grant read only access to manifest files
                        Trace-Execution "Granting read only access to $manifestPath"
                        icacls $manifestPath /grant Everyone:R
                        Trace-Execution "Granting read only access to $manifestDllPath"
                        icacls $manifestDllPath /grant Everyone:R


                        $publisherList = wevtutil ep
                        if ($publisherList.Contains($Using:eventSourcePublisher))
                        {
                            Trace-Execution "Publisher $Using:eventSourcePublisher already exists. Uninstalling."
                            wevtutil uninstall-manifest $manifestPath /resourceFilePath:"$manifestDllPath" /messageFilePath:"$manifestDllPath"
                            Trace-Execution "Successfully uninstalled publisher $Using:eventSourcePublisher."
                        }

                        # Register the EventSource with Windows
                        Trace-Execution "wevtutil installing manifest $manifestPath with resourceFilePath and messageFilePath $manifestDllPath"
                        wevtutil install-manifest $manifestPath /resourceFilePath:"$manifestDllPath" /messageFilePath:"$manifestDllPath"

                        Trace-Execution "wevtutil setting log size to $Using:eventSourceLogSizeInBytes"
                        wevtutil set-log $Using:eventSourceLogName /MaxSize:"$Using:eventSourceLogSizeInBytes"
                    }
            }
            catch
            {
                Trace-Execution "Registering Observability EventSource failed with error: $_"
                throw $_
            }

            Trace-Execution "Registering Observability EventSource $eventSourceLogName with Windows EventLog suceeded."
        }
    }

    static CreateObservabilityVolume([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        $volumeLabel = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.Host.ObservabilityVolumeLabel
        $volumeSize = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.Host.ObservabilityDriveSizeInBytes

        $driveAccessPath = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.Host.ObservabilityDriveAccessPath.Path
        $driveAccessPath = $Global:ExecutionContext.InvokeCommand.ExpandString($driveAccessPath)

        $PhysicalDriveLetter = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.Host.PhysicalDriveLetter
        $volumeFileName = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilityDriveFileName
        $volumeLocation = "${PhysicalDriveLetter}:"
        $volumePath = Join-Path -Path $volumeLocation -ChildPath $volumeFileName

        Write-ObservabilityVolumeCreationStartTelemetry `
            -ComputerNames ($hostIps -join " ") `
            -VolumeFilePath $volumePath `
            -VolumeAccessPath $driveAccessPath `
            -VolumeLabel $volumeLabel `
            -VolumeSize $volumeSize

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        # Add Observability Volume to each Host
        $scriptBlock = {
            param (
                [string]
                [parameter(Mandatory=$true)]
                $VolumePath,

                [string]
                [parameter(Mandatory=$true)]
                $AccessPath,

                [string]
                [parameter(Mandatory=$true)]
                $VolumeLocation,

                [string]
                [Parameter(Mandatory=$true)]
                $VolumeLabel,

                [string]
                [Parameter(Mandatory=$true)]
                $VolumeSize
            )
            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
            if (Test-Path -Path $AccessPath)
            {
                Write-ObservabilityLog "Folder $AccessPath already present. Skipping Observability volume creation."
            }
            else
            {
                Add-ObservabilityVolumeWithRetry -Path $VolumePath -AccessPath $AccessPath -VolumeLabel $VolumeLabel -Size $VolumeSize -StaticSize
                Add-VolumeAccessPath -AccessPath $AccessPath -VolumePath $VolumePath
                Add-MountVolumeScheduledTask -Path $VolumePath
            }
        }

        $argList = @($volumePath, $driveAccessPath, $volumeLocation, $volumeLabel, $volumeSize)
        Invoke-Command `
            -ComputerName $hostIps `
            -ScriptBlock $scriptBlock `
            -ArgumentList $argList `
            -Credential $localAdminCredential `
            -Authentication Credssp
        Write-ObservabilityLog "Observability Volume Setup Succeeded"
    }

    static SetUptimeScheduledTask([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityUptimeHelpers.psm1"

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }
        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        Write-InfoLog "Obtaining local admin credential..."
        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        Write-InfoLog "Starting Uptime scheduled task Setup"
        Write-InfoLog "Hosts: $hostNames"
        $scriptBlock = {
            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityUptimeHelpers.psm1"
            $hostName = $env:COMPUTERNAME
            Write-InfoLog "Starting uptime scheduled task on host $hostName."
            try
            {
                Set-UptimeTaskWithRetry
                Write-InfoLog "Uptime scheduled task on host $hostName succeeded."
            }
            catch
            {
                Write-ErrorLog "Uptime scheduled task on host $hostName failed with exception $_ ."
                throw $_
            }
        }

        Invoke-Command -ComputerName $hostIps -ScriptBlock $scriptBlock -Credential $localAdminCredential -Authentication Credssp | Out-Null
        Write-InfoLog "Uptime scheduled task completed."
    }

    static SetObservabilityEventTask([CloudEngine.Configurations.EceInterfaceParameters] $Parameters, $eventName, $eventScriptBlock)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        Write-InfoLog "Starting $eventName events task Setup"
        Write-InfoLog "Hosts: $hostNames"
        $exceptionMessage = ""
        $scriptBlock = $eventScriptBlock

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }
        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        foreach ($hostIp in $hostIps)
        {
            Write-InfoLog "Starting $eventName events task on host $hostIp."
            $result = Invoke-Command -ComputerName $hostIp -ScriptBlock $scriptBlock -Credential $localAdminCredential -Authentication Credssp

            if($result -eq $true)
            {
                Write-InfoLog "$eventName events task on host $hostIp succeeded."
            }
            else
            {
                Write-ErrorLog "$eventName events task on host $hostIp failed with exception $result."
                $exceptionMessage += "${hostIp}: $result`n"
            }
        }

        if($exceptionMessage)
        {
            throw $exceptionMessage
        }
    }

    static SetCensusEventScheduledTask([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityCensusHelpers.psm1"
        $scriptBlock = {
            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityCensusHelpers.psm1"
            Set-CensusTaskWithRetry
        }

        [ObservabilityConfig]::SetObservabilityEventTask($Parameters, "CensusEvent", $scriptBlock)

        Write-InfoLog "Census events scheduled task completed."
    }

    static SetRegistrationEventOneTimeTask([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityCensusHelpers.psm1"
        $scriptBlock = {
            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityCensusHelpers.psm1"
            Set-RegistrationEventsTaskWithRetry
        }

        [ObservabilityConfig]::SetObservabilityEventTask($Parameters, "RegistrationEvents", $scriptBlock)

        Write-InfoLog "Registration events one-time task completed."
    }

    static CreateVolumeFoldersAndPruner([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }
        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        $folderCleanupThresholdPercent = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.FolderQuotaCleanupThresholdInPercent
        $folderFreeSpaceThresholdPercent = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.FolderQuotaFreeSpaceThresholdInPercent
        $purgeFolderFrequencyInMinutes = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.PurgeFolderFrequencyInMinutes
        $subFolderConfigFileName = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.Host.ObservabilitySubFolderConfigFileName
        $driveAccessPath = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.Host.ObservabilityDriveAccessPath.Path
        $driveAccessPath = $Global:ExecutionContext.InvokeCommand.ExpandString($driveAccessPath)

        Write-ObservabilityLog "Starting Observability Volume Folder and Pruner Setup"
        Write-ObservabilityLog "Hosts: $hostNames"
        Write-ObservabilityLog "Volume folder mount access path: $driveAccessPath"
        Write-ObservabilityLog "Observability subfolder folder cleanup threshold: $folderCleanupThresholdPercent"
        Write-ObservabilityLog "Observability subfolder folder free space threshold: $folderFreeSpaceThresholdPercent"
        Write-ObservabilityLog "Observability volume purge frequency in minutes: $purgeFolderFrequencyInMinutes"

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        # Add Observability Volume to each Host
        $scriptBlock = {
            param (
                [string]
                [parameter(Mandatory=$true)]
                $AccessPath,

                [string]
                [Parameter(Mandatory=$true)]
                $FolderCleanupThresholdPercent,

                [string]
                [Parameter(Mandatory=$true)]
                $FolderFreeSpaceThresholdPercent,

                [string]
                [Parameter(Mandatory=$true)]
                $PurgeFolderFrequencyInMinutes,

                [string]
                [Parameter(Mandatory=$true)]
                $SubFolderConfigFileName
            )
            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
            New-VolumeFoldersAndPrunerWithRetry `
                -AccessPath $AccessPath `
                -CleanupThresholdPercent $FolderCleanupThresholdPercent `
                -FreeSpaceThresholdPercent $FolderFreeSpaceThresholdPercent `
                -PurgeFolderFrequencyInMinutes $PurgeFolderFrequencyInMinutes `
                -SubFolderConfigFileName $SubFolderConfigFileName
        }

        $argList = @(
            $driveAccessPath,
            $folderCleanupThresholdPercent,
            $folderFreeSpaceThresholdPercent,
            $purgeFolderFrequencyInMinutes,
            $subFolderConfigFileName
        )
        Invoke-Command `
            -ComputerName $hostIps `
            -ScriptBlock $scriptBlock `
            -ArgumentList $argList `
            -Credential $localAdminCredential `
            -Authentication Credssp
        Write-ObservabilityLog "Observability subfolder and pruner Setup Succeeded"
    }

    # Set registry key HKLM\Software\Microsoft\AzureStack DeviceType to AzureEdge
    static SetDeviceTypeRegistryKey([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
        Write-ObservabilityLog "SetDeviceTypeRegistryKey start."

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }
        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        try
        {
            Invoke-Command `
                -ComputerName $hostIps `
                -Credential $localAdminCredential `
                -Authentication Credssp `
                -ScriptBlock {
                    Write-Verbose "Setting HKLM\Software\Microsoft\AzureStack DeviceType registry key to AzureEdge."
                    $registryPath = 'HKLM:\SOFTWARE\Microsoft\AzureStack\'
                    if (!(Test-Path -Path $registryPath))
                    {
                        New-Item -Path $registryPath -Force
                    }
                    New-ItemProperty -Path $registryPath -Name 'DeviceType' -PropertyType 'String' -Value "AzureEdge" -Force
                    Write-Verbose "Finished DeviceType Registry key setup on $($env:COMPUTERNAME)"
                }
            Write-ObservabilityLog "Succeeded in setting AzureStack DeviceType Registry key."
        }
        catch
        {
            Write-ObservabilityErrorLog "[Error] DeviceType registry key set up failed with an error : $_ "
            throw $_
        }
    }

    # Set up AzureStack environment to enable Autologger and UTC Telemetry via MA
    # Reg key set up needs to happend upfornt during host configuration
    static SetUpUtcExporterFeature([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }
        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        Write-ObservabilityLog "Set up AzureStack environment to enable Autologger and UTC Telemetry via MA."

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        try
        {
            Invoke-Command `
                -ComputerName $hostIps `
                -Credential $localAdminCredential `
                -Authentication Credssp `
                -ScriptBlock {
                    $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                    Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
                    
                    $utcExporterPath = "$($env:SystemRoot)\System32\UtcExporters"
                    # Create UtcExporters folder in system32
                    if (-not (Test-Path -Path $utcExporterPath))
                    {
                        New-Item -Path "$($env:SystemRoot)\System32" -ItemType Directory -Name 'UtcExporters' -Force
                    }

                    $GenevaNameSpace = "AEOprdTely"
                    if(Test-IsCIEnv)
                    {
                        $GenevaNameSpace = "AEOppeTely"
                    }

                    Write-ObservabilityLog "Set up the required regkey to enable utc exporter Feature"
                    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack' -Name 'AllowExporters' -PropertyType 'DWORD' -Value 1 -Force
                    New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack\exporters' -Force
                    New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack\exporters\GenevaExporter' -Force
                    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack\exporters\GenevaExporter' -Name 'DllPath' -PropertyType 'String' -Value "$($utcExporterPath)\UtcGenevaExporter.dll" -Force
                    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack\exporters\GenevaExporter' -Name 'GenevaNamespace' -PropertyType 'String' -Value $GenevaNameSpace -Force
                    New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Diagnostics\DiagTrack\TestHooks' -Name 'SkipSignatureMitigation' -PropertyType 'DWORD' -Value 1 -Force

                    # Update UTC Service binary
                    Write-ObservabilityLog "Updating UTC service dll"
                    Stop-Service "diagtrack" -Force
                    Start-Sleep -Seconds 10
                    Write-ObservabilityLog "Copy UTC Exporter dll to $($utcExporterPath)"
                    Copy-Item -Path "$observabilityNugetPath\lib\net472\UtcGenevaExporter.dll" -Destination $utcExporterPath -Force
                    Start-Service "diagtrack"

                    Write-ObservabilityLog "Finished UTC Exporter setup on $($env:COMPUTERNAME)"
                }
            Write-ObservabilityLog "Set up AzureStack environment to enable Autologger and UTC Telemetry via MA succeeded."
        }
        catch
        {
            Write-ObservabilityErrorLog "[Error] UTC Exporter set up failed with an error : $_ "
            throw $_
        }
    }

    # Install VC Runtime on all hosts
    static InstallVcRuntime([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }
        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]
        Write-ObservabilityLog "Starting installation of X64 VC Redistributable."

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        try
        {
            Invoke-Command `
                -ComputerName $hostIps `
                -Credential $localAdminCredential `
                -Authentication Credssp `
                -ScriptBlock {
                $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

                Write-ObservabilityLog "[Starting] installation of VC Redistributable on host $($env:COMPUTERNAME)"
                $vcRedistFilePath = "$observabilityNugetPath\content\VS17\VC_redist.x64.exe"
                if(Test-Path -Path $vcRedistFilePath) {
                    Start-Process -File $vcRedistFilePath -ArgumentList "/install /quiet /norestart" -Wait -NoNewWindow
                } else {
                    $errMsg = "[ERROR] VC Redistributable [$vcRedistilePath] not found on host $($env:COMPUTERNAME)"
                    Write-ObservabilityErrorLog $errMsg
                    throw $errMsg
                }
                Write-ObservabilityLog "[Finished] installation of VC Redistributable on host $($env:COMPUTERNAME)"
            }
        }
        catch
        {
            Write-ObservabilityErrorLog "[Failed] installation of VC Redistributable: $_ "
            throw $_
        }
        Write-ObservabilityLog "Finished installation of X64 VC Redistributable."
    }

    static CreateObservabilityVolumeOnNC([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        Write-ObservabilityLog "Starting observability volume setup on NC VMs"
        $ncVMs = $Parameters.Roles["NC"].PublicConfiguration.Nodes.Node.Name
        $volumeFileName = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilityDriveFileName
        $volumeLabel = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilityVolumeLabel
        $volumeSize = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilityDriveSizeInBytes
        $driveAccessPath = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilityDriveAccessPath.Path
        $driveAccessPath = $Global:ExecutionContext.InvokeCommand.ExpandString($driveAccessPath)

        $folderCleanupThresholdPercent = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.FolderQuotaCleanupThresholdInPercent
        $folderFreeSpaceThresholdPercent = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.FolderQuotaFreeSpaceThresholdInPercent
        $purgeFolderFrequencyInMinutes = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.PurgeFolderFrequencyInMinutes
        $subFolderConfigFileName = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilitySubFolderConfigFileName
        $domainUserCredential = [ObservabilityConfig]::GetDomainCredential($Parameters)

        $scriptBlock = {
            param (
                [string]
                [parameter(Mandatory=$true)]
                $VolumePath,

                [string]
                [parameter(Mandatory=$true)]
                $HostComputerName,

                [string]
                [parameter(Mandatory=$true)]
                $AccessPath,

                [string]
                [parameter(Mandatory=$true)]
                $FolderCleanupThresholdPercent,

                [string]
                [parameter(Mandatory=$true)]
                $FolderFreeSpaceThresholdPercent,

                [string]
                [Parameter(Mandatory=$true)]
                $PurgeFolderFrequencyInMinutes,

                [string]
                [parameter(Mandatory=$true)]
                $SubFolderConfigFileName,

                [PSCredential]
                [parameter(Mandatory=$true)]
                $Credential
            )
            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

            $remoteVolumePath = "\\$HostComputerName\$VolumePath"
            $remoteVolumePath = $remoteVolumePath -replace ":", "$"
            Add-VolumeAccessPath -AccessPath $AccessPath -VolumePath $remoteVolumePath
            Add-MountVolumeScheduledTask -Path $remoteVolumePath -Credential $Credential
            New-VolumeFoldersAndPrunerWithRetry `
                -AccessPath $AccessPath `
                -CleanupThresholdPercent $FolderCleanupThresholdPercent `
                -FreeSpaceThresholdPercent $FolderFreeSpaceThresholdPercent `
                -PurgeFolderFrequencyInMinutes $PurgeFolderFrequencyInMinutes `
                -SubFolderConfigFileName $SubFolderConfigFileName
            Set-FolderQuotas -AccessPath $AccessPath -SubFolderConfigFileName $SubFolderConfigFileName
        }

        if(-not($ncVMs -is [System.Array])) # Only 1 VM exists
        {
            $ncVMs = @($ncVMs)
        }
        foreach($ncVM in $ncVMs)
        {
            $hostComputerName = $env:COMPUTERNAME
            Write-ObservabilityLog "Starting observability volume onboarding for $ncVM."
            try
            {
                Get-VM $ncVM | Out-Null # Test that VM is accessbile
            }
            catch
            {
                Write-ObservabilityLog "$ncVM not found on $hostComputerName. No op."
                continue
            }
            $vmHardDrivePath = (Get-VMHardDiskDrive $ncVM).Path
            if($vmHardDrivePath -is [System.Array])
            {
                $vmHardDrivePath = $vmHardDrivePath[0]
            }
            $volumeLocation = Split-Path $vmHardDrivePath -Parent
            $volumePath = Join-Path -Path $volumeLocation -ChildPath $volumeFileName

            if(Test-Path $driveAccessPath)
            {
                Write-Observability "Folder $driveAccessPath already created. Skipping Observability Volume creation."
            }
            else
            {
                Write-ObservabilityLog "Adding observability volume at volume path $volumePath"
                Add-ObservabilityVolumeWithRetry -Path $volumePath -AccessPath $driveAccessPath -VolumeLabel $volumeLabel -Size $volumeSize -StaticSize
                if((Get-DiskImage $volumePath).Attached)
                {
                    Dismount-VHD $volumePath
                }
                $argList = @(
                    $volumePath,
                    $hostComputerName,
                    $driveAccessPath,
                    $folderCleanupThresholdPercent,
                    $folderFreeSpaceThresholdPercent,
                    $purgeFolderFrequencyInMinutes,
                    $subFolderConfigFileName,
                    $domainUserCredential
                )
                Invoke-Command `
                    -ComputerName $ncVM `
                    -ScriptBlock $scriptBlock `
                    -Credential $domainUserCredential `
                    -Authentication Credssp `
                    -ArgumentList $argList
                Write-ObservabilityLog "Finished observability volume onboarding for $ncVM."
            }
        }
    }

    static RegisterObservabilityEventSourceOnNC([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $eventSources = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.EventSources.EventSource
        $ncVMs = $Parameters.Roles["NC"].PublicConfiguration.Nodes.Node.Name

        $domainUserCredential = [ObservabilityConfig]::GetDomainCredential($Parameters)

        foreach ($eventSource in $eventSources)
        {
            $eventSourceRootName = $eventSource.EventSourceRootName
            $eventSourceLogName = $eventSource.EventSourceLogName
            $eventSourceLogSizeInBytes = $eventSource.EventSourceLogSizeInBytes

            Trace-Execution "Registering Observability EventSource $eventSourceLogName with Windows EventLog"
            $scriptBlock = {
                param (
                    [string]
                    [parameter(Mandatory=$true)]
                    $EventSourceRootName,

                    [string]
                    [parameter(Mandatory=$true)]
                    $EventSourceLogName,

                    [string]
                    [parameter(Mandatory=$true)]
                    $EventSourceLogSizeInBytes
                )
                $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                $manifestDllPath = "$observabilityNugetPath\lib\net472\$EventSourceRootName.dll"
                $manifestPath = "$observabilityNugetPath\lib\net472\$EventSourceRootName.man"

                # Grant read only access to manifest files
                Trace-Execution "Granting read only access to $manifestPath"
                icacls $manifestPath /grant Everyone:R
                Trace-Execution "Granting read only access to $manifestDllPath"
                icacls $manifestDllPath /grant Everyone:R

                # Register the EventSource with Windows
                Trace-Execution "wevtutil installing manifest $manifestPath with resourceFilePath and messageFilePath $manifestDllPath"
                wevtutil install-manifest $manifestPath /resourceFilePath:"$manifestDllPath" /messageFilePath:"$manifestDllPath"

                Trace-Execution "wevtutil setting log size to $EventSourceLogSizeInBytes"
                wevtutil set-log $EventSourceLogName /MaxSize:"$EventSourceLogSizeInBytes"
            }

            try
            {
                # Register eventsource on hosts
                Invoke-Command `
                    -ComputerName $ncVMs `
                    -ScriptBlock $scriptBlock `
                    -Credential $domainUserCredential `
                    -Authentication Credssp `
                    -ArgumentList @($eventSourceRootName, $eventSourceLogName, $eventSourceLogSizeInBytes)
            }
            catch
            {
                Trace-Execution "Registering Observability EventSource failed with error: $_"
                throw $_
            }

            Trace-Execution "Registering Observability EventSource $eventSourceLogName with Windows EventLog suceeded."
        }
    }

    static SetFolderQuotas ([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        $subFolderConfigFileName = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilitySubFolderConfigFileName
        $driveAccessPath = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.Volumes.NC.ObservabilityDriveAccessPath.Path
        $driveAccessPath = $Global:ExecutionContext.InvokeCommand.ExpandString($driveAccessPath)

        Write-ObservabilityLog "Starting observability volume fsrm quota setup on $hostNames"
        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        $scriptBlock = {
            param (
                [string]
                [parameter(Mandatory=$true)]
                $AccessPath,

                [string]
                [parameter(Mandatory=$true)]
                $SubFolderConfigFileName
            )
            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

            Set-FolderQuotas -AccessPath $AccessPath -SubFolderConfigFileName $SubFolderConfigFileName
        }
        try
        {
            Invoke-Command `
                -ComputerName $hostIps `
                -Credential $localAdminCredential `
                -Authentication Credssp `
                -ScriptBlock $scriptBlock `
                -ArgumentList @($driveAccessPath, $subFolderConfigFileName)
        }
        catch
        {
            Write-ObservabilityErrorLog "[Failed] setup of FSRM Quotas: $_ "
            throw $_
        }
    }

    static [PSCredential] GetLocalCredential([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        Write-ObservabilityLog "Obtaining local admin credential..."
        $localAdminCredential = $null
        try
        {
            $cloudRole = $Parameters.Roles["Cloud"].PublicConfiguration
            $securityInfo = $cloudRole.PublicInfo.SecurityInfo
            $localAdmin = $securityInfo.LocalUsers.User | Where-Object Role -eq $Parameters.Configuration.Role.PrivateInfo.Accounts.BuiltInAdminAccountID
            $localAdminCredential = $Parameters.GetCredential($localAdmin.Credential)
        }
        catch
        {
            Write-ObservabilityErrorLog "Failed to obtain local admin credentials: $_ "
            throw $_
        }
        Write-ObservabilityLog "Local admin credential obtained."

        if ($localAdminCredential.UserName -eq "removed")
        {
            Write-ObservabilityLog "The local admin credential obtained has been removed. Using domain credential instead."
            return [ObservabilityConfig]::GetDomainCredential($Parameters)
        }
        return $localAdminCredential
    }

    static [PSCredential] GetDomainCredential([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        Write-ObservabilityLog "Obtaining domain user credentials..."
        $domainUserCredential = $null
        try
        {
            $cloudRole = $Parameters.Roles["Cloud"].PublicConfiguration
            $securityInfo = $cloudRole.PublicInfo.SecurityInfo
            $physicalMachinesRole = $Parameters.Configuration.Role
            $domainName = $Parameters.Roles.Domain.PublicConfiguration.PublicInfo.DomainConfiguration.Fqdn

            $domainUser = $securityInfo.DomainUsers.User | Where-Object Role -EQ $physicalMachinesRole.PrivateInfo.Accounts.DomainUserAccountID
            $domainUserCredential = $Parameters.GetCredential($domainUser.Credential)
            # Making sure that the credential is domain qualified, PowerShell Direct require credential to be domain qualified
            if($($domainUserCredential.GetNetworkCredential().Domain) -eq "")
            {
                $domainUserCredential = New-Object -TypeName PSCredential -ArgumentList "$domainName\$($domainUserCredential.UserName)", $($domainUserCredential.Password)
            }
            Write-ObservabilityLog "Domain user credentials obtained."
        }
        catch
        {
            Write-ObservabilityErrorLog "Failed to obtain domain user credentials: $_ "
            throw $_
        }
        return $domainUserCredential
    }

    static InstallBootstrapObservability([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $exceptionMessage = ""
        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        try
        {
            Write-ObservabilityLog "$env:COMPUTERNAME Bootstrap Observability installation start."
            $deploymentLaunchType = Get-DeploymentLaunchype
            if ($deploymentLaunchType -eq "CloudDeployment")
            {
                Write-ObservabilityLog "$env:COMPUTERNAME This stamp was launched via CloudDeployment. Skipping Bootstrap Observability installation."
                return
            }

            $cloudRole = $Parameters.Roles["Cloud"].PublicConfiguration

            $cloudId = $cloudRole.PublicInfo.CloudId
            $arcForServerMsiFilePath = $cloudRole.PublicInfo.DefaultInfraStorageLocations.DefaultLocalShare

            $proxyUrl = [ObservabilityConfig]::GetProxyUrl($Parameters)
            $registrationParams = [ObservabilityConfig]::GetRegistrationParameters($Parameters)

            $scriptBlock = {
                param (
                    [string]
                    [parameter(Mandatory=$true)]
                    $AgentMsiPath,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $AccessToken,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $SubscriptionId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $TenantId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $AccountId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $ResourceGroupName,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $CloudId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $EnvironmentName,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $Region,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $StampId
                )

                $errorMessage = ""
                $setHostNICIPAddressLogFile = Join-Path -Path $env:systemdrive -ChildPath $LogFileRelativePath
                Start-Transcript -Append -Path $setHostNICIPAddressLogFile
                try
                {
                    $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                    Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

                    $ResourceName = Get-ArcResourceName
                    Write-ObservabilityLog "$env:COMPUTERNAME Going to install Arc-for-server agent..."
                    Install-ArcForServerAgent `
                        -AgentMsiPath $AgentMsiPath `
                        -AccessToken $AccessToken `
                        -SubscriptionId $SubscriptionId `
                        -TenantId $TenantId `
                        -ResourceGroupName $ResourceGroupName `
                        -EnvironmentName $EnvironmentName `
                        -Region $Region `
                        -ResourceName $ResourceName `
                        -ProxyUrl $using:proxyUrl | Out-Null

                    Write-ObservabilityLog "$env:COMPUTERNAME Going to download Observability Extension..."
                    Install-ArcForServerExtensions `
                        -AccessToken $AccessToken `
                        -SubscriptionId $SubscriptionId `
                        -TenantId $TenantId `
                        -AccountId $AccountId `
                        -ResourceGroupName $ResourceGroupName `
                        -ResourceName $ResourceName `
                        -EnvironmentName $EnvironmentName `
                        -Region $Region | Out-Null

                    $hostNameHash = Get-Sha256Hash -ClearString (hostname)
                    $nodeId = "$($StampId)-$hostNameHash"
                    Write-BootstrapNodeIdAndHardwareIdHashTelemetry -BootstrapNodeId $nodeId
                }
                catch{
                    $errorMessage = $PSItem.ToString()
                    Write-ObservabilityErrorLog $errorMessage
                    throw $PSItem.Exception.Message
                }
                finally
                {
                    Write-ArcForServerInstallationStopTelemetry `
                        -ComputerName $env:COMPUTERNAME `
                        -Message "Bootstrap Observability installation end" `
                        -ExceptionDetails $errorMessage
                }
            }

            $argList = @(
                $arcForServerMsiFilePath,
                $registrationParams.ArmAccessToken,
                $registrationParams.SubscriptionId,
                $registrationParams.TenantId,
                $registrationParams.AccountId,
                $registrationParams.ResourceGroupName,
                $cloudId,
                $registrationParams.EnvironmentName,
                $registrationParams.Region,
                $registrationParams.ResourceName
            )

            Invoke-Command `
                -ComputerName $hostIps `
                -ScriptBlock $scriptBlock `
                -ArgumentList $argList `
                -Credential $localAdminCredential `
                -Authentication Credssp
        }
        catch
        {
            $errMsg = "Bootstrap Observability installation failed with $_"
            $exceptionMessage += $errMsg
            Write-ObservabilityErrorLog $errMsg
            throw
        }

        Write-ObservabilityLog "$env:COMPUTERNAME Bootstrap Observability installation end."
    }

    static InstallRemoteSupportArcExtension([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $exceptionMessage = ""
        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)
        
        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        try 
        {
            Write-ObservabilityLog "$env:COMPUTERNAME Remote Support Arc installation start."

            $deploymentLaunchType = Get-DeploymentLaunchype
            if ($deploymentLaunchType -eq "CloudDeployment")
            {
                Write-ObservabilityLog "$env:COMPUTERNAME This stamp was launched via CloudDeployment. Skipping RemoteSupport Arc installation."
                return
            }

            $registrationParams = [ObservabilityConfig]::GetRegistrationParameters($Parameters)
        
            $scriptBlock = {
                param (
                    [string]
                    [Parameter(Mandatory=$true)]
                    $AccessToken,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $SubscriptionId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $TenantId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $AccountId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $ResourceGroupName,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $EnvironmentName,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $Region,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $StampId
                )

                $errorMessage = ""
                $setHostNICIPAddressLogFile = Join-Path -Path $env:systemdrive -ChildPath $LogFileRelativePath
                Start-Transcript -Append -Path $setHostNICIPAddressLogFile
                try {
                    $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                    Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
                    Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityConstants.psm1"

                    $ResourceName = Get-ArcResourceName

                    Write-ObservabilityLog "$env:COMPUTERNAME Going to download Remote Support extension..."
                    Install-ArcForServerExtensions `
                        -AccessToken $AccessToken `
                        -SubscriptionId $SubscriptionId `
                        -TenantId $TenantId `
                        -AccountId $AccountId `
                        -ResourceGroupName $ResourceGroupName `
                        -ResourceName $ResourceName `
                        -EnvironmentName $EnvironmentName `
                        -Region $Region `
                        -Type $ObservabilityConfigConstants.RemoteSupportExtensionType | Out-Null
                    
                    # Bring extension out of listener mode if it is
                    StartArcRemoteSupportAgent 
                }
                catch {
                    $errorMessage = $PSItem.ToString()
                    Write-ObservabilityErrorLog $errorMessage
                    throw $PSItem.Exception.Message
                }
                finally
                {
                    Write-ArcForServerInstallationStopTelemetry `
                        -ComputerName $env:COMPUTERNAME `
                        -Message "Remote Support Arc extension installation end" `
                        -ExceptionDetails $errorMessage
                }
            }

            $argList = @(
                $registrationParams.ArmAccessToken,
                $registrationParams.SubscriptionId,
                $registrationParams.TenantId,
                $registrationParams.AccountId,
                $registrationParams.ResourceGroupName,
                $registrationParams.EnvironmentName,
                $registrationParams.Region,
                $registrationParams.ResourceName
            )

            Invoke-Command `
                -ComputerName $hostIps `
                -ScriptBlock $scriptBlock `
                -ArgumentList $argList `
                -Credential $localAdminCredential `
                -Authentication Credssp
        }
        catch 
        {
            $errMsg = "Remote Support Arc Extension installation failed with $_"
            $exceptionMessage += $errMsg
            Write-ObservabilityErrorLog $errMsg
            throw
        }

        Write-ObservabilityLog "$env:COMPUTERNAME Remote Support Arc Extension installation end."
    }

    static UninstallBootstrapObservability([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        Write-ObservabilityLog "$env:COMPUTERNAME Bootstrap Observability uninstallation start."
        
        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]
        
        $domainUserCredential = [ObservabilityConfig]::GetDomainCredential($Parameters)
        $cloudRole      = $Parameters.Roles["Cloud"].PublicConfiguration

        $arcForServerMsiFilePath = $cloudRole.PublicInfo.DefaultInfraStorageLocations.DefaultLocalShare
        Write-ObservabilityLog "$env:COMPUTERNAME Arc For Server MSI Path: $arcForServerMsiFilePath"

        $registrationParams = [ObservabilityConfig]::GetRegistrationParameters($Parameters)


        $scriptBlock = {
            param (
                [string]
                [parameter(Mandatory=$true)]
                $AgentMsiPath,

                [string]
                [Parameter(Mandatory=$true)]
                $AccessToken,

                [string]
                [Parameter(Mandatory=$true)]
                $SubscriptionId,

                [string]
                [Parameter(Mandatory=$true)]
                $AccountId,

                [string]
                [Parameter(Mandatory=$true)]
                $ResourceGroupName,

                [string]
                [Parameter(Mandatory=$true)]
                $CloudId
            )

            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

            # Import MiscConstants to remove GMAScenario reg key
            $gmaNugetName = "Microsoft.AzureStack.Observability.GenevaMonitoringAgent"
            $gmaPackageContentPath = Join-Path $(Get-ASArtifactPath -NugetName $gmaNugetName) -ChildPath "content"
            Import-Module "$gmaPackageContentPath\GMATenantJsonHelper.psm1" -DisableNameChecking
            $gmaScenarioRegKeyPath = $MiscConstants.GMAScenarioRegKey.Path
            $gmaScenarioRegKeyName = $MiscConstants.GMAScenarioRegKey.Name
            if (Test-RegKeyExists -Path $gmaScenarioRegKeyPath -Name $gmaScenarioRegKeyName)
            {
                Remove-ItemProperty `
                    -Path $gmaScenarioRegKeyPath `
                    -Name $gmaScenarioRegKeyName `
                    -Force
                Write-ObservabilityLog "Removed registry key $gmaScenarioRegKeyName at path $gmaScenarioRegKeyPath"
            }

            Uninstall-ArcForServerExtensions `
                        -AccessToken $AccessToken `
                        -SubscriptionId $SubscriptionId `
                        -AccountId $AccountId `
                        -ResourceGroupName $ResourceGroupName `
                        -CloudId $CloudId


            $result = Uninstall-ArcForServerAgent `
                        -AgentMsiPath $AgentMsiPath `
                        -AccessToken $AccessToken
 
            return $result
        }

        # Install Arc for server agent on each Host
        $exceptionMessage = ""
        foreach($hostIp in $hostIps)
        {
            $argList = @($arcForServerMsiFilePath, $registrationParams.ArmAccessToken, $registrationParams.SubscriptionId, $registrationParams.AccountId, $registrationParams.ResourceGroupName, $registrationParams.CloudId)
            $result = Invoke-Command `
                -ComputerName $hostIp `
                -ScriptBlock $scriptBlock `
                -ArgumentList $argList `
                -Credential $domainUserCredential `
                -Authentication Credssp
            if ($result -eq $true)
            {
                Write-ObservabilityLog "Arc for server agent setup on host $hostIp succeeded."
            }
            else
            {
                Write-ObservabilityLog "Arc for server agent setup on host $hostIp failed with exception $result."
                $exceptionMessage += "${hostIp}: $result`n"
            }
        }

        if($exceptionMessage)
        {
            throw $exceptionMessage
        }

        Write-ObservabilityLog "$env:COMPUTERNAME Bootstrap Observability uninstallation end."
    }

    static SetupArcAgent([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
        
        try
        {
            Write-ObservabilityLog "$env:COMPUTERNAME Arc Agent update start."
            $cloudRole = $Parameters.Roles["Cloud"].PublicConfiguration
            $arcForServerMsiFilePath = $cloudRole.PublicInfo.DefaultInfraStorageLocations.DefaultLocalShare
    
            $errorMessage = ""
            
            Write-ObservabilityLog "$env:COMPUTERNAME Going to update Arc-for-server agent..."
            Update-ArcForServerAgent -AgentMsiPath $arcForServerMsiFilePath | Out-Null
        }
        catch{
            $errorMessage = $PSItem.ToString()
            Write-ObservabilityErrorLog $errorMessage
            throw $PSItem.Exception.Message
        }
        Write-ObservabilityLog "$env:COMPUTERNAME Arc Agent update end."
    }

    static ConnectArcAgent([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $exceptionMessage = ""

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        try
        {
            Write-ObservabilityLog "$env:COMPUTERNAME Arc Agent connect start."

            $proxyUrl = [ObservabilityConfig]::GetProxyUrl($Parameters)
            $registrationParams = [ObservabilityConfig]::GetRegistrationParameters($Parameters)

            $scriptBlock = {
                param (
                    [string]
                    [Parameter(Mandatory=$true)]
                    $AccessToken,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $SubscriptionId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $TenantId,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $ResourceGroupName,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $EnvironmentName,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $Region,

                    [string]
                    [Parameter(Mandatory=$true)]
                    $StampId
                )

                $errorMessage = ""
                try
                {
                    $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                    Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

                    $ResourceName = Get-ArcResourceName
                    Write-ObservabilityLog "$env:COMPUTERNAME Going to connect Arc-for-server agent..."
                    Connect-ArcForServerAgent `
                        -AccessToken $AccessToken `
                        -SubscriptionId $SubscriptionId `
                        -TenantId $TenantId `
                        -ResourceGroupName $ResourceGroupName `
                        -EnvironmentName $EnvironmentName `
                        -Region $Region `
                        -ResourceName $ResourceName `
                        -ProxyUrl $using:proxyUrl | Out-Null
                }
                catch{
                    $errorMessage = $PSItem.ToString()
                    Write-ObservabilityErrorLog $errorMessage
                    throw $PSItem.Exception.Message
                }
            }

            $argList = @(
                $registrationParams.ArmAccessToken,
                $registrationParams.SubscriptionId,
                $registrationParams.TenantId,
                $registrationParams.ResourceGroupName,
                $registrationParams.EnvironmentName,
                $registrationParams.Region,
                $registrationParams.ResourceName
            )

            $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

            Invoke-Command `
                -Credential $localAdminCredential `
                -Authentication Credssp `
                -ComputerName $hostNames `
                -ScriptBlock $scriptBlock `
                -ArgumentList $argList
        }
        catch
        {
            $exceptionMessage += "ArcAgent connect failed with $_"
            Write-ObservabilityErrorLog $exceptionMessage
            throw
        }

        Write-ObservabilityLog "$env:COMPUTERNAME Arc Agent connect end."
    }

        <#
        .SYNOPSIS
        Evaluation function to identify what type of GMA configuration action to use.
        Following are the cases involved during evaluation :
            case 1 : If the interface is invoked in case of Deployment then run configuration on all nodes.
            case 2 : If the interface is invoked in case of AddNode or RepairNode then run configuration on only that node.
             
        .EXAMPLE
        [GMATenantJson]::EvaluateGMAConfigurationType($Parameters)
 
        .PARAMETER Parameters
        The ECE role parameters for this interface.
    #>

    static [CloudEngine.Actions.ConditionalActionDescription] EvaluateListenerModeConfigurationType([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $ErrorActionPreference = "Stop"

        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        # Evalute for ArcA deployment
        if (Test-IsArcADeployment -Parameters $Parameters)
        {
            Write-ObservabilityLog "EvaluateListenerModeConfigurationType: Skip executing SetWatchdogToListenerMode for ArcA deployment" -Verbose
            return [CloudEngine.Actions.ConditionalActionDescription]::CreateNegative()
        }

        ## For classes in PS, we need to use the call stack to get the current executing function.
        $functionName = $(Get-PSCallStack)[0].FunctionName

        try {
            Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1

            $cloudRolePath = "ObservabilityConfig"
            $listenerModeOnAllNodes = "SetListenerModeOnAllNodes"
            $listenerModeOnOneNode = "SetListenerModeOnOneNode"
            $onAllNodesAction = [CloudEngine.Actions.ConditionalActionDescription]::CreateWithDefinedAction($cloudRolePath, $listenerModeOnAllNodes)
            $onOneNodeAction = [CloudEngine.Actions.ConditionalActionDescription]::CreateWithDefinedAction($cloudRolePath, $listenerModeOnOneNode)

            $nodeName = Get-ExecutionContextNodeName -Parameters $Parameters

            if($null -ne $nodeName)
            {
                # In add node or repair node case, ExecutionContextNodeName should have exactly one value.
                Trace-Execution "Execution context node was determined. Listener Mode will be set on $nodeName only."
                return $onOneNodeAction
            }

            # In regular deployment case, ExecutionContextNodeName will be null.
            Trace-Execution "No exceution context node was determined. Listener Mode will set on all the nodes."
            return $onAllNodesAction
        }
        catch {
            Trace-Error "$functionName :Failed to evaluate ListenerMode configuration type on node $($env:COMPUTERNAME) due to following error : $_"
            throw
        }

    }

    static StopArcExtensionObservabilityAgent([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $domainUserCredential = [ObservabilityConfig]::GetDomainCredential($Parameters)

        $hostName = Get-ExecutionContextNodeName -Parameters $Parameters

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIp = $allHosts[$hostName]

        Invoke-Command `
            -ComputerName $hostIp `
            -Credential $domainUserCredential `
            -Authentication Credssp `
            -ScriptBlock {
                $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

                $ObsAgentServiceName = "AzureStack Observability Agent"
                $ObsAgentServiceDisplayName = "AzureStack Arc Extension Observability Agent"
                $stopDelayInSeconds = 10

                $service = Get-Service | Where-Object {$_.Name -eq $ObsAgentServiceName -and $_.DisplayName -eq $ObsAgentServiceDisplayName }
                if($service)
                {
                    if ($service.Status -ne "Stopped")
                    {
                        Write-ObservabilityLog "Stopping service $ObsAgentServiceName with display name $ObsAgentServiceDisplayName on host $($env:COMPUTERNAME)"
                        $service | Stop-Service
                        Write-ObservabilityLog "Sleeping $stopDelayInSeconds seconds after stopping $ObsAgentServiceName before unregistering."
                        Start-Sleep -Seconds $stopDelayInSeconds
                    }
                    Write-ObservabilityLog "Unregistering service $ObsAgentServiceName."
                    sc.exe delete $ObsAgentServiceName
                    Write-ObservabilityLog "Successfully unregistered service $ObsAgentServiceDisplayName"
                }
                else
                {
                    Write-ObservabilityLog "Service $ObsAgentServiceName not found. Noop."
                }
            }
    }

    static StopRemSupAgent([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        # Making this no-op since it's going in the same payload as InstallRemoteSupportArcExtension
        # Will remove the action plan for this in another payload
    }

    static SetWatchdogToListenerMode([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $domainUserCredential = [ObservabilityConfig]::GetDomainCredential($Parameters)

        $hostName = Get-ExecutionContextNodeName -Parameters $Parameters

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIp = $allHosts[$hostName]

        Invoke-Command `
            -ComputerName $hostIp `
            -Credential $domainUserCredential `
            -Authentication Credssp `
            -ScriptBlock {
                $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
                $registryPath = 'HKLM:\SOFTWARE\Microsoft\AzureStack\Observability'
                Write-ObservabilityLog "Setting $registryPath WatchdogListenerMode registry key to 1 on $($env:COMPUTERNAME)."
                if (!(Test-Path -Path $registryPath))
                {
                    New-Item -Path $registryPath -Force
                }
                New-ItemProperty -Path $registryPath -Name 'WatchdogListenerMode' -PropertyType 'DWord' -Value 1 -Force
                Write-ObservabilityLog "Finished setting WatchdogListenerMode Registry key to DWord 1 on $($env:COMPUTERNAME)"

                $timeLimitInSeconds = 600
                $retryPeriod = 10
                $elapsed = 0

                $maHostProcess = Get-Process "MonAgentHost" -ErrorAction SilentlyContinue
                $maCoreProcess = Get-Process "MonAgentCore" -ErrorAction SilentlyContinue
                while($maHostProcess -or $maCoreProcess)
                {
                    if($maHostProcess)
                    {
                        $pids = $maHostProcess.Id | Out-String
                        Write-ObservabilityLog "MonAgentHost Active Process Ids: `n $pids"
                    }
                    if($maCoreProcess)
                    {
                        $pids = $maCoreProcess.Id | Out-String
                        Write-ObservabilityLog "MonAgentCore Active Process Ids: `n $pids"
                    }

                    if($elapsed -gt $timeLimitInSeconds)
                    {
                        $errMsg = "WatchdogListenerMode has failed to stop Monitoring agent processes after $timeLimitInSeconds."
                        Write-ObservabilityErrorLog $errMsg
                        throw $errMsg
                    }
                    Write-ObservabilityLog "Monitoring Agent processes have not yet stopped. Retrying in $retryPeriod seconds."
                    Start-Sleep -Seconds $retryPeriod
                    $elapsed += $retryPeriod
                    $maHostProcess = Get-Process "MonAgentHost" -ErrorAction SilentlyContinue
                    $maCoreProcess = Get-Process "MonAgentCore" -ErrorAction SilentlyContinue
                }
                Write-ObservabilityLog "MonitoringAgent has been successfully stopped after Watchdog has been set to listener mode."
            }
    }

    static SetGMATenantJsonRegistryKeys([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
        Write-ObservabilityLog "SetGMATenantJsonRegistryKeys start"

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIps = $allHosts[$hostNames]

        $gmaNugetName = "Microsoft.AzureStack.Observability.GenevaMonitoringAgent"
        $gmaPackageContentPath = Join-Path $(Get-ASArtifactPath -NugetName $gmaNugetName) -ChildPath "content"
        Import-Module "$gmaPackageContentPath\GMATenantJsonHelper.psm1" -DisableNameChecking

        ## GMA cache folder path
        $gmaCacheFolderName = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.GMACacheFolderName
        $gmaCacheFolderPath = Join-Path -Path $env:SystemDrive -ChildPath $gmaCacheFolderName

        ## Determine GcsEnvironment
        $gcsEnvironment = "Prod" ## default environment

        ## Check if the reg key created for CI exists or not, if yes then change the GCSEnvironment to point to PPE.
        if(Test-IsCIEnv)
        {
            $gcsEnvironment = "Ppe"
        }

        $envInfoFilePath = "$GmaPackageContentPath\EnvironmentInfo.json"
        $tenantInfoContent = Get-Content $envInfoFilePath -Raw | ConvertFrom-Json
        $envInfo = $tenantInfoContent.$GcsEnvironment

        # Settings from EnvironmentInfo.json
        $gcsEndpoint = $envInfo.EndPoint
        $gcsAccount = $envInfo.Account
        $genevaConfigVersion = $envInfo.ConfigVersion

        # Settings from ECE
        $assemblyVersion = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.Version
        $registrationSubscriptionId = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.RegistrationSubscriptionId
        $registrationResourceGroupName = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.RegistrationResourceGroupName
        $stampId = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.RegistrationResourceName
        $gcsRegionName = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.RegistrationRegion
        $clusterName = $Parameters.Roles["Cluster"].PublicConfiguration.Clusters.Node.Name
        $cloudId = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.CloudId
        $deviceArmResourceUri = "/Subscriptions/$registrationSubscriptionId/resourceGroups/$registrationResourceGroupName/providers/Microsoft.AzureStackHCI/clusters/$stampId"
        $osBuild = Get-OSBuildVersion
        $registrationArcResourceGroupName = $registrationResourceGroupName
        $arcResourceGroupName = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.RegistrationArcServerResourceGroupName

        if (![String]::IsNullOrEmpty($arcResourceGroupName)) {
            Trace-Execution "Using RegistrationArcServerResourceGroupName $arcResourceGroupName for ArcServer resource in Tenant Json"
            $registrationArcResourceGroupName = $arcResourceGroupName
        }

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)
        Invoke-Command `
            -ComputerName $hostIps `
            -Credential $localAdminCredential `
            -Authentication Credssp `
            -ScriptBlock {
                $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
                $gmaPackageContentPath = Join-Path $(Get-ASArtifactPath -NugetName $Using:gmaNugetName) -ChildPath "content"
                Import-Module "$gmaPackageContentPath\GMATenantJsonHelper.psm1" -DisableNameChecking

               # Will unset GMA scenario registry path at bootstrap uninstall
                Set-GMAScenarioRegistryKeyToBootstrap | Out-Null

                # For Bootstrap Scenario, nodeid is stampid-sha256(hostname)
                $hostNameHash = Get-Sha256Hash -ClearString (hostname)
                $nodeId = "$($Using:stampId)-$hostNameHash"
                $arcAgentResourceId = Get-ArcResourceId -SubscriptionId $Using:registrationSubscriptionId -ResourceGroupName $Using:registrationArcResourceGroupName -CloudId $Using:cloudId

                $configTypes = @("Telemetry", "Diagnostics", "Health", "Metrics", "Security")
                foreach($configType in $configTypes)
                {
                    $envInfo = $Using:envInfo
                    $gcsNameSpace = $envInfo.Namespaces.$configType

                    if ($configType -eq "Metrics")
                    {
                        $gcsNameSpace = Get-MetricsNamespaceRegionMapping -Region $using:gcsRegionName -MetricsNameSpace $envInfo.Namespaces.$configType
                        $envInfo
                        #Set environment variables required for 3P metrics
                        Set-EnvironmentVariablesForMetrics `
                            -GcsEnvironment $using:gcsEnvironment `
                            -EnvInfoFilePath $using:envInfoFilePath `
                            -AssemblyBuildVersion $Using:assemblyVersion `
                            -ClusterName $Using:clusterName `
                            -HciResourceUri $Using:deviceArmResourceUri
                    }

                    # cacheLocalPath will be overwritten by Extension Install script because cache location for bootstrap is not known until install time
                    $cacheLocalPath = Join-Path -Path $Using:gmaCacheFolderPath -ChildPath $($configType + "Cache")
                    Set-TenantConfigRegistryKeys `
                        -ConfigType $configType `
                        -Version "1.0" `
                        -GcsAuthIdType "AuthMSIToken" `
                        -GcsEnvironment $Using:gcsEndpoint `
                        -GcsGenevaAccount $Using:gcsAccount `
                        -GcsNamespace $gcsNameSpace `
                        -GcsRegion $Using:gcsRegionName `
                        -GenevaConfigVersion $Using:genevaConfigVersion `
                        -LocalPath $cacheLocalPath `
                        -DisableUpdate "true" `
                        -DisableCustomImds "true" `
                        -MONITORING_AEO_REGION $Using:gcsRegionName `
                        -MONITORING_AEO_DEVICE_ARM_RESOURCE_URI $Using:deviceArmResourceUri `
                        -MONITORING_AEO_STAMPID $Using:stampId `
                        -MONITORING_AEO_CLUSTER_NAME $Using:clusterName `
                        -MONITORING_AEO_OSBUILD $Using:osBuild `
                        -MONITORING_AEO_ASSEMBLYBUILD $Using:assemblyVersion `
                        -MONITORING_AEO_NODEID $nodeId `
                        -MONITORING_AEO_NODE_ARC_RESOURCE_URI $arcAgentResourceId `
                        -MONITORING_AEO_CLUSTER_NODE_NAME "%COMPUTERNAME%"
                }
                $hostname = hostname
                Write-ObservabilityLog "SetGMATenantJsonRegistryKeys on $hostname succeeded."
            }
    }

    static GenerateTelemetryFromCachedFiles([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1

        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        Write-ObservabilityLog "$env:COMPUTERNAME Generate Telemetry from Cached files start."

        $cloudRole      = $Parameters.Roles["Cloud"].PublicConfiguration
        $domainCredential = [ObservabilityConfig]::GetDomainCredential($Parameters)
        $cloudId = $cloudRole.PublicInfo.CloudId

        # Get host names using execution context
        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        $scriptBlock = {
            param (
                [string]
                [parameter(Mandatory=$true)]
                $CorrelationId

            )

            $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
            $logOrchestratorNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.LogOrchestrator"
            Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

            $result = Invoke-CachedTelemetryFilesParsing `
                        -LogOrchestratorNugetPath $logOrchestratorNugetPath `
                        -CorrelationId $CorrelationId

            return $result
        }

        # Install Arc for server agent on each Host
        $exceptionMessage = ""
        foreach($hostName in $hostNames)
        {
            $argList = @($cloudId)
            $result = Invoke-Command `
                -ComputerName $hostName `
                -ScriptBlock $scriptBlock `
                -ArgumentList $argList `
                -Credential $domainCredential `
                -Authentication Credssp
            if ($result -eq $true)
            {
                Write-ObservabilityLog "Generate Telemetry from Cached files on host $hostName succeeded."
            }
            else
            {
                Write-ObservabilityLog "Generate Telemetry from Cached files on host $hostName failed with exception $result."
                $exceptionMessage += "${hostName}: $result`n"
            }
        }

        if($exceptionMessage)
        {
            throw $exceptionMessage
        }

        Write-ObservabilityLog "$env:COMPUTERNAME Generate Telemetry from Cached files end."
    }

    static SyncDiagnosticLevel([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Trace-Execution "Getting parameters for Set-AzStackHCI" -Verbose
        $computerName = Get-Cluster | Select-Object -expand Name
        $resourceId = Get-AzureStackHCI | Select-Object -expand AzureResourceUri
        
        $streamingData = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.StreamingDataClient
        Trace-Execution "Streaming Data = $streamingData" -Verbose
        $episodicDataUpload = $Parameters.Roles["ObservabilityConfig"].PublicConfiguration.PublicInfo.EpisodicDataUpload
        Trace-Execution "Episodic Data Upload = $episodicDataUpload" -Verbose
        
        if ($streamingData) { 
            if ($episodicDataUpload) { 
                $diagnosticLevel = "Enhanced" 
            }
            else { 
                $diagnosticLevel = "Basic" 
            } 
        } else {
            $diagnosticLevel = "Off"
        }
        
        Trace-Execution "Diagnostic Level will be set to $diagnosticLevel" -Verbose

        Trace-Execution "Calling GetRegistrationParameters" -Verbose
        $registrationParams = [ObservabilityConfig]::GetRegistrationParameters($Parameters)
        
        Trace-Execution "Calling Set-AzStackHCI. Parameters = ComputerName $computerName, ResourceId $resourceId, DiagnosticLevel $diagnosticLevel, AccountId $($registrationParams.AccountId)" -Verbose
        Set-AzStackHCI -ComputerName $computerName `
                        -ResourceId $resourceId `
                        -DiagnosticLevel $diagnosticLevel `
                        -ArmAccessToken $registrationParams.ArmAccessToken `
                        -AccountId $registrationParams.AccountId `
                        -Confirm:$false `
                        -Verbose
        
        $retryAttempt = 0
        $retrySleepTimeInSeconds = 10
        $Retries = 5
        $success = $false
        while(-not($success) -and ($retryAttempt -lt $Retries))
        {
            $retryAttempt = $retryAttempt + 1
            Trace-Execution "Attempt $retryAttempt of $Retries" -Verbose
            try
            {

                Trace-Execution "Calling Sync-AzureStackHCI" -Verbose
                Sync-AzureStackHCI -Verbose
                
                Trace-Execution "Calling Get-AzureStackHCI" -Verbose
                $portalDiagnosticLevel = Get-AzureStackHCI | Select-Object -expand DiagnosticLevel
                
                if ($portalDiagnosticLevel -eq $diagnosticLevel) { 
                    Trace-Execution "Portal diagnostic level was successfully set to $portalDiagnosticLevel" -Verbose
                    $success = $true 
                } else { 
                    throw "The Diagnostic Level does not match. Portal was not set to $diagnosticLevel, instead is $portalDiagnosticLevel" 
                }
            }
            catch
            {
                if ($retryAttempt -lt $Retries)
                {
                    $exceptionMessage = $_.Exception.Message
                    Trace-Execution "Failure during syncing diagnostic level: '$exceptionMessage'. Retrying." -Verbose
                }
                else
                {
                    Trace-Error "Syncing Diagnostic Level failed with error: $_"
                }
                Start-Sleep -Seconds $retrySleepTimeInSeconds
            }
        }

        Trace-Execution "Syncing Diagnostic Level successful. Set to: $diagnosticLevel" -Verbose
    }

    static UpdateGMATenantJsonNodeId([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1

        $hostName = Get-ExecutionContextNodeName -Parameters $Parameters
        # Get Host IPs for all hosts
        $allHosts = Get-NetworkMgmtIPv4FromECEForAllHosts -Parameters $Parameters
        # Filter host IPs for only hosts from execution context. This is to cover ScaleOut scenario
        $hostIp = $allHosts[$hostName]

        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
        $assemblyBuild = ""
        try
        {
            Write-ObservabilityLog "Getting Assembly Build using GetStampVersion"
            Import-Module EceClient
            $ececlient = Create-ECEClusterServiceClient
            $assemblyBuild = $ececlient.GetStampVersion().GetAwaiter().GetResult()
            if ($assemblyBuild -eq "99.9999.9.10")
            {
                Write-ObservabilityLog "Getting Assembly Build using GetStampVersion returned $assemblyBuild, which is a possibly erroneous override. Using Assembly version in ECE parameters."
                $assemblyBuild = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.Version
            }
        }
        catch
        {
            Write-ObservabilityLog "Getting Assembly Build using GetStampVersion failed. Using Assembly version in ECE parameters"
            $assemblyBuild = $Parameters.Roles["Cloud"].PublicConfiguration.PublicInfo.Version
        }
        Write-ObservabilityLog "Assembly Build value of $assemblyBuild obtained."

        $localAdminCredential = [ObservabilityConfig]::GetLocalCredential($Parameters)

        Invoke-Command `
            -Credential $localAdminCredential `
            -Authentication Credssp `
            -ComputerName $hostIp `
            -ScriptBlock {
                $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
                Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

                $success = $false
                $extError = ""

                # Get NodeId
                $azureStackHciDetails = Get-AzureStackHCI
                $StampId = $azureStackHciDetails.AzureResourceName
                $nodeId = $StampId + "-" + (Get-ClusterNode(hostname)).Id

                $registryPath = 'HKLM:\SOFTWARE\Microsoft\AzureStack\Observability\TenantJson'
                $nodeIdKey = "MONITORING_AEO_NODEID"
                $assemblyBuildKey = "MONITORING_AEO_ASSEMBLYBUILD"

                Write-ObservabilityLog "$($env:COMPUTERNAME): Setting keys $nodeIdKey to $nodeId and $assemblyBuildKey to $using:assemblyBuild at registry path $registryPath."
                if (!(Test-Path -Path $registryPath))
                {
                    New-Item -Path $registryPath -Force
                }
                New-ItemProperty -Path $registryPath -Name $nodeIdKey -PropertyType 'String' -Value $nodeId -Force
                New-ItemProperty -Path $registryPath -Name $assemblyBuildKey -PropertyType 'String' -Value $using:assemblyBuild -Force
                Write-ObservabilityLog "Finished setting registry keys $nodeIdKey and $assemblyBuildKey on $($env:COMPUTERNAME)"

                $paths = (Get-ChildItem "C:\Packages\Plugins\Microsoft.AzureStack.Observability*TelemetryAndDiagnostics*\*\" -ErrorAction SilentlyContinue).FullName
                foreach ($extRootPath in $paths)
                {
                    Write-ObservabilityLog "Found Observability TelemetryAndDiagnostics extension at $extRootPath."
                    if($success)
                    {
                        Write-ObservabilityLog "NodeId already updated successfully. Ignoring extension at $extRootPath."
                    }
                    else
                    {
                        try
                        {
                            Import-Module (Join-Path -Path $extRootPath -ChildPath 'scripts\ExtensionHelper.psm1') `
                                -DisableNameChecking `
                                -Verbose:$false
                            $logFile = Get-HandlerLogFile

                            $gmaPackageContentPath = Get-GmaPackageContentPath
                            Import-Module (Join-Path -Path "$gmaPackageContentPath" -ChildPath 'GMATenantJsonHelper.psm1') `
                                -DisableNameChecking `
                                -Verbose:$false

                            $cacheDirectories = New-CacheDirectories -LogFile $logFile
                            $gmaCacheFolderPath = $cacheDirectories.GMACache
                            $jsonDropLocation = Join-Path -Path $gmaCacheFolderPath -ChildPath "JsonDropLocation"

                            foreach ($configType in $global:MiscConstants.ConfigTypes.Values)
                            {
                                $jsonConfigFileName = "AEO" + $configType + ".json"
                                $tenantJsonFilePath = Join-Path -Path $jsonDropLocation -ChildPath $jsonConfigFileName
                                Write-ObservabilityLog "Creating file $tenantJsonFilePath."
                                Set-TenantConfigJsonFile -ConfigType $configType -FilePath $tenantJsonFilePath -LogFile $logFile
                                Write-ObservabilityLog "Creation of file $tenantJsonFilePath succeeded."
                            }
                            $success = $true
                        }
                        catch
                        {
                            Write-ObservabilityErrorLog "Updating NodeId in tenant jsons failed with error $_"
                            $extError = $_
                        }
                    }
                }
                if (-not $success)
                {
                    if ($extError)
                    {
                        throw "Updating NodeId in tenant jsons failed with error $extError"
                    }
                    else
                    {
                        $errMsg = "Could not update NodeId in tenant jsons because no TelemetryAndDiagnostics Extension was found at C:\Packages\Plugins."
                        Write-ObservabilityErrorLog $errMsg
                        throw $errMsg
                    }
                }
        }
    }
        
    static DeleteObservabilityAgents([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
        $obsServices = @(
            "AzureStack Observability Agent",
            "AzureStack Observability FDA",
            "AzureStack Observability GenevaMonitoringAgent",
            "AzureStack Observability RemoteSupportAgent"
        )
        $stopDelayInSeconds = 10
        $agentManifestPath = "C:\Agents\AgentManifests"

        $obsServices | ForEach-Object {
            $service = Get-Service -Name $_ -ErrorAction SilentlyContinue | Where-Object {$_.DisplayName -notlike "*Arc Extension*"}
            if ($service)
            {
                try
                {
                    Write-ObservabilityLog "Stopping service $($service.DisplayName)."
                    $service | Stop-Service
                    Write-ObservabilityLog "Successfully stopped service $($service.DisplayName). Sleeping for $stopDelayInSeconds before unregistering service."
                    Start-Sleep -Seconds $stopDelayInSeconds
                    Write-ObservabilityLog "Unregistering service $($service.DisplayName)."
                    sc.exe delete $service.Name
                    Write-ObservabilityLog "Stopping and unregistering of service $($service.DisplayName) succeeded."
                    $manifestPath = "$agentManifestPath\$($service.DisplayName).json"
                    if (Test-Path -Path $manifestPath)
                    {
                        Write-ObservabilityLog "Deleting agent manifest at $manifestPath."
                        Remove-Item $manifestPath -Force
                        Write-ObservabilityLog "Deletion of agent manifest at $manifestPath succeeded."
                    }
                }
                catch
                {
                    Write-ObservabilityErrorLog "Stopping and unregistering of service $($service.DisplayName) failed with error $_"
                }
            }
        }
    }

    static SetListenerModeOff([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
        $registryPath = 'HKLM:\SOFTWARE\Microsoft\AzureStack\Observability'
        Write-ObservabilityLog "Setting $registryPath WatchdogListenerMode registry key to 0 on $($env:COMPUTERNAME)."
        if (!(Test-Path -Path $registryPath))
        {
            New-Item -Path $registryPath -Force
        }
        New-ItemProperty -Path $registryPath -Name 'WatchdogListenerMode' -PropertyType 'DWord' -Value 0 -Force
        Write-ObservabilityLog "Finished setting WatchdogListenerMode Registry key to DWord 0 on $($env:COMPUTERNAME)"
        $timeLimitInSeconds = 600
        $retryPeriod = 10
        $elapsed = 0

        $maCoreProcess = Get-Process "MonAgentCore" -ErrorAction SilentlyContinue
        while($null -eq $maCoreProcess)
        {
            if($elapsed -gt $timeLimitInSeconds)
            {
                $errMsg = "Watchdog has failed to start Monitoring agent processes after $timeLimitInSeconds."
                Write-ObservabilityErrorLog $errMsg
                throw $errMsg
            }
            Write-ObservabilityLog "Monitoring Agent processes have not yet started. Retrying in $retryPeriod seconds."
            Start-Sleep -Seconds $retryPeriod
            $elapsed += $retryPeriod
            $maCoreProcess = Get-Process "MonAgentCore" -ErrorAction SilentlyContinue
        }
        Write-ObservabilityLog "MonitoringAgent has been successfully started. Watchdog listener mode has been set to off."
    }

    static StartArcExtensionObsAgent([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $success = $false
        $paths = (Get-ChildItem "C:\Packages\Plugins\Microsoft.AzureStack.Observability*TelemetryAndDiagnostics*\*\" -ErrorAction SilentlyContinue).FullName
        $extError = ""
        foreach ($extRootPath in $paths)
        {
            Write-ObservabilityLog "Found Observability TelemetryAndDiagnostics extension at $extRootPath."

            if ($success)
            {
                Write-ObservabilityLog "TelemetryAndDiagnostics Arc Extension Observability Agent already started. Ignoring extension at $extRootPath."
            }
            else
            {
                try
                {
                    Import-Module (Join-Path -Path $extRootPath -ChildPath 'scripts\ExtensionHelper.psm1') `
                        -DisableNameChecking `
                        -Verbose:$false

                    $logFile = Get-HandlerLogFile

                    ## Misc constants is defined here: https://msazure.visualstudio.com/One/_git/ASZ-Observability-MonitoringAgent?path=/src/GenevaMonitoringAgent/DeploymentScripts/GMATenantJsonHelper.psm1
                    ## Register Obs Agent as Windows service
                    $obsAgent = $global:MiscConstants.ObsServiceDetails.ObsAgent
                    $binaryFilePath = Join-Path -Path $global:ObsArtifactsPaths.ObservabilityAgent `
                        -ChildPath $obsAgent.BinaryFileName
                                        
                    Write-ObservabilityLog "Registering $($obsAgent.DisplayName) service at path $binaryFilePath"
                    Register-ServiceForObservability `
                        -ServiceName $obsAgent.Name `
                        -ServiceDisplayName $obsAgent.DisplayName `
                        -ServiceBinaryFilePath $binaryFilePath `
                        -LogFile $logFile

                    ## Start Observability Agent.
                    Write-ObservabilityLog "Starting $($obsAgent.DisplayName) service"
                    Start-ServiceForObservability `
                        -ServiceName $obsAgent.Name `
                        -LogFile $logFile

                    Write-ObservabilityLog "Observability Agent $($obsAgent.DisplayName) successfully registered and started"
                    $success = $true
                }
                catch
                {
                    Write-ObservabilityErrorLog "Starting TelemetryAndDiagnostics Arc Extension Observability Agent failed with error $_"
                    $extError = $_
                }
            }
        }
        if (-not $success)
        {
            if ($extError)
            {
                throw "Starting TelemetryAndDiagnostics Arc Extension Observability Agent failed with error $extError"
            }
            else
            {
                $errMsg = "Could not start Arc Extension Observability Agent because no Arc Extension was found at C:\Packages\Plugins."
                Write-ObservabilityErrorLog $errMsg
                throw $errMsg
            }
        }
    }

    static RegenerateGMATenantJsonFiles([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $success = $false
        $paths = (Get-ChildItem "C:\Packages\Plugins\Microsoft.AzureStack.Observability*TelemetryAndDiagnostics*\*\" -ErrorAction SilentlyContinue).FullName
        $extError = ""
        foreach ($extRootPath in $paths)
        {
            Write-ObservabilityLog "Found Observability TelemetryAndDiagnostics extension at $extRootPath."
            if($success)
            {
                Write-ObservabilityLog "GMA Tenant Json files already updated successfully. Ignoring extension at $extRootPath."
            }
            else
            {
                try
                {
                    Import-Module (Join-Path -Path $extRootPath -ChildPath 'scripts\ExtensionHelper.psm1') `
                        -DisableNameChecking `
                        -Verbose:$false
                    $logFile = Get-HandlerLogFile

                    $gmaPackageContentPath = Get-GmaPackageContentPath
                    Import-Module (Join-Path -Path "$gmaPackageContentPath" -ChildPath 'GMATenantJsonHelper.psm1') `
                        -DisableNameChecking `
                        -Verbose:$false

                    $cacheDirectories = New-CacheDirectories -LogFile $logFile
                    $gmaCacheFolderPath = $cacheDirectories.GMACache
                    $jsonDropLocation = Join-Path -Path $gmaCacheFolderPath -ChildPath "JsonDropLocation"

                    foreach ($configType in $global:MiscConstants.ConfigTypes.Values)
                    {
                        $jsonConfigFileName = "AEO" + $configType + ".json"
                        $tenantJsonFilePath = Join-Path -Path $jsonDropLocation -ChildPath $jsonConfigFileName
                        Write-ObservabilityLog "Creating file $tenantJsonFilePath."
                        Set-TenantConfigJsonFile -ConfigType $configType -FilePath $tenantJsonFilePath -LogFile $logFile
                        Write-ObservabilityLog "Creation of file $tenantJsonFilePath succeeded."
                    }
                    $success = $true
                }
                catch
                {
                    Write-ObservabilityErrorLog "Regenerating tenant jsons failed with error $_"
                    $extError = $_
                }
            }
        }
        if (-not $success)
        {
            if ($extError)
            {
                throw "Regenerating GMA tenant jsons failed with error $extError"
            }
            else
            {
                $errMsg = "Could not regenerate GMA tenant jsons because no TelemetryAndDiagnostics Extension was found at C:\Packages\Plugins."
                Write-ObservabilityErrorLog $errMsg
                throw $errMsg
            }
        }
    }

    static RestoreMAWatchdogRegKeyAndService([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        $functionName = "RestoreMAWatchdogRegKeyAndService"
        Write-ObservabilityLog "Starting $functionName."

        $HCITelemetryRegKey = @{
            Path = 'HKLM:\SYSTEM\Software\Microsoft\MAWatchdogService\HCITelemetry'
            Name = 'AllowTelemetry'
            PropertyType = 'String'
            Value = 'True'
        }
        $regKey = $(Get-ItemProperty -Path $HCITelemetryRegKey.Path -Name $HCITelemetryRegKey.Name -ErrorAction SilentlyContinue)
        if($null -ne $regKey)
        {
            Write-ObservabilityLog "$functionName : Registry key $($HCITelemetryRegKey.Name) at $($HCITelemetryRegKey.Path) already exists. Noop."
        }
        else
        {
            Write-ObservabilityLog "$functionName : Registry key $($HCITelemetryRegKey.Name) at $($HCITelemetryRegKey.Path) does not exist. Restoring."
            $watchdogServiceName = "WatchdogAgent"
            if (-not (Test-Path -Path $HCITelemetryRegKey.Path))
            {
                New-Item -Path $HCITelemetryRegKey.Path -Force
            }
            New-ItemProperty `
                -Path $HCITelemetryRegKey.Path `
                -Name $HCITelemetryRegKey.Name `
                -PropertyType $HCITelemetryRegKey.PropertyType `
                -Value $HCITelemetryRegKey.Value `
                -Force | Out-Null

            Write-ObservabilityLog "$functionName : Created registry key $($HCITelemetryRegKey.Name) at $($HCITelemetryRegKey.Path) with value $($HCITelemetryRegKey.Value)."
            $watchdogAgent = Get-Service $watchdogServiceName -ErrorAction SilentlyContinue
            if($watchdogAgent)
            {
                Write-ObservabilityLog "$functionName : Restarting $watchdogServiceName windows service."
                $watchdogAgent | Restart-Service -ErrorAction SilentlyContinue
            }
        }
    }

    static [Hashtable] GetRegistrationParameters([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        Import-Module $PSScriptRoot\Roles\Common\RoleHelpers.psm1
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"
        $cloudDeploymentNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Solution.Deploy.CloudDeployment"
        Import-Module Az.Accounts -Force

        $hostNames = Get-ExecutionContextNodeName -Parameters $Parameters
        if($null -eq $hostNames)
        {
            $hostNames = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        }

        Trace-Execution "Getting registration parameters from ECE role parameters"
        $nodeNames      = $Parameters.Roles["BareMetal"].PublicConfiguration.Nodes.Node.Name
        $cloudRole      = $Parameters.Roles["Cloud"].PublicConfiguration
        $securityInfo   = $cloudRole.PublicInfo.SecurityInfo
        $registrationParams = @{
            EnvironmentName         = $cloudRole.PublicInfo.RegistrationCloudName
            SubscriptionId          = $cloudRole.PublicInfo.RegistrationSubscriptionId
            TenantId                = $cloudRole.PublicInfo.RegistrationTenantId
            Region                  = $cloudRole.PublicInfo.RegistrationRegion
            ResourceGroupName       = $cloudRole.PublicInfo.RegistrationResourceGroupName
            ResourceName            = $cloudRole.PublicInfo.RegistrationResourceName
            CloudId                 = $cloudRole.PublicInfo.CloudId
            EnableAzureArcServer    = [System.Convert]::ToBoolean($cloudRole.PublicInfo.EnableAzureArcServer)
            ComputerName            = $nodeNames | Select-Object -First 1
        }

        if (![String]::IsNullOrEmpty($cloudRole.PublicInfo.RegistrationArcServerResourceGroupName)) {
            Trace-Execution "Using RegistrationArcServerResourceGroupName $($cloudRole.PublicInfo.RegistrationArcServerResourceGroupName) for ArcServer registration"
            $registrationParams.ResourceGroupName = $cloudRole.PublicInfo.RegistrationArcServerResourceGroupName
        }

        $registrationParameterSet = $cloudRole.PublicInfo.RegistrationParameterSet
        if ($registrationParameterSet -eq "DefaultSet") {
            Trace-Execution "RegistrationParameterSet $registrationParameterSet, getting access tokens using user token cache"
            $registrationTokenCacheUser = $securityInfo.AADUsers.User | ? Role -EQ $Parameters.Configuration.Role.PrivateInfo.Accounts.RegistrationTokenCacheID
            $registrationTokenCacheCred = $Parameters.GetCredential($registrationTokenCacheUser.Credential)
            $clientId = $cloudRole.PublicInfo.RegistrationClientId
            Trace-Execution "Using clientId $clientId to get access token"
            Trace-Execution "Going to use RegistrationHelpers $cloudDeploymentNugetPath\content\Setup\Common\RegistrationHelpers.psm1"
            Import-Module "$cloudDeploymentNugetPath\content\Setup\Common\RegistrationHelpers.psm1"
            $armAccessToken     = Get-AccessToken -AzureEnvironment $registrationParams.EnvironmentName -TenantId $registrationParams.TenantId -TokenCacheCred $registrationTokenCacheCred -ClientId $clientId
            Trace-Execution "Access tokens length using token cache is $($armAccessToken.AccessToken.Length)"

            $registrationParams += @{
                AccountId           = $registrationTokenCacheCred.UserName
                ArmAccessToken      = $armAccessToken.AccessToken
            }
        } else {
            Trace-Execution "RegistrationParameterSet $registrationParameterSet, getting access tokens using service principal"
            $registrationSPUser = $securityInfo.AADUsers.User | ? Role -EQ $Parameters.Configuration.Role.PrivateInfo.Accounts.RegistrationSPID
            $registrationSPCred = $Parameters.GetCredential($registrationSPUser.Credential)
            Login-AzAccount -Environment $registrationParams.EnvironmentName -Credential $registrationSPCred -Tenant $registrationParams.TenantId -ServicePrincipal
            $armAccessToken = Get-AzAccessToken -Verbose
            Trace-Execution "Access token length using service principal is $($armAccessToken.Token.Length)"

            $registrationParams += @{
                AccountId           = $registrationSPCred.UserName
                ArmAccessToken      = $armAccessToken.Token
            }
        }

        if($registrationParams.ArmAccessToken.Length -eq 0)
        {
            throw "GetRegistrationParameters failed to retrieve AccessToken"
        }

        return $registrationParams
    }

    static [string] GetProxyUrl([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        Write-ObservabilityLog "Checking if proxy settings exist"
        $proxySettings = Get-ASProxySettings -Parameters $Parameters
        $proxyUrl = $proxySettings.HTTP

        if ($proxyUrl)
        {
            if (-not (($proxyUrl -cmatch "http://") -or ($proxyUrl -cmatch "https://")))
            {
                $proxyUrl = "http://$proxyUrl"
            }
        }

        if ($proxyUrl)
        {
            Write-ObservabilityLog "Using proxy url $proxyUrl for Arc Agent connection."
        }
        return $proxyUrl
    }

    <#
        .SYNOPSIS
        Evaluation function to determine run SetupObservability or skip it for ArcA deployment
        ArcA currently does not support Arc4Server, skip Observability feature for ArcA deployment
             
        .EXAMPLE
        [GMATenantJson]::EvaluateSetupObservability($Parameters)
 
        .PARAMETER Parameters
        The ECE role parameters for this interface.
    #>

    static [CloudEngine.Actions.ConditionalActionDescription] EvaluateSetupObservability([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $ErrorActionPreference = "Stop"

        return [ObservabilityConfig]::EvaluateObservabilityAction($Parameters, "SetupObservability")
    }

    <#
        .SYNOPSIS
        Evaluation function to identify run InstallBootstrapObservability or skip it for ArcA deployment
        ArcA currently does not support Arc4Server, skip Observability feature for ArcA deployment
             
        .EXAMPLE
        [GMATenantJson]::EvaluateInstallBootstrapObservability($Parameters)
 
        .PARAMETER Parameters
        The ECE role parameters for this interface.
    #>

    static [CloudEngine.Actions.ConditionalActionDescription] EvaluateInstallBootstrapObservability([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $ErrorActionPreference = "Stop"

        return [ObservabilityConfig]::EvaluateObservabilityAction($Parameters, "InstallBootstrapObservability")
    }

    <#
        .SYNOPSIS
        Evaluation function to identify run PostRegistrationObservabilitySetup or skip it for ArcA deployment
        ArcA currently does not support Arc4Server, skip Observability feature for ArcA deployment
             
        .EXAMPLE
        [GMATenantJson]::EvaluatePostRegistrationObservabilitySetup($Parameters)
 
        .PARAMETER Parameters
        The ECE role parameters for this interface.
    #>

    static [CloudEngine.Actions.ConditionalActionDescription] EvaluatePostRegistrationObservabilitySetup([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $ErrorActionPreference = "Stop"

        return [ObservabilityConfig]::EvaluateObservabilityAction($Parameters, "PostRegistrationObservabilitySetup")
    }

    <#
        .SYNOPSIS
        Evaluation function to identify run EvaluateSendTelemetryFromCachedFiles or skip it for ArcA deployment
        ArcA currently does not support Arc4Server, skip Observability feature for ArcA deployment
             
        .EXAMPLE
        [GMATenantJson]::EvaluateSendTelemetryFromCachedFiles($Parameters)
 
        .PARAMETER Parameters
        The ECE role parameters for this interface.
    #>

    static [CloudEngine.Actions.ConditionalActionDescription] EvaluateSendTelemetryFromCachedFiles([CloudEngine.Configurations.EceInterfaceParameters] $Parameters)
    {
        $ErrorActionPreference = "Stop"

        return [ObservabilityConfig]::EvaluateObservabilityAction($Parameters, "SendTelemetryFromCachedFiles")
    }

    static [CloudEngine.Actions.ConditionalActionDescription] EvaluateObservabilityAction([CloudEngine.Configurations.EceInterfaceParameters] $Parameters, [string] $actionName)
    {
        $ErrorActionPreference = "Stop"

        $observabilityNugetPath = Get-ASArtifactPath -NugetName "Microsoft.AzureStack.Observability.ObservabilityDeployment"
        Import-Module "$observabilityNugetPath\content\Powershell\ObservabilityHelpers.psm1"

        if (-not (Test-IsArcADeployment -Parameters $Parameters))
        {
            Write-ObservabilityLog "EvaluateObservabilityAction: Execute $actionName"
            return [CloudEngine.Actions.ConditionalActionDescription]::CreateWithDefinedAction("ObservabilityConfig", $actionName)
        }
        
        Write-ObservabilityLog "EvaluateObservabilityAction: Skip executing $actionName for ArcA deployment" -Verbose
        return [CloudEngine.Actions.ConditionalActionDescription]::CreateNegative()
    }
}
# SIG # Begin signature block
# MIInvwYJKoZIhvcNAQcCoIInsDCCJ6wCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLC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