Skip to content

Commit

Permalink
Update media connector sample
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicbetts committed Nov 20, 2024
1 parent ce36254 commit 45e4b39
Show file tree
Hide file tree
Showing 32 changed files with 885 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
azure-iot-operations
1 change: 1 addition & 0 deletions samples/media-connector-invoke-test/.config_aio_namespace
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
azure-iot-operations
1 change: 1 addition & 0 deletions samples/media-connector-invoke-test/.config_resources_path
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${PSScriptRoot}/resources
34 changes: 34 additions & 0 deletions samples/media-connector-invoke-test/Install-ResourceFile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#Requires -Version 7
<#
Install a resource file.
#>
param (
[Parameter(
Mandatory=$true,
HelpMessage="The resource file.")]
[string]$resourceFile
)

Write-Host "`n"
Write-Host (Split-Path -Path $PSCommandPath -Leaf).ToUpper() -ForegroundColor White

$aioConnectorsNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_connectors_namespace") -Raw).Trim()
Write-Host "AIO connectors namespace: $aioConnectorsNamespace"

$resourcesDirectory = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_resources_path") -Raw).Trim()
$resourcesDirectory = $ExecutionContext.InvokeCommand.ExpandString(${resourcesDirectory})
Write-Host "Resources directory: $resourcesDirectory"

Write-Host "Resource file: $resourceFile"

$fileFullPath=(Join-Path -Path $resourcesDirectory -ChildPath $resourceFile)
Write-Host "Resource file full path: ${fileFullPath}"

Write-Host "Applying the resource..."
. kubectl apply -n ${aioConnectorsNamespace} -f ${fileFullPath}
If ($LastExitCode -ne 0) {
Write-Host "Error: The resource could not be applied."
Exit $LastExitCode
} Else {
Write-Host "The resource was applied successfully.`n"
}
22 changes: 22 additions & 0 deletions samples/media-connector-invoke-test/Invoke-GetTaskDebugInfo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
Get the task debug info
#>
param (
[Parameter(
HelpMessage="AIO namespace.")]
[string]$aioNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath .aio_namespace) -Raw),
[Parameter(
HelpMessage="Asset name.")]
[string]$assetName,
[Parameter(
HelpMessage="Datapoint name.")]
[string]$datapointName
)

$mrpcTopic = "$aioNamespace/asset-operations/${assetName}/get-task-debug-info"

$mrpcResponseTopic = "$mrpcTopic/response"

$mrpcPayload = "{`"datapoint`":`"${datapointName}`"}"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-mRPC.ps1") -mrpcTopic $mrpcTopic -mrpcResponseTopic $mrpcResponseTopic -mrpcPayload $mrpcPayload
22 changes: 22 additions & 0 deletions samples/media-connector-invoke-test/Invoke-GetTaskErrorString.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
Get the task error string
#>
param (
[Parameter(
HelpMessage="AIO namespace.")]
[string]$aioNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath .aio_namespace) -Raw),
[Parameter(
HelpMessage="Asset name.")]
[string]$assetName,
[Parameter(
HelpMessage="Datapoint name.")]
[string]$datapointName
)

$mrpcTopic = "$aioNamespace/asset-operations/${assetName}/get-task-error-string"

$mrpcResponseTopic = "$mrpcTopic/response"

$mrpcPayload = "{`"datapoint`":`"${datapointName}`"}"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-mRPC.ps1") -mrpcTopic $mrpcTopic -mrpcResponseTopic $mrpcResponseTopic -mrpcPayload $mrpcPayload
22 changes: 22 additions & 0 deletions samples/media-connector-invoke-test/Invoke-GetTaskOutputString.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
Get the task output string
#>
param (
[Parameter(
HelpMessage="AIO namespace.")]
[string]$aioNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath .aio_namespace) -Raw),
[Parameter(
HelpMessage="Asset name.")]
[string]$assetName,
[Parameter(
HelpMessage="Datapoint name.")]
[string]$datapointName
)

$mrpcTopic = "$aioNamespace/asset-operations/${assetName}/get-task-output-string"

$mrpcResponseTopic = "$mrpcTopic/response"

$mrpcPayload = "{`"datapoint`":`"${datapointName}`"}"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-mRPC.ps1") -mrpcTopic $mrpcTopic -mrpcResponseTopic $mrpcResponseTopic -mrpcPayload $mrpcPayload
22 changes: 22 additions & 0 deletions samples/media-connector-invoke-test/Invoke-GetTaskState.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<#
Get the task state
#>
param (
[Parameter(
HelpMessage="AIO namespace.")]
[string]$aioNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath .aio_namespace) -Raw),
[Parameter(
HelpMessage="Asset name.")]
[string]$assetName,
[Parameter(
HelpMessage="Datapoint name.")]
[string]$datapointName
)

$mrpcTopic = "$aioNamespace/asset-operations/${assetName}/get-task-state"

$mrpcResponseTopic = "$mrpcTopic/response"

$mrpcPayload = "{`"datapoint`":`"${datapointName}`"}"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-mRPC.ps1") -mrpcTopic $mrpcTopic -mrpcResponseTopic $mrpcResponseTopic -mrpcPayload $mrpcPayload
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#Requires -Version 7
<#
Install a resource pair (aep/asset), monitor it, and uninstall it.
#>
param (
[Parameter(
Mandatory,
HelpMessage="The AEP name.")]
[string]$aepName = "",
[Parameter(
Mandatory,
HelpMessage="The asset name.")]
[string]$assetName = "",
[Parameter(
Mandatory,
HelpMessage="The datapoint name.")]
[string]$datapointName = "",
[Parameter(
Mandatory,
HelpMessage="The monitor expression.")]
[string]$monitorExpresion = ""
)

Write-Host "`n"
Write-Host (Split-Path -Path $PSCommandPath -Leaf).ToUpper() -ForegroundColor White

(Join-Path -Path $PSScriptRoot -ChildPath "Test-Prerequisites.ps1") | Out-Null

$aioNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_namespace") -Raw).Trim()
Write-Host "AIO namespace: $aioNamespace"

$aioConnectorsNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_connectors_namespace") -Raw).Trim()
Write-Host "AIO connectors namespace: $aioConnectorsNamespace"

Write-Host "AEP Name: $aepName"

Write-Host "Asset Name: $assetName"

Write-Host "Datapoint Name: $datapointName"

Write-Host "Installing the resource files..."
. (Join-Path -Path $PSScriptRoot -ChildPath "Install-ResourceFile.ps1") -resourceFile "${aepName}.yaml"
. (Join-Path -Path $PSScriptRoot -ChildPath "Install-ResourceFile.ps1") -resourceFile "${assetName}.yaml"

Write-Host "Waiting for the snapshot-to-mqtt task to be ready...`n"
Start-Sleep -Seconds 3

try {
Write-Host "Starting the monitor command...`n"
$monitorExpresion = $ExecutionContext.InvokeCommand.ExpandString(${monitorExpresion})
Invoke-Expression "${monitorExpresion}"

} finally {

Write-Host "Uninstalling the resource files...`n"
. (Join-Path -Path $PSScriptRoot -ChildPath "Uninstall-ResourceFile.ps1") -resourceFile "${assetName}.yaml"
. (Join-Path -Path $PSScriptRoot -ChildPath "Uninstall-ResourceFile.ps1") -resourceFile "${aepName}.yaml"

Write-Host "Snapshot-to-mqtt task test completed.`n"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Requires -Version 7

$aioConnectorsNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_connectors_namespace") -Raw).Trim()
Write-Host "AIO connectors namespace: $aioConnectorsNamespace"

$aepName = "aep-public-http-anonymous-1"
Write-Host "AEP name: $aepName"

$assetName = "asset-public-http-anonymous-1-clip-to-fs-autostart"
Write-Host "Asset name: $assetName"

$datapointName = "clip-to-fs"
Write-Host "Datapoint name: $datapointName"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-ResourceInstallMonitorAndUninstall.ps1") `
-aepName $aepName `
-assetName $assetName `
-datapointName $datapointName `
-monitorExpresion `
". (Join-Path -Path $PSScriptRoot -ChildPath `"Start-FileSystemMonitor.ps1`") -pathToMonitor /tmp/$aioConnectorsNamespace/data/$assetName/"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$aioConnectorsNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_connectors_namespace") -Raw).Trim()
Write-Host "AIO connectors namespace: $aioConnectorsNamespace"

$aepName = "aep-public-http-anonymous-1"
Write-Host "AEP name: $aepName"

$assetName = "asset-public-http-anonymous-1-clip-to-mqtt-autostart"
Write-Host "Asset name: $assetName"

$datapointName = "clip-to-mqtt"
Write-Host "Datapoint name: $datapointName"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-ResourceInstallMonitorAndUninstall.ps1") `
-aepName $aepName `
-assetName $assetName `
-datapointName $datapointName `
-monitorExpresion `
". (Join-Path -Path $PSScriptRoot -ChildPath `"Start-MqttListener.ps1`") -listenTopics $aioConnectorsNamespace/data/$assetName/#"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Requires -Version 7

$aioConnectorsNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_connectors_namespace") -Raw).Trim()
Write-Host "AIO connectors namespace: $aioConnectorsNamespace"

$aepName = "aep-public-http-anonymous-1"
Write-Host "AEP name: $aepName"

$assetName = "asset-public-http-anonymous-1-snapshot-to-fs-autostart"
Write-Host "Asset name: $assetName"

$datapointName = "snapshot-to-fs"
Write-Host "Datapoint name: $datapointName"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-ResourceInstallMonitorAndUninstall.ps1") `
-aepName $aepName `
-assetName $assetName `
-datapointName $datapointName `
-monitorExpresion `
". (Join-Path -Path $PSScriptRoot -ChildPath `"Start-FileSystemMonitor.ps1`") -pathToMonitor /tmp/$aioConnectorsNamespace/data/$assetName/"
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Requires -Version 7

$aioConnectorsNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_connectors_namespace") -Raw).Trim()
Write-Host "AIO connectors namespace: $aioConnectorsNamespace"

$aepName = "aep-public-http-anonymous-1"
Write-Host "AEP name: $aepName"

$assetName = "asset-public-http-anonymous-1-snapshot-to-mqtt-autostart"
Write-Host "Asset name: $assetName"

$datapointName = "snapshot-to-mqtt"
Write-Host "Datapoint name: $datapointName"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-ResourceInstallMonitorAndUninstall.ps1") `
-aepName $aepName `
-assetName $assetName `
-datapointName $datapointName `
-monitorExpresion `
". (Join-Path -Path $PSScriptRoot -ChildPath `"Start-MqttListener.ps1`") -listenTopics $aioConnectorsNamespace/data/$assetName/#"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#Requires -Version 7

$aioConnectorsNamespace = (Get-Content -Path (Join-Path -Path $PSScriptRoot -ChildPath ".config_aio_connectors_namespace") -Raw).Trim()
Write-Host "AIO connectors namespace: $aioConnectorsNamespace"

$aepName = "aep-public-http-anonymous-1"
Write-Host "AEP name: $aepName"

$assetName = "asset-public-http-anonymous-1-stream-to-rtsp-autostart"
Write-Host "Asset name: $assetName"

$datapointName = "stream-to-rtsp"
Write-Host "Datapoint name: $datapointName"

. (Join-Path -Path $PSScriptRoot -ChildPath "Invoke-ResourceInstallMonitorAndUninstall.ps1") `
-aepName $aepName `
-assetName $assetName `
-datapointName $datapointName `
-monitorExpresion `
". (Join-Path -Path $PSScriptRoot -ChildPath `"Start-RtspStreamViewer.ps1`") -assetName $assetName ; `
try { Write-Host `"`nHit Ctrl+C to terminate`" ; Start-Sleep -Seconds 3600 } finally { Write-Host `"`nContinuing...`n`" }"
Loading

0 comments on commit 45e4b39

Please sign in to comment.