variable collection of policies per component

* new feature variable collection of policies per component in DCAE
* massive refactoring
* dissolved the external PolicyEngine.py into policy_receiver.py
   - kept only the web-socket communication to PolicyEngine
* new /healthcheck - shows some stats of service running
* Unit Test coverage 75%

Change-Id: I816b7d5713ae0dd88fa73d3656f272b4f3e7946e
Issue-ID: DCAEGEN2-249
Signed-off-by: Alex Shatov <alexs@att.com>
diff --git a/policyhandler/discovery.py b/policyhandler/discovery.py
index 7e16b90..33c3265 100644
--- a/policyhandler/discovery.py
+++ b/policyhandler/discovery.py
@@ -41,6 +41,8 @@
     CONSUL_SERVICE_MASK = "http://consul:8500/v1/catalog/service/{0}"
     CONSUL_KV_MASK = "http://consul:8500/v1/kv/{0}"
     SERVICE_MASK = "http://{0}:{1}"
+    SERVICE_ADDRESS = "ServiceAddress"
+    SERVICE_PORT = "ServicePort"
     _logger = logging.getLogger("policy_handler.discovery")
 
 
@@ -51,23 +53,25 @@
         DiscoveryClient._logger.info("discover %s", service_path)
         response = requests.get(service_path)
         response.raise_for_status()
-        service = response.json()[0]
-        return DiscoveryClient.SERVICE_MASK.format( \
-                service["ServiceAddress"], service["ServicePort"])
+        service = response.json()
+        if not service:
+            DiscoveryClient._logger.error("failed discover %s", service_path)
+            return
+        service = service[0]
+        return DiscoveryClient.SERVICE_MASK.format(
+            service[DiscoveryClient.SERVICE_ADDRESS], service[DiscoveryClient.SERVICE_PORT]
+        )
 
     @staticmethod
     def get_value(key):
         """get the value for the key from consul-kv"""
         response = requests.get(DiscoveryClient.CONSUL_KV_MASK.format(key))
         response.raise_for_status()
-        data = response.json()[0]
-        value = base64.b64decode(data["Value"]).decode("utf-8")
-        DiscoveryClient._logger.info("consul-kv key=%s data=%s value(%s)", \
-            key, json.dumps(data), value)
+        data = response.json()
+        if not data:
+            DiscoveryClient._logger.error("failed get_value %s", key)
+            return
+        value = base64.b64decode(data[0]["Value"]).decode("utf-8")
+        DiscoveryClient._logger.info("consul-kv key=%s value(%s) data=%s",
+                                     key, value, json.dumps(data))
         return json.loads(value)
-
-    @staticmethod
-    def put_kv(key, value):
-        """put the value under the key in consul-kv"""
-        response = requests.put(DiscoveryClient.CONSUL_KV_MASK.format(key), data=value)
-        response.raise_for_status()