Added the deployment and initialization of base services required for
vOLT-HA. These are consul, zookeeper, and kafka. All services are
deployed in 3 member clusters. voltha is also started as a single
instance to demonstrate that it interacts with the consul cluster and
creates the keys in the KV store as expected.
Added updates to the documentation to ensure it's crystal clear how the
bare metal server needs to be set up.
This update continues to address VOL-6.

Change-Id: I909f2e70b117589ba7e119a9840a2c810a7991cb
diff --git a/install/ansible/group_vars/all b/install/ansible/group_vars/all
index e13d45f..28cd368 100644
--- a/install/ansible/group_vars/all
+++ b/install/ansible/group_vars/all
@@ -35,3 +35,4 @@
   - kamon/grafana_graphite
   - gliderlabs/registrator
   - centurylink/ca-certs
+  - zookeeper
diff --git a/install/ansible/roles/voltha/files/consul_config/base_config.json b/install/ansible/roles/voltha/files/consul_config/base_config.json
new file mode 100644
index 0000000..217fc09
--- /dev/null
+++ b/install/ansible/roles/voltha/files/consul_config/base_config.json
@@ -0,0 +1,9 @@
+{
+	"server": true,
+	"ui": true, 
+	"bootstrap_expect": 3,
+	"client_addr": "0.0.0.0",
+	"disable_update_check": true,
+	"retry_join": ["10.10.10.3", "10.10.10.4", "10.10.10.5"]
+}
+
diff --git a/install/ansible/roles/voltha/tasks/voltha.yml b/install/ansible/roles/voltha/tasks/voltha.yml
index a52b7d9..e55a018 100644
--- a/install/ansible/roles/voltha/tasks/voltha.yml
+++ b/install/ansible/roles/voltha/tasks/voltha.yml
@@ -60,6 +60,13 @@
   when: target == "cluster"

   tags: [voltha]

 

+- name: Configuration files are on the cluster host

+  copy:

+    src: "files/consul_config"

+    dest: "{{ target_voltha_dir }}"

+  when: target == "cluster"

+  tags: [voltha]

+

 - name: Docker containers for Voltha are pulled

   command: docker pull {{ docker_registry }}/{{ item }}

   with_items: "{{ voltha_containers }}"

@@ -70,11 +77,12 @@
   with_items: "{{ voltha_containers }}"

   when: target == "cluster"

   tags: [voltha]

-- name: Old docker image tags are removed

-  command: docker rmi {{ docker_registry }}/{{ item }}

-  with_items: "{{ voltha_containers }}"

-  when: target == "cluster"

-  tags: [voltha]

+#- name: Old docker image tags are removed

+#  command: docker rmi {{ docker_registry }}/{{ item }}

+#  with_items: "{{ voltha_containers }}"

+#  when: target == "cluster"

+#  tags: [voltha]

+

 

 # Update the insecure registry to reflect the current installer.

 # The installer name can change depending on whether test mode

@@ -115,3 +123,48 @@
   with_items: "{{ voltha_containers }}"

   when: target == "installer"

   tags: [voltha]

+

+- name: consul overlay network exists

+  command: docker network create --driver overlay --subnet 10.10.10.0/29 consul_net

+  when: target == "startup"

+  tags: [voltha]

+

+- name: kafka overlay network exists

+  command: docker network create --driver overlay --subnet 10.10.11.0/24 kafka_net

+  when: target == "startup"

+  tags: [voltha]

+

+- name: voltha overlay network exists

+  command: docker network create --driver overlay --subnet 10.10.12.0/24 voltha_net

+  when: target == "startup"

+  tags: [voltha]

+

+- name: consul cluster is running

+  command: docker service create --name consul --network consul_net --network voltha_net -e 'CONSUL_BIND_INTERFACE=eth0' --mode global --publish "8300:8300" --publish "8400:8400" --publish "8500:8500" --publish "8600:8600/udp" --mount type=bind,source=/cord/incubator/voltha/consul_config,destination=/consul/config consul agent -config-dir /consul/config

+  when: target == "startup"

+  tags: [voltha]

+

+- name: zookeeper node zk1 is running

+  command: docker service create --name zk1 --network kafka_net --network voltha_net -e 'ZOO_MY_ID=1' -e "ZOO_SERVERS=server.1=0.0.0.0:2888:3888 server.2=zk2:2888:3888 server.3=zk3:2888:3888" zookeeper

+  when: target == "startup"

+  tags: [voltha]

+

+- name: zookeeper node zk2 is running

+  command: docker service create --name zk2 --network kafka_net --network voltha_net -e 'ZOO_MY_ID=2' -e "server.1=zk1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zk3:2888:3888" zookeeper

+  when: target == "startup"

+  tags: [voltha]

+

+- name: zookeeper node zk3 is running

+  command: docker service create --name zk3 --network kafka_net --network voltha_net -e 'ZOO_MY_ID=3' -e "ZOO_SERVERS=server.1=zk1:2888:3888 server.2=zk2:2888:3888 server.3=0.0.0.0:2888:3888" zookeeper

+  when: target == "startup"

+  tags: [voltha]

+

+- name: kafka is running

+  command: docker service create --name kafka --network voltha_net  -e "KAFKA_ADVERTISED_PORT=9092" -e "KAFKA_ZOOKEEPER_CONNECT=zk1:2181,zk2:2181,zk3:2181" -e "KAFKA_HEAP_OPTS=-Xmx256M -Xms128M" --mode global --publish "9092:9092" wurstmeister/kafka

+  when: target == "startup"

+  tags: [voltha]

+

+- name: voltha is running on a single host for testing

+  command: docker service create --name voltha_core --network voltha_net cord/voltha voltha/voltha/main.py -v --consul=consul:8500 --kafka=kafka

+  when: target == "startup"

+  tags: [voltha]

diff --git a/install/ansible/swarm-master-backup.yml b/install/ansible/swarm-master-backup.yml
deleted file mode 100644
index 1e8eb3b..0000000
--- a/install/ansible/swarm-master-backup.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-- hosts: swarm-master-backup
-  remote_user: voltha
-  serial: 1
-  vars:
-    target: swarm-master-backup
-  roles:
-    - swarm
diff --git a/install/ansible/swarm-master.yml b/install/ansible/swarm-master.yml
deleted file mode 100644
index 2c956d2..0000000
--- a/install/ansible/swarm-master.yml
+++ /dev/null
@@ -1,7 +0,0 @@
-- hosts: swarm-master
-  remote_user: voltha
-  serial: 1
-  vars:
-    target: swarm-master
-  roles:
-    - swarm
diff --git a/install/ansible/swarm.yml b/install/ansible/swarm.yml
new file mode 100644
index 0000000..5ed7c8f
--- /dev/null
+++ b/install/ansible/swarm.yml
@@ -0,0 +1,14 @@
+- hosts: swarm-master
+  remote_user: voltha
+  serial: 1
+  vars:
+    target: swarm-master
+  roles:
+    - swarm
+- hosts: swarm-master-backup
+  remote_user: voltha
+  serial: 1
+  vars:
+    target: swarm-master-backup
+  roles:
+    - swarm
diff --git a/install/ansible/voltha.yml b/install/ansible/voltha.yml
index b9a2c24..8216c6b 100644
--- a/install/ansible/voltha.yml
+++ b/install/ansible/voltha.yml
@@ -9,4 +9,10 @@
     - docker
     - docker-compose
     - voltha
-#    - java
+- hosts: swarm-master
+  remote_user: voltha
+  serial: 1
+  vars:
+    target: startup
+  roles:
+    - voltha