MYRIAD-267 Mount local Myriad development folder into build VM

In order to make easier the development, an improvement is
mount the local (laptop) development repository of Myriad
into the "build" VM. So you can edit out of the VM and you
get the build output within the VM for using it.

JIRA:
    [MYRIAD-267] https://issues.apache.org/jira/browse/MYRIAD-267

Pull Request:
    Closes #112

Author:    Javi Roman <jroman.espinar@gmail.com>
Date:      Wed Jun 6 15:40:59 2018 +0200
diff --git a/vagrant/libvirt/mesos/README.md b/vagrant/libvirt/mesos/README.md
index 02d6584..a2939d2 100644
--- a/vagrant/libvirt/mesos/README.md
+++ b/vagrant/libvirt/mesos/README.md
@@ -232,14 +232,44 @@
 
 http://100.0.10.101:8192
 
+# Export local repository to VM environment
+
+For an useful development environment, we can sync a local folder into the VM
+named "build". We can export our Myriad local repository by means of the following
+environment variable:
+
+export MYRIAD_SOURCES=/home/user/incubator-myriad
+
+This folder will be mounted (NFS mount) from the host machine to the guest
+machine ("build" VM in our case).
+
+Vagrant has built-in support to orchestrate the configuration of the NFS server
+on the host and guest for you.
+
+Before using synced folders backed by NFS, the host machine must have NFS
+server installed. The following an example for a RPM based machine:
+
+```
+sudo yum install nfs-utils libnfsidmap
+
+sudo systemctl enable rpcbind
+sudo systemctl enable nfs-server
+
+sudo systemctl start rpcbind
+sudo systemctl start nfs-server
+sudo systemctl start rpc-statd
+sudo systemctl start nfs-idmapd
+
+sudo firewall-cmd --permanent --add-service=nfs
+sudo firewall-cmd --permanent --add-service=mountd
+sudo firewall-cmd --permanent --add-service=rpc-bind
+sudo firewall-cmd --reload
+
+sudo firewall-cmd --list-all
+```
+
 # Happy Hacking
 
 At this point you have a local development environment ready for Myriad
 Framework hacking!
 
-
-
-
-
-
-
diff --git a/vagrant/libvirt/mesos/Vagrantfile b/vagrant/libvirt/mesos/Vagrantfile
index c5cc2af..e9e8eaf 100644
--- a/vagrant/libvirt/mesos/Vagrantfile
+++ b/vagrant/libvirt/mesos/Vagrantfile
@@ -56,8 +56,6 @@
 end
 
 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
-  # Disabling the default /vagrant share
-  config.vm.synced_folder ".", "/vagrant", disabled: true
   config.ssh.insert_key = false
 
   i = 0
@@ -66,6 +64,15 @@
     config.vm.define servers["name"] do |node|
       node.vm.box = servers["box"]
       node.vm.hostname = servers["name"]
+
+      if node.vm.hostname == 'build' && !ENV['MYRIAD_SOURCES'].nil?
+        node.vm.synced_folder ENV['MYRIAD_SOURCES'], "/mnt", type:"nfs",
+            linux__nfs_options: ['rw','no_subtree_check','no_root_squash','async'],
+            nfs_udp: false
+      else
+        config.vm.synced_folder ".", "/vagrant", disabled: true
+      end
+
       node.vm.network "private_network", ip: servers["ip"]
       node.vm.provider :libvirt do |domain|
         domain.uri = 'qemu+unix:///system'
diff --git a/vagrant/libvirt/mesos/check-env.sh b/vagrant/libvirt/mesos/check-env.sh
index c51ae75..23f32e9 100644
--- a/vagrant/libvirt/mesos/check-env.sh
+++ b/vagrant/libvirt/mesos/check-env.sh
@@ -23,6 +23,7 @@
 [ -z $MESOS_ARCH ] || echo "- MESOS_ARCH: $MESOS_ARCH"
 [ -z $HADOOP_VERSION ] || echo "- HADOOP_VERSION: $HADOOP_VERSION"
 [ -z $ZOOKEEPER_VERSION ] || echo "- ZOOKEEPER_VERSION: $ZOOKEEPER_VERSION"
+[ -z $MYRIAD_SOURCES ] || echo "- MYRIAD_SOURCES: $MYRIAD_SOURCES"
 
 echo
 echo "'vagrant up --provider=libvirt' and happy hacking!"
diff --git a/vagrant/libvirt/mesos/provisioning/group_vars/all/defaults.yml b/vagrant/libvirt/mesos/provisioning/group_vars/all/defaults.yml
index a509c11..aa3b06e 100644
--- a/vagrant/libvirt/mesos/provisioning/group_vars/all/defaults.yml
+++ b/vagrant/libvirt/mesos/provisioning/group_vars/all/defaults.yml
@@ -93,6 +93,7 @@
 hadoop_logs_folder: "{{ nfs_shared_folder }}/hadoop/logs"
 hadoop_etc_folder: "{{ nfs_shared_folder }}/hadoop/etc/hadoop"
 
+with_local_sources: "{{ lookup('env','MYRIAD_SOURCES') }}"
 
 
 
diff --git a/vagrant/libvirt/mesos/provisioning/roles/devel/tasks/main.yml b/vagrant/libvirt/mesos/provisioning/roles/devel/tasks/main.yml
index 67bfc8e..9aa3a62 100644
--- a/vagrant/libvirt/mesos/provisioning/roles/devel/tasks/main.yml
+++ b/vagrant/libvirt/mesos/provisioning/roles/devel/tasks/main.yml
@@ -45,6 +45,14 @@
     dest: "{{ nfs_shared_folder }}/{{ myriad_cloned_folder }}"
     version: "{{ myriad_repo_branch }}"
     update: no
+  when: with_local_sources | trim == ''
+
+- name: Apache Myriad repo
+  file:
+    src: "/mnt"
+    dest: "/opt/myriad"
+    state: link
+  when: with_local_sources | trim != ''
 
 - name: Copy exports file.
   template:
diff --git a/vagrant/libvirt/mesos/setup-env b/vagrant/libvirt/mesos/setup-env
index d17d2a7..b42d34c 100644
--- a/vagrant/libvirt/mesos/setup-env
+++ b/vagrant/libvirt/mesos/setup-env
@@ -19,5 +19,6 @@
 export MESOS_ARCH=1m4a
 export HADOOP_VERSION=2.7.0
 export ZOOKEEPER_VERSION=3.4.11
+# export MYRIAD_SOURCES=/home/user/incubator-myriad/
 
 sh check-env.sh