Exemplo n.º 1
0
 def read_data_from_db(self, metric_namespace: str, metric_name: str, data_type, job_level=False):
     with DB.connection_context():
         metrics = []
         try:
             query_sql = 'select f_key, f_value from t_tracking_metric_{} where ' \
                         'f_job_id = "{}" and f_component_name = "{}" and f_role = "{}" and f_party_id = "{}"' \
                         'and f_task_id = "{}" and f_metric_namespace = "{}" and f_metric_name= "{}" and f_type="{}" order by f_id'.format(
                 self.get_table_index(), self.job_id, self.component_name if not job_level else 'dag', self.role,
                 self.party_id, self.task_id, metric_namespace, metric_name, data_type)
             cursor = DB.execute_sql(query_sql)
             for row in cursor.fetchall():
                 yield deserialize_b64(row[0]), deserialize_b64(row[1])
         except Exception as e:
             schedule_logger(self.job_id).exception(e)
         return metrics
Exemplo n.º 2
0
def save_metric_meta(job_id, component_name, task_id, role, party_id):
    request_data = request.json
    tracker = Tracking(job_id=job_id, component_name=component_name, task_id=task_id, role=role, party_id=party_id)
    metric_meta = deserialize_b64(request_data['metric_meta'])
    tracker.save_metric_meta(metric_namespace=request_data['metric_namespace'], metric_name=request_data['metric_name'],
                             metric_meta=metric_meta, job_level=request_data['job_level'])
    return get_json_result()
Exemplo n.º 3
0
 def restore(self, model_id: str, model_version: str, store_address: dict):
     """
     Restore model from mysql to local cache
     :param model_id:
     :param model_version:
     :param store_address:
     :return:
     """
     try:
         self.get_connection(config=store_address)
         model = PipelinedModel(model_id=model_id,
                                model_version=model_version)
         with DB.connection_context():
             models_in_tables = MachineLearningModel.select().where(MachineLearningModel.f_model_id == model_id,
                                                                    MachineLearningModel.f_model_version == model_version).\
                 order_by(MachineLearningModel.f_slice_index)
             if not models_in_tables:
                 raise Exception(
                     "Restore model {} {} from mysql failed: {}".format(
                         model_id, model_version,
                         "can not found model in table"))
             f_content = ''
             for models_in_table in models_in_tables:
                 if not f_content:
                     f_content = models_in_table.f_content
                 else:
                     f_content += models_in_table.f_content
             model_archive_data = deserialize_b64(f_content)
             if not model_archive_data:
                 raise Exception(
                     "Restore model {} {} from mysql failed: {}".format(
                         model_id, model_version,
                         "can not get model archive data"))
             with open(model.archive_model_file_path(), "wb") as fw:
                 fw.write(model_archive_data)
             model.unpack_model(model.archive_model_file_path())
             LOGGER.info(
                 "Restore model to {} from mysql successfully".format(
                     model.archive_model_file_path()))
         self.close_connection()
     except Exception as e:
         LOGGER.exception(e)
         raise Exception("Restore model {} {} from mysql failed".format(
             model_id, model_version))