<commit_before>require 'sshkit/backends/netssh'

module Capistrano_karaf
  module Backend
    class SshProxy < SSHKit::Backend::Netssh

      @pool = SSHKit::Backend::ConnectionPool.new

      def capture(*args)
          karaf_role = fetch :karaf_role, :karaf
          if host.has_role? karaf_role
            
            karaf_username = fetch :karaf_username, "smx"
            karaf_password = fetch :karaf_password, "<PASSWORD>"
            karaf_port = fetch :karaf_port, "8101"

            args1 = ["sshpass", "-p", karaf_password, "ssh", "-o", "NoHostAuthenticationForLocalhost=yes", "#{karaf_username}@localhost", "-p", karaf_port].concat(args)
            options = { verbosity: Logger::DEBUG }.merge(args1.extract_options!)
            _execute(*[*args1, options]).full_stdout.strip
          else
            options = { verbosity: Logger::DEBUG }.merge(args.extract_options!)
            _execute(*[*args, options]).full_stdout.strip
          end
      end

      def execute(*args)
          karaf_role = fetch :karaf_role, :karaf
          if host.has_role? karaf_role

            karaf_username = fetch :karaf_username, "smx"
            karaf_password = fetch :karaf_password, "<PASSWORD>"
            karaf_port = fetch :karaf_port, "8101"

            args1 = ["sshpass", "-p", karaf_password, "ssh", "-o", "NoHostAuthenticationForLocalhost=yes", "#{karaf_username}@localhost", "-p", karaf_port].concat(args)
            _execute(*args1).success?
          else
            _execute(*args).success?<commit_msg>Retry a command 3 times if we get an exception<commit_after>require 'sshkit/backends/netssh'

module Capistrano_karaf
  module Backend
    class SshProxy < SSHKit::Backend::Netssh

      @pool = SSHKit::Backend::ConnectionPool.new

      def capture(*args)
          karaf_role = fetch :karaf_role, :karaf
          if host.has_role? karaf_role
            
            karaf_username = fetch :karaf_username, "smx"
            karaf_password = fetch :karaf_password, "<PASSWORD>"
            karaf_port = fetch :karaf_port, "8101"

            args1 = ["sshpass", "-p", karaf_password, "ssh", "-o", "NoHostAuthenticationForLocalhost=yes", "-o", "StrictHostKeyChecking=no", "#{karaf_username}@localhost", "-p", karaf_port].concat(args)
            options = { verbosity: Logger::DEBUG }.merge(args1.extract_options!)

            r = nil
            counter = 0
            ex = nil
            begin
                counter += 1
                begin
                    r = _execute(*[*args1, options])
                    ex = nil
                    break
                rescue SSHKit::Command::Failed => e
                    output << SSHKit::LogMessage.new(Logger::WARN, "Got exception while running command #{args1} on host #{host.hostname}")
                    ex = e
                end
            end while counter < 4

            raise ex unless ex.nil?
            r.full_stdout.strip
          else
            options = { verbosity: Logger::DEBUG }.merge(args.extract_options!)
            _execute(*[*args, options]).full_stdout.strip
          end
      end

      def execute(*args)
          karaf_role = fetch :karaf_role, :karaf
          if host.has_role? karaf_role

            karaf_username = fetch :karaf_username, "smx"
            karaf_password = fetch :karaf_password, "<PASSWORD>"
            karaf_port = fetch :karaf_port, "8101"

            args1 = ["sshpass", "-p", karaf_password, "ssh", "-o", "NoHostAuthenticationForLocalhost=yes", "-o", "StrictHostKeyChecking=no", "#{karaf_username}@localhost", "-p", karaf_port].concat(args)
            r = nil
            counter = 0
            ex = nil
            begin
                counter += 1
                begin
                    r = _execute(*args1)
                    ex = nil
                    break
                rescue SSHKit::Command::Failed => e
                    output << SSHKit::LogMessage.new(Logger::WARN, "Got exception while running command #{args1} on host #{host.hostname}")
                    ex = e
                end
            end while counter < 4
            
            raise ex unless ex.nil?            
            r.success?
          else
            _execute(*args).success?
{'fraction_non_alphanumeric': 0.1116870876531574, 'fraction_numerical': 0.00824693685202639, 'mean_word_length': 1.9175257731958764, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5704955', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1185, 'n_words': 274}