Revert "Migrates alarms to MongoDB"

This reverts commit 0085a4a8870a73a9186b0a2305ba00bae44a6ea0.

Change-Id: Ifd94058969c1480863a67529a9d5ed70e5e062c3
Signed-off-by: Gianpietro Lavado <glavado@whitestack.com>
diff --git a/osm_mon/server/service.py b/osm_mon/server/service.py
index 60cb3ec..1d546e3 100755
--- a/osm_mon/server/service.py
+++ b/osm_mon/server/service.py
@@ -21,10 +21,12 @@
 # contact: bdiaz@whitestack.com or glavado@whitestack.com
 ##
 import logging
+import uuid
 
+from osm_mon.core import database
 from osm_mon.core.common_db import CommonDbClient
 from osm_mon.core.config import Config
-from osm_mon.core.models import Alarm
+from osm_mon.core.database import AlarmRepository, Alarm, AlarmTagRepository
 
 log = logging.getLogger(__name__)
 
@@ -36,16 +38,41 @@
 
     def create_alarm(self,
                      name: str,
-                     threshold: float,
+                     threshold: str,
                      operation: str,
                      severity: str,
                      statistic: str,
                      metric_name: str,
                      tags: dict) -> Alarm:
-        alarm = Alarm(name, severity, threshold, operation, statistic, metric_name, tags)
-        self.common_db.create_alarm(alarm)
-        return alarm
+        database.db.connect()
+        try:
+            with database.db.atomic():
+                alarm = AlarmRepository.create(
+                    uuid=str(uuid.uuid4()),
+                    name=name,
+                    threshold=threshold,
+                    operation=operation.lower(),
+                    severity=severity.lower(),
+                    statistic=statistic.lower(),
+                    metric=metric_name
+                )
+                for k, v in tags.items():
+                    AlarmTagRepository.create(
+                        name=k,
+                        value=v,
+                        alarm=alarm
+                    )
+                return alarm
+
+        finally:
+            database.db.close()
 
     def delete_alarm(self,
                      alarm_uuid: str) -> None:
-        self.common_db.delete_alarm(alarm_uuid)
+        database.db.connect()
+        try:
+            with database.db.atomic():
+                alarm = AlarmRepository.get(Alarm.uuid == alarm_uuid)
+                alarm.delete_instance()
+        finally:
+            database.db.close()