Esempio n. 1
0
    def put_execution_type(self,
                           execution_type: metadata_store_pb2.ExecutionType,
                           can_add_fields: bool = False,
                           can_delete_fields: bool = False,
                           all_fields_match: bool = True) -> int:
        """Inserts or updates an execution type.

    Similar to put artifact/context type, if no execution type exists in the
    database with the given name, it creates a new execution type (and a
    database).

    If an execution type with the same name already exists (let's call it
    old_execution_type), then the impact depends upon the other options.

    If execution_type == old_execution_type, then nothing happens.

    Otherwise, if there is a field where execution_type and old_execution_type
    have different types, then it fails.

    Otherwise, if can_add_fields is False and execution_type has a field
    old_execution_type is missing, then it fails.

    Otherwise, if all_fields_match is True and old_execution_type has a field
    execution_type is missing, then it fails.

    Otherwise, if can_delete_fields is True and old_execution_type has a field
    execution_type is missing, then it deletes that field.

    Otherwise, it does nothing.
    Args:
      execution_type: the type to add or update.
      can_add_fields: if true, you can add fields with this operation. If false,
        then if there are more fields in execution_type than in the database,
        the call fails.
      can_delete_fields: if true, you can remove fields with this operation. If
        false, then if there are more fields.
      all_fields_match: if true, all fields must match, and the method fails if
        they are not the same.

    Returns:
      the type id of the type.
    Raises:
      ValueError: If a constraint is violated.
    """
        request = metadata_store_service_pb2.PutExecutionTypeRequest()
        request.can_add_fields = can_add_fields
        request.can_delete_fields = can_delete_fields
        request.all_fields_match = all_fields_match
        request.execution_type.CopyFrom(execution_type)
        response = metadata_store_service_pb2.PutExecutionTypeResponse()

        self._call('PutExecutionType', request, response)
        return response.type_id
Esempio n. 2
0
    def put_execution_type(self,
                           execution_type: metadata_store_pb2.ExecutionType,
                           can_add_fields: bool = False,
                           can_omit_fields: bool = False) -> int:
        """Inserts or updates an execution type.

    If no type exists in the database with the given name, it creates a new
    type and returns the type_id.

    If the request type with the same name already exists (let's call it
    stored_type), the method enforces the stored_type can be updated only when
    the request type is backward compatible for the already stored instances.

    Backwards compatibility is violated iff:

      a) there is a property where the request type and stored_type have
         different value type (e.g., int vs. string)
      b) `can_add_fields = false` and the request type has a new property that
         is not stored.
      c) `can_omit_fields = false` and stored_type has an existing property
         that is not provided in the request type.

    Args:
      execution_type: the request type to be inserted or updated.
      can_add_fields:
          when true, new properties can be added;
          when false, returns ALREADY_EXISTS if the request type has
          properties that are not in stored_type.
      can_omit_fields:
          when true, stored properties can be omitted in the request type;
          when false, returns ALREADY_EXISTS if the stored_type has
          properties not in the request type.

    Returns:
      the type_id of the response.

    Raises:
      AlreadyExistsError: If the type is not backward compatible.
      InvalidArgumentError: If the request type has no name, or any property
          value type is unknown.
    """
        request = metadata_store_service_pb2.PutExecutionTypeRequest(
            can_add_fields=can_add_fields,
            can_omit_fields=can_omit_fields,
            execution_type=execution_type)
        response = metadata_store_service_pb2.PutExecutionTypeResponse()
        self._call('PutExecutionType', request, response)
        return response.type_id