Class: HybridPlatformsConductor::Connector

Inherits:
Plugin
  • Object
show all
Defined in:
lib/hybrid_platforms_conductor/connector.rb

Overview

Base class for any connector

Constant Summary

Constants included from LoggerHelpers

LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR

Instance Method Summary collapse

Methods inherited from Plugin

extend_config_dsl_with, valid?

Methods included from LoggerHelpers

#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar

Constructor Details

#initialize(logger: Logger.new(STDOUT), logger_stderr: Logger.new(STDERR), config: Config.new, cmd_runner: CmdRunner.new, nodes_handler: NodesHandler.new) ⇒ Connector

Constructor

Parameters
  • logger (Logger): Logger to be used [default: Logger.new(STDOUT)]

  • logger_stderr (Logger): Logger to be used for stderr [default: Logger.new(STDERR)]

  • config (Config): Config to be used. [default: Config.new]

  • cmd_runner (CmdRunner): Command executor to be used. [default: CmdRunner.new]

  • nodes_handler (NodesHandler): NodesHandler to be used. [default: NodesHandler.new]



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hybrid_platforms_conductor/connector.rb', line 17

def initialize(
  logger: Logger.new(STDOUT),
  logger_stderr: Logger.new(STDERR),
  config: Config.new,
  cmd_runner: CmdRunner.new,
  nodes_handler: NodesHandler.new
)
  super(logger: logger, logger_stderr: logger_stderr, config: config)
  @cmd_runner = cmd_runner
  @nodes_handler = nodes_handler
  # If the connector has an initializer, use it
  init if respond_to?(:init)
end

Instance Method Details

#prepare_for(node, timeout, stdout_io, stderr_io) ⇒ Object

Prepare a connector to be run for a given node in a given context. It is required to call this method before using the following methods:

  • remote_bash

  • run_cmd

Paramaters
  • node (String): The node this connector is currently targeting

  • timeout (Integer or nil): Timeout this connector’s process should have (in seconds), or nil if none

  • stdout_io (IO): IO to log stdout to

  • stderr_io (IO): IO to log stderr to



41
42
43
44
45
46
# File 'lib/hybrid_platforms_conductor/connector.rb', line 41

def prepare_for(node, timeout, stdout_io, stderr_io)
  @node = node
  @timeout = timeout
  @stdout_io = stdout_io
  @stderr_io = stderr_io
end

#with_connection_to(nodes, no_exception: false) {|nodes| ... } ⇒ Object

Prepare connections to a given set of nodes. Useful to prefetch metadata or open bulk connections.

Parameters
  • nodes (Array<String>): Nodes to prepare the connection to

  • no_exception (Boolean): Should we still continue if some nodes have connection errors? [default: false]

  • Proc: Code called with the connections prepared.

    • Parameters
      • connected_nodes (Array<String>): The list of connected nodes (should be equal to nodes unless no_exception == true and some nodes failed to connect)

Yields:

  • (nodes)


57
58
59
# File 'lib/hybrid_platforms_conductor/connector.rb', line 57

def with_connection_to(nodes, no_exception: false)
  yield nodes
end