SIENTIAPDE-988
Enhance README and Docker setup; improve IngestorManager and DataManager functionality, add error handling, and implement unit tests for OPC initialization and subscription management.
This commit is contained in:
30
simulator/Dockerfile
Normal file
30
simulator/Dockerfile
Normal file
@@ -0,0 +1,30 @@
|
||||
# syntax=docker/dockerfile:1.4
|
||||
|
||||
FROM python:3.11-slim
|
||||
|
||||
# Enable use of SSH agent/socket
|
||||
# This line enables SSH during build
|
||||
# (don't forget the syntax header above)
|
||||
RUN apt-get update && apt-get install -y git openssh-client && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Use build-time SSH mount for Git clone
|
||||
# The SSH key will NOT remain in the image
|
||||
# IMPORTANT: this block requires BuildKit
|
||||
# and the --ssh flag during docker build
|
||||
|
||||
# SSH config to skip host key check (safe in CI/local dev)
|
||||
RUN mkdir -p /root/.ssh && echo "StrictHostKeyChecking no" > /root/.ssh/config
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Clone using SSH
|
||||
ARG GIT_REPO
|
||||
ARG GIT_BRANCH=main
|
||||
|
||||
# Mount SSH key just for this RUN
|
||||
RUN --mount=type=ssh git clone --branch ${GIT_BRANCH} ${GIT_REPO} .
|
||||
|
||||
# Install requirements if exists
|
||||
RUN if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; fi
|
||||
|
||||
CMD ["python", "server.py"]
|
||||
54
simulator/redis-feeder.py
Normal file
54
simulator/redis-feeder.py
Normal file
@@ -0,0 +1,54 @@
|
||||
import redis
|
||||
import json
|
||||
import os
|
||||
|
||||
# Redis connection settings
|
||||
redis_host = os.getenv("REDIS_HOST", "localhost")
|
||||
redis_port = int(os.getenv("REDIS_PORT", 6379))
|
||||
|
||||
# Connect to Redis
|
||||
r = redis.Redis(host=redis_host, port=redis_port, decode_responses=True)
|
||||
|
||||
# Define the key pattern to target
|
||||
pattern = "slot:opc_tags:*"
|
||||
|
||||
# Step 1: Find and delete matching keys
|
||||
print("🔍 Searching for keys matching:", pattern)
|
||||
for key in r.scan_iter(match=pattern):
|
||||
r.delete(key)
|
||||
print(f"❌ Deleted: {key}")
|
||||
|
||||
# Step 2: Insert new data
|
||||
# Example new OPC tag data
|
||||
new_data = {
|
||||
"slot:opc_tags:1": {
|
||||
"server1": {
|
||||
"name": "server1",
|
||||
"url": "opc.tcp://localhost:4840",
|
||||
"server_uri": "http://opcua-server.simulator",
|
||||
"tags": {
|
||||
'ns=2;i=2': {
|
||||
'tag_name': 'Counter',
|
||||
'frequency': 1000,
|
||||
'topics': ['opcua', 'counter'],
|
||||
},
|
||||
'ns=2;i=3': {
|
||||
'tag_name': 'Rollout',
|
||||
'frequency': 1000,
|
||||
"topics": ['opcua', 'rollout'],
|
||||
},
|
||||
'ns=2;i=4': {
|
||||
'tag_name': 'Square',
|
||||
'frequency': 1000,
|
||||
"topics": ['opcua'],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for key, val in new_data.items():
|
||||
r.set(key, json.dumps(val))
|
||||
print(f"✅ Set: {key} -> {val}")
|
||||
|
||||
print("🚀 OPC tag keys replaced successfully.")
|
||||
Reference in New Issue
Block a user