libraries/helpers.rb
# Checks against the current gerrit version
#
# @return [Boolean]
Checks against the current gerrit version
Checks against the current gerrit version
def run_gsql (sql)
      war_path = "#{node['gerrit']['home']}/war/gerrit-#{node['gerrit']['version']}.war"
      cmd = "java -jar #{war_path} gsql --format JSON -c '#{sql}' -d #{node['gerrit']['install_dir']}"
      sql_shell = Mixlib::ShellOut.new(cmd, :user => node['gerrit']['user'], :cwd => "#{node['gerrit']['home']}/war")
      sql_shell.run_command
      if sql_shell.error?
        msg = "Gerrit::Helpers.run_gsql('#{sql}' execution error"
        sql_shell.invalid!(msg)
      end
      lines = sql_shell.stdout.split("\n")
      result = Array.new
      lines.each do |line|
        parsed = JSON.parse(line)
        if parsed && parsed['type'] == 'error'
          raise "Gerrt::Helpers.run_gsql('#{sql}') failed #{parsed}"
        elsif parsed && parsed['type'] == 'row'
          result.push(parsed['columns'])
        elsif parsed && parsed['type'] == 'query-stats' || parsed['type'] == 'update-stats'
        else
          msg = "unknown json type attribute in result '#{parsed}'"
          raise "Gerrit::Helpers.run_gsql('#{sql}') #{msg}"
        end
      end
      return result
    end
def run_gsql ( sql ) war_path = "#{node['gerrit']['home']}/war/gerrit-#{node['gerrit']['version']}.war" cmd = "java -jar #{war_path} gsql --format JSON -c '#{sql}' -d #{node['gerrit']['install_dir']}" sql_shell = Mixlib :: ShellOut . new ( cmd , :user => node [ 'gerrit' ] [ 'user' ] , :cwd => "#{node['gerrit']['home']}/war" ) sql_shell . run_command if sql_shell . error? msg = "Gerrit::Helpers.run_gsql('#{sql}' execution error" sql_shell . invalid! ( msg ) end lines = sql_shell . stdout . split ( "\n" ) result = Array . new lines . each do | line | parsed = JSON . parse ( line ) if parsed && parsed [ 'type' ] == 'error' raise "Gerrt::Helpers.run_gsql('#{sql}') failed #{parsed}" elsif parsed && parsed [ 'type' ] == 'row' result . push ( parsed [ 'columns' ] ) elsif parsed && parsed [ 'type' ] == 'query-stats' || parsed [ 'type' ] == 'update-stats' else msg = "unknown json type attribute in result '#{parsed}'" raise "Gerrit::Helpers.run_gsql('#{sql}') #{msg}" end end return result end
Checks against the current gerrit version
Checks against the current gerrit version
#raise msg # gerrit gsql returns *two* jsons separated by newline in case of success, first line is sufficient for us # ignore query-stats
None
Boolean
sql
<not_specific>