Пример #1
0
def delete_model(parameters: dict, namespace: str, id_token):
    if not tenant_exists(namespace, id_token):
        raise TenantDoesNotExistException(namespace)

    model_path = f"{parameters['modelName']}-{parameters['modelVersion']}"
    bucket = minio_resource.Bucket(name=namespace)
    model_in_bucket = bucket.objects.filter(Prefix=model_path)

    if not model_exists(model_in_bucket):
        raise ModelDoesNotExistException(model_path)

    apps_api_client = get_k8s_apps_api_client(id_token)
    try:
        deployments = apps_api_client.list_namespaced_deployment(namespace)
    except ApiException as apiException:
        raise KubernetesGetException('deployment', apiException)

    endpoint_names = endpoints_using_model(deployments, model_path)
    if endpoint_names:
        raise ModelDeleteException(
            f'model is used by endpoints: {endpoint_names}')

    for key in model_in_bucket:
        key.delete()

    return model_path
Пример #2
0
def list_models(namespace: str, id_token):
    if not tenant_exists(namespace, id_token):
        raise TenantDoesNotExistException(namespace)

    apps_api_client = get_k8s_apps_api_client(id_token)
    try:
        deployments = apps_api_client.list_namespaced_deployment(namespace)
    except ApiException as apiException:
        raise KubernetesGetException('deployment', apiException)

    try:
        bucket = minio_resource.Bucket(name=namespace)
    except ClientError as clientError:
        raise MinioCallException(
            f'An error occurred during bucket reading: {clientError}')

    models = []
    for object in bucket.objects.all():
        if object.size > 0:
            model_path = object.key.split('/')[0].rsplit('-', 1)
            model_name = model_path[0]
            model_version = model_path[-1]
            model_size = object.size
            deployment_count = len(
                endpoints_using_model(deployments, model_path))
            models.append(
                (model_name, model_version, model_size, deployment_count))

    if not models:
        return f"There are no models present in {namespace} tenant\n"
    else:
        return f'Models in {namespace} tenant ' \
               f'(model name, model version, model size, deployed count): {models}\n'
Пример #3
0
def check_endpoint_model(namespace, model_name):
    try:
        bucket = minio_resource.Bucket(name=namespace)
    except ClientError:
        logger.warning(f'Endpoint was created successfully.'
                       f'"{namespace}" bucket not accessible. '
                       f'Model existence cannot be verified."\n')
        return False

    for object in bucket.objects.filter(Prefix=model_name + '/'):
        if object.size > 0:
            return True
    return False
def delete_model(parameters: dict, namespace: str, id_token):
    # TODO Add checking if model is used by endpoint
    if not tenant_exists(namespace, id_token):
        raise TenantDoesNotExistException(namespace)

    model_path = f"{parameters['modelName']}/{parameters['modelVersion']}/"
    bucket = minio_resource.Bucket(name=namespace)
    model_in_bucket = bucket.objects.filter(Prefix=model_path)

    if not model_exists(model_in_bucket):
        raise ModelDoesNotExistException(model_path)

    for key in model_in_bucket:
        key.delete()

    logger.info(f'Model {model_path} deleted')
    return model_path
def delete_bucket(name):
    response = 'Bucket {} does not exist'.format(name)
    existed = True
    try:
        bucket = minio_resource.Bucket(name)
        bucket.objects.all().delete()
        response = bucket.delete()
    except ClientError as clientError:
        if clientError.response['Error']['Code'] != NO_SUCH_BUCKET_EXCEPTION:
            raise MinioCallException(
                "A error occurred during bucket deletion: {}".format(
                    clientError))
        existed = False
    if existed:
        logger.info('Bucket {} deleted'.format(name))
    else:
        logger.info('Bucket {} does not exist'.format(name))
    return response
def list_models(namespace: str, id_token):
    # TODO Add checking if model is used by endpoint
    if not tenant_exists(namespace, id_token):
        raise TenantDoesNotExistException(namespace)

    try:
        bucket = minio_resource.Bucket(name=namespace)
    except ClientError as clientError:
        raise MinioCallException(
            f'An error occurred during bucket reading: {clientError}')

    models = []
    for object in bucket.objects.all():
        if object.size > 0:
            model = dict()
            model_path = object.key.split('/', 2)
            model['path'] = object.key
            model['name'] = model_path[0]
            model['version'] = model_path[1]
            model['size'] = object.size
            models.append(model)

    logger.info(f'Models present in {namespace} tenant: {models}')
    return models