ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Attributes | List of all members
adctk.ldms_publisher.LDMSSystemMessagePublisher Class Reference

Publish data via file to ldms_message_publish once via process recreated at each call. More...

Inheritance diagram for adctk.ldms_publisher.LDMSSystemMessagePublisher:
Inheritance graph
[legend]
Collaboration diagram for adctk.ldms_publisher.LDMSSystemMessagePublisher:
Collaboration graph
[legend]

Public Member Functions

 __init__ (self)
 
int config (self, **kwargs)
 Configure the plugin with the options given.
 
- Public Member Functions inherited from adctk.ldms_publisher.LDMSPipeMessagePublisher
int initialize (self)
 Set up any resources needed for reuse in publish().
 
 publish (self, builder.Builder b)
 
 finalize (self)
 Clean up any resources set up in initialize (files, pipes, etc).
 
- Public Member Functions inherited from adctk.publisher.Publisher
str name (self)
 Get the name which a factory or error message should use.
 
str version (self)
 
dict[str, str] get_option_defaults (self)
 
None pause (self)
 Cause publish calls to be ignored until resume is called.
 
None resume (self)
 Cancel an prior calls to pause.
 
int publish_str (self, str json_string)
 
int publish_obj (self, obj)
 

Public Attributes

 defaults
 
 dir_
 
 port
 
 auth
 
 tag
 
 host
 
- Public Attributes inherited from adctk.ldms_publisher.LDMSPipeMessagePublisher
 plugin_prefix
 
 defaults
 
 prog
 
 port
 
 auth
 
 tag
 
 host
 
 timeout
 
 mode
 
 state
 
- Public Attributes inherited from adctk.publisher.Publisher
 defaults
 
 plugin_prefix
 
 paused
 
 state
 
 mode
 

Protected Member Functions

int _post (self, str msg)
 
- Protected Member Functions inherited from adctk.publisher.Publisher
str _get (self, dict[str, str] opts, str field)
 
bool _get_bool (self, dict[str, str] opts, str field)
 

Static Protected Attributes

str _name = "ldms-system-message"
 
str _version = "1.0.0"
 
- Static Protected Attributes inherited from adctk.ldms_publisher.LDMSPipeMessagePublisher
str _name = "ldms-pipe-message"
 
str _version = "1.0.0"
 
- Static Protected Attributes inherited from adctk.publisher.Publisher
str _name = "unknown"
 
str _version = "0.0.0"
 

Additional Inherited Members

- Static Public Member Functions inherited from adctk.publisher.Publisher
tuple[float] get_timeout_defaults ()
 Get the adc server connect and response timeouts defined in the environment ADC_SERVER_CONNECT_TIMEOUT and ADC_SERVER_POST_TIMEOUT as a tuple or default values if not defined.
 
str get_url_default ()
 Get the alleged adc server url base from environment ADC_SERVER_URL or the default if it is not present.
 
str get_port_default ()
 Get the adc server port number to use if it is properly defined in the environment ADC_SERVER_PORT or the default if it is not.
 
- Static Public Attributes inherited from adctk.publisher.Publisher
 API_VERSION = adc_version.AdcVersion()._dict()
 

Detailed Description

Publish data via file to ldms_message_publish once via process recreated at each call.

Environment Variables

Constructor & Destructor Documentation

◆ __init__()

adctk.ldms_publisher.LDMSSystemMessagePublisher.__init__ (   self)

Reimplemented from adctk.ldms_publisher.LDMSPipeMessagePublisher.

314 def __init__(self):
315 super().__init__()
316 self.defaults = _defaults_system_message
317 self.dir_: str = None
318

Member Function Documentation

◆ _post()

int adctk.ldms_publisher.LDMSSystemMessagePublisher._post (   self,
str   msg 
)
protected

Reimplemented from adctk.ldms_publisher.LDMSPipeMessagePublisher.

323 def _post(self, msg:str ) ->int:
324 if not self.dir_:
325 self.initialize()
326 f = None
327 try:
328 f, filepath = tempfile.mkstemp( prefix="adctk-json-system-message-msg-", dir=self.dir_ )
329 f.write(msg)
330 f.close()
331 cmd = [self.prog,
332 "-t", "json",
333 "-x", "sock",
334 "-p", self.port,
335 "-a", self.auth,
336 "-m", self.tag,
337 "-h", self.host,
338 "-f", filepath
339 ]
340 log.logger.info("LDMSSystem-publisher command: %s", cmd)
341 with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
342 stdout, stderr = process.communicate(timeout=self.timeout)
343 output_string = stdout.decode("utf-8")
344 error_string = stderr.decode("utf-8")
345 log.logger.debug("Output: %s", output_string)
346 log.logger.debug("Error: (may be empty): %s", error_string)
347 ret = process.wait()
348 if ret != 0:
349 log.logger.warning("LDMSSystem-publisher: publish process failed "\
350 "with error: %s", ret)
351 except subprocess.TimeoutExpired:
352 log.logger.warning("LDMSSystem-publisher: timeout expired")
353 if f:
354 os.unlink(filepath)
355 return ret

◆ config()

int adctk.ldms_publisher.LDMSSystemMessagePublisher.config (   self,
**  kwargs 
)

Configure the plugin with the options given.

For plugin QQQ, Environment variables ADC_QQQ_PLUGIN_<key> will override the plugin default for any key not defined in kwargs. Here QQQ is plugin.name().upper(). Generic options:

Parameters
kwargsIf env_prefix is included in kwargs, replaces plugin environment variables with those which are prefixed using env_prefix.
env_prefixTypically, env_prefix is set to "PPP_ADC_QQQ_PLUGIN_" if application PPP wants to override the defaults of adctk plugin QQQ. Here QQQ is plugin.name().upper(). If no prefixed version of the variable is present, the plugin default is used. kwargs takes precedence over environment variables. Plugin defaults are used if not overridden by kwargs or an environment variable.
Returns
int non-zero if configuration cannot be completed using the arguments, environment, and default.

Reimplemented from adctk.ldms_publisher.LDMSPipeMessagePublisher.

319 def config(self, **kwargs) -> int:
320 self.dir_ = self._get(kwargs, "DIRECTORY")
321 return super().config(**kwargs)
322

Member Data Documentation

◆ _name

str adctk.ldms_publisher.LDMSSystemMessagePublisher._name = "ldms-system-message"
staticprotected

◆ _version

str adctk.ldms_publisher.LDMSSystemMessagePublisher._version = "1.0.0"
staticprotected

◆ auth

adctk.ldms_publisher.LDMSSystemMessagePublisher.auth

◆ defaults

adctk.ldms_publisher.LDMSSystemMessagePublisher.defaults

◆ dir_

adctk.ldms_publisher.LDMSSystemMessagePublisher.dir_

◆ host

adctk.ldms_publisher.LDMSSystemMessagePublisher.host

◆ port

adctk.ldms_publisher.LDMSSystemMessagePublisher.port

◆ tag

adctk.ldms_publisher.LDMSSystemMessagePublisher.tag

The documentation for this class was generated from the following file: