Exemple #1
0
    def add(self, metadata_type, allow_table_lock=False):
        """
        :param datacube.model.MetadataType metadata_type:
        :param allow_table_lock:
            Allow an exclusive lock to be taken on the table while creating the indexes.
            This will halt other user's requests until completed.

            If false, creation will be slightly slower and cannot be done in a transaction.
        :rtype: datacube.model.MetadataType
        """
        # This column duplication is getting out of hand:
        MetadataType.validate(metadata_type.definition)

        existing = self.get_by_name(metadata_type.name)
        if existing:
            # They've passed us the same one again. Make sure it matches what is stored.
            check_doc_unchanged(existing.definition,
                                jsonify_document(metadata_type.definition),
                                'Metadata Type {}'.format(metadata_type.name))
        else:
            with self._db.connect() as connection:
                connection.add_metadata_type(
                    name=metadata_type.name,
                    definition=metadata_type.definition,
                    concurrently=not allow_table_lock)
        return self.get_by_name(metadata_type.name)
Exemple #2
0
    def can_update(self, metadata_type, allow_unsafe_updates=False):
        """
        Check if metadata type can be updated. Return bool,safe_changes,unsafe_changes

        Safe updates currently allow new search fields to be added, description to be changed.

        :param datacube.model.MetadataType metadata_type: updated MetadataType
        :param bool allow_unsafe_updates: Allow unsafe changes. Use with caution.
        :rtype: bool,list[change],list[change]
        """
        MetadataType.validate(metadata_type.definition)

        existing = self.get_by_name(metadata_type.name)
        if not existing:
            raise ValueError(
                'Unknown metadata type %s, cannot update – did you intend to add it?'
                % metadata_type.name)

        updates_allowed = {
            ('description', ):
            changes.allow_any,
            # You can add new fields safely but not modify existing ones.
            (
                'dataset', ):
            changes.allow_extension,
            ('dataset', 'search_fields'):
            changes.allow_extension
        }

        doc_changes = get_doc_changes(
            existing.definition, jsonify_document(metadata_type.definition))
        good_changes, bad_changes = changes.classify_changes(
            doc_changes, updates_allowed)

        return allow_unsafe_updates or not bad_changes, good_changes, bad_changes
Exemple #3
0
 def from_doc(self, definition):
     """
     :param dict definition:
     :rtype: datacube.model.MetadataType
     """
     MetadataType.validate(definition)
     return self._make(definition)
Exemple #4
0
    def add(self, definition, allow_table_lock=False):
        """
        :type definition: dict
        :param allow_table_lock:
            Allow an exclusive lock to be taken on the table while creating the indexes.
            This will halt other user's requests until completed.

            If false, creation will be slightly slower and cannot be done in a transaction.
        :rtype: datacube.model.MetadataType
        """
        # This column duplication is getting out of hand:
        MetadataType.validate(definition)

        name = definition['name']

        existing = self._db.get_metadata_type_by_name(name)
        if existing:
            # They've passed us the same one again. Make sure it matches what is stored.
            # TODO: Support for adding/updating search fields?
            fields.check_doc_unchanged(existing.definition, definition,
                                       'Metadata Type {}'.format(name))
        else:
            self._db.add_metadata_type(name=name,
                                       definition=definition,
                                       concurrently=not allow_table_lock)
        return self.get_by_name(name)
Exemple #5
0
    def add(self, definition, allow_table_lock=False):
        """
        :type definition: dict
        :param allow_table_lock:
            Allow an exclusive lock to be taken on the table while creating the indexes.
            This will halt other user's requests until completed.

            If false, creation will be slightly slower and cannot be done in a transaction.
        :rtype: datacube.model.MetadataType
        """
        # This column duplication is getting out of hand:
        MetadataType.validate(definition)

        name = definition['name']

        existing = self._db.get_metadata_type_by_name(name)
        if existing:
            # They've passed us the same one again. Make sure it matches what is stored.
            # TODO: Support for adding/updating search fields?
            check_doc_unchanged(
                existing.definition,
                definition,
                'Metadata Type {}'.format(name)
            )
        else:
            self._db.add_metadata_type(
                name=name,
                definition=definition,
                concurrently=not allow_table_lock
            )
        return self.get_by_name(name)
Exemple #6
0
 def metadata_type_from_doc(definition: dict) -> MetadataType:
     """
     :param definition:
     """
     MetadataType.validate(definition)  # type: ignore
     return MetadataType(
         definition,
         dataset_search_fields=Index.get_dataset_fields(definition))
Exemple #7
0
 def metadata_type_from_doc(definition):
     """
     :param dict definition:
     :rtype: datacube.model.MetadataType
     """
     MetadataType.validate(definition)
     return MetadataType(
         definition,
         dataset_search_fields=Index.get_dataset_fields(definition))