def list_events(query, include=None): result = ManagerElasticsearch.search_events(body=query, include=include) events = ManagerElasticsearch.extract_search_result_values(result) metadata = ManagerElasticsearch.build_list_result_metadata(query, result) return ListResult(events, metadata)
def list_events(self, query, include=None): result = self._search(query, include=include) result_items = result['hits']['hits'] events = [item['_source'] for item in result_items] metadata = ManagerElasticsearch.build_list_result_metadata(query, result) return ListResult(events, metadata)
def _list_docs(self, doc_type, model_class, body=None, fields=None): include = list(fields) if fields else True result = self._connection.search(index=STORAGE_INDEX_NAME, doc_type=doc_type, body=body, _source=include) docs = ManagerElasticsearch.extract_search_result_values(result) # ES doesn't return _version if using its search API. if doc_type == NODE_INSTANCE_TYPE: for doc in docs: doc['version'] = None items = [self._fill_missing_fields_and_deserialize(doc, model_class) for doc in docs] metadata = ManagerElasticsearch.build_list_result_metadata(body, result) return ListResult(items, metadata)
def _list_docs(self, doc_type, model_class, body=None, fields=None): include = list(fields) if fields else True result = self._connection.search(index=STORAGE_INDEX_NAME, doc_type=doc_type, body=body, _source=include) docs = [hit['_source'] for hit in result['hits']['hits']] # ES doesn't return _version if using its search API. if doc_type == NODE_INSTANCE_TYPE: for doc in docs: doc['version'] = None items = [self._fill_missing_fields_and_deserialize(doc, model_class) for doc in docs] metadata = ManagerElasticsearch.build_list_result_metadata(body, result) return ListResult(items, metadata)
def delete(self, filters=None, pagination=None, sort=None, range_filters=None, **kwargs): """Delete events/logs connected to a certain Deployment ID """ query = self._build_query(filters=filters, pagination=pagination, sort=sort, range_filters=range_filters) events = ManagerElasticsearch.search_events(body=query) metadata = ManagerElasticsearch.build_list_result_metadata(query, events) events = ManagerElasticsearch.extract_info_for_deletion(events) get_blueprints_manager().delete_events(events) # We don't really want to return all of the deleted events, so it's a # bit of a hack to only return the number of events to delete - if any # of the events weren't deleted, we'd have gotten an error from the # method above return ListResult([len(events)], metadata)