class_docstr: Helper class to handle metadata I/O.
  
  Not thread-safe without external synchronisation.
docstr: Creates or fetches the pipeline contexts needed for the run.
  
  There are two potential contexts:
    - Context for the pipeline.
    - Context for the current pipeline run. This is optional, only available
      when run_id is specified.
  
  Args:
    pipeline_info: pipeline information for current run.
  
  Returns:
    a list (of size one or two) of context.
docstr_tok: ["Creates","or","fetches","the","pipeline","contexts","needed","for","the","run",".","There","are","two","potential","contexts",":","-","Context","for","the","pipeline",".","-","Context","for","the","current","pipeline","run",".","This","is","optional",",","only","available","when","run_id","is","specified",".","Args",":","pipeline_info",":","pipeline","information","for","current","run",".","Returns",":","a","list","(","of","size","one","or","two",")","of","context","."]
code: def register_pipeline_contexts_if_not_exists(
      self,
      pipeline_info: data_types.PipelineInfo,
  ) -> List[metadata_store_pb2.Context]:
      """Creates or fetches the pipeline contexts needed for the run.
  
      There are two potential contexts:
        - Context for the pipeline.
        - Context for the current pipeline run. This is optional, only available
          when run_id is specified.
  
      Args:
        pipeline_info: pipeline information for current run.
  
      Returns:
        a list (of size one or two) of context.
      """
      # Gets the pipeline level context.
      result = []
      pipeline_context = self._register_context_if_not_exist(
          context_type_name=_CONTEXT_TYPE_PIPELINE,
          context_name=pipeline_info.pipeline_context_name,
          properties={
              _CONTEXT_TYPE_KEY_PIPELINE_NAME: pipeline_info.pipeline_name
          },
      )
      result.append(pipeline_context)
      absl.logging.debug(
          "Pipeline context [%s : %s]",
          pipeline_info.pipeline_context_name,
          pipeline_context.id,
      )
      # If run id exists, gets the pipeline run level context.
      if pipeline_info.run_id:
          pipeline_run_context = self._register_context_if_not_exist(
              context_type_name=_CONTEXT_TYPE_PIPELINE_RUN,
              context_name=pipeline_info.pipeline_run_context_name,
              properties={
                  _CONTEXT_TYPE_KEY_PIPELINE_NAME: pipeline_info.pipeline_name,
                  _CONTEXT_TYPE_KEY_RUN_ID: pipeline_info.run_id,
              },
          )
          result.append(pipeline_run_context)
          absl.logging.debug(
              "Pipeline run context [%s : %s]",
              pipeline_info.pipeline_run_context_name,
              pipeline_run_context.id,
          )
      return result
  
imports: import collections
  import copy
  import hashlib
  import itertools
  import os
  import random
  import time
  import types
  from typing import Any, Dict, List, Optional, Set, Tuple, Type, Union
  import absl
  from tfx.dsl.io import fileio
  from tfx.orchestration import data_types
  from tfx.orchestration.portable.mlmd import event_lib
  from tfx.types import artifact
  from tfx.types import artifact_utils
  import ml_metadata
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 33 for calling the Metadata obj's underlying member method code with example usage: obj.register_pipeline_contexts_if_not_exists(pipeline_info) and returns: result