def delete_algorithm_model(identifier, request_id, params):
    response = AlgorithmModelDeployResultEvent(
        AlgorithmEventErrorCodes.ALGO_EVENT_SUCCESS,
        AlgorithmDeployEventType.ALGO_DELETE_ALGO_MODEL)

    if "AlgoID" not in params.keys():
        response.Result = AlgorithmEventErrorCodes.ALGO_EVENT_PARAM_ERR
        return response.to_json()

    algo_id = params["AlgoID"]
    """判断该algo_id是否有任务在运行"""
    response.AlgoID = algo_id
    if algo_id in dict_cloud_task_id_algo_id.values():
        response.Result = AlgorithmEventErrorCodes.ALGO_EVENT_DELETE_ERR
        return response.to_json()

    module_path = conf.get_string("Default", "algoModuleDir")
    algo_path = module_path + "/" + algo_id + "/"
    if os.path.exists(algo_path):
        shutil.rmtree(algo_path)
    else:
        response.Result = AlgorithmEventErrorCodes.ALGO_EVENT_INVALID_ALGO_ID_ERR

        return response.to_json()

    return response.to_json()
Exemple #2
0
 def __init__(self):
     if "ACCESS_KEY_ID" in os.environ:
         self.access_key_id = os.environ["ACCESS_KEY_ID"]
     else:
         self.access_key_id = conf.get_string("OSS_CFG", "access_key_id")
     if "ACCESS_KEY_SECRET" in os.environ:
         self.access_key_secret = os.environ["ACCESS_KEY_SECRET"]
     else:
         self.access_key_secret = conf.get_string("OSS_CFG",
                                                  "access_key_secret")
     if "BUCKET_NAME" in os.environ:
         self.bucket_name = os.environ["BUCKET_NAME"]
     else:
         self.bucket_name = conf.get_string("OSS_CFG", "bucket_name")
     if "ENDPOINT" in os.environ:
         self.endpoint = os.environ["ENDPOINT"]
     else:
         self.endpoint = conf.get_string("OSS_CFG", "endpoint")
     self.bucket = oss2.Bucket(
         oss2.Auth(self.access_key_id, self.access_key_secret),
         self.endpoint, self.bucket_name)
     return
def download_model(identifier, request_id, params):
    """
    :param identifier:
    :param request_id:
    :param params:
    :return:
    """
    log.info("download_model params:%s" % params)
    response = AlgorithmModelDeployResultEvent(
        AlgorithmEventErrorCodes.ALGO_EVENT_SUCCESS,
        AlgorithmDeployEventType.ALGO_DEPLOY_ALGO_MODEL)

    if "AlgoURL" not in params.keys() or "AlgoID" not in params.keys():
        response.Result = AlgorithmEventErrorCodes.ALGO_EVENT_PARAM_ERR
        return response.to_json()

    url = params["AlgoURL"]
    algo_id = params["AlgoID"]
    response.AlgoID = algo_id

    module_path = conf.get_string("Default", "algoModuleDir")
    algo_path = module_path + "/" + algo_id + "/"
    if os.path.isdir(algo_path) is False:
        os.mkdir(algo_path)
    algo_name = os.path.join(module_path, "temp_" + algo_id)
    try:
        urllib.request.urlretrieve(url, algo_name, schedule_hook)

        file_zip = zipfile.ZipFile(algo_name, 'r')
        for file in file_zip.namelist():
            file_zip.extract(file, algo_path)
        file_zip.close()
        os.remove(algo_name)
    except Exception as e:
        response.Result = AlgorithmEventErrorCodes.ALGO_EVENT_DOWNLOAD_ERR
        if os.path.exists(algo_name):
            os.remove(algo_name)
        return response.to_json()

    return response.to_json()
 def __init__(self):
     self.path = conf.get_string("Default", "algoModuleDir")
     self.dict_modules = {}
     self.dict_single_modules = {}
     # self.dict_module_info = {}
     return
                                                                                    code,
                                                                                    str(data),
                                                                                    message))


def on_thing_event_post(event, request_id, code, data, reply_message, user_data):
    log.info("on_thing_event_post event: {} request_id:{}, code:{}, data:{}, reply_message:{}".format(event,
                                                                                                      request_id,
                                                                                                      code,
                                                                                                      str(data),
                                                                                                      reply_message))


if "LINKKIT_LOADED" not in os.environ:
    os.environ.setdefault("LINKKIT_LOADED", "TRUE")
    host_name = conf.get_string("LinkKit", "host_name")
    if "PRODUCT_KEY" in os.environ:
        product_key = os.environ["PRODUCT_KEY"]
    else:
        product_key = conf.get_string("LinkKit", "product_key")
    log.info("product_key={}".format(product_key))

    if "DEVICE_NAME" in os.environ:
        device_name = os.environ["DEVICE_NAME"]
    else:
        device_name = conf.get_string("LinkKit", "device_name")
    log.info("device_name={}".format(device_name))

    if "DEVICE_SECRET" in os.environ:
        device_secret = os.environ["DEVICE_SECRET"]
    else:
def query_algo_model_list():
    module_path = conf.get_string("Default", "algoModuleDir")
    return os.listdir(module_path)