Skip to content
Snippets Groups Projects
Commit 1e24f45d authored by Taya Snijder's avatar Taya Snijder
Browse files

merged master

parents 18fda380 d38353a7
No related branches found
No related tags found
1 merge request!27Resolve #2021 "04 16 branched from master apsctl device"
......@@ -16,14 +16,14 @@ from tango.server import Device, command
from tango import DevState, DebugIt
# Additional import
from src.attribute_wrapper import *
from util.attribute_wrapper import attribute_wrapper
from util.lofar_logging import log_exceptions
__all__ = ["hardware_device"]
from src.wrappers import only_in_states
from util.wrappers import only_in_states, fault_on_error
#@log_exceptions()
class hardware_device(Device):
"""
......@@ -74,6 +74,8 @@ class hardware_device(Device):
@command()
@only_in_states([DevState.FAULT, DevState.OFF])
@DebugIt()
@fault_on_error()
@log_exceptions()
def Initialise(self):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
......@@ -87,20 +89,11 @@ class hardware_device(Device):
self.set_state(DevState.STANDBY)
# @only_in_states([DevState.INIT])
# def Standby(self):
# """
# Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
#
# :return:None
# """
#
# self.standby()
# self.set_state(DevState.STANDBY)
@command()
@only_in_states([DevState.STANDBY])
@DebugIt()
@fault_on_error()
@log_exceptions()
def On(self):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
......@@ -112,6 +105,7 @@ class hardware_device(Device):
@command()
@DebugIt()
@log_exceptions()
def Off(self):
"""
Command to ask for shutdown of this device.
......@@ -133,6 +127,7 @@ class hardware_device(Device):
@command()
@only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY])
@DebugIt()
@log_exceptions()
def Fault(self):
"""
FAULT state is used to indicate our connection with the OPC-UA server is down.
......@@ -154,8 +149,6 @@ class hardware_device(Device):
pass
def on(self):
pass
def standby(self):
pass
def initialise(self):
pass
......
File moved
File moved
File moved
......@@ -22,32 +22,38 @@ def only_in_states(allowed_states):
return wrapper
def only_when_on(func):
def only_when_on():
"""
Wrapper to call and return the wrapped function if the device is
in the ON state. Otherwise None is returned and nothing
will be called.
"""
@wraps(func)
def when_on_wrapper(self, *args, **kwargs):
if self.get_state() == DevState.ON:
return func(self, *args, **kwargs)
def inner(func):
@wraps(func)
def when_on_wrapper(self, *args, **kwargs):
if self.get_state() == DevState.ON:
return func(self, *args, **kwargs)
return None
return None
return when_on_wrapper
return when_on_wrapper
return inner
def fault_on_error(func):
def fault_on_error():
"""
Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs.
"""
@wraps(func)
def error_wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
self.error_stream("Function failed. Trace: %s", traceback.format_exc())
self.Fault()
return None
def inner(func):
@wraps(func)
def error_wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
self.error_stream("Function failed. Trace: %s", traceback.format_exc())
self.Fault()
return None
return error_wrapper
return error_wrapper
return inner
This diff is collapsed.
version: '2'
services:
maria-db:
archiver-maria-db:
image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mariadb_hdbpp:latest
container_name: archiver-maria-db
network_mode: ${NETWORK_MODE}
......@@ -23,7 +23,7 @@ services:
depends_on:
- databaseds
- dsconfig
- maria-db
- archiver-maria-db
environment:
- TANGO_HOST=${TANGO_HOST}
- HdbManager=archiving/hdbpp/confmanager01
......@@ -40,7 +40,7 @@ services:
depends_on:
- databaseds
- dsconfig
- maria-db
- archiver-maria-db
environment:
- TANGO_HOST=${TANGO_HOST}
- HdbManager=archiving/hdbpp/confmanager01
......
......@@ -16,7 +16,7 @@ services:
depends_on:
- databaseds
- dsconfig
- maria-db
- archiver-maria-db
- hdbpp-es
- hdbpp-cm
volumes:
......
......@@ -25,3 +25,7 @@ ENV TINI_VERSION v0.6.0
ENV JUPYTER_RUNTIME_DIR=/tmp
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN sudo chmod +x /usr/bin/tini
# Make sure Jupyter can write to the home directory
ENV HOME=/home/tango
RUN chmod a+rwx /home/tango
#! /usr/bin/env python3
import logging
def configure_logging():
# Always also log the hostname because it makes the origin of the log clear.
import socket
hostname = socket.gethostname()
# Set up logging in a way that it can be understood by a human reader, be
# easily grep'ed, be parsed with a couple of shell commands and
# easily fed into an Kibana/Elastic search system.
logging.basicConfig(format = '%(asctime)s.%(msecs)d %(levelname)s - HOST="{}" PID="%(process)d" TNAME="%(threadName)s" TID="%(thread)d" FILE="%(pathname)s" LINE="%(lineno)d" FUNC="%(funcName)s" MSG="%(message)s"'.format(hostname), datefmt = '%Y-%m-%dT%H:%M:%S', level = logging.INFO, Force = True)
#! /usr/bin/env python3
def startup(device: str, force_restart: bool):
'''
Start a LOFAR Tango device:
pcc = startup(device = 'LTS/PCC/1', force_restart = False)
'''
import tango
proxy = tango.DeviceProxy(device)
state = proxy.state()
if force_restart is True:
print("Forcing device {} restart.".format(device))
proxy.off()
state = proxy.state()
if state is not tango._tango.DevState.OFF:
print("Device {} cannot perform off although restart has been enforced, state = {}. Please investigate.".format(device, state))
return proxy
if state is not tango._tango.DevState.OFF:
print("Device {} is not in OFF state, cannot start it. state = {}".format(device, state))
return proxy
print("Device {} is in OFF, performing initialisation.".format(device))
proxy.initialise()
state = proxy.state()
if state is not tango._tango.DevState.STANDBY:
print("Device {} cannot perform initialise, state = {}. Please investigate.".format(device, state))
return proxy
print("Device {} is in STANDBY, performing on.".format(device))
proxy.on()
state = proxy.state()
if state is not tango._tango.DevState.ON:
print("Device {} cannot perform on, state = {}. Please investigate.".format(device, state))
else:
print("Device {} has successfully reached ON state.".format(device))
return proxy
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment