<commit_before>
module.exports = []

module.exports.push (ctx) ->
  require('./core').configure ctx
  ctx.config.hdp.pig_user ?= 'pig'
  ctx.config.hdp.pig_conf_dir ?= '/etc/pig/conf'

###
http://docs.hortonworks.com/HDPDocuments/HDP1/HDP-1.3.1/bk_installing_manually_book/content/rpm-chap5-1.html
###
module.exports.push name: 'HDP Pig # Install', timeout: -1, callback: (ctx, next) ->
  ctx.service
    name: 'pig'
  , (err, serviced) ->
    next err, if serviced then ctx.OK else ctx.PASS

module.exports.push name: 'HDP Pig # Users', callback: (ctx, next) ->
  {hadoop_group} = ctx.config.hdp
  ctx.execute
    cmd: "useradd pig -r -M -g #{hadoop_group} -s /bin/bash -c \"Used by Hadoop Pig service\""
    code: 0
    code_skipped: 9
  , (err, executed) ->
    next err, if executed then ctx.OK else ctx.PASS

module.exports.push name: 'HDP Pig # Configure', callback: (ctx, next) ->
  # Note, HDP default file comes without any config. We
  # could do the same, start with empty config object
  # that user could overwrite
  next null, ctx.PASS

module.exports.push name: 'HDP Pig # Env', callback: (ctx, next) ->
  {hadoop_group, pig_conf_dir, pig_user} = ctx.config.hdp
  ctx.render
    source: "#{__dirname}/files/pig/pig-env.sh"
    destination: "#{pig_conf_dir}/pig-env.sh"
    context: ctx
    local_source: true
    uid: pig_user
    gid: hadoop_group
    mode: 0o755
  , (err, rendered) ->
    next err, if rendered then ctx.OK else ctx.PASS

<commit_msg>Test pig<commit_after>
mkcmd = require './lib/mkcmd'

module.exports = []
module.exports.push 'histi/actions/nc'

module.exports.push (ctx) ->
  require('./hdfs').configure ctx
  require('../actions/nc').configure ctx
  ctx.config.hdp.pig_user ?= 'pig'
  ctx.config.hdp.pig_conf_dir ?= '/etc/pig/conf'

###
http://docs.hortonworks.com/HDPDocuments/HDP1/HDP-1.3.1/bk_installing_manually_book/content/rpm-chap5-1.html
###
module.exports.push name: 'HDP Pig # Install', timeout: -1, callback: (ctx, next) ->
  ctx.service
    name: 'pig'
  , (err, serviced) ->
    next err, if serviced then ctx.OK else ctx.PASS

module.exports.push name: 'HDP Pig # Users', callback: (ctx, next) ->
  # 6th feb 2014: pig user isnt created by YUM, might change in a future HDP release
  {hadoop_group} = ctx.config.hdp
  ctx.execute
    cmd: "useradd pig -r -M -g #{hadoop_group} -s /bin/bash -c \"Used by Hadoop Pig service\""
    code: 0
    code_skipped: 9
  , (err, executed) ->
    next err, if executed then ctx.OK else ctx.PASS

module.exports.push name: 'HDP Pig # Configure', callback: (ctx, next) ->
  # Note, HDP default file comes without any config. We
  # could do the same, start with empty config object
  # that user could overwrite
  next null, ctx.PASS

module.exports.push name: 'HDP Pig # Env', callback: (ctx, next) ->
  {hadoop_group, pig_conf_dir, pig_user} = ctx.config.hdp
  ctx.render
    source: "#{__dirname}/files/pig/pig-env.sh"
    destination: "#{pig_conf_dir}/pig-env.sh"
    context: ctx
    local_source: true
    uid: pig_user
    gid: hadoop_group
    mode: 0o755
  , (err, rendered) ->
    next err, if rendered then ctx.OK else ctx.PASS

module.exports.push name: 'HDP PIG # Check', callback: (ctx, next) ->
  rm = ctx.hosts_with_module 'histi/hdp/yarn_rm', 1
  ctx.waitForConnection rm, 8050, (err) ->
    return next err if err
    ctx.execute
      cmd: mkcmd.test ctx, """
      if hdfs dfs -test -d /user/test/pig_#{ctx.config.host}/result; then exit 2; fi
      hdfs dfs -rm -r /user/test/pig_#{ctx.config.host}
      hdfs dfs -mkdir -p /user/test/pig_#{ctx.config.host}
      echo -e 'a|1\\\\nb|2\\\\nc|3' | hdfs dfs -put - /user/test/pig_#{ctx.config.host}/data
      """
      code_skipped: 2
    , (err, executed) ->
      return next err, ctx.PASS if err or not executed
      ctx.write
        content: """
        data = LOAD '/user/test/pig_#{ctx.config.host}/data' USING PigStorage(',') AS (text, number);
        result = foreach data generate UPPER(text), number+2;
        STORE result INTO '/user/test/pig_#{ctx.config.host}/result' USING PigStorage(); 
        """
        destination: '/home/test/test.pig'
      , (err, written) ->
        return next err if err
        ctx.execute
          cmd: mkcmd.test ctx, """
          pig /home/test/test.pig
          rm -rf /home/test/test.pig
          hdfs dfs -test -d /user/test/pig_#{ctx.config.host}/result
          """
        , (err, executed) ->
          next err, ctx.OK


{'fraction_non_alphanumeric': 0.14707207207207207, 'fraction_numerical': 0.00945945945945946, 'mean_word_length': 2.818572656921754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '6763512', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1605, 'n_words': 427}