Commit ef2cb6fa authored by Matias Guijarro's avatar Matias Guijarro

Merge branch '43-test-make-jolokia-port-configurable' into 'master'

Resolve "[test] make jolokia port configurable"

Closes #43

See merge request !30
parents 8d66b971 a558a0f8
......@@ -45,44 +45,47 @@ class StompClient():
_TIMEOUT = 0.1
JOLOKIA_CONSUMER_COUNT_URL = 'api/jolokia/read/org.apache.activemq:type=Broker,brokerName=metadata,destinationType=Queue,destinationName=icatIngest/ConsumerCount'
JOLOKIA_PORT = '8778'
JOLOKIA_PORT = 8778
_JOLOKIA_USERNAME = 'user'
_JOLOKIA_PASSWORD = 'user'
# Logger
LOG = logging.getLogger("StompClient")
def __init__(self, queueURLs, queueName, beamlineID, manager=None):
def __init__(self, queueURLs, queueName, beamlineID, manager=None, jolokia_port=None):
self.queueName = queueName
self.beamlineID = beamlineID
self.isSimulationMode = False
self.heartbeat = 0
self.heartbeat_set = 0
self.connected = False
self.manager = manager
self.listener=None
self.listener = None
proxy_handler = urllib.request.ProxyHandler({})
opener = urllib.request.build_opener(proxy_handler)
urllib.request.install_opener(opener)
# In case queueURLs is empty then messagingClient is set in status simulation
self.isSimulationMode = False
self._jolokia_port = jolokia_port
if len(queueURLs) == 1:
if queueURLs[0] == '':
self.isSimulationMode = True
self.LOG.info("Messaging client to ActiveMQ is in SIMULATION mode. beamline=%s" %(beamlineID))
self.cfgURL = "simulator"
return
self.cfgURL = 'failover:(tcp://' + ',tcp://'.join(queueURLs) + ')'
self.cfgURL += '?maxReconnectAttempts=3,initialReconnectDelay=250,maxReconnectDelay=1000'
self.client = Stomp(StompConfig(self.cfgURL,version=StompSpec.VERSION_1_1))
self.LOG.info("Messaging client to ActiveMQ is connected. queueURLs=%s beamline=%s" % (queueURLs, beamlineID))
@property
def jolokia_port(self):
if self._jolokia_port:
return str(self._jolokia_port)
else:
return str(self.JOLOKIA_PORT)
def getConfigURL(self):
return self.cfgURL
......@@ -102,7 +105,7 @@ class StompClient():
if self.connected:
host = self.client._transport.host
try:
request = urllib.request.Request("http://%s:%s/%s" %(host, self.JOLOKIA_PORT, self.JOLOKIA_CONSUMER_COUNT_URL))
request = urllib.request.Request("http://%s:%s/%s" %(host, self.jolokia_port, self.JOLOKIA_CONSUMER_COUNT_URL))
request.add_header('Authorization', b'Basic ' + base64.b64encode(toBytes(self._JOLOKIA_USERNAME + ':' + self._JOLOKIA_PASSWORD)))
result = urllib.request.urlopen(request, timeout=1)
jres = json.load(result)
......
......@@ -98,7 +98,7 @@ class MetaExperiment (tango.LatestDeviceImpl):
traceback.print_exc(file=sys.stdout)
# JMS client
self.client = StompClient(self.queueURLs, self.queueName, self.beamlineID)
self.client = StompClient(self.queueURLs, self.queueName, self.beamlineID, jolokia_port=self.jolokiaPort)
self.info_stream("Configuration URL=%s" %self.client.getConfigURL())
self.Connect()
......@@ -284,6 +284,10 @@ class MetaExperimentClass(tango.DeviceClass):
[tango.DevString,
"Name of the stomp queue for sending ingestion requests",
["/queue/icatIngest"] ],
'jolokiaPort':
[tango.DevInt,
"Jolokia port (same host as queueURLs)",
[8778] ]
}
......
......@@ -189,7 +189,7 @@ class MetadataManager (tango.LatestDeviceImpl):
self.proxy = tango.DeviceProxy(self.get_name())
# JMS client
# we need to proxy to be created
self.client = StompClient(self.queueURLs, self.queueName, self.beamlineID, self)
self.client = StompClient(self.queueURLs, self.queueName, self.beamlineID, manager=self, jolokia_port=self.jolokiaPort)
self.logger.info("Init MetadataManager. url=%s, queue=%s metadatamanager=%s beamline=%s" % (self.client.getConfigURL(), self.queueName, self.get_name(), self.beamlineID))
self.Connect()
# MetaExp client
......@@ -1092,7 +1092,11 @@ class MetadataManagerClass(tango.DeviceClass):
'API_KEY':
[tango.DevString,
"API_KEY for connecting to ICAT+",
[""] ]
[""] ],
'jolokiaPort':
[tango.DevInt,
"Jolokia port (same host as queueURLs)",
[8778] ]
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment