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.LDMSPipePublisher Class Reference

Publish data over a pipe to ldmsd_stream_publish once via pipe recreated at each call. More...

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

Public Member Functions

 __init__ (self)
 
int config (self, **kwargs)
 Configure the plugin with the options given.
 
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

 plugin_prefix
 
 defaults
 
 prog
 
 port
 
 auth
 
 stream
 
 host
 
 timeout
 
 mode
 
 state
 
- Public Attributes inherited from adctk.publisher.Publisher
 defaults
 
 plugin_prefix
 
 paused
 
 state
 
 mode
 

Protected Member Functions

int _post (self, 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-pipe-stream"
 
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 over a pipe to ldmsd_stream_publish once via pipe recreated at each call.

Environment Variables

Constructor & Destructor Documentation

◆ __init__()

adctk.ldms_publisher.LDMSPipePublisher.__init__ (   self)

Reimplemented from adctk.publisher.Publisher.

Reimplemented in adctk.ldms_publisher.LDMSSystemPublisher.

55 def __init__(self):
56 super().__init__()
57 self.plugin_prefix = "ADC_LDMSD_STREAM_PUBLISH_PLUGIN_"
58 self.defaults = _defaults_pipe
59 self.prog: str = None
60 self.port: str = None
61 self.auth: str = None
62 self.timeout: int = 2
63 self.stream: str = None
64 self.host: str = None
65

Member Function Documentation

◆ _post()

int adctk.ldms_publisher.LDMSPipePublisher._post (   self,
  msg 
)
protected

Reimplemented in adctk.ldms_publisher.LDMSSystemPublisher.

90 def _post(self, msg) ->int:
91 try:
92 cmd = [self.prog,
93 "-t", "json",
94 "-x", "sock",
95 "-p", self.port,
96 "-a", self.auth,
97 "-s", self.stream,
98 "-h", self.host
99 ]
100 log.logger.info("LDMSPipe-publisher command: %s", cmd)
101 process = subprocess.Popen(cmd, stdin=subprocess.PIPE,
102 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
103 text=True)
104 process.stdin.write(msg)
105 process.stdin.flush()
106 process.stdin.close()
107 stdout, stderr = process.communicate(timeout=self.timeout)
108 output_string = stdout.decode("utf-8")
109 error_string = stderr.decode("utf-8")
110 log.logger.debug("Output: %s Error: %s", output_string, error_string)
111 ret = process.returncode
112 if ret != 0:
113 log.logger.warning("LDMSPipe-publisher: publish process failed with error: %d",
114 ret)
115 except subprocess.TimeoutExpired:
116 process.kill()
117 stdout, stderr = process.communicate()
118 log.logger.warning("LDMSPipe-publisher: timeout expired")
119 return ret
120

◆ config()

int adctk.ldms_publisher.LDMSPipePublisher.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.publisher.Publisher.

Reimplemented in adctk.ldms_publisher.LDMSSystemPublisher.

66 def config(self, **kwargs) -> int:
67 self.prog = self._get(kwargs, "PROG")
68 self.port = self._get(kwargs, "PORT")
69 self.auth = self._get(kwargs, "AUTH")
70 self.stream = self._get(kwargs, "STREAM")
71 self.host = self._get(kwargs, "HOST")
72 timeout = self._get(kwargs, "TIMEOUT")
73 try:
74 x = int(timeout)
75 self.timeout = x
76 except ValueError:
77 log.logger.error("LDMSPipe-publisher TIMEOUT %s is invalid."\
78 " Integer needed from %s%s.", timeout, self.plugin_prefix, "TIMEOUT")
79 return 0
80

◆ finalize()

adctk.ldms_publisher.LDMSPipePublisher.finalize (   self)

Clean up any resources set up in initialize (files, pipes, etc).

Reimplemented from adctk.publisher.Publisher.

127 def finalize(self):
128 pass # nothing to do here. LDMSPipePublisher.finalize
129

◆ initialize()

int adctk.ldms_publisher.LDMSPipePublisher.initialize (   self)

Set up any resources needed for reuse in publish().

Reimplemented from adctk.publisher.Publisher.

81 def initialize(self) -> int:
82 if self.mode == publisher.Publisher.Mode.CONFIG:
83 self.config()
84 if self.mode != publisher.Publisher.Mode.INIT:
85 self.state = publisher.Publisher.State.ERR
86 return errno.EINVAL
87 self.mode = publisher.Publisher.Mode.PUB_OR_FINAL
88 return 0
89

◆ publish()

adctk.ldms_publisher.LDMSPipePublisher.publish (   self,
builder.Builder  b 
)
publish json extracted from builder to _base_url server

Reimplemented from adctk.publisher.Publisher.

121 def publish(self, b: builder.Builder):
122 """publish json extracted from builder to _base_url server"""
123 s = b.get_json_dump()
124 ret = self._post(s)
125 return ret
126

Member Data Documentation

◆ _name

str adctk.ldms_publisher.LDMSPipePublisher._name = "ldms-pipe-stream"
staticprotected

◆ _version

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

◆ auth

adctk.ldms_publisher.LDMSPipePublisher.auth

◆ defaults

adctk.ldms_publisher.LDMSPipePublisher.defaults

◆ host

adctk.ldms_publisher.LDMSPipePublisher.host

◆ mode

adctk.ldms_publisher.LDMSPipePublisher.mode

◆ plugin_prefix

adctk.ldms_publisher.LDMSPipePublisher.plugin_prefix

◆ port

adctk.ldms_publisher.LDMSPipePublisher.port

◆ prog

adctk.ldms_publisher.LDMSPipePublisher.prog

◆ state

adctk.ldms_publisher.LDMSPipePublisher.state

◆ stream

adctk.ldms_publisher.LDMSPipePublisher.stream

◆ timeout

adctk.ldms_publisher.LDMSPipePublisher.timeout

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