def execute_query(self, discovery_query, id_only=True, query_args=None, query_params=None): try: if "QUERYEXP" in discovery_query: ds_query, ds_name = discovery_query, discovery_query["query_args"].get("datastore", DataStore.DS_RESOURCES) else: log.info("DatastoreDiscovery.execute_query(): discovery_query=\n%s", pprint.pformat(discovery_query)) ds_query, ds_name = self._build_ds_query(discovery_query, id_only=id_only) current_actor_id=get_ion_actor_id(self.process) ds_query.setdefault("query_params", {}) if query_params: ds_query["query_params"].update(query_params) ds_query["query_params"]["current_actor"] = current_actor_id log.debug("DatastoreDiscovery.execute_query(): ds_query=\n%s", pprint.pformat(ds_query)) ds = self._get_datastore(ds_name) access_args = create_access_args(current_actor_id=current_actor_id, superuser_actor_ids=self.container.resource_registry.get_superuser_actors()) query_results = ds.find_by_query(ds_query, access_args=access_args) log.info("Datastore discovery query resulted in %s rows", len(query_results)) if query_args and query_args.get("query_info", False): query_info = dict(_query_info=True, query=ds_query, access_args=access_args, ds_name=ds_name) query_info.update(ds_query.get("_result", {})) query_results.append(query_info) return query_results except Exception as ex: log.exception("DatastoreDiscovery.execute_query() failed") return []
def execute_query(self, discovery_query, id_only=True): try: if "QUERYEXP" in discovery_query: ds_query, ds_name = discovery_query, discovery_query["query_exp"].get("datastore", DataStore.DS_RESOURCES) else: log.info("DatastoreDiscovery.execute_query(): discovery_query=\n%s", pprint.pformat(discovery_query)) ds_query, ds_name = self._build_ds_query(discovery_query, id_only=id_only) log.debug("DatastoreDiscovery.execute_query(): ds_query=\n%s", pprint.pformat(ds_query)) ds = self._get_datastore(ds_name) access_args = create_access_args(current_actor_id=get_ion_actor_id(self.process), superuser_actor_ids=self.container.resource_registry.get_superuser_actors()) res = ds.find_by_query(ds_query, access_args=access_args) log.info("Datastore discovery query resulted in %s rows", len(res)) return res except Exception as ex: log.exception("DatastoreDiscovery.execute_query() failed") return []