generated from NASA-PDS/template-repo-python
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
thomas loubrieu
committed
Sep 6, 2023
1 parent
2143bf7
commit d80fbfe
Showing
6 changed files
with
99 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .legacy_registry_sync import run # noqa | ||
from .legacy_registry_sync import run # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 26 additions & 21 deletions
47
src/pds/registrysweepers/legacy_registry_sync/opensearch_loaded_product.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
import elasticsearch | ||
import os | ||
|
||
import elasticsearch | ||
|
||
# Optional Environment variable used for the Cross Cluster Search | ||
# connections aliases. Each element is separated by a "," | ||
CCS_CONN = "CCS_CONN" | ||
|
||
|
||
def get_cross_cluster_indices(): | ||
""" | ||
Get the aliases for the Cross Cluster Search from an environment variable | ||
@return: the aliases in a list including the main index. | ||
""" | ||
|
||
indices = ["registry"] | ||
|
||
if CCS_CONN in os.environ: | ||
clusters = os.environ[CCS_CONN].split(',') | ||
clusters = os.environ[CCS_CONN].split(",") | ||
indices.extend([f"{c}:registry" for c in clusters]) | ||
|
||
return indices | ||
|
||
|
||
def get_already_loaded_lidvids(product_classes=[], es_conn=None): | ||
def get_already_loaded_lidvids(product_classes=None, es_conn=None): | ||
""" | ||
Get the lidvids of the PDS4 products already loaded in the (new) registry. | ||
Note that this function should not be applied to the product classes Product_Observational or documents, there would be too many results. | ||
query = { | ||
"query": { | ||
"bool": { | ||
"should": [], | ||
"minimum_should_match": 1 | ||
} | ||
}, | ||
"fields": ["_id"] | ||
} | ||
@param product_classes: list of the product classes you are interested in, | ||
e.g. "Product_Bundle", "Product_Collection" ... | ||
@param es_conn: elasticsearch.ElasticSearch instance for the ElasticSearch or OpenSearch connection | ||
@return: the list of the already loaded PDS4 lidvid | ||
""" | ||
|
||
query = {"query": {"bool": {"should": [], "minimum_should_match": 1}}, "fields": ["_id"]} | ||
|
||
prod_class_prop = "pds:Identification_Area/pds:product_class" | ||
query["query"]["bool"]["should"] = [ | ||
dict(match_phrase={prod_class_prop: prod_class}) for prod_class in product_classes | ||
] | ||
|
||
prod_id_resp = elasticsearch.helpers.scan( | ||
es_conn, | ||
index=get_cross_cluster_indices(), | ||
query=query, | ||
scroll="3m") | ||
|
||
if product_classes is not None: | ||
query["query"]["bool"]["should"] = [ | ||
dict(match_phrase={prod_class_prop: prod_class}) for prod_class in product_classes | ||
] | ||
|
||
prod_id_resp = elasticsearch.helpers.scan(es_conn, index=get_cross_cluster_indices(), query=query, scroll="3m") | ||
return [p["_id"] for p in prod_id_resp] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters