Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 1 | import { |
| 2 | getConnectivityServices, |
| 3 | getSipDetail, |
| 4 | getSips, |
| 5 | } from './dcs' |
| 6 | import { |
| 7 | getDevices, |
| 8 | getPorts, |
| 9 | } from './onos' |
| 10 | |
| 11 | |
| 12 | /** |
| 13 | * Provide onos port list along with sip uuid. |
| 14 | * @returns {Promise<*[]>} |
| 15 | */ |
| 16 | export 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 Okui | 559bd1c | 2019-01-17 14:17:32 -0800 | [diff] [blame^] | 33 | const sipIdMap = sipDetails |
| 34 | .filter(filterOnlyDsrSips) |
| 35 | .reduce((_sipIdMap, sipDetail) => { |
Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 36 | _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 Okui | 559bd1c | 2019-01-17 14:17:32 -0800 | [diff] [blame^] | 56 | } |
| 57 | |
| 58 | function filterOnlyDsrSips(sipDetail) { |
| 59 | return sipDetail["layer-protocol-name"] === 'DSR' |
Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 60 | } |