Commit 258f2dbd authored by Waleed Akbar's avatar Waleed Akbar
Browse files

basic changes in the KPI Manager and Value API

parent 1879fb18
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -19,14 +19,14 @@ LOGGER = logging.getLogger(__name__)

APP_NAME = 'tfs'
ECHO = False                # False: No dump SQL commands and transactions executed
CRDB_URI_TEMPLATE = 'cockroachdb://{:s}:{:s}@127.0.0.1:{:s}/{:s}?sslmode={:s}'
# CRDB_URI_TEMPLATE = 'cockroachdb://{:s}:{:s}@127.0.0.1:{:s}/{:s}?sslmode={:s}'
CRDB_NAMESPACE = "crdb"
CRDB_SQL_PORT  = "26257"
CRDB_DATABASE  = "kpi"
CRDB_USERNAME  = "tfs"
CRDB_PASSWORD  = "tfs123"
CRDB_SSLMODE   = "require"
# CRDB_URI_TEMPLATE = 'cockroachdb://{:s}:{:s}@cockroachdb-public.{:s}.svc.cluster.local:{:s}/{:s}?sslmode={:s}'
CRDB_URI_TEMPLATE = 'cockroachdb://{:s}:{:s}@cockroachdb-public.{:s}.svc.cluster.local:{:s}/{:s}?sslmode={:s}'

class KpiEngine:
    # def __init__(self):
@@ -34,10 +34,10 @@ class KpiEngine:

    @staticmethod
    def get_engine() -> sqlalchemy.engine.Engine:
        crdb_uri = CRDB_URI_TEMPLATE.format(
                CRDB_USERNAME, CRDB_PASSWORD, CRDB_SQL_PORT, CRDB_DATABASE, CRDB_SSLMODE)
        # crdb_uri = CRDB_URI_TEMPLATE.format(
        #         CRDB_USERNAME, CRDB_PASSWORD, CRDB_NAMESPACE, CRDB_SQL_PORT, CRDB_DATABASE, CRDB_SSLMODE)
        #         CRDB_USERNAME, CRDB_PASSWORD, CRDB_SQL_PORT, CRDB_DATABASE, CRDB_SSLMODE)
        crdb_uri = CRDB_URI_TEMPLATE.format(
                CRDB_USERNAME, CRDB_PASSWORD, CRDB_NAMESPACE, CRDB_SQL_PORT, CRDB_DATABASE, CRDB_SSLMODE)
        try:
            # engine = sqlalchemy.create_engine(
            #     crdb_uri, connect_args={'application_name': APP_NAME}, echo=ECHO, future=True)
+1 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ class KpiManagerServiceServicerImpl(KpiManagerServiceServicer):
                response = KpiModel.convert_row_to_KpiDescriptor(row)
            return response
        except Exception as e:
            print ('Unable to search kpi id. {:}'.format(e))
            LOGGER.debug('Unable to search kpi id. {:}'.format(e))

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
+4 −1
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ class KpiValueWriter:
        kpi_id = KpiId()
        kpi_id.kpi_id.uuid = kpi_value_uuid
        print("KpiId generated: {:}".format(kpi_id))
        print("Kpi manger client created: {:}".format(kpi_manager_client))
        # print("Kpi manger client created: {:}".format(kpi_manager_client))

        try:
            kpi_descriptor_object = KpiDescriptor()
@@ -103,7 +103,10 @@ class KpiValueWriter:
            print("kpi descriptor received: {:}".format(kpi_descriptor_object))
            if isinstance (kpi_descriptor_object, KpiDescriptor):
                LOGGER.info("Extracted row: {:}".format(kpi_descriptor_object))
                print("Extracted row: {:}".format(kpi_descriptor_object))
            else:
                LOGGER.info("Error in extracting row {:}".format(kpi_descriptor_object))
                print("Error in extracting row {:}".format(kpi_descriptor_object))
        except Exception as e:
            LOGGER.info("Unable to get Descriptor. Error: {:}".format(e))
            print ("Unable to get Descriptor. Error: {:}".format(e))