Skip to content

Commit

Permalink
Merge pull request #2499 from luiscast84/ag_manufacturing
Browse files Browse the repository at this point in the history
MQTT Sim for Agora and MCR updates on Event Grid connector
  • Loading branch information
dkirby-ms authored Apr 16, 2024
2 parents e51025b + 61f586e commit ea58d5f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ metadata:
namespace: azure-iot-operations
spec:
image:
repository: e4kpreview.azurecr.io/mqttbridge
tag: 0.1.0-preview-rc6
repository: mcr.microsoft.com/azureiotoperations/mqttbridge
tag: 0.1.0-preview
pullPolicy: IfNotPresent
protocol: v5
bridgeInstances: 1
Expand Down
8 changes: 6 additions & 2 deletions azure_jumpstart_ag/artifacts/PowerShell/AgLogonScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,15 @@ if ($industry -eq "manufacturing") {
#Deploy-ManufacturingConfigs
}

if ($industry -eq "manufacturing") {
##############################################################
# Get MQ IP address
##############################################################
if ($industry -eq "manufacturing") {
Configure-MQTTIpAddress
$mqttIpArray=Configure-MQTTIpAddress
##############################################################
# Deploy MQTT Simulator
##############################################################
Deploy-MQTTSimulator -AgConfig $global:AgConfig -Credentials $global:Credentials -mqttIpArray $mqttIpArray
}

#####################################################################
Expand Down
1 change: 1 addition & 0 deletions azure_jumpstart_ag/artifacts/PowerShell/Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ if($industry -eq "retail"){
elseif ($industry -eq "manufacturing") {
Invoke-WebRequest ($templateBaseUrl + "artifacts/settings/Bookmarks-manufacturing") -OutFile "$AgToolsDir\Bookmarks"
Invoke-WebRequest ($templateBaseUrl + "artifacts/settings/mq_cloudConnector.yml") -OutFile "$AgToolsDir\mq_cloudConnector.yml"
Invoke-WebRequest ($templateBaseUrl + "artifacts/settings/mqtt_simulator.yml") -OutFile "$AgToolsDir\mqtt_simulator.yml"
Invoke-WebRequest ($templateBaseUrl + "artifacts/settings/mqtt_explorer_settings.json") -OutFile "$AgToolsDir\mqtt_explorer_settings.json"
Invoke-WebRequest ($templateBaseUrl + "artifacts/settings/influxdb-setup.yml") -OutFile "$AgToolsDir\influxdb-setup.yml"
Invoke-WebRequest ($templateBaseUrl + "artifacts/settings/influxdb-configmap.yml") -OutFile "$AgToolsDir\influxdb-configmap.yml"
Expand Down
38 changes: 34 additions & 4 deletions azure_jumpstart_ag/artifacts/PowerShell/Modules/manufacturing.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ function Deploy-InfluxDb {
$influxdb_setupYaml = "$aioToolsDir\influxdb_setup.yml"
$influxdbYaml = "$aioToolsDir\influxdb.yml"
$influxImportYaml = "$aioToolsDir\influxdb-import-dashboard.yml"
$mqttExplorerSettings = "$aioToolsDir\mqtt_explorer_settings.json"

do {
$simulatorPod = kubectl get pods -n $aioNamespace -o json | ConvertFrom-Json
Expand Down Expand Up @@ -381,7 +380,7 @@ function Deploy-AIO {
Write-Host "`n"
Write-Host "[$(Get-Date -Format t)] Error: An error occured while deploying AIO on the cluster...Retrying" -ForegroundColor DarkRed
Write-Host "`n"
az iot ops init --cluster $arcClusterName -g $resourceGroup --kv-id $keyVaultId --sp-app-id $spnClientId --sp-secret $spnClientSecret --sp-object-id $spnObjectId --mq-service-type loadBalancer --mq-insecure true --simulate-plc false --only-show-errors
az iot ops init --cluster $arcClusterName -g $resourceGroup --kv-id $keyVaultId --sp-app-id $spnClientId --sp-secret $spnClientSecret --sp-object-id $spnObjectId --mq-service-type loadBalancer --mq-insecure true --simulate-plc false --no-block --only-show-errors
$retryCount++
}
else {
Expand Down Expand Up @@ -432,7 +431,7 @@ function Deploy-AIO {

Start-Sleep -Seconds 60

## Adding MQTT load balancer
## Adding MQTT bridge to Event Grid MQTT
$mqconfigfile = "$AgToolsDir\mq_cloudConnector.yml"
Write-Host "[$(Get-Date -Format t)] INFO: Configuring the MQ Event Grid bridge" -ForegroundColor DarkGray
$eventGridHostName = (az eventgrid namespace list --resource-group $resourceGroup --query "[0].topicSpacesConfiguration.hostname" -o tsv --only-show-errors)
Expand Down Expand Up @@ -509,7 +508,9 @@ function Deploy-ESA {
}

function Configure-MQTTIpAddress {
foreach ($cluster in $AgConfig.SiteConfig.GetEnumerator()) {
$mqttIpArray = @()
$clusters = $AgConfig.SiteConfig.GetEnumerator() | Sort-Object Name
foreach ($cluster in $clusters) {
$clusterName = $cluster.Name.ToLower()
kubectx $clusterName | Out-File -Append -FilePath ($AgConfig.AgDirectories["AgLogsDir"] + "\ClusterSecrets.log")
Write-Host "[$(Get-Date -Format t)] INFO: Getting MQ IP address" -ForegroundColor DarkGray
Expand All @@ -527,8 +528,37 @@ function Configure-MQTTIpAddress {
$null -eq $mqttIp -and $matchingServices.Count -ne 0
)

$mqttIpArray += $mqttIp

Invoke-Command -VMName $clusterName -Credential $Credentials -ScriptBlock {
netsh interface portproxy add v4tov4 listenport=1883 listenaddress=0.0.0.0 connectport=1883 connectaddress=$using:mqttIp
}
}

return $mqttIpArray
}

function Deploy-MQTTSimulator {
param (
$AgConfig,
[PSCredential]$Credentials,
[array]$mqttIpArray
)

$index = 0
$mqsimulatorfile = "$AgToolsDir\mqtt_simulator.yml"

$clusters = $AgConfig.SiteConfig.GetEnumerator() | Sort-Object Name

foreach ($cluster in $clusters) {
$mqttIp = $mqttIpArray[$index]
$clusterName = $cluster.Name.ToLower()
Write-Host "[$(Get-Date -Format t)] INFO: Deploying MQTT Simulator to the $clusterName cluster" -ForegroundColor Gray
Write-Host "`n"
kubectx $clusterName
(Get-Content $mqsimulatorfile ) -replace 'MQTTIpPlaceholder', $mqttIp | Set-Content $mqsimulatorfile
netsh interface portproxy add v4tov4 listenport=1883 listenaddress=0.0.0.0 connectport=1883 connectaddress=$mqttIp
kubectl apply -f $mqsimulatorfile -n $aioNamespace
$index++
}
}
4 changes: 2 additions & 2 deletions azure_jumpstart_ag/artifacts/settings/mq_cloudConnector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ metadata:
namespace: azure-iot-operations
spec:
image:
repository: e4kpreview.azurecr.io/mqttbridge
tag: 0.1.0-preview-rc6
repository: mcr.microsoft.com/azureiotoperations/mqttbridge
tag: 0.1.0-preview
pullPolicy: IfNotPresent
protocol: v5
bridgeInstances: 1
Expand Down
6 changes: 4 additions & 2 deletions azure_jumpstart_ag/artifacts/settings/mqtt_listener.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ spec:
- name: MQTT_Port
value: "1883"
- name: MQTT_TOPIC1
value: "topic/productionline"
value: "topic/weldingrobot"
- name: MQTT_TOPIC2
value: "topic/fryer"
value: "topic/productionline"
- name: MQTT_TOPIC3
value: "topic/assemblyline"
- name: INFLUX_URL
value: "http://influxPlaceholder:8086"
- name: INFLUX_TOKEN
Expand Down
28 changes: 28 additions & 0 deletions azure_jumpstart_ag/artifacts/settings/mqtt_simulator.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: mqtt-simulator-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mqtt-simulator
template:
metadata:
labels:
app: mqtt-simulator
spec:
containers:
- name: mqtt-simulator
image: agoraarmbladev.azurecr.io/mqtt-simulator:latest
resources:
limits:
cpu: "1"
memory: "500Mi"
env:
- name: MQTT_BROKER
value: "MQTTIpPlaceholder"
- name: MQTT_PORT
value: "1883"
- name: FRECUENCY
value: "5"

0 comments on commit ea58d5f

Please sign in to comment.