initial commit

Change-Id: I650d5bf4f7c7896c91662e70f283e58fcd136363
diff --git a/Jenkinsfile b/Jenkinsfile
new file mode 100644
index 0000000..f4eee1f
--- /dev/null
+++ b/Jenkinsfile
@@ -0,0 +1,115 @@
+import groovy.json.JsonSlurperClassic
+
+env.IGNORE_LIST = ["All-Users"]
+
+env.approvers = 'andy@opennetworking.org,llp@opennetworking.org'
+env.recipients = 'cord-discuss@opencord.org'
+
+@NonCPS
+def jsonParseList(def json) {
+    j = json.minus(")]}'")
+    resp = new groovy.json.JsonSlurperClassic().parseText(j)
+    list = []
+    for (i in resp.keySet()) {
+        list << i
+    }
+    return list
+}
+
+@NonCPS
+def jsonParseMap(def json) {
+    def j = json.minus(")]}'")
+    return new groovy.json.JsonSlurperClassic().parseText(j)
+}
+
+def createBranch(def proj, def branch, def parent) {
+    cmd = 'ssh -p 29418 gerrit.opencord.org gerrit create-branch ' + proj + " " + branch + " " + parent
+    sh returnStdout: true, script: cmd
+}
+
+int checkBranchExists(def proj) {
+    if (env.IGNORE_LIST.contains(proj)) {
+        return 0
+    }
+    url = 'https://gerrit.opencord.org/projects/' + proj + '/branches/' + env.BRANCH_NAME
+    response = httpRequest url: url, validResponseCodes: '200,404'
+    if (response.status == 404) {
+        createBranch(proj, env.BRANCH_NAME, 'master')
+        return 1
+    }
+    return 0
+}
+
+node ('master') {
+
+    stage 'Check and create support branches'
+    def url = 'https://gerrit.opencord.org/projects/?type=CODE'
+    def response = httpRequest url: url, validResponseCodes: '200'
+    def info = jsonParseList(response.content)
+    int created = 0
+    for (index = 0; index < info.size(); index++) {
+        created += checkBranchExists(info[index])
+    }
+
+    if (created == 0) {
+
+        def now = new Date()
+        def metadata = 'None'
+        branch = 'cord-' + now.format("yyyyMMddHHmm", TimeZone.getTimeZone('UTC'))
+
+        stage 'Release?'
+        timeout(time: 12, unit: 'HOURS') {
+            mail to: env.approvers,
+                subject: "Job '${JOB_NAME}' is waiting up for promotion",
+                body: "Please go to ${BUILD_URL}input and promote or abort the release. It will timeout after 12 hours."
+            metadata = input id: 'release-build', message: 'Should I perform a release?',
+                parameters: [booleanParam(defaultValue: true,
+                description: 'Release onos applications (assumes versions have been updated)', name: 'build_onos_apps'),
+                string(defaultValue: branch, description: 'Release version', name: 'release_version')], submitter: 'llp,acb'
+        }
+
+        if (metadata['release_version'] == 'None') {
+            error 'Release version cannot be None'
+        }
+
+        stage 'Create new manifest branch'
+        createBranch('manifest', metadata['release_version'], env.BRANCH_NAME)
+        checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: metadata['release_version'] ]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'WipeWorkspace'], [$class: 'CleanBeforeCheckout']], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'dd9d4677-2415-4f82-8e79-99dcd530f023', url: 'ssh://jenkins@gerrit.opencord.org:29418/manifest']]]
+        sh returnStdout: true, script: 'git checkout ' + metadata['release_version']
+        sh returnStdout: true, script: 'git pull origin ' + metadata['release_version']
+        sh returnStdout: true, script: 'cp ' + env.JENKINS_HOME + '/tmp/manifest-' + env.BRANCH_NAME + '.xml default.xml'
+
+        sh returnStdout: true, script: 'git commit -a -m "JENKINS: Updating manifest"'
+        sh returnStdout: true, script: 'git push origin ' + metadata['release_version']
+
+        stage 'Build and Release ONOS applications'
+
+        if (metadata['build_onos_apps']) {
+            checkout changelog: false, poll: false, scm: [$class: 'RepoScm', currentBranch: true,
+                manifestBranch: env.BRANCH_NAME, manifestGroup: 'onos',
+                manifestRepositoryUrl: 'https://gerrit.opencord.org/manifest', quiet: true]
+            if (env.BRANCH_NAME == 'master') {
+                sh returnStdout: true, script: 'cd onos-apps/apps && mvn clean deploy'
+            } else {
+                sh returnStdout: true, script: 'cd onos-apps/apps && mvn -Prelease clean deploy'
+            }
+        }
+
+        mail to: env.recipients,
+            subject: 'Nightly bleeding edge ' + metadata['release_version'] + ' released',
+            replyTo: 'cord-dev@opencord.org',
+            body: '''Hi CORD Community,
+
+                        |A new bleeding edge version of cord is available, feel free to test it.
+                        |You can obtain it using the following commands:
+
+                        |repo init -u https://gerrit.opencord.org/manifest -b '''.stripMargin() + metadata['release_version'] + '''
+                        |repo sync
+
+                        |Have fun!
+
+                        |--
+                        |CORD Automated Release
+                    '''.stripMargin()
+    }
+}
diff --git a/default.xml b/default.xml
new file mode 100644
index 0000000..e6c792b
--- /dev/null
+++ b/default.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest>
+
+  <remote  name="opencord"
+           fetch=".."
+           review="https://gerrit.opencord.org/"
+           revision="master" />
+  <default revision="master"
+           remote="opencord"
+           sync-j="4" />
+
+<project path="helm-charts" name="helm-charts" groups="build"/>
+<project path="automation-tools" name="automation-tools" groups="build"/>
+
+<project path="xos" name="xos" groups="core"/>
+<project path="xos-gui" name="xos-gui" groups="core"/>
+<project path="xos-tosca" name="xos-tosca" groups="core"/>
+<project path="xos-sample-gui-extension" name="xos-sample-gui-extension" groups="core"/>
+<project path="xos-rest-gw" name="xos-rest-gw" groups="core"/>
+
+<project path="services/kubernetes-service" name="kubernetes-service" groups="services,platform"/>
+<project path="services/openstack" name="openstack" groups="services,platform"/>
+<project path="services/onos-service" name="onos-service" groups="services,platform"/>
+
+<project path="services/addressmanager" name="addressmanager" groups="services"/>
+<project path="services/templateservice" name="templateservice" groups="services"/>
+<project path="services/fabric" name="fabric" groups="services"/>
+<project path="services/hypercache" name="hypercache" groups="services"/>
+
+<project path="services/monitoring" name="monitoring" groups="services"/>
+<project path="services/vrouter" name="vrouter" groups="services"/>
+<project path="services/vsg" name="vsg" groups="services"/>
+<project path="services/vsg-hw" name="vsg-hw" groups="services"/>
+<project path="services/vtr" name="vtr" groups="services"/>
+<project path="services/globalxos" name="globalxos" groups="services"/>
+<project path="services/olt-service" name="olt-service" groups="services"/>
+<project path="services/vtn-service" name="vtn-service" groups="services"/>
+<project path="services/hippie-oss" name="hippie-oss" groups="services"/>
+<project path="services/vbbu" name="vBBU" groups="services"/>
+<project path="services/vmme" name="vMME" groups="services"/>
+<project path="services/vpgwc" name="vPGWC" groups="services"/>
+<project path="services/vsgw" name="vSGW" groups="services"/>
+<project path="services/progran" name="progran" groups="services"/>
+<project path="services/vhss" name="vHSS" groups="services"/>
+<project path="services/hss_db" name="hss_db" groups="services"/>
+<project path="services/vmm" name="vMM" groups="services"/>
+<project path="services/vsm" name="vSM" groups="services"/>
+<project path="services/venb" name="venb" groups="services"/>
+<project path="services/internetemulator" name="internetemulator" groups="services"/>
+<project path="services/sdn-controller" name="sdn-controller" groups="services"/>
+<project path="services/vspgwc" name="vspgwc" groups="services"/>
+<project path="services/vspgwu" name="vspgwu" groups="services"/>
+<project path="services/epc-service" name="epc-service" groups="services"/>
+<project path="services/vEE" name="vEE" groups="services"/>
+<project path="services/vEG" name="vEG" groups="services"/>
+<project path="services/vnaas" name="vnaas" groups="services"/>
+<project path="services/exampleservice" name="exampleservice" groups="services"/>
+<project path="services/simpleexampleservice" name="simpleexampleservice" groups="services"/>
+<project path="services/acordion" name="acordion" groups="services"/>
+
+<project path="profiles/rcord" name="rcord" groups="services,profiles"/>
+<project path="profiles/ecord" name="ecord" groups="services,profiles"/>
+<project path="profiles/mcord" name="mcord" groups="services,profiles"/>
+
+<project path="component/chameleon" name="chameleon" groups="component">
+    <linkfile src="." dest="component/voltha/chameleon"/>
+</project>
+<project path="component/voltha" name="voltha" groups="component"/>
+
+</manifest>
diff --git a/manifest.dtd b/manifest.dtd
new file mode 100644
index 0000000..7b2c66c
--- /dev/null
+++ b/manifest.dtd
@@ -0,0 +1,61 @@
+<!ELEMENT manifest (notice?,
+                    remote*,
+                    default?,
+                    manifest-server?,
+                    remove-project*,
+                    project*,
+                    extend-project*,
+                    repo-hooks?)>
+<!ELEMENT notice (#PCDATA)>
+<!ELEMENT remote EMPTY>
+<!ATTLIST remote name         ID    #REQUIRED>
+<!ATTLIST remote alias        CDATA #IMPLIED>
+<!ATTLIST remote fetch        CDATA #REQUIRED>
+<!ATTLIST remote pushurl      CDATA #IMPLIED>
+<!ATTLIST remote review       CDATA #IMPLIED>
+<!ATTLIST remote revision     CDATA #IMPLIED>
+<!ELEMENT default EMPTY>
+<!ATTLIST default remote      IDREF #IMPLIED>
+<!ATTLIST default revision    CDATA #IMPLIED>
+<!ATTLIST default dest-branch CDATA #IMPLIED>
+<!ATTLIST default sync-j      CDATA #IMPLIED>
+<!ATTLIST default sync-c      CDATA #IMPLIED>
+<!ATTLIST default sync-s      CDATA #IMPLIED>
+<!ELEMENT manifest-server EMPTY>
+<!ATTLIST manifest-server url CDATA #REQUIRED>
+<!ELEMENT project (annotation*,
+                   project*,
+                   copyfile*,
+                   linkfile*)>
+<!ATTLIST project name        CDATA #REQUIRED>
+<!ATTLIST project path        CDATA #IMPLIED>
+<!ATTLIST project remote      IDREF #IMPLIED>
+<!ATTLIST project revision    CDATA #IMPLIED>
+<!ATTLIST project dest-branch CDATA #IMPLIED>
+<!ATTLIST project groups      CDATA #IMPLIED>
+<!ATTLIST project sync-c      CDATA #IMPLIED>
+<!ATTLIST project sync-s      CDATA #IMPLIED>
+<!ATTLIST project upstream CDATA #IMPLIED>
+<!ATTLIST project clone-depth CDATA #IMPLIED>
+<!ATTLIST project force-path CDATA #IMPLIED>
+<!ELEMENT annotation EMPTY>
+<!ATTLIST annotation name  CDATA #REQUIRED>
+<!ATTLIST annotation value CDATA #REQUIRED>
+<!ATTLIST annotation keep  CDATA "true">
+<!ELEMENT copyfile EMPTY>
+<!ATTLIST copyfile src  CDATA #REQUIRED>
+<!ATTLIST copyfile dest CDATA #REQUIRED>
+<!ELEMENT linkfile EMPTY>
+<!ATTLIST linkfile src CDATA #REQUIRED>
+<!ATTLIST linkfile dest CDATA #REQUIRED>
+<!ELEMENT extend-project EMPTY>
+<!ATTLIST extend-project name CDATA #REQUIRED>
+<!ATTLIST extend-project path CDATA #IMPLIED>
+<!ATTLIST extend-project groups CDATA #IMPLIED>
+<!ELEMENT remove-project EMPTY>
+<!ATTLIST remove-project name  CDATA #REQUIRED>
+<!ELEMENT repo-hooks EMPTY>
+<!ATTLIST repo-hooks in-project CDATA #REQUIRED>
+<!ATTLIST repo-hooks enabled-list CDATA #REQUIRED>
+<!ELEMENT include EMPTY>
+<!ATTLIST include name CDATA #REQUIRED>
diff --git a/validate_manifest.sh b/validate_manifest.sh
new file mode 100755
index 0000000..a582322
--- /dev/null
+++ b/validate_manifest.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+# validate_manifest.sh
+#
+# Validates the repo manifest, per the DTD format given here:
+# https://gerrit.googlesource.com/git-repo/+/master/docs/manifest-format.txt
+
+echo "Verifying default.xml using manifest.dtd"
+
+# check that xmllint is available
+if ! [ -x "$(command -v xmllint)" ]
+then
+  echo "Please install 'xmllint' to use this script"
+  exit 1
+fi
+
+# run the verification
+xmllint --noout --dtdvalid manifest.dtd default.xml
+status=$?
+
+if [ $status -ne 0 ]
+then
+  echo "FAILURE: default.xml isn't valid - exit status: $status"
+  exit $status
+else
+  echo "SUCCESS: default.xml validated correctly"
+  exit 0
+fi