#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

- name: "install accumulo from tarball"
  unarchive: src={{ tarballs_dir }}/{{ accumulo_tarball }} dest={{ install_dir }} creates={{ accumulo_home }} copy=yes
- name: "copy default accumulo configuration"
  command: cp {{ accumulo_home }}/conf/templates/{{ item }} {{ accumulo_home }}/conf/ creates={{ accumulo_home }}/conf/{{ item }}
  with_items:
    - auditLog.xml
    - generic_logger.xml
    - monitor_logger.xml
    - log4j.properties
  when: accumulo_major_version == '1'
- name: "configure accumulo 1.0 configuration"
  template: src={{ item }} dest={{ accumulo_home }}/conf/{{ item }}
  with_items:
    - accumulo-env.sh
    - accumulo-site.xml
    - client.conf
    - gc
    - tracers
    - masters
    - monitor
  when: accumulo_major_version == '1'
- name: "configure tservers using managed templates"
  template: src=tservers dest={{ accumulo_home }}/conf/slaves
  when: accumulo_major_version == '1'
- name: "configure accumulo 2.0.X configuration"
  template: src={{ item }} dest={{ accumulo_home }}/conf/{{ item }}
  with_items:
    - accumulo-env.sh
    - accumulo.properties
    - accumulo-client.properties
    - gc
    - masters
    - monitor
    - tracers
    - tservers
  when: accumulo_version is version('2.0.0','>=') and accumulo_version is version('2.1.0','<')
- name: "configure accumulo >= 2.1.0 configuration"
  template: src={{ item }} dest={{ accumulo_home }}/conf/{{ item }}
  with_items:
    - accumulo-env.sh
    - accumulo.properties
    - accumulo-client.properties
    - cluster.yaml
  when: accumulo_version is version('2.1.0','>=')
- name: "configure accumulo 2.0.0 logging"
  command: cp {{ accumulo_home }}/conf/templates/{{ item }} {{ accumulo_home }}/conf/ creates={{ accumulo_home }}/conf/{{ item }}
  with_items:
    - log4j-service.properties
  when: accumulo_version is version('2.0.0','>=') and accumulo_version is version('2.1.0','<')
- name: "configure accumulo >= 2.1.0 logging"
  command: cp {{ accumulo_home }}/conf/templates/{{ item }} {{ accumulo_home }}/conf/ creates={{ accumulo_home }}/conf/{{ item }}
  with_items:
    - log4j2.properties
    - log4j2-service.properties
  when: accumulo_version is version('2.1.0','>=')
- name: "configure accumulo to send metrics (if metrics server exists)"
  template: src={{ item }} dest={{ accumulo_home }}/conf/{{ item }}
  with_items:
    - hadoop-metrics2-accumulo.properties
  when: "'metrics' in groups"
- name: "build accumulo native libraries"
  command: "{{ accumulo_build_native_cmd[accumulo_major_version] }}"
  args:
    creates: "{{ accumulo_home }}/lib/native/libaccumulo.so"
- name: "Create accumulo log dir"
  file: path={{ worker_data_dirs[0] }}/logs/accumulo state=directory
- name: "Copy the modified accumulo-cluster script that supports systemd to bin"
  template: src=accumulo-cluster-systemd dest={{ accumulo_home }}/bin/accumulo-cluster-systemd mode=0755
  when: use_systemd
- name: "Remove the existing accumulo-service and accumulo-cluster scripts"
  file: path={{ accumulo_home }}/bin/{{ item }} state=absent
  with_items:
    - accumulo-service
    - accumulo-cluster
  when: use_systemd
- name: "Create a symlink for accumulo-cluster-systemd"
  file: src={{ accumulo_home }}/bin/accumulo-cluster-systemd dest={{ accumulo_home }}/bin/accumulo-cluster mode=0755 state=link
  when: use_systemd
