def init_metadata(self): if not TestWrapper.INIT: # This is necessary as I added an analyzer with a keyword tokenizer # which requires an index to be closed and reopened. self.connection.indices.delete(index=self.index, ignore=404) Metadata.init(index=self.index, using=self.connection) self.connection.indices.refresh(index=self.index) TestWrapper.INIT = True
def initialize(self): config = self.read_config() connection = Connection(config["connectionString"], config.get("accessKey"), config.get("secretKey"), config.get("region")) index_exists = connection.indices.exists(index=connection.es_index) if not index_exists: Metadata.init(using=connection, index=connection.es_index) connection.indices.refresh(index=connection.es_index)
def _get_metadata(self, key): """ Attempts to get existing metadata and creates one if it does not exist. Args: key(string): Unique key that represents the unique id of the metadata document. Returns: pyshelf.search.metadata.Metadata """ meta_doc = Metadata.get(id=key, index=self.index, using=self.connection, ignore=404) if not meta_doc: meta_doc = Metadata() meta_doc.meta.id = key meta_doc.meta.index = self.index return meta_doc
def add_metadata(self, key, metadata): self.init_metadata() meta = Metadata() meta.meta.id = key meta.meta.index = self.index meta.update_all(metadata) meta.save(using=self.connection)
def compare(self, resource_url, bucket_name): identity = ResourceIdentity(resource_url) cloud_portal = self.factory.create_cloud_portal(bucket_name) cloud_metadata = cloud_portal.load(identity.cloud_metadata) if not cloud_metadata: self.fail("Failed to find metadata in cloud for {0}".format(identity.cloud_metadata)) # Make extra sure our data will show up self.es_connection.indices.refresh(index=self.index) metadata = Metadata.get(index=self.index, using=self.es_connection, id=identity.search, ignore=404) if not metadata: self.test.fail("Failed to find metadata in search for {0}".format(identity.search)) metadata = self._map_es_metadata(metadata) self.test.asserts.json_equals(cloud_metadata, metadata)
def compare(self, resource_url): identity = ResourceIdentity(resource_url) cloud_portal = self.factory.create_cloud_portal(identity.bucket_name) cloud_metadata = cloud_portal.load(identity.cloud_metadata) if not cloud_metadata: self.fail("Failed to find metadata in cloud for {0}".format( identity.cloud_metadata)) # Make extra sure our data will show up self.es_connection.indices.refresh(index=self.index) metadata = Metadata.get(index=self.index, using=self.es_connection, id=identity.search, ignore=404) if not metadata: self.test.fail("Failed to find metadata in search for {0}".format( identity.search)) metadata = self._map_es_metadata(metadata) self.test.asserts.json_equals(cloud_metadata, metadata)
def get_metadata(self, id): return Metadata.get(index=self.index, using=self.connection, id=id, ignore=404)