From e6d0d67fdbe3fc70c996c8df33bd65d3b151dfad Mon Sep 17 00:00:00 2001 From: herbert Date: Sat, 14 Dec 2019 01:05:47 +0100 Subject: update odlux and featureaggregator v2 update odlux and featureaggregator bundles Issue-ID: SDNC-1008 Signed-off-by: herbert Change-Id: I0018d7bfa3a0e6896c1b210b539a574af9808e22 Signed-off-by: herbert --- .../apps/connectApp/src/services/connectService.ts | 208 +++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts (limited to 'sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts') diff --git a/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts b/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts new file mode 100644 index 000000000..7a410f4ae --- /dev/null +++ b/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts @@ -0,0 +1,208 @@ +/** + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt odlux + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. + * ================================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * ============LICENSE_END========================================================================== + */ + +import { requestRest } from '../../../../framework/src/services/restService'; +import { NetworkElementConnection, ConnectionStatus, UpdateNetworkElement } from '../models/networkElementConnection'; +import { convertPropertyNames, replaceUpperCase } from '../../../../framework/src/utilities/yangHelper'; +import { Result } from '../../../../framework/src/models/elasticSearch'; + +import { Topology, TopologyNode } from '../models/topologyNetconf'; +import { guiCutThrough } from '../models/guiCutTrough'; + +/** +* Represents a web api accessor service for all Network Elements actions. +*/ +class ConnectService { + + /** + * Inserts a network elements. + */ + public async createNetworkElement(element: NetworkElementConnection): Promise { + const path = `/restconf/operations/data-provider:create-network-element-connection`; + const result = await requestRest(path, { + method: "POST", body: JSON.stringify(convertPropertyNames({ input: element }, replaceUpperCase)) + }); + return result || null; + } + + /** + * Updates a network element. + */ + public async updateNetworkElement(element: UpdateNetworkElement): Promise { + const path = `/restconf/operations/data-provider:update-network-element-connection`; + const result = await requestRest(path, { + method: "POST", body: JSON.stringify(convertPropertyNames({ input: element }, replaceUpperCase)) + }); + return result || null; + } + + /** + * Deletes a network element. + */ + public async deleteNetworkElement(element: UpdateNetworkElement): Promise { + const query = { + "id": element.id + }; + const path = `/restconf/operations/data-provider:delete-network-element-connection`; + const result = await requestRest(path, { + method: "POST", body: JSON.stringify(convertPropertyNames({ input: query }, replaceUpperCase)) + }); + return result || null; + } + + /** Mounts network element. */ + public async mountNetworkElement(networkElement: NetworkElementConnection): Promise { + const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + networkElement.nodeId; + const mountXml = [ + '', + `${networkElement.nodeId}`, + `${networkElement.host}`, + `${networkElement.port}`, + `${networkElement.username}`, + `${networkElement.password}`, + ' false', + + ' ', + ' false', + ' 20000', + ' 100', + ' 2000', + ' 1.5', + + ' ', + ' 120', + ''].join(''); + + try { + const result = await requestRest(path, { + method: 'PUT', + headers: { + 'Content-Type': 'application/xml', + 'Accept': 'application/xml' + }, + body: mountXml + }); + // expect an empty answer + return result !== null; + } catch { + return false; + } + }; + + /** Unmounts a network element by its id. */ + public async unmountNetworkElement(nodeId: string): Promise { + const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + nodeId; + + try { + const result = await requestRest(path, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/xml', + 'Accept': 'application/xml' + }, + }); + // expect an empty answer + return result !== null; + + } catch { + return false; + } + }; + + /** Yang capabilities of the selected network elements. */ + public async infoNetworkElement(nodeId: string): Promise { + const path = 'restconf/operational/network-topology:network-topology/topology/topology-netconf/node/' + nodeId; + const topologyRequestPomise = requestRest(path, { method: "GET" }); + + return topologyRequestPomise && topologyRequestPomise.then(result => { + return result && result.node && result.node[0] || null; + }); + } + + /** + * Get the connection state of the network element. + */ + public async getNetworkElementConnectionStatus(element: string): Promise<(ConnectionStatus)[] | null> { + const path = `/restconf/operations/data-provider:read-network-element-connection-list`; + const query = { + "input": { + "filter": [{ + "property": "node-id", + "filtervalue": element + }], + "pagination": { + "size": 20, + "page": 1 + } + } + } + const result = await requestRest>(path, { method: "POST", body: JSON.stringify(query) }); + return result && result.output && result.output.data && result.output.data.map(ne => ({ + status: ne.status + })) || null; + } + + public async getWebUriExtensionForNetworkElementAsync(ne: string) { + const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + ne + '/yang-ext:mount/core-model:network-element'; + try { + const result = await requestRest(path, { method: "GET" }); + + if (result['network-element'].extension) { + const webUri = result['network-element'].extension.find((item: any) => item['value-name'] === "webUri") + if (webUri) { + return webUri.value as string; + } + } + } catch (error) { + console.log(ne + ' unrechable: ' + error) + } + + return undefined; + + } + + public getAllWebUriExtensionsForNetworkElementListAsync(ne: string[]) { + + let promises: any[] = []; + let webUris: guiCutThrough[] = [] + + ne.forEach(nodeId => { + const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + nodeId + '/yang-ext:mount/core-model:network-element'; + + // add search request to array + promises.push(requestRest(path, { method: "GET" }) + .then(result => { + + if (result['network-element'] && result['network-element'].extension) { + const webUri = result['network-element'].extension.find((item: any) => item['value-name'] === "webUri") + if (webUri) { + webUris.push({ webUri: webUri.value, nodeId: nodeId }); + } + } + }) + .catch(error => console.log("network element is unreachable: " + error))) + + }) + + // wait until all promises are done and return weburis + return Promise.all(promises).then(result => { return webUris }); + } + +} +export const connectService = new ConnectService(); +export default connectService; -- cgit 1.2.3-korg