added microservice management client for communication with core sotrage/readings code
+from foglamp.common.storage_client.storage_client import ReadingsStorageClient, StorageClient
from abc import ABC, abstractmethod
import argparse
+import http.client
__author__ = "Ashwin Gopalakrishnan"
__copyright__ = "Copyright (c) 2017 OSIsoft, LLC"
@@ -9,11 +11,14 @@ __version__ = "${VERSION}"
class ArgumentParserError(Exception):
pass
-
class FoglampProcess(ABC):
_core_management_host = None
_core_management_port = None
_name = None
+ _m_client = None
+ _readings_storage = None
+ _storage = None
+
def __init__(self):
try:
@@ -26,16 +31,19 @@ class FoglampProcess(ABC):
raise ValueError("--address is not specified")
elif self._core_management_port is None:
raise ValueError("--port is not specified")
- elif self._name:
+ elif self._name is None:
raise ValueError("--name is not specified")
+ self._m_client = self.MicroserviceManagementClient(self._core_management_host,self._core_management_port)
+ self._readings_storage = ReadingsStorageClient(self._core_management_host, self._core_management_port)
+ self._storage = StorageClient(self._core_management_host, self._core_management_port)
+
@abstractmethod
def run(self):
pass
def get_arg_value(self, argument_name):
""" Parses command line arguments for a single argument of name argument_name. Returns the value of the argument specified or None if argument was not specified.
-
Keyword Arguments:
argument_name -- name of command line argument to retrieve value for
@@ -49,7 +57,6 @@ class FoglampProcess(ABC):
Known Exceptions:
ArgumentParserError
"""
-
class SilentArgParse(argparse.ArgumentParser):
def error(self, message):
raise ArgumentParserError(message)
@@ -63,3 +70,39 @@ class FoglampProcess(ABC):
else:
return list(vars(parser_result[0]).values())[0]
+ class MicroserviceManagementClient(object):
+ _management_client_conn = None
+
+ def __init__(self,core_management_host, core_management_port):
+ self._management_client_conn = http.client.HTTPConnection("{0}:{1}".format(core_management_host, core_management_port))
+
+ def register_service(self, service_registration_payload):
+ # register with core
+ self._management_client_conn.request(method='POST', url='/foglamp/service', body=json.dumps(service_registration_payload))
+ r = self._management_client_conn.getresponse()
+ if r.status in range(400, 500):
+ # _LOGGER.error("Client error code: %d", r.status)
+ r.raise_for_status()
+ if r.status in range(500, 600):
+ # _LOGGER.error("Server error code: %d", r.status)
+ r.raise_for_status()
+ res = r.read().decode()
+ self._management_client_conn.close()
+ response = json.loads(res)
+ try:
+ cls._microservice_id = response["id"]
+ # _LOGGER.info('Device - Registered Service %s', response["id"])
+ except:
+ pass
+ #_LOGGER.error("Device - Could not register")
+
+ def unregister_service(self):
+ pass
+ def register_interest(self):
+ pass
+ def unregister_interest(self):
+ pass
+ def get_services(self):
+ pass
+
+
