Skip to content

Commit

Permalink
code for testing
Browse files Browse the repository at this point in the history
Uses docker to up two recceivers and channelfinder
  • Loading branch information
jacomago committed Apr 18, 2024
1 parent 1f73833 commit 6d08f03
Show file tree
Hide file tree
Showing 11 changed files with 291 additions and 17 deletions.
22 changes: 22 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.8 as build

WORKDIR /home/recceiver

COPY . ./server

RUN python -m venv venv && \
venv/bin/pip install \
--no-cache-dir \
-i https://artifactory.esss.lu.se/artifactory/api/pypi/pypi-virtual/simple \
-r server/requirements.txt

RUN venv/bin/python -m pip install ./server

FROM python:3.8-slim

WORKDIR /home/recceiver

COPY --from=build /home/recceiver/venv venv

CMD venv/bin/twistd --pidfile= --nodaemon recceiver --config cf.conf

4 changes: 3 additions & 1 deletion server/README → server/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Server testing
# Recceiver

## Server testing

Setup

Expand Down
60 changes: 60 additions & 0 deletions server/cf1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# run with
#twistd -n recceiver -f <thisfile>.conf

[recceiver]

# list of broadcast addresses.
# default
#addrlist = 255.255.255.255:5049
# for local testing w/ firewall
#addrlist = 127.255.255.255:5049

# Listen for TCP connections on this interface and port.
# Port also used as source for UDP broadcasts.
# Default uses wildcard address and a random port.
#bind = 0.0.0.0:0

# Processing chain
procs = cf

# Time interval for sending recceiver advertisments
#announceInterval = 15.0

# Idle Timeout for TCP connections.
#tcptimeout = 15.0

# Time to wait before commiting updates
# Doesn't effect IOC clients
#commitInterval = 5.0

# Maximum concurrent "active" clients
# to allow.
#maxActive = 20

# The channelFinder client is configuration information is
# stored in /etc/channelfinderapi.conf as described in the client

[cf]
# a space-separated list of infotags to set as CF Properties
#infotags = archive foo bar blah
# List environment variables that should be written as channel finder properties
#
# Comma-separated list of VARIABLE:PropertyName,
# specifying which environment VARIABLEs to pass on to the channel finder
# and defining the corresponding PropertyName
#environment_vars=ENGINEER:Engineer,EPICS_BASE:EpicsVersion,PWD:WorkingDirectory
# Turn on optional alias and recordType properties
#alias = on
#recordType = on
#recordDesc = on

# Mark all channels as 'Inactive' when processor is stopped (default: True)
cleanOnStop = True
# Mark all channels as 'Inactive' when processor is started (default: True)
cleanOnStart = True

recceiverID = recc1
[DEFAULT]
BaseURL = http://cf:8080/ChannelFinder
username = admin
password = password
61 changes: 61 additions & 0 deletions server/cf2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# run with
#twistd -n recceiver -f <thisfile>.conf

[recceiver]

# list of broadcast addresses.
# default
#addrlist = 255.255.255.255:5049
# for local testing w/ firewall
#addrlist = 127.255.255.255:5049

# Listen for TCP connections on this interface and port.
# Port also used as source for UDP broadcasts.
# Default uses wildcard address and a random port.
#bind = 0.0.0.0:0

# Processing chain
procs = cf

# Time interval for sending recceiver advertisments
#announceInterval = 15.0

# Idle Timeout for TCP connections.
#tcptimeout = 15.0

# Time to wait before commiting updates
# Doesn't effect IOC clients
#commitInterval = 5.0

# Maximum concurrent "active" clients
# to allow.
#maxActive = 20

# The channelFinder client is configuration information is
# stored in /etc/channelfinderapi.conf as described in the client

[cf]
# a space-separated list of infotags to set as CF Properties
#infotags = archive foo bar blah
# List environment variables that should be written as channel finder properties
#
# Comma-separated list of VARIABLE:PropertyName,
# specifying which environment VARIABLEs to pass on to the channel finder
# and defining the corresponding PropertyName
#environment_vars=ENGINEER:Engineer,EPICS_BASE:EpicsVersion,PWD:WorkingDirectory
# Turn on optional alias and recordType properties
#alias = on
#recordType = on
#recordDesc = on

# Mark all channels as 'Inactive' when processor is stopped (default: True)
#cleanOnStop = True
# Mark all channels as 'Inactive' when processor is started (default: True)
cleanOnStart = True

recceiverID = recc2

[DEFAULT]
BaseURL = http://cf:8080/ChannelFinder
username = admin
password = password
97 changes: 97 additions & 0 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
version: '3'

services:
cf:
image: ghcr.io/channelfinder/channelfinderservice:master
hostname: cf
networks:
- net-cf
ports:
- "8080:8080"
- "8443:8443"
depends_on:
elasticsearch:
condition: service_healthy
restart: true
environment:
ELASTICSEARCH_NETWORK_HOST: elasticsearch-cf
ELASTICSEARCH_QUERY_SIZE: 10
demo_auth.enabled: true
demo_auth.users: admin
demo_auth.pwds: password
demo_auth.roles: ADMIN
EPICS_PVAS_INTF_ADDR_LIST: "0.0.0.0"
aa.enabled: false
logging.level.org.springframework.web: DEBUG
healthcheck:
test: curl -s -f http://cf:8080/ChannelFinder
interval: 10s
timeout: 60s
retries: 5

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.4
hostname: elasticsearch-cf
networks:
- net-cf
environment:
cluster.name: channelfinder
discovery.type: single-node
bootstrap.memory_lock: "true"
xpack.security.enabled: "false"
healthcheck:
test: curl -s -f http://localhost:9200/_cluster/health
interval: 10s
timeout: 60s
retries: 5
volumes:
- channelfinder-es-data:/usr/share/elasticsearch/data

recc1:
build: .
networks:
- net-recc-1
- net-cf
depends_on:
cf:
condition: service_healthy
restart: true
volumes:
- type: bind
source: cf1.conf
target: /home/recceiver/cf.conf
read_only: true
- type: bind
source: cf1.conf
target: /home/recceiver/channelfinderapi.conf
read_only: true
recc2:
build: .
networks:
- net-recc-2
- net-cf
depends_on:
cf:
condition: service_healthy
restart: true
volumes:
- type: bind
source: cf2.conf
target: /home/recceiver/cf.conf
read_only: true
- type: bind
source: cf2.conf
target: /home/recceiver/channelfinderapi.conf
read_only: true

volumes:
channelfinder-es-data:
driver: local

networks:
net-cf:
driver: bridge
net-recc-1:
driver: bridge
net-recc-2:
driver: bridge
11 changes: 6 additions & 5 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -9,11 +9,12 @@ authors = [
]
description="resync server"
version="1.5"
readme = "README.rst"
readme = "README.md"
requires-python = ">=3.6"
dependencies = [
# "requests",
"twisted",
"twisted",
"requests",
"channelfinder"
]

[project.urls]
Expand All @@ -24,4 +25,4 @@ packages = ["recceiver", "twisted.plugins"]
include-package-data = true

[tool.setuptools.package-data]
twisted = ["plugins/recceiver_plugin.py"]
twisted = ["plugins/recceiver_plugin.py"]
3 changes: 3 additions & 0 deletions server/recceiver/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from zope.interface import implementer

from twisted import plugin
from twisted.internet import pollreactor
pollreactor.install()

from twisted.python import usage, log
from twisted.internet import reactor, defer
from twisted.internet.error import CannotListenError
Expand Down
10 changes: 4 additions & 6 deletions server/recceiver/cfstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import logging
import socket
_log = logging.getLogger(__name__)

from zope.interface import implementer

from requests import RequestException, ConnectionError
Expand All @@ -20,6 +18,7 @@
import json
from channelfinder import ChannelFinderClient

_log = logging.getLogger(__name__)

# ITRANSACTION FORMAT:
#
Expand Down Expand Up @@ -283,9 +282,8 @@ def clean_service(self):
_log.info("CF Clean Started")
channels = self.get_active_channels(recceiverid)
if channels is not None:
while channels is not None and len(channels) > 0:
self.clean_channels(owner, channels)
channels = self.get_active_channels(recceiverid)
self.clean_channels(owner, channels)
channels = self.get_active_channels(recceiverid)
_log.info("CF Clean Completed")
return
else:
Expand All @@ -302,7 +300,7 @@ def clean_service(self):
return

def get_active_channels(self, recceiverid):
return self.client.findByArgs(prepareFindArgs(self.conf, [('pvStatus', 'Active'), (RECCEIVERID_KEY, recceiverid)], 10000))
return self.client.findByArgs(prepareFindArgs(self.conf, [('pvStatus', 'Active'), (RECCEIVERID_KEY, recceiverid)], 0))

def clean_channels(self, owner, channels):
new_channels = []
Expand Down
3 changes: 3 additions & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channelfinder==3.0.0.post2
twisted==22.8.0
requests==2.28.1
5 changes: 0 additions & 5 deletions server/setup.py

This file was deleted.

32 changes: 32 additions & 0 deletions server/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import json

import urllib3


def fake_channel(ch_name: str, recc: str, status: str):
return {
"name": ch_name,
"owner": recc,
"properties": [
{"name": "recceiverID", "owner": recc, "value": recc},
{"name": "pvStatus", "owner": recc, "value": status},
],
}


def insert_fake_data(recc: str, cf: str, chs: list[str], status: str):
http = urllib3.PoolManager()
headers = urllib3.make_headers(basic_auth="admin:password")
headers.update({"Content-Type": "application/json"})
req = http.request(
"PUT",
cf + "/ChannelFinder/resources/channels",
headers=headers,
body=json.dumps([fake_channel(ch, recc, status) for ch in chs]),
)


cf = "http://localhost:8080"

insert_fake_data("recc1", cf, ["ch_1_" + str(i) for i in range(10002)], "Active")
insert_fake_data("recc2", cf, ["ch_2_" + str(i) for i in range(100)], "Active")

0 comments on commit 6d08f03

Please sign in to comment.