Initial Commit for ODTN demo repo with demo scripts and demo app
Change-Id: I812c9fbe7a4b5d454038860acbb936fa9b189438
diff --git a/odtn-phase1-demo/src/resources/dcs.js b/odtn-phase1-demo/src/resources/dcs.js
new file mode 100644
index 0000000..c3dd27c
--- /dev/null
+++ b/odtn-phase1-demo/src/resources/dcs.js
@@ -0,0 +1,149 @@
+export function getSips() {
+
+ return new Promise((resolve, reject) => {
+ fetch(`/dcs/operations/tapi-common:get-service-interface-point-list`, {
+ method: 'POST',
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: "{}"
+ })
+ .then(res => {
+ if (res.ok) {
+ res.json().then(data => resolve(data["tapi-common:output"]["sip"]))
+ } else {
+ reject(res.text())
+ }
+ })
+ .catch(err => {
+ console.error(err)
+ })
+ })
+}
+
+export function getSipDetail(uuid) {
+
+ return new Promise((resolve, reject) => {
+ fetch(`/dcs/data/tapi-common:context/service-interface-point=${uuid}`, {
+ method: 'GET',
+ })
+ .then(res => {
+ if (res.ok) {
+ res.json().then(data => resolve(data["tapi-common:service-interface-point"][0]))
+ } else {
+ reject(res.text())
+ }
+ })
+ .catch(err => {
+ console.error(err)
+ })
+ })
+}
+
+
+export function getConnectivityServices() {
+
+ return new Promise((resolve, reject) => {
+ fetch(`/dcs/operations/tapi-connectivity:get-connectivity-service-list`, {
+ method: 'POST',
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: '{}'
+ })
+ .then(res => {
+ console.log(res)
+ if (res.ok) {
+ res.json().then(data => resolve(data["tapi-connectivity:output"]["service"]))
+ } else {
+ reject(res.text())
+ }
+ })
+ .catch(err => {
+ console.error(err)
+ })
+ })
+}
+
+
+export function createConnectivityService(sip1, sip2) {
+
+ return new Promise((resolve, reject) => {
+ fetch(`/dcs/operations/tapi-connectivity:create-connectivity-service`, {
+ method: 'POST',
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: getCreateRequestBody(sip1, sip2)
+ })
+ .then(res => {
+ console.log(res)
+ if (res.ok) {
+ res.json().then(data => resolve(data["tapi-connectivity:output"]["service"]))
+ } else {
+ reject(res.text())
+ }
+ })
+ .catch(err => {
+ console.error(err)
+ })
+ })
+}
+
+
+export function deleteConnectivityServices(uuid) {
+
+ return new Promise((resolve, reject) => {
+ fetch(`/dcs/operations/tapi-connectivity:delete-connectivity-service`, {
+ method: 'POST',
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: getDeleteRequestBody(uuid)
+ })
+ .then(res => {
+ console.log(res)
+ if (res.ok) {
+ resolve()
+ } else {
+ reject(res.text())
+ }
+ })
+ .catch(err => {
+ console.error(err)
+ })
+ })
+}
+
+
+function getCreateRequestBody(sip1, sip2){
+ return `{
+ "tapi-connectivity:input":
+ {
+ "end-point" : [
+ {
+ "local-id": "id1",
+ "service-interface-point": {
+ "service-interface-point-uuid" : "${sip1}"
+ }
+ }
+ ,
+ {
+ "local-id": "id2",
+ "service-interface-point": {
+ "service-interface-point-uuid" : "${sip2}"
+ }
+ }
+ ]
+ }
+}`
+}
+
+function getDeleteRequestBody(uuid){
+ return `{
+ "tapi-connectivity:input":
+ {
+ "service-id-or-name" : "${uuid}"
+ }
+}`
+}
\ No newline at end of file
diff --git a/odtn-phase1-demo/src/resources/getResources.js b/odtn-phase1-demo/src/resources/getResources.js
new file mode 100644
index 0000000..d92b3f2
--- /dev/null
+++ b/odtn-phase1-demo/src/resources/getResources.js
@@ -0,0 +1,54 @@
+import {
+ getConnectivityServices,
+ getSipDetail,
+ getSips,
+} from './dcs'
+import {
+ getDevices,
+ getPorts,
+} from './onos'
+
+
+/**
+ * Provide onos port list along with sip uuid.
+ * @returns {Promise<*[]>}
+ */
+export function getResources() {
+
+ return Promise.all([getDevices(), getSips()])
+ .then(([devices, sips]) => {
+ if(!devices || !sips){
+ throw new Error('Device not found')
+ }
+ const promisePorts = Promise.all(devices.map(device => {
+ return getPorts(device.id)
+ }))
+ const promiseSipDetails = Promise.all(sips.map(sip => {
+ return getSipDetail(sip.uuid)
+ }))
+ return Promise.all([promisePorts, promiseSipDetails, getConnectivityServices()])
+ })
+ .then(([deviceDetails, sipDetails, connectivityService]) => {
+
+ const sipIdMap = sipDetails.reduce((_sipIdMap, sipDetail) => {
+ _sipIdMap[sipDetail.name.filter(kv => kv["value-name"] === "onos-cp")[0].value] = sipDetail.uuid
+ return _sipIdMap
+ }, {})
+ console.log(sipIdMap)
+
+ deviceDetails.forEach(deviceDetail => {
+ deviceDetail.ports.forEach(port => {
+ const key = `${port.element}/${port.port}`
+ if(sipIdMap[key]) {
+ port.sipId = sipIdMap[key]
+ }
+ })
+ })
+
+ return [ deviceDetails || [], connectivityService || [] ]
+ })
+ .catch(err => {
+ console.error(err)
+ })
+
+}
\ No newline at end of file
diff --git a/odtn-phase1-demo/src/resources/onos.js b/odtn-phase1-demo/src/resources/onos.js
new file mode 100644
index 0000000..116a879
--- /dev/null
+++ b/odtn-phase1-demo/src/resources/onos.js
@@ -0,0 +1,37 @@
+export function getDevices() {
+
+ return new Promise((resolve, reject) => {
+ fetch(`/onos/devices`, {
+ method: 'GET',
+ })
+ .then(res => {
+ if (res.ok) {
+ res.json().then(data => resolve(data["devices"]))
+ } else {
+ reject(res.text())
+ }
+ })
+ .catch(err => {
+ console.error(err)
+ })
+ })
+}
+
+export function getPorts(devices) {
+
+ return new Promise((resolve, reject) => {
+ fetch(`/onos/devices/${devices}/ports`, {
+ method: 'GET',
+ })
+ .then(res => {
+ if (res.ok) {
+ res.json().then(data => resolve(data))
+ } else {
+ reject(res.text())
+ }
+ })
+ .catch(err => {
+ console.error(err)
+ })
+ })
+}