Sha256: ea6b50485fc1d63c07265d5940af1e4bf05781dea93efd39b5d0b58562312041

Contents?: true

Size: 1.63 KB

Versions: 14

Compression:

Stored size: 1.63 KB

Contents

require 'yajl'

module Logical::Naf
  module LogParser
    class Machine < Base

      def initialize(params)
        super(params)
      end

      def logs
        retrieve_logs
      end

      private

      def insert_log_line(elem)
        "&nbsp;&nbsp;<span>#{elem['output_time']} <font color='333399'><b>jid(#{elem['job_id']}):</b></font> #{elem['message']}</br></span>"
      end

      def sort_jsons
        # Sort log lines based on timestamp
        @jsons = jsons.sort { |x, y| Time.parse(x['output_time']) <=> Time.parse(y['output_time']) }
      end

      def parse_newest_log
        if newest_log.scan(/jid\(\d*\)\: /).present?
          newest_log.slice!(/jid\(\d*\)\: /)
        end
        newest_log
      end

      def retrieve_log_files_from_s3
        s3_log_reader.log_files
      end

      def get_files
        if log_type == 'old' && read_from_s3 == 'true'
          get_s3_files do
            @s3_log_reader = ::Logical::Naf::LogReader.new
            return retrieve_log_files_from_s3
          end
        else
          files = Dir["#{::Naf::PREFIX_PATH}/#{::Naf.schema_name}/jobs/*/*"]
          if files.present?
            # Sort log files based on time
            return files.sort { |x, y| Time.parse(y.scan(DATE_REGEX)[0][0]) <=> Time.parse(x.scan(DATE_REGEX)[0][0]) }
          else
            get_s3_files do
              @read_from_s3 = 'true'
              @s3_log_reader = ::Logical::Naf::LogReader.new
              return retrieve_log_files_from_s3
            end
          end
        end
      end

      def get_job_id(file)
        file.scan(/\d+_\d{8}/).first.split('_').first
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
naf-2.1.9 app/models/logical/naf/log_parser/machine.rb
naf-2.1.8 app/models/logical/naf/log_parser/machine.rb
naf-2.1.6 app/models/logical/naf/log_parser/machine.rb
naf-2.1.5 app/models/logical/naf/log_parser/machine.rb
naf-2.1.4 app/models/logical/naf/log_parser/machine.rb
naf-2.1.3 app/models/logical/naf/log_parser/machine.rb
naf-2.1.2 app/models/logical/naf/log_parser/machine.rb
naf-2.1.1 app/models/logical/naf/log_parser/machine.rb
naf-2.1.0 app/models/logical/naf/log_parser/machine.rb
naf-2.0.4 app/models/logical/naf/log_parser/machine.rb
naf-2.0.3 app/models/logical/naf/log_parser/machine.rb
naf-2.0.2 app/models/logical/naf/log_parser/machine.rb
naf-2.0.1 app/models/logical/naf/log_parser/machine.rb
naf-2.0.0 app/models/logical/naf/log_parser/machine.rb