Ejemplo n.º 1
0
def save_model_info(model_info):
    model = MLModel()
    model.f_create_time = current_timestamp()
    for k, v in model_info.items():
        attr_name = 'f_%s' % k
        if hasattr(MLModel, attr_name):
            setattr(model, attr_name, v)
        elif hasattr(MLModel, k):
            setattr(model, k, v)
    try:
        rows = model.save(force_insert=True)
        if rows != 1:
            raise Exception("Create {} failed".format(MLModel))
        if RuntimeConfig.zk_client is not None:
            ServiceUtils.register(
                RuntimeConfig.zk_client,
                gen_party_model_id(role=model.f_role,
                                   party_id=model.f_party_id,
                                   model_id=model.f_model_id),
                model.f_model_version)
        return model
    except peewee.IntegrityError as e:
        if e.args[0] == 1062:
            sql_logger(job_id=model_info.get("job_id", "fate_flow")).warning(e)
        else:
            raise Exception("Create {} failed:\n{}".format(MLModel, e))
    except Exception as e:
        raise Exception("Create {} failed:\n{}".format(MLModel, e))
Ejemplo n.º 2
0
 def execute_update(cls, old_obj, model, update_info, update_filters):
     update_fields = {}
     for k, v in update_info.items():
         attr_name = 'f_%s' % k
         if hasattr(model, attr_name) and attr_name not in model.get_primary_keys_name():
             update_fields[operator.attrgetter(attr_name)(model)] = v
     if update_fields:
         if update_filters:
             operate = old_obj.update(update_fields).where(*update_filters)
         else:
             operate = old_obj.update(update_fields)
         sql_logger(job_id=update_info.get("job_id", "fate_flow")).info(operate)
         return operate.execute() > 0
     else:
         return False
Ejemplo n.º 3
0
 def create_job_family_entity(cls, entity_model, entity_info):
     obj = entity_model()
     obj.f_create_time = current_timestamp()
     for k, v in entity_info.items():
         attr_name = 'f_%s' % k
         if hasattr(entity_model, attr_name):
             setattr(obj, attr_name, v)
     try:
         rows = obj.save(force_insert=True)
         if rows != 1:
             raise Exception("Create {} failed".format(entity_model))
     except peewee.IntegrityError as e:
         if e.args[0] == 1062:
             sql_logger(job_id=entity_info.get("job_id", "fate_flow")).warning(e)
         else:
             raise Exception("Create {} failed:\n{}".format(entity_model, e))
     except Exception as e:
         raise Exception("Create {} failed:\n{}".format(entity_model, e))
Ejemplo n.º 4
0
def save_model_info(model_info):
    model = MLModel()
    model.f_create_time = current_timestamp()
    for k, v in model_info.items():
        attr_name = 'f_%s' % k
        if hasattr(MLModel, attr_name):
            setattr(model, attr_name, v)
        elif hasattr(MLModel, k):
            setattr(model, k, v)
    try:
        rows = model.save(force_insert=True)
        if rows != 1:
            raise Exception("Create {} failed".format(MLModel))
        return model
    except peewee.IntegrityError as e:
        if e.args[0] == 1062:
            sql_logger(job_id=model_info.get("job_id", "fate_flow")).warning(e)
        else:
            raise Exception("Create {} failed:\n{}".format(MLModel, e))
    except Exception as e:
        raise Exception("Create {} failed:\n{}".format(MLModel, e))