Merge "Included a documentation directory"
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..389a0b4
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,42 @@
+# Copyright 2017 Intel Research and Development Ireland Limited
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Intel Corporation
+
+# Licensed 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.
+
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: prithiv.mohan@intel.com or adrian.hoban@intel.com
+
+#__author__ = "Prithiv Mohan"
+#__date__   = "25/Sep/2017"
+
+FROM ubuntu:16.04
+RUN  apt-get update && \
+  DEBIAN_FRONTEND=noninteractive apt-get --yes install git tox make python python-pip debhelper && \
+  DEBIAN_FRONTEND=noninteractive apt-get --yes install wget python-dev python-software-properties python-stdeb&& \
+  DEBIAN_FRONTEND=noninteractive pip install -U pip && \
+  DEBIAN_FRONTENT=noninteractive pip install -U requests logutils jsonschema lxml && \
+  DEBIAN_FRONTEND=noninteractive pip install -U setuptools setuptools-version-command stdeb jsmin && \
+  DEBIAN_FRONTEND=noninteractive pip install -U six pyvcloud bottle cherrypy pyopenssl && \
+  DEBIAN_FRONTEND=noninteractive apt-get --yes install default-jre libmysqlclient-dev && \
+  DEBIAN_FRONTEND=noninteractive apt-get --yes install libmysqlclient-dev libxml2 && \
+  DEBIAN_FRONTEND=noninteractive pip install -U MySQL-python \
+                                                python-openstackclient \
+                                                python-keystoneclient \
+                                                aodhclient \
+                                                gnocchiclient \
+                                                boto==2.48 \
+                                                python-cloudwatchlogs-logging \
+                                                py-cloudwatch
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..f2e0417
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,32 @@
+properties([
+    parameters([
+        string(defaultValue: env.BRANCH_NAME, description: '', name: 'GERRIT_BRANCH'),
+        string(defaultValue: 'osm/MON', description: '', name: 'GERRIT_PROJECT'),
+        string(defaultValue: env.GERRIT_REFSPEC, description: '', name: 'GERRIT_REFSPEC'),
+        string(defaultValue: env.GERRIT_PATCHSET_REVISION, description: '', name: 'GERRIT_PATCHSET_REVISION'),
+        string(defaultValue: 'https://osm.etsi.org/gerrit', description: '', name: 'PROJECT_URL_PREFIX'),
+        booleanParam(defaultValue: false, description: '', name: 'TEST_INSTALL'),
+        string(defaultValue: 'artifactory-osm', description: '', name: 'ARTIFACTORY_SERVER'),
+    ])
+])
+
+def devops_checkout() {
+    dir('devops') {
+        git url: "${PROJECT_URL_PREFIX}/osm/devops", branch: params.GERRIT_BRANCH
+    }
+}
+
+node {
+    checkout scm
+    devops_checkout()
+
+    ci_helper = load "devops/jenkins/ci-pipelines/ci_stage_2.groovy"
+    ci_helper.ci_pipeline( 'MON',
+                           params.PROJECT_URL_PREFIX,
+                           params.GERRIT_PROJECT,
+                           params.GERRIT_BRANCH,
+                           params.GERRIT_REFSPEC,
+                           params.GERRIT_PATCHSET_REVISION,
+                           params.TEST_INSTALL,
+                           params.ARTIFACTORY_SERVER)
+}
diff --git a/Makefile b/Makefile
index af9afa7..491a83d 100644
--- a/Makefile
+++ b/Makefile
@@ -26,63 +26,57 @@
 all: package install
 
 clean_deb:
-        rm -rf .build
+	rm -rf .build
 
 clean:
-        rm -rf build
+	rm -rf build
 
 prepare:
-        pip install --upgrade setuptools
-        mkdir -p build/
-        VER1=$(shell git describe | sed -e 's/^v//' |cut -d- -f1); \
-        VER2=$(shell git describe | cut -d- -f2); \
-        VER3=$(shell git describe | cut -d- -f3); \
-        cp MANIFEST.in build/
-        cp requirements.txt build/
-        cp README.rst build/
-        cp stdeb.cfg build/
-        cp kafkad build/
-        cp -r core build/
-        cp -r plugins build/
-        cp -r devops_stages build/
-        cp -r test build/
-        cp setup.py build/
+	pip install --upgrade setuptools
+	mkdir -p build/
+	cp MANIFEST.in build/
+	cp requirements.txt build/
+	cp README.rst build/
+	cp stdeb.cfg build/
+	cp kafkad build/
+	cp -r core build/
+	cp -r plugins build/
+	cp -r devops_stages build/
+	cp -r test build/
+	cp -r scripts build/
+	cp setup.py build/
 
 build: clean openstack_plugins prepare
-        python -m py_compile build/plugins/OpenStack/*.py
+	python -m py_compile build/plugins/OpenStack/*.py
 
 build: clean vrops_plugins prepare
-        python -m py_compile build/plugins/vRealiseOps/*.py
+	python -m py_compile build/plugins/vRealiseOps/*.py
 
 build: clean cloudwatch_plugins prepare
-        python -m py_compile build/plugins/CloudWatch/*.py
+	python -m py_compile build/plugins/CloudWatch/*.py
 
 build: clean core prepare
-        python -m py_compile build/core/message_bus/*.py
+	python -m py_compile build/core/message_bus/*.py
 
 pip: prepare
-        cd build ./setup.py sdist
-        cd build ./plugin_setup.py sdist
+	cd build ./setup.py sdist
+	cd build ./plugin_setup.py sdist
 
 package: clean clean_deb prepare
-        apt-get --yes install python-software-properties \
-        python-pip \
-        python-stdeb \
-        libmysqlclient-dev \
-        libxml2 \
-        python-dev
-        cd build && python setup.py --command-packages=stdeb.command sdist_dsc --with-python2=True
-        cd build/deb_dist/* && dpkg-buildpackage -rfakeroot -uc -us
-        mkdir -p .build
-        cp build/deb_dist/python-*.deb .build/
-        pip install -r build/requirements.txt
+	cd build && python setup.py --command-packages=stdeb.command sdist_dsc --with-python2=True
+	cd build/deb_dist/* && dpkg-buildpackage -rfakeroot -uc -us
+	mkdir -p .build
+	cp build/deb_dist/python-*.deb .build/
 
 install:
-        DEBIAN_FRONTEND=noninteractive apt-get update && \
-        DEBIAN_FRONTEND=noninteractive apt-get install --yes python-pip && \
-        pip install --upgrade pip
+	DEBIAN_FRONTEND=noninteractive apt-get update && \
+	DEBIAN_FRONTEND=noninteractive apt-get install --yes python-pip && \
+	pip install --upgrade pip
         #dpkg -i build/deb_dist/*.deb
 
 develop: prepare
-        pip install -r requirements.txt
-        cd build && ./setup.py develop
+	pip install -r requirements.txt
+	cd build && ./setup.py develop
+
+build-docker-from-source:
+	docker build -t osm:MON -f docker/Dockerfile
\ No newline at end of file
diff --git a/core/kafka.service b/devops_stages/stage-archive.sh
similarity index 65%
copy from core/kafka.service
copy to devops_stages/stage-archive.sh
index f517811..8f6e11d 100644
--- a/core/kafka.service
+++ b/devops_stages/stage-archive.sh
@@ -19,21 +19,15 @@
 # For those usages not covered by the Apache License, Version 2.0 please
 # contact: prithiv.mohan@intel.com or adrian.hoban@intel.com
 
-[Unit]
-Description=Apache Kafka server (broker)
-Documentation=http://kafka.apache.org/documentation.html
-Requires=network.target remote-fs.target
-After=network.target remote-fs.target
+#__author__ = "Prithiv Mohan"
+#__date__   = "25/Sep/2017"
 
-[Service]
-Type=simple
-PIDFile=/var/run/kafka.pid
-#User=root
-#Group=kafka
-ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
-ExecStop=/opt/kafka/bin/kafka-server-stop.sh
-Restart=on-failure
-SyslogIdentifier=kafka
 
-[Install]
-WantedBy=multi-user.target
+#!/bin/sh
+rm -rf pool
+rm -rf dists
+mkdir -p pool/MON
+mv .build/*.deb pool/MON/
+mkdir -p dists/unstable/MON/binary-amd64/
+apt-ftparchive packages pool/MON > dists/unstable/MON/binary-amd64/Packages
+gzip -9fk dists/unstable/MON/binary-amd64/Packages
diff --git a/plugins/vRealiseOps/mon_plugin_vrops.py b/plugins/vRealiseOps/mon_plugin_vrops.py
index 986376b..309cec9 100644
--- a/plugins/vRealiseOps/mon_plugin_vrops.py
+++ b/plugins/vRealiseOps/mon_plugin_vrops.py
@@ -35,7 +35,7 @@
 from OpenSSL.crypto import load_certificate, FILETYPE_PEM
 import os
 import datetime
-from socket import gethostname
+from socket import getfqdn
 
 from requests.packages.urllib3.exceptions import InsecureRequestWarning
 requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
@@ -48,8 +48,8 @@
 #To Do - Add actual webhook url & certificate
 #SSL_CERTIFICATE_FILE_NAME = 'vROPs_Webservice/SSL_certificate/www.vrops_webservice.com.cert'
 #webhook_url = "https://mano-dev-1:8080/notify/" #for testing
-webhook_url = "https://" + gethostname() + ":8080/notify/"
-SSL_CERTIFICATE_FILE_NAME = ('vROPs_Webservice/SSL_certificate/' + gethostname() + ".cert")
+webhook_url = "https://" + getfqdn() + ":8080/notify/"
+SSL_CERTIFICATE_FILE_NAME = ('vROPs_Webservice/SSL_certificate/' + getfqdn() + ".cert")
 #SSL_CERTIFICATE_FILE_NAME = 'vROPs_Webservice/SSL_certificate/10.172.137.214.cert' #for testing
 
 MODULE_DIR = os.path.dirname(__file__)
diff --git a/plugins/vRealiseOps/vROPs_Webservice/install.sh b/plugins/vRealiseOps/vROPs_Webservice/install.sh
index 8cb7454..e81344b 100755
--- a/plugins/vRealiseOps/vROPs_Webservice/install.sh
+++ b/plugins/vRealiseOps/vROPs_Webservice/install.sh
@@ -23,10 +23,10 @@
 
 BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
 SSL_Cert_Dir="${BASEDIR}/SSL_certificate"
-THISHOST=$(hostname)
+THISHOST=$(hostname -f)
 Domain_Name="${THISHOST}"
 #Domain_Name="www.vrops_webservice.com"
-WebServiceFile='vrops_webservice.py'
+WebServiceFile="${BASEDIR}/vrops_webservice"
 
 echo '
  #################################################################
@@ -36,7 +36,7 @@
 #Function to install packages using apt-get
 function install_packages(){
       [ -x /usr/bin/apt-get ] && apt-get install -y $*
-       
+
        #check properly installed
        for PACKAGE in $*
        do
@@ -49,7 +49,7 @@
           fi
        done
    }
-  
+
 apt-get update  # To get the latest package lists
 
 [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-yaml python-bottle python-jsonschema python-requests libxml2-dev libxslt-dev python-dev python-pip openssl"
@@ -78,8 +78,9 @@
 
 nohup python "${WebServiceFile}" &
 
-echo '	
+echo '
  #################################################################
  #####              Done                                  #####
  #################################################################'
 
+
diff --git a/plugins/vRealiseOps/vROPs_Webservice/vrops_webservice b/plugins/vRealiseOps/vROPs_Webservice/vrops_webservice
index 547f4ff..98533f1 100755
--- a/plugins/vRealiseOps/vROPs_Webservice/vrops_webservice
+++ b/plugins/vRealiseOps/vROPs_Webservice/vrops_webservice
@@ -33,7 +33,7 @@
 
 from bottle import (ServerAdapter, route, run, server_names, redirect, default_app,
                      request, response, template, debug, TEMPLATE_PATH , static_file)
-from socket import gethostname
+from socket import getfqdn
 from datetime import datetime
 from xml.etree import ElementTree as ET
 import logging
@@ -55,8 +55,8 @@
 #Set Constants
 BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 CERT_DIR = os.path.join(BASE_DIR, "SSL_certificate")
-certificate_name = gethostname() + ".cert"
-key_name = gethostname() + ".key"
+certificate_name = getfqdn() + ".cert"
+key_name = getfqdn() + ".key"
 CERTIFICATE = os.path.join(CERT_DIR, certificate_name)
 KEY = os.path.join(CERT_DIR, key_name)
 #CERTIFICATE = os.path.join(CERT_DIR, "www.vrops_webservice.com.cert")
@@ -225,17 +225,18 @@
 
         try:
             server.start()
-            logger.info("Started vROPs Web Serverice")
+            logger.info("Started vROPs Web Service")
         except Exception as exp:
             server.stop()
-            logger.error("Exception: {} Stopped vROPs Web Serverice".format(exp))
+            logger.error("Exception: {} Stopped vROPs Web Service".format(exp))
 
 
 if __name__ == "__main__":
     #Start SSL Web Service
-    logger.info("Start vROPs Web Serverice")
+    logger.info("Start vROPs Web Service")
     app = default_app()
     server_names['sslwebserver'] = SSLWebServer
-    run(app=app,host=gethostname(), port=8080, server='sslwebserver')
+    run(app=app,host=getfqdn(), port=8080, server='sslwebserver')
+
 
 
diff --git a/requirements.txt b/requirements.txt
index 35f7137..d701122 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -19,6 +19,7 @@
 # For those usages not covered by the Apache License, Version 2.0 please
 # contact: prithiv.mohan@intel.com or adrian.hoban@intel.com
 
+stdeb
 MySQL-python
 lxml
 requests
diff --git a/core/kafka.service b/scripts/kafka.sh
similarity index 88%
rename from core/kafka.service
rename to scripts/kafka.sh
index f517811..fcdde67 100644
--- a/core/kafka.service
+++ b/scripts/kafka.sh
@@ -19,6 +19,8 @@
 # For those usages not covered by the Apache License, Version 2.0 please
 # contact: prithiv.mohan@intel.com or adrian.hoban@intel.com
 
+mkdir -p /etc/systemd/system/
+cat  > /etc/systemd/system/kafka.service  << EOF
 [Unit]
 Description=Apache Kafka server (broker)
 Documentation=http://kafka.apache.org/documentation.html
@@ -37,3 +39,7 @@
 
 [Install]
 WantedBy=multi-user.target
+EOF
+systemctl daemon-reload
+systemctl enable kafka.service
+systemctl start kafka.service
diff --git a/setup.py b/setup.py
index 01f6dea..f0e8f43 100644
--- a/setup.py
+++ b/setup.py
@@ -38,6 +38,7 @@
 _copyright = 'Intel Research and Development Ireland'
 _url = 'https://osm.etsi.org/gitweb/?p=osm/MON.git;a=tree'
 _requirements = [
+    "stdeb",
     "MySQL-python",
     "requests",
     "logutils",
@@ -76,7 +77,7 @@
       package_data = {_name: ['core/message_bus/*.py', 'core/models/*.json',
                       'plugins/OpenStack/Aodh/*.py', 'plugins/OpenStack/Gnocchi/*.py',
                       'plugins/vRealiseOps/*', 'plugins/CloudWatch/*']},
-      data_files = [('/etc/systemd/system/', ['core/kafka.service']),
+      data_files = [('/etc/systemd/system/', ['scripts/kafka.sh']),
                    ],
       scripts=['plugins/vRealiseOps/vROPs_Webservice/vrops_webservice',
                'kafkad'],