Sha256: 830bf19652322edd1a463a6c6bffc839676a61340c876a91dbd1d1eb6f1aedcb

Contents?: true

Size: 1.64 KB

Versions: 16

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

16 entries across 16 versions & 1 rubygems

Version Path
marty-5.2.0 other/marty/diagnostic/nodes.rb
marty-5.1.4 other/marty/diagnostic/nodes.rb
marty-5.1.3 other/marty/diagnostic/nodes.rb
marty-5.1.2 other/marty/diagnostic/nodes.rb
marty-5.1.1 other/marty/diagnostic/nodes.rb
marty-5.1.0 other/marty/diagnostic/nodes.rb
marty-3.1.0 other/marty/diagnostic/nodes.rb
marty-3.0.1 other/marty/diagnostic/nodes.rb
marty-4.0.0.rc2 other/marty/diagnostic/nodes.rb
marty-3.0.0 other/marty/diagnostic/nodes.rb
marty-2.9.3 other/marty/diagnostic/nodes.rb
marty-2.9.2 other/marty/diagnostic/nodes.rb
marty-2.9.1 other/marty/diagnostic/nodes.rb
marty-2.8.0 other/marty/diagnostic/nodes.rb
marty-2.7.3 other/marty/diagnostic/nodes.rb
marty-2.7.2 other/marty/diagnostic/nodes.rb