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 22, 2024
1 parent ce36254 commit 97a02eb
Show file tree
Hide file tree
Showing 33 changed files with 893 additions and 10 deletions.
11 changes: 6 additions & 5 deletions samples/aio-onvif-connector-ptz-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ kubectl apply -f aep.yaml

To create a PTZ asset assigned to the asset endpoint you created in the previous step, create a file called *asset.yaml* with the following content:

```yaml
```yaml
apiVersion: deviceregistry.microsoft.com/v1
kind: Asset
metadata:
Expand Down Expand Up @@ -171,11 +171,12 @@ Create a file called *broker-listener.yaml* with the following content:
apiVersion: mqttbroker.iotoperations.azure.com/v1
kind: BrokerListener
metadata:
name: test-listener
name: aio-broker-listener-non-tls
namespace: azure-iot-operations
spec:
brokerRef: default
serviceType: LoadBalancer
serviceName: aio-broker-listener-non-tls
ports:
- port: 1883
protocol: Mqtt
Expand All @@ -194,15 +195,15 @@ kubectl apply -f broker-listener.yaml -n azure-iot-operations
Update the Azure IoT Operations configuration to use the broker listener you created in the previous step:

```bash
kubectl set env deployment/aio-opc-supervisor opcuabroker_MqttOptions__MqttBroker=mqtt://test-listener.azure-iot-operations:1883 opcuabroker_MqttOptions__AuthenticationMethod=None -n azure-iot-operations
kubectl set env deployment/aio-opc-supervisor opcuabroker_MqttOptions__MqttBroker=mqtt://aio-broker-listener-non-tls.azure-iot-operations:1883 opcuabroker_MqttOptions__AuthenticationMethod=None -n azure-iot-operations
```

### Port forward the broker listener

Port forward the broker listener to your local machine in a second terminal:

```bash
kubectl port-forward svc/test-listener -n azure-iot-operations 1883:1883
kubectl port-forward svc/aio-broker-listener-non-tls -n azure-iot-operations 1883:1883
```

Leave this shell open to keep the port forward active.
Expand Down Expand Up @@ -230,6 +231,6 @@ To remove the resources created in the previous steps and restore the configurat
kubectl delete secret c210-1-credentials
kubectl delete assetendpointprofile c210-4a826d41
kubectl delete asset c210-4a826d41-ptz
kubectl delete brokerlistener test-listener -n azure-iot-operations
kubectl delete brokerlistener aio-broker-listener-non-tls -n azure-iot-operations
kubectl set env deployment/aio-opc-supervisor opcuabroker_MqttOptions__MqttBroker=mqtts://aio-broker.azure-iot-operations:18883 opcuabroker_MqttOptions__AuthenticationMethod=ServiceAccountToken -n azure-iot-operations
```
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 97a02eb

Please sign in to comment.