def verify_context_change(self, old_context): """Verify that the starting and post-sync contexts are different, or issue an error.""" new_context = heavy_client.load_server_info(self.observatory).operational_context if old_context == new_context: log.error("Expected operational context switch but starting and post-sync contexts are both", repr(old_context)) else: log.info("Operational context updated from", repr(old_context), "to", repr(new_context))
def push_context(self): """Push the final context recorded in the local cache to the CRDS server so it can be displayed as the operational state of a pipeline. """ info = heavy_client.load_server_info(self.observatory) with log.error_on_exception("Failed pushing cached operational context name to CRDS server"): api.push_remote_context(self.observatory, "operational", self.args.push_context, info.operational_context) log.info("Pushed cached operational context name", repr(info.operational_context), "to CRDS server")
def load_all_type_constraints(observatory): """Load all the type constraint files from `observatory` package. There are constraints that apply to: ALL instruments and types ALL types of one instrument ALL instruments of one type One instrument and type Generally these should be thought of as designed for successive refinement, so all constraints are applied, but as their scope narrows they can become stricter. Since increasing strictness and refinement require more knowledge, the development order of the constraints mirrored that. However, in the (revised) loading below, constraints are loaded by order of decreasing strictness; this makes it possible to define strict constants/replacements early in the loading process and to apply those to customize the more generalized constraints loaded later. """ from crds.core import rmap, heavy_client pmap_name = heavy_client.load_server_info(observatory).operational_context pmap = rmap.get_cached_mapping(pmap_name) locator = utils.get_locator_module(observatory) for instr in pmap.selections: imap = pmap.get_imap(instr) for filekind in imap.selections: if imap.selections[filekind] == "N/A": continue try: suffix = locator.TYPES.filekind_to_suffix(instr, filekind) except Exception as exc: log.warning("Missing suffix coverage for", repr((instr, filekind)), ":", exc) else: locator.get_all_tpninfos( instr, suffix, "tpn") # With core schema, one type loads all locator.get_all_tpninfos( instr, suffix, "ld_tpn") # With core schema, one type loads all locator.get_all_tpninfos( "all", suffix, "tpn") # With core schema, one type loads all locator.get_all_tpninfos( "all", suffix, "ld_tpn") # With core schema, one type loads all locator.get_all_tpninfos(instr, "all", "tpn") locator.get_all_tpninfos(instr, "all", "ld_tpn") locator.get_all_tpninfos("all", "all", "tpn") locator.get_all_tpninfos("all", "all", "ld_tpn")
def update_context(self): """Update the CRDS operational context in the cache. Handle pipeline-specific targeted features of (a) verifying a context switch as actually recorded in the local CRDS cache and (b) echoing/pushing the pipeline context back up to the CRDS server for tracking using an id/authorization key. If errors occurred during the sync and --force_config_update is not set, """ if not log.errors() or self.args.force_config_update: if self.args.verify_context_change: old_context = heavy_client.load_server_info(self.observatory).operational_context heavy_client.update_config_info(self.observatory) if self.args.verify_context_change: self.verify_context_change(old_context) if self.args.push_context: self.push_context() else: log.warning("Errors occurred during sync, skipping CRDS cache config and context update.")
def load_all_type_constraints(observatory): """Load all the type constraint files from `observatory` package. There are constraints that apply to: ALL instruments and types ALL types of one instrument ALL instruments of one type One instrument and type Generally these should be thought of as designed for successive refinement, so all constraints are applied, but as their scope narrows they can become stricter. Since increasing strictness and refinement require more knowledge, the development order of the constraints mirrored that. However, in the (revised) loading below, constraints are loaded by order of decreasing strictness; this makes it possible to define strict constants/replacements early in the loading process and to apply those to customize the more generalized constraints loaded later. """ from crds.core import rmap, heavy_client pmap_name = heavy_client.load_server_info(observatory).operational_context pmap = rmap.get_cached_mapping(pmap_name) locator = utils.get_locator_module(observatory) for instr in pmap.selections: imap = pmap.get_imap(instr) for filekind in imap.selections: if imap.selections[filekind] == "N/A": continue try: suffix = locator.TYPES.filekind_to_suffix(instr, filekind) except Exception as exc: log.warning("Missing suffix coverage for", repr((instr, filekind)), ":", exc) else: locator.get_all_tpninfos(instr, suffix, "tpn") # With core schema, one type loads all locator.get_all_tpninfos(instr, suffix, "ld_tpn") # With core schema, one type loads all locator.get_all_tpninfos("all", suffix, "tpn") # With core schema, one type loads all locator.get_all_tpninfos("all", suffix, "ld_tpn") # With core schema, one type loads all locator.get_all_tpninfos(instr, "all", "tpn") locator.get_all_tpninfos(instr, "all", "ld_tpn") locator.get_all_tpninfos("all","all","tpn") locator.get_all_tpninfos("all","all","ld_tpn")