qq_lib.properties.resubmit_host
1# Released under MIT License. 2# Copyright (c) 2025-2026 Ladislav Bartos and Robert Vacha Lab 3 4 5import re 6from abc import ABC, abstractmethod 7from dataclasses import dataclass 8 9 10@dataclass(frozen=True) 11class ResubmitHost(ABC): 12 """ 13 A host target for resubmitting a loop or continuous job. 14 15 This abstract base class represents a destination host where a batch job 16 can be resubmitted. Concrete implementations resolve to actual hostnames 17 via the `convert` method. 18 19 Subclasses: 20 InputHost: Resolves to the original input machine. 21 WorkHost: Resolves to the current working node. 22 ExplicitHost: Resolves to an explicitly specified hostname. 23 """ 24 25 @classmethod 26 def from_str(cls, s: str) -> "ResubmitHost": 27 """ 28 Parses a single resubmission host from a string. 29 30 Args: 31 s (str): String representation of the resubmission host. 32 33 Returns: 34 ResubmitHost: The corresponding `ResubmitHost` variant. 35 """ 36 match s.lower().strip(): 37 case "input": 38 return InputHost() 39 case "working" | "work": 40 return WorkHost() 41 case _: 42 return ExplicitHost(s.strip()) 43 44 @classmethod 45 def multi_from_str(cls, raw: str) -> list["ResubmitHost"]: 46 """ 47 Parses multiple resubmission hosts from a delimited string. 48 49 Args: 50 raw (str): String containing one or more host specifiers separated by 51 colons, commas, or spaces. 52 Examples: "input:node132.random.server.org", "work,input", or "node123 node234". 53 54 Returns: 55 list[ResubmitHost]: A list of parsed `ResubmitHost` instances. 56 """ 57 host_strings = re.split(r"[:,\s]+", raw.strip()) 58 host_strings = [hs for hs in host_strings if hs] 59 60 return [ResubmitHost.from_str(host_str) for host_str in host_strings] 61 62 @abstractmethod 63 def to_str(self) -> str: 64 """ 65 Convert the resubmission host into its string representation. 66 67 Returns: 68 str: String, unresolved representation of the resubmission host. 69 """ 70 71 @abstractmethod 72 def resolve(self, input_host: str, working_node: str) -> str: 73 """ 74 Resolves this resubmission host to a concrete hostname. 75 76 Args: 77 input_host (str): The name of the machine from which the job was originally submitted. 78 working_node (str): The name of the node on which the job is currently running. 79 For multi-node jobs, use the main node. 80 81 Returns: 82 str: The resolved hostname string. 83 """ 84 85 86@dataclass(frozen=True) 87class InputHost(ResubmitHost): 88 """ 89 A resubmission host that resolves to the original input machine. 90 """ 91 92 def to_str(self) -> str: 93 return "input" 94 95 def resolve(self, input_host: str, working_node: str) -> str: 96 _ = working_node 97 return input_host 98 99 100@dataclass(frozen=True) 101class WorkHost(ResubmitHost): 102 """ 103 A resubmission host that resolves to the current working node. 104 """ 105 106 def to_str(self) -> str: 107 return "working" 108 109 def resolve(self, input_host: str, working_node: str) -> str: 110 _ = input_host 111 return working_node 112 113 114@dataclass(frozen=True) 115class ExplicitHost(ResubmitHost): 116 """ 117 A resubmission host that stores an explicit hostname. 118 119 Attributes: 120 hostname: The explicit hostname to use for resubmission. 121 """ 122 123 hostname: str 124 125 def to_str(self) -> str: 126 return self.hostname 127 128 def resolve(self, input_host: str, working_node: str) -> str: 129 _ = input_host, working_node 130 return self.to_str()
11@dataclass(frozen=True) 12class ResubmitHost(ABC): 13 """ 14 A host target for resubmitting a loop or continuous job. 15 16 This abstract base class represents a destination host where a batch job 17 can be resubmitted. Concrete implementations resolve to actual hostnames 18 via the `convert` method. 19 20 Subclasses: 21 InputHost: Resolves to the original input machine. 22 WorkHost: Resolves to the current working node. 23 ExplicitHost: Resolves to an explicitly specified hostname. 24 """ 25 26 @classmethod 27 def from_str(cls, s: str) -> "ResubmitHost": 28 """ 29 Parses a single resubmission host from a string. 30 31 Args: 32 s (str): String representation of the resubmission host. 33 34 Returns: 35 ResubmitHost: The corresponding `ResubmitHost` variant. 36 """ 37 match s.lower().strip(): 38 case "input": 39 return InputHost() 40 case "working" | "work": 41 return WorkHost() 42 case _: 43 return ExplicitHost(s.strip()) 44 45 @classmethod 46 def multi_from_str(cls, raw: str) -> list["ResubmitHost"]: 47 """ 48 Parses multiple resubmission hosts from a delimited string. 49 50 Args: 51 raw (str): String containing one or more host specifiers separated by 52 colons, commas, or spaces. 53 Examples: "input:node132.random.server.org", "work,input", or "node123 node234". 54 55 Returns: 56 list[ResubmitHost]: A list of parsed `ResubmitHost` instances. 57 """ 58 host_strings = re.split(r"[:,\s]+", raw.strip()) 59 host_strings = [hs for hs in host_strings if hs] 60 61 return [ResubmitHost.from_str(host_str) for host_str in host_strings] 62 63 @abstractmethod 64 def to_str(self) -> str: 65 """ 66 Convert the resubmission host into its string representation. 67 68 Returns: 69 str: String, unresolved representation of the resubmission host. 70 """ 71 72 @abstractmethod 73 def resolve(self, input_host: str, working_node: str) -> str: 74 """ 75 Resolves this resubmission host to a concrete hostname. 76 77 Args: 78 input_host (str): The name of the machine from which the job was originally submitted. 79 working_node (str): The name of the node on which the job is currently running. 80 For multi-node jobs, use the main node. 81 82 Returns: 83 str: The resolved hostname string. 84 """
A host target for resubmitting a loop or continuous job.
This abstract base class represents a destination host where a batch job
can be resubmitted. Concrete implementations resolve to actual hostnames
via the convert method.
Subclasses:
InputHost: Resolves to the original input machine. WorkHost: Resolves to the current working node. ExplicitHost: Resolves to an explicitly specified hostname.
26 @classmethod 27 def from_str(cls, s: str) -> "ResubmitHost": 28 """ 29 Parses a single resubmission host from a string. 30 31 Args: 32 s (str): String representation of the resubmission host. 33 34 Returns: 35 ResubmitHost: The corresponding `ResubmitHost` variant. 36 """ 37 match s.lower().strip(): 38 case "input": 39 return InputHost() 40 case "working" | "work": 41 return WorkHost() 42 case _: 43 return ExplicitHost(s.strip())
Parses a single resubmission host from a string.
Arguments:
- s (str): String representation of the resubmission host.
Returns:
ResubmitHost: The corresponding
ResubmitHostvariant.
45 @classmethod 46 def multi_from_str(cls, raw: str) -> list["ResubmitHost"]: 47 """ 48 Parses multiple resubmission hosts from a delimited string. 49 50 Args: 51 raw (str): String containing one or more host specifiers separated by 52 colons, commas, or spaces. 53 Examples: "input:node132.random.server.org", "work,input", or "node123 node234". 54 55 Returns: 56 list[ResubmitHost]: A list of parsed `ResubmitHost` instances. 57 """ 58 host_strings = re.split(r"[:,\s]+", raw.strip()) 59 host_strings = [hs for hs in host_strings if hs] 60 61 return [ResubmitHost.from_str(host_str) for host_str in host_strings]
Parses multiple resubmission hosts from a delimited string.
Arguments:
- raw (str): String containing one or more host specifiers separated by colons, commas, or spaces. Examples: "input:node132.random.server.org", "work,input", or "node123 node234".
Returns:
list[ResubmitHost]: A list of parsed
ResubmitHostinstances.
63 @abstractmethod 64 def to_str(self) -> str: 65 """ 66 Convert the resubmission host into its string representation. 67 68 Returns: 69 str: String, unresolved representation of the resubmission host. 70 """
Convert the resubmission host into its string representation.
Returns:
str: String, unresolved representation of the resubmission host.
72 @abstractmethod 73 def resolve(self, input_host: str, working_node: str) -> str: 74 """ 75 Resolves this resubmission host to a concrete hostname. 76 77 Args: 78 input_host (str): The name of the machine from which the job was originally submitted. 79 working_node (str): The name of the node on which the job is currently running. 80 For multi-node jobs, use the main node. 81 82 Returns: 83 str: The resolved hostname string. 84 """
Resolves this resubmission host to a concrete hostname.
Arguments:
- input_host (str): The name of the machine from which the job was originally submitted.
- working_node (str): The name of the node on which the job is currently running. For multi-node jobs, use the main node.
Returns:
str: The resolved hostname string.
87@dataclass(frozen=True) 88class InputHost(ResubmitHost): 89 """ 90 A resubmission host that resolves to the original input machine. 91 """ 92 93 def to_str(self) -> str: 94 return "input" 95 96 def resolve(self, input_host: str, working_node: str) -> str: 97 _ = working_node 98 return input_host
A resubmission host that resolves to the original input machine.
Convert the resubmission host into its string representation.
Returns:
str: String, unresolved representation of the resubmission host.
96 def resolve(self, input_host: str, working_node: str) -> str: 97 _ = working_node 98 return input_host
Resolves this resubmission host to a concrete hostname.
Arguments:
- input_host (str): The name of the machine from which the job was originally submitted.
- working_node (str): The name of the node on which the job is currently running. For multi-node jobs, use the main node.
Returns:
str: The resolved hostname string.
Inherited Members
101@dataclass(frozen=True) 102class WorkHost(ResubmitHost): 103 """ 104 A resubmission host that resolves to the current working node. 105 """ 106 107 def to_str(self) -> str: 108 return "working" 109 110 def resolve(self, input_host: str, working_node: str) -> str: 111 _ = input_host 112 return working_node
A resubmission host that resolves to the current working node.
Convert the resubmission host into its string representation.
Returns:
str: String, unresolved representation of the resubmission host.
110 def resolve(self, input_host: str, working_node: str) -> str: 111 _ = input_host 112 return working_node
Resolves this resubmission host to a concrete hostname.
Arguments:
- input_host (str): The name of the machine from which the job was originally submitted.
- working_node (str): The name of the node on which the job is currently running. For multi-node jobs, use the main node.
Returns:
str: The resolved hostname string.
Inherited Members
115@dataclass(frozen=True) 116class ExplicitHost(ResubmitHost): 117 """ 118 A resubmission host that stores an explicit hostname. 119 120 Attributes: 121 hostname: The explicit hostname to use for resubmission. 122 """ 123 124 hostname: str 125 126 def to_str(self) -> str: 127 return self.hostname 128 129 def resolve(self, input_host: str, working_node: str) -> str: 130 _ = input_host, working_node 131 return self.to_str()
A resubmission host that stores an explicit hostname.
Attributes:
- hostname: The explicit hostname to use for resubmission.
Convert the resubmission host into its string representation.
Returns:
str: String, unresolved representation of the resubmission host.
129 def resolve(self, input_host: str, working_node: str) -> str: 130 _ = input_host, working_node 131 return self.to_str()
Resolves this resubmission host to a concrete hostname.
Arguments:
- input_host (str): The name of the machine from which the job was originally submitted.
- working_node (str): The name of the node on which the job is currently running. For multi-node jobs, use the main node.
Returns:
str: The resolved hostname string.