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 | 458da6d | 2019-02-15 10:09:21 -0800 | [diff] [blame^] | 33 | const dsrSipIdMap = sipDetails |
| 34 | .filter(filterSipsByLayer.bind(null, "DSR")) |
Hiroki Okui | 559bd1c | 2019-01-17 14:17:32 -0800 | [diff] [blame] | 35 | .reduce((_sipIdMap, sipDetail) => { |
Hiroki Okui | 458da6d | 2019-02-15 10:09:21 -0800 | [diff] [blame^] | 36 | _sipIdMap[sipDetail.name.filter(kv => kv["value-name"] === "onos-cp")[0].value] = sipDetail.uuid |
| 37 | return _sipIdMap |
| 38 | }, {}) |
| 39 | const mediaSipIdMap = sipDetails |
| 40 | .filter(filterSipsByLayer.bind(null, "PHOTONIC_MEDIA")) |
| 41 | .reduce((_sipIdMap, sipDetail) => { |
| 42 | _sipIdMap[sipDetail.name.filter(kv => kv["value-name"] === "onos-cp")[0].value] = sipDetail.uuid |
| 43 | return _sipIdMap |
| 44 | }, {}) |
| 45 | const portMap = {} |
| 46 | |
| 47 | console.log('DSR SIP ID Map', dsrSipIdMap) |
| 48 | console.log('PhotinicMedia SIP ID Map', mediaSipIdMap) |
Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 49 | |
| 50 | deviceDetails.forEach(deviceDetail => { |
| 51 | deviceDetail.ports.forEach(port => { |
| 52 | const key = `${port.element}/${port.port}` |
Hiroki Okui | 458da6d | 2019-02-15 10:09:21 -0800 | [diff] [blame^] | 53 | if(dsrSipIdMap[key]) { |
| 54 | port.sipId = dsrSipIdMap[key] |
Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 55 | } |
Hiroki Okui | 458da6d | 2019-02-15 10:09:21 -0800 | [diff] [blame^] | 56 | if(mediaSipIdMap[key]) { |
| 57 | port.mediaSipId = mediaSipIdMap[key] |
| 58 | } |
| 59 | portMap[key] = port |
| 60 | }) |
| 61 | }) |
| 62 | |
| 63 | deviceDetails.forEach(deviceDetail => { |
| 64 | deviceDetail.ports.filter(filterClientSidePort).forEach(cliPort => { |
| 65 | const linePortKey = `${cliPort.element}/${parseInt(cliPort.port) + 100}` |
| 66 | cliPort.associatedLinePort = portMap[linePortKey] |
Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 67 | }) |
| 68 | }) |
| 69 | |
| 70 | return [ deviceDetails || [], connectivityService || [] ] |
| 71 | }) |
| 72 | .catch(err => { |
| 73 | console.error(err) |
| 74 | }) |
| 75 | |
Hiroki Okui | 559bd1c | 2019-01-17 14:17:32 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Hiroki Okui | 458da6d | 2019-02-15 10:09:21 -0800 | [diff] [blame^] | 78 | function filterClientSidePort(port) { |
| 79 | return Math.floor( parseInt(port.port) / 100 ) === 1 |
| 80 | } |
| 81 | |
| 82 | function filterSipsByLayer(layerProtocolName, sipDetail) { |
| 83 | return sipDetail["layer-protocol-name"] === layerProtocolName |
Andrea Campanella | 362b7d3 | 2018-12-11 18:57:12 +0100 | [diff] [blame] | 84 | } |