# NEO: data deduplication must be enabled

[buildout]
extends =
  ../../component/gnupg/buildout.cfg
  test-fluentd-common.cfg

[template-erp5-patched]
extra =
  [request-balancer]
  config-inituser-login = {{ dumps(inituser_login) }}
  config-inituser-password = $${publish-early:inituser-password}

[template-balancer]
recipe =
target = ${template-balancer-patched:location}

[template-balancer-base]
<= template-balancer
recipe = slapos.recipe.build:download

[template-balancer-patched]
<= template-fluentd
base = ${template-balancer-base:target}
method = raw_lf
tags =
  {%- set port, backend_list = haproxy_dict['fluentd'] %}
  {%- for i in range(len(backend_list)) %}
  {%-   do tags.__setitem__('wendelin_tag_' ~ i, ipv4 ~ ':' ~ port) %}
  {%- endfor %}

[data.gpg]
recipe = slapos.recipe.build:download
url = http://download.shacache.org/0f56a59ab3bc3193e70c1996fe69260e1b225bc53bbb7509cb3ae036006653dec69b3384cd624eefed81c85e692e4b4b7cb3d25c6244c298070569dddf7216b1
md5sum = 374e00dfbd28f27819ccfff31d169c9c

[gpg-decrypt]
recipe = slapos.recipe.build
gpg = ${gnupg:location}/bin/gpg
install =
  import subprocess
  args = (options['gpg'], '-d', '--batch', '--passphrase-fd', '0',
          '-o', location, options['input'])
  p = subprocess.Popen(args, stdin=subprocess.PIPE)
  p.communicate(options['password'])
  retcode = p.poll()
  if retcode:
    raise subprocess.CalledProcessError(retcode, ' '.join(args))

[data]
<= gpg-decrypt
location = ${data.gpg:location}/data.log
input = ${data.gpg:target}

[feeder]
feeder =
  #
    import mmap, os, random
    data = mmap.mmap(os.open('${data:location}', os.O_RDONLY),
                     0, prot=mmap.PROT_READ)
    size = 1024 * 1024
    max_seek = len(data) - size
    while True:
      a = random.randint(0, max_seek)
      a = {'data': data[a:a+size]}
      for i in xrange(20):
        emit('', a)
        time.sleep(interval)
