CORD-782: monitoring service support for external analytics apps

Change-Id: I81a850642b19340d6bd7fb9528e936d7ab6e6e82
diff --git a/xos/test/deploy_auto_scale_app.yaml b/xos/test/deploy_auto_scale_app.yaml
new file mode 100644
index 0000000..53258fd
--- /dev/null
+++ b/xos/test/deploy_auto_scale_app.yaml
@@ -0,0 +1,30 @@
+---
+- hosts: "{{ hosts }}"
+
+  tasks:
+    - name: install pip and related packages
+      apt: name="{{ item }}" state=present update-cache=yes
+      become: yes
+      with_items:
+        - python-pip
+        - python-dev
+        - build-essential
+        - git
+        - msgpack-python
+
+    - name: install python packages
+      pip: name="{{ item }}" state=present
+      become: yes
+      with_items:
+        - virtualenv
+        - Flask
+        - kafka-python
+        - oslo.utils
+        - Babel
+
+    - name: create clone directory
+      file: path=~/auto-scale2 state=directory
+
+    - name: clone auto-scale repo
+      git: repo=https://gerrit.opencord.org/xos-external-app-examples dest=~/auto-scale2
+
diff --git a/xos/test/kill-mon.py b/xos/test/kill-mon.py
new file mode 100644
index 0000000..0287ac8
--- /dev/null
+++ b/xos/test/kill-mon.py
@@ -0,0 +1,18 @@
+import os
+import sys
+sys.path.append("/opt/xos")
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
+import django
+from core.models import *
+#from services.exampleservice.models import *
+from services.monitoring.models import *
+django.setup()
+
+for o in CeilometerService.get_service_objects().all():
+   print "Delete", o
+   o.delete()
+
+print "wait for perma-deletion"
+
+while MonitoringChannel.deleted_objects.all().exists() or CeilometerService.deleted_objects.all().exists():
+    pass
diff --git a/xos/test/monitoring_in_loop.sh b/xos/test/monitoring_in_loop.sh
new file mode 100755
index 0000000..d35e545
--- /dev/null
+++ b/xos/test/monitoring_in_loop.sh
@@ -0,0 +1,10 @@
+while [[ 1 ]]; do
+    make cord-monitoringservice
+    if [[ $? -ne 0 ]]; then
+       echo "fail!"
+       exit
+    fi
+    docker cp kill-mon.py cordpod_xos_ui_1:/opt/xos/
+    sudo docker exec -it cordpod_xos_ui_1 python /opt/xos/kill-mon.py
+    sleep 10s
+done
diff --git a/xos/test/monitoringservice_analytics.yaml b/xos/test/monitoringservice_analytics.yaml
new file mode 100644
index 0000000..627c1be
--- /dev/null
+++ b/xos/test/monitoringservice_analytics.yaml
@@ -0,0 +1,114 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Setup Slice for analytics applications.
+
+imports:
+   - custom_types/xos.yaml
+   - custom_types/monitoring_tosca_types.yaml
+
+topology_template:
+  node_templates:
+    service_ceilometer:
+      type: tosca.nodes.CeilometerService
+      properties:
+          no-create: true
+          no-update: true
+          no-delete: true
+
+    service_analytics:
+      type: tosca.nodes.Service
+      requirements:
+          - monitoring_tenant:
+              node: service_ceilometer
+              relationship: tosca.relationships.TenantOfService
+      properties:
+          kind: analytics
+
+# private network template, created in fixtures.yml
+    Private:
+      type: tosca.nodes.NetworkTemplate
+
+# site, fully created in deployment.yaml
+    mysite:
+      type: tosca.nodes.Site
+
+    trusty-server-multi-nic:
+      type: tosca.nodes.Image
+
+    m1.small:
+      type: tosca.nodes.Flavor
+
+# management network, fully created in management-net.yaml
+    management:
+      type: tosca.nodes.network.Network.XOS
+      properties:
+        no-create: true
+        no-delete: true
+        no-update: true
+
+# public network, fully created in public-net.yaml
+    public:
+      type: tosca.nodes.network.Network.XOS
+      properties:
+        no-create: true
+        no-delete: true
+        no-update: true
+
+    analytics_app_network:
+      type: tosca.nodes.network.Network.XOS
+      properties:
+          ip_version: 4
+          labels: analytics_app_private_network
+      requirements:
+          - network_template:
+              node: Private
+              relationship: tosca.relationships.UsesNetworkTemplate
+          - owner:
+              node: mysite_analytics
+              relationship: tosca.relationships.MemberOfSlice
+          - connection:
+              node: mysite_analytics
+              relationship: tosca.relationships.ConnectsToSlice
+
+    mysite_analytics:
+      type: tosca.nodes.Slice
+      properties:
+          network: noauto
+      requirements:
+          - service:
+              node: service_analytics
+              relationship: tosca.relationships.MemberOfService
+          - site:
+              node: mysite
+              relationship: tosca.relationships.MemberOfSite
+          - management:
+              node: management
+              relationship: tosca.relationships.ConnectsToNetwork
+          - public:
+              node: public
+              relationship: tosca.relationships.ConnectsToNetwork
+          - default_image:
+                node: trusty-server-multi-nic
+                relationship: tosca.relationships.DefaultImage
+          - m1.small:
+              node: m1.small
+              relationship: tosca.relationships.DefaultFlavor
+
+    # Virtual machines
+    auto_scale_virtual_machine:
+      type: tosca.nodes.Compute
+      capabilities:
+        # Host container properties
+        host:
+         properties:
+           num_cpus: 1
+           disk_size: 20 GB
+           mem_size: 2 GB
+      requirements:
+          - slice:
+                node: mysite_analytics
+                relationship: tosca.relationships.MemberOfSlice
+          - image:
+                node: trusty-server-multi-nic
+                relationship: tosca.relationships.UsesImage
+
diff --git a/xos/test/service_for_scale.yaml b/xos/test/service_for_scale.yaml
new file mode 100644
index 0000000..4d5a6c8
--- /dev/null
+++ b/xos/test/service_for_scale.yaml
@@ -0,0 +1,75 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Setup example service/slice to demonstrate auto-scaling for that service/slice.
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    service_xyz:
+      type: tosca.nodes.Service
+      properties:
+          kind: xyz
+
+# private network template, created in fixtures.yml
+    Private:
+      type: tosca.nodes.NetworkTemplate
+
+# site, fully created in deployment.yaml
+    mysite:
+      type: tosca.nodes.Site
+
+    trusty-server-multi-nic:
+      type: tosca.nodes.Image
+
+    m1.small:
+      type: tosca.nodes.Flavor
+
+# management network, fully created in management-net.yaml
+    management:
+      type: tosca.nodes.network.Network.XOS
+      properties:
+        no-create: true
+        no-delete: true
+        no-update: true
+
+    mysite_scalable_xyz:
+      type: tosca.nodes.Slice
+      properties:
+          network: noauto
+      requirements:
+          - service:
+              node: service_xyz
+              relationship: tosca.relationships.MemberOfService
+          - site:
+              node: mysite
+              relationship: tosca.relationships.MemberOfSite
+          - management:
+              node: management
+              relationship: tosca.relationships.ConnectsToNetwork
+          - default_image:
+                node: trusty-server-multi-nic
+                relationship: tosca.relationships.DefaultImage
+          - m1.small:
+              node: m1.small
+              relationship: tosca.relationships.DefaultFlavor
+
+    # Virtual machines
+    xyz_service_vm1:
+      type: tosca.nodes.Compute
+      capabilities:
+        # Host container properties
+        host:
+         properties:
+           num_cpus: 1
+           disk_size: 20 GB
+           mem_size: 2 GB
+      requirements:
+          - slice:
+                node: mysite_scalable_xyz
+                relationship: tosca.relationships.MemberOfSlice
+          - image:
+                node: trusty-server-multi-nic
+                relationship: tosca.relationships.UsesImage
+