Sha256: 030cc7948bc1a3a03c29bf1ffa0c3dee1ed53258cc55bc45eac9d0ef6d1e2c45

Contents?: true

Size: 1.64 KB

Versions: 18

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

18 entries across 18 versions & 1 rubygems

Version Path
marty-14.3.0 lib/marty/diagnostic/nodes.rb
marty-14.0.0 lib/marty/diagnostic/nodes.rb
marty-13.0.2 lib/marty/diagnostic/nodes.rb
marty-11.0.0 lib/marty/diagnostic/nodes.rb
marty-10.0.3 lib/marty/diagnostic/nodes.rb
marty-10.0.2 lib/marty/diagnostic/nodes.rb
marty-10.0.0 lib/marty/diagnostic/nodes.rb
marty-9.5.1 lib/marty/diagnostic/nodes.rb
marty-9.5.0 lib/marty/diagnostic/nodes.rb
marty-9.3.3 lib/marty/diagnostic/nodes.rb
marty-9.3.2 lib/marty/diagnostic/nodes.rb
marty-9.3.0 lib/marty/diagnostic/nodes.rb
marty-8.5.0 lib/marty/diagnostic/nodes.rb
marty-8.4.1 lib/marty/diagnostic/nodes.rb
marty-8.3.1 lib/marty/diagnostic/nodes.rb
marty-8.2.0 lib/marty/diagnostic/nodes.rb
marty-8.0.0 lib/marty/diagnostic/nodes.rb
marty-6.1.0 lib/marty/diagnostic/nodes.rb