Sha256: f5beae5b5f015caefc43ef032e897c36d9d3a3814d79c9db7fa503bfe27f8f8a

Contents?: true

Size: 1.64 KB

Versions: 17

Compression:

Stored size: 1.64 KB

Contents

require_relative 'aws/ec2_instance'

module Marty::Diagnostic; class Nodes < Base
  diagnostic_fn aggregatable: false do
    begin
      pg_nodes = Node.get_nodes.sort
    rescue StandardError => e
      next error(e.message)
    end

    next pg_nodes.join("\n") unless
      Marty::Diagnostic::Aws::Ec2Instance.is_aws?

    begin
      instance_data = Marty::Diagnostic::Aws::Ec2Instance.new
    rescue StandardError => e
      next error(pg_nodes.join("\n") +
                 "\nAws Communication Error: #{e.message}")
    end

    begin
      a_nodes = instance_data.nodes.sort
      next pg_nodes.join("\n") if a_nodes == pg_nodes

      # generate instance information when there is an issue
      # between aws and postgres
      instances = instance_data.instances
      { 'nodes' => error('There is a discrepancy between nodes connected to '\
                        "Postgres and those discovered through AWS EC2.\n"\
                        "Postgres: \n#{pg_nodes.join("\n")}\n"\
                        "AWS: \n#{a_nodes.join("\n")}"),
       'pending'       => error_if(instances.pending),
       'running'       => valid_if(instances.running),
       'shutting_down' => error_if(instances.shutting_down),
       'terminated'    => error_if(instances.terminated),
       'stopping'      => error_if(instances.stopping),
       'stopped'       => error_if(instances.stopped),
      }.delete_if { |k, v| v.empty? }
    rescue StandardError => e
      error(e.message)
    end
  end

  def self.valid_if arr
    return arr.join("\n") unless arr.empty?

    error('---')
  end

  def self.error_if arr
    return arr if arr.empty?

    error(arr.join("\n"))
  end
end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
marty-2.7.1 other/marty/diagnostic/nodes.rb
marty-2.7.0 other/marty/diagnostic/nodes.rb
marty-2.6.8 other/marty/diagnostic/nodes.rb
marty-2.6.7 other/marty/diagnostic/nodes.rb
marty-2.6.6 other/marty/diagnostic/nodes.rb
marty-2.6.5 other/marty/diagnostic/nodes.rb
marty-2.6.4 other/marty/diagnostic/nodes.rb
marty-2.6.3 other/marty/diagnostic/nodes.rb
marty-2.6.2 other/marty/diagnostic/nodes.rb
marty-2.6.1 other/marty/diagnostic/nodes.rb
marty-2.6.0 other/marty/diagnostic/nodes.rb
marty-2.5.9 other/marty/diagnostic/nodes.rb
marty-2.5.8 other/marty/diagnostic/nodes.rb
marty-2.5.7 other/marty/diagnostic/nodes.rb
marty-2.5.6 other/marty/diagnostic/nodes.rb
marty-2.5.5 other/marty/diagnostic/nodes.rb
marty-2.5.4 other/marty/diagnostic/nodes.rb