blob: c555a6659ead2562da242d57c72f0c5167d3dc2a [file] [log] [blame]
Andrea Campanella362b7d32018-12-11 18:57:12 +01001import {
2 getConnectivityServices,
3 getSipDetail,
4 getSips,
5} from './dcs'
6import {
7 getDevices,
8 getPorts,
9} from './onos'
10
11
12/**
13 * Provide onos port list along with sip uuid.
14 * @returns {Promise<*[]>}
15 */
16export function getResources() {
17
18 return Promise.all([getDevices(), getSips()])
19 .then(([devices, sips]) => {
20 if(!devices || !sips){
21 throw new Error('Device not found')
22 }
23 const promisePorts = Promise.all(devices.map(device => {
24 return getPorts(device.id)
25 }))
26 const promiseSipDetails = Promise.all(sips.map(sip => {
27 return getSipDetail(sip.uuid)
28 }))
29 return Promise.all([promisePorts, promiseSipDetails, getConnectivityServices()])
30 })
31 .then(([deviceDetails, sipDetails, connectivityService]) => {
32
Hiroki Okui559bd1c2019-01-17 14:17:32 -080033 const sipIdMap = sipDetails
34 .filter(filterOnlyDsrSips)
35 .reduce((_sipIdMap, sipDetail) => {
Andrea Campanella362b7d32018-12-11 18:57:12 +010036 _sipIdMap[sipDetail.name.filter(kv => kv["value-name"] === "onos-cp")[0].value] = sipDetail.uuid
37 return _sipIdMap
38 }, {})
39 console.log(sipIdMap)
40
41 deviceDetails.forEach(deviceDetail => {
42 deviceDetail.ports.forEach(port => {
43 const key = `${port.element}/${port.port}`
44 if(sipIdMap[key]) {
45 port.sipId = sipIdMap[key]
46 }
47 })
48 })
49
50 return [ deviceDetails || [], connectivityService || [] ]
51 })
52 .catch(err => {
53 console.error(err)
54 })
55
Hiroki Okui559bd1c2019-01-17 14:17:32 -080056}
57
58function filterOnlyDsrSips(sipDetail) {
59 return sipDetail["layer-protocol-name"] === 'DSR'
Andrea Campanella362b7d32018-12-11 18:57:12 +010060}