コード例 #1
0
def _list_jobs(
    api: CustomObjectsApi,
    namespace: str,
    project: Optional[str] = None,
    table_name: Optional[str] = None,
) -> List[JobInfo]:
    result = []

    # Batch, Streaming Ingestion jobs
    if project and table_name:
        table_name_hash = _generate_project_table_hash(project, table_name)
        response = api.list_namespaced_custom_object(
            **_crd_args(namespace),
            label_selector=f"{LABEL_FEATURE_TABLE_HASH}={table_name_hash}",
        )
    elif project:
        response = api.list_namespaced_custom_object(
            **_crd_args(namespace),
            label_selector=f"{LABEL_PROJECT}={project}",
        )
    else:
        # Retrieval jobs
        response = api.list_namespaced_custom_object(
            **_crd_args(namespace),
            label_selector=LABEL_JOBID,
        )

    for item in response["items"]:
        result.append(_resource_to_job_info(item))
    return result
コード例 #2
0
def _unschedule_job(api: CustomObjectsApi, namespace: str, resource_name: str):
    try:
        api.delete_namespaced_custom_object(
            **_scheduled_crd_args(namespace),
            name=resource_name,
        )
    except client.ApiException as e:
        if e.status != 404:
            raise
コード例 #3
0
def _cancel_job_by_id(api: CustomObjectsApi, namespace: str, job_id: str):
    try:
        api.delete_namespaced_custom_object(
            **_crd_args(namespace), name=_job_id_to_resource_name(job_id),
        )
    except client.ApiException as e:
        if e.status == 404:
            return None
        else:
            raise
コード例 #4
0
def _submit_job(api: CustomObjectsApi, resource, namespace: str) -> JobInfo:
    # create the resource
    response = api.create_namespaced_custom_object(
        **_crd_args(namespace),
        body=resource,
    )
    return _resource_to_job_info(response)
コード例 #5
0
def _list_jobs(api: CustomObjectsApi, namespace: str) -> List[JobInfo]:
    response = api.list_namespaced_custom_object(
        **_crd_args(namespace),
        label_selector=LABEL_JOBID,
    )

    result = []
    for item in response["items"]:
        result.append(_resource_to_job_info(item))
    return result
コード例 #6
0
def _get_job_by_id(api: CustomObjectsApi, namespace: str,
                   job_id: str) -> Optional[JobInfo]:
    try:
        response = api.get_namespaced_custom_object(
            **_crd_args(namespace), name=_job_id_to_resource_name(job_id))

        return _resource_to_job_info(response)
    except client.ApiException as e:
        if e.status == 404:
            return None
        else:
            raise
コード例 #7
0
def _list_jobs(api: CustomObjectsApi,
               namespace: str,
               table_name: Optional[str] = None) -> List[JobInfo]:
    result = []

    # Batch, Streaming Ingestion jobs
    if table_name:
        table_name_hash = hashlib.md5(table_name.encode()).hexdigest()
        response = api.list_namespaced_custom_object(
            **_crd_args(namespace),
            label_selector=f"{LABEL_FEATURE_TABLE_HASH}={table_name_hash}",
        )
    else:
        # Retrieval jobs
        response = api.list_namespaced_custom_object(
            **_crd_args(namespace),
            label_selector=LABEL_JOBID,
        )

    for item in response["items"]:
        result.append(_resource_to_job_info(item))
    return result
コード例 #8
0
def _submit_scheduled_job(api: CustomObjectsApi, name: str, resource: dict,
                          namespace: str):
    try:
        api.get_namespaced_custom_object(**_scheduled_crd_args(namespace),
                                         name=name)
    except client.ApiException as e:
        if e.status == 404:
            api.create_namespaced_custom_object(**_scheduled_crd_args(
                namespace),
                                                body=resource)
            return
        else:
            raise e
    api.patch_namespaced_custom_object(
        **_scheduled_crd_args(namespace),
        name=name,
        body=resource,
    )