summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts')
-rw-r--r--sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts246
1 files changed, 120 insertions, 126 deletions
diff --git a/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts b/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts
index b50a06ee1..7a410f4ae 100644
--- a/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts
+++ b/sdnr/wt/odlux/apps/connectApp/src/services/connectService.ts
@@ -15,150 +15,66 @@
* the License.
* ============LICENSE_END==========================================================================
*/
-import { RequiredNetworkElementType } from '../models/requiredNetworkElements';
-import { MountedNetworkElementType } from '../models/mountedNetworkElements';
-import { Topology, TopologyNode } from '../models/topologyNetconf';
import { requestRest } from '../../../../framework/src/services/restService';
-import { Result, HitEntry } from '../../../../framework/src/models/elasticSearch';
+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.
- */
+* Represents a web api accessor service for all Network Elements actions.
+*/
class ConnectService {
- /**
- * Gets all known required network elements from the backend.
- */
- public async getAllRequiredNetworkElements(): Promise<(RequiredNetworkElementType & { _id: string })[] | null> {
- const path = 'database/mwtn/required-networkelement/_search';
- const query = { "query": { "match_all": {} } };
-
- const result = await requestRest<Result<RequiredNetworkElementType>>(path, { method: "POST", body: JSON.stringify(query) });
- return result && result.hits && result.hits.hits && result.hits.hits.map(ne => ({
- _id: ne._id,
- mountId: ne._source && ne._source.mountId,
- host: ne._source && ne._source.host,
- port: ne._source && ne._source.port,
- username: ne._source && ne._source.username,
- password: ne._source && ne._source.password,
- })) || null;
- }
- public async getRequiredNetworkElementByMountId(mountId:string): Promise<(RequiredNetworkElementType & { _id: string }) | null> {
- const path = `database/mwtn/required-networkelement/${mountId}`;
-
- const result = await requestRest<HitEntry<RequiredNetworkElementType> & { found: boolean }>(path, { method: "GET" });
- return result && result.found && result._source && {
- _id: result._id,
- mountId: result._source.mountId,
- host: result._source.host,
- port: result._source.port,
- username: result._source.username,
- password: result._source.password,
- } || null;
+ /**
+ * Inserts a network elements.
+ */
+ public async createNetworkElement(element: NetworkElementConnection): Promise<NetworkElementConnection | null> {
+ const path = `/restconf/operations/data-provider:create-network-element-connection`;
+ const result = await requestRest<NetworkElementConnection>(path, {
+ method: "POST", body: JSON.stringify(convertPropertyNames({ input: element }, replaceUpperCase))
+ });
+ return result || null;
}
/**
- * Inserts data into the required network elements table.
- */
- public async insertRequiredNetworkElement(element: RequiredNetworkElementType): Promise<RequiredNetworkElementType | null> {
- const path = `database/mwtn/required-networkelement/${ element.mountId }`;
- const result = await requestRest<RequiredNetworkElementType>(path, { method: "POST", body: JSON.stringify(element) });
+ * Updates a network element.
+ */
+ public async updateNetworkElement(element: UpdateNetworkElement): Promise<NetworkElementConnection | null> {
+ const path = `/restconf/operations/data-provider:update-network-element-connection`;
+ const result = await requestRest<NetworkElementConnection>(path, {
+ method: "POST", body: JSON.stringify(convertPropertyNames({ input: element }, replaceUpperCase))
+ });
return result || null;
}
/**
- * Deletes data from the Required Network Elements backend.
+ * Deletes a network element.
*/
- public async deleteRequiredNetworkElement(element: RequiredNetworkElementType): Promise<RequiredNetworkElementType | null> {
- const path = `database/mwtn/required-networkelement/${ element.mountId }`;
- const result = await requestRest<RequiredNetworkElementType>(path, { method: "DELETE", body: JSON.stringify(element) });
+ public async deleteNetworkElement(element: UpdateNetworkElement): Promise<NetworkElementConnection | null> {
+ const query = {
+ "id": element.id
+ };
+ const path = `/restconf/operations/data-provider:delete-network-element-connection`;
+ const result = await requestRest<NetworkElementConnection>(path, {
+ method: "POST", body: JSON.stringify(convertPropertyNames({ input: query }, replaceUpperCase))
+ });
return result || null;
}
- private static mapTopologyNode = (mountPoint: TopologyNode, required: boolean ) => {
- // handle onfCapabilities
- let onfCapabilities: { module: string, revision: string }[] | undefined = undefined;
-
- const capId = 'netconf-node-topology:available-capabilities';
- if (mountPoint[capId] && mountPoint[capId]['available-capability']) {
- onfCapabilities = mountPoint[capId]['available-capability'].filter((cap) => {
- return cap.capability.includes('?revision=');
- }).map((cap) => {
- return {
- module: cap.capability.split(')')[1],
- revision: cap.capability.split('?revision=')[1].substring(0, 10)
- };
- }).sort((a, b) => {
- if (a.module < b.module) return -1;
- if (a.module > b.module) return 1;
- return 0;
- });
- }
-
- // handle clustered-connection-status
- const statusId = 'netconf-node-topology:clustered-connection-status';
- let client = 'localhost';
-
- if (mountPoint[statusId] && mountPoint[statusId]['netconf-master-node']) {
- let node = mountPoint[statusId]['netconf-master-node'];
- node = node.substring(node.indexOf('@'));
- client = node.substring(1, node.indexOf(':'));
- }
- const mountId = mountPoint["node-id"];
- return {
- mountId: mountId,
- host: mountPoint["netconf-node-topology:host"],
- port: mountPoint["netconf-node-topology:port"],
- connectionStatus: mountPoint['netconf-node-topology:connection-status'],
- capabilities: onfCapabilities || [],
- required: required,
- client
- }
- }
-
- /** Get all mounted network elements and fills the property required according to the database contents. */
- public async getMountedNetworkElementsList(): Promise<MountedNetworkElementType[] | null> {
- const path = 'restconf/operational/network-topology:network-topology/topology/topology-netconf';
-
- const topologyRequestPomise = requestRest<{ topology: Topology[] | null }>(path, { method: "GET" });
- const requiredNetworkElementsPromise = this.getAllRequiredNetworkElements();
-
- const [netconfResponse, requiredNetworkElements] = await Promise.all([topologyRequestPomise, requiredNetworkElementsPromise]);
-
- // process topologyNetconf (get all known network elements)
- const topologyNetconf = netconfResponse && netconfResponse.topology && netconfResponse.topology.find(topology => topology["topology-id"] === 'topology-netconf');
- let mountPoints = topologyNetconf && topologyNetconf.node && topologyNetconf.node.filter(
- mountPoint => mountPoint['node-id'] !== 'controller-config').map(mountedElement => {
- const required = requiredNetworkElements && requiredNetworkElements.some(
- requiredElement => requiredElement.mountId === mountedElement["node-id"]);
- return ConnectService.mapTopologyNode(mountedElement, !!required);
- });
-
- return mountPoints || [];
- }
-
- /** Get one mounted network element. */
- public async getMountedNetworkElementByMountId(mountId: string): Promise<MountedNetworkElementType | null> {
- const path = 'restconf/operational/network-topology:network-topology/topology/topology-netconf/node/' + mountId;
- const getMountedNetworkElementByMountIdPromise = requestRest<{ node: TopologyNode[] | null }>(path, { method: "GET" });
- const getRequiredNetworkElementByMountIdPromise = this.getRequiredNetworkElementByMountId(mountId);
-
- const [mountedNetworkElement, requiredNetworkElement] = await Promise.all([getMountedNetworkElementByMountIdPromise, getRequiredNetworkElementByMountIdPromise]);
- return mountedNetworkElement && mountedNetworkElement.node && ConnectService.mapTopologyNode(mountedNetworkElement.node[0], requiredNetworkElement && requiredNetworkElement.mountId === mountedNetworkElement.node[0]["node-id"] || false) || null;
- }
-
- /** Mounts an required network element. */
- public async mountNetworkElement(networkElement: RequiredNetworkElementType): Promise<boolean> {
- const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + networkElement.mountId;
+ /** Mounts network element. */
+ public async mountNetworkElement(networkElement: NetworkElementConnection): Promise<boolean> {
+ const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + networkElement.nodeId;
const mountXml = [
'<node xmlns="urn:TBD:params:xml:ns:yang:network-topology">',
- `<node-id>${ networkElement.mountId }</node-id>`,
- `<host xmlns="urn:opendaylight:netconf-node-topology">${ networkElement.host }</host>`,
- `<port xmlns="urn:opendaylight:netconf-node-topology">${ networkElement.port }</port>`,
- `<username xmlns="urn:opendaylight:netconf-node-topology">${ networkElement.username }</username>`,
- `<password xmlns="urn:opendaylight:netconf-node-topology">${ networkElement.password }</password>`,
+ `<node-id>${networkElement.nodeId}</node-id>`,
+ `<host xmlns="urn:opendaylight:netconf-node-topology">${networkElement.host}</host>`,
+ `<port xmlns="urn:opendaylight:netconf-node-topology">${networkElement.port}</port>`,
+ `<username xmlns="urn:opendaylight:netconf-node-topology">${networkElement.username}</username>`,
+ `<password xmlns="urn:opendaylight:netconf-node-topology">${networkElement.password}</password>`,
' <tcp-only xmlns="urn:opendaylight:netconf-node-topology">false</tcp-only>',
' <!-- non-mandatory fields with default values, you can safely remove these if you do not wish to override any of these values-->',
@@ -189,8 +105,8 @@ class ConnectService {
};
/** Unmounts a network element by its id. */
- public async unmountNetworkElement(mountId: string): Promise<boolean> {
- const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + mountId;
+ public async unmountNetworkElement(nodeId: string): Promise<boolean> {
+ const path = 'restconf/config/network-topology:network-topology/topology/topology-netconf/node/' + nodeId;
try {
const result = await requestRest<string>(path, {
@@ -208,6 +124,84 @@ class ConnectService {
}
};
+ /** Yang capabilities of the selected network elements. */
+ public async infoNetworkElement(nodeId: string): Promise<TopologyNode | null> {
+ const path = 'restconf/operational/network-topology:network-topology/topology/topology-netconf/node/' + nodeId;
+ const topologyRequestPomise = requestRest<Topology>(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<Result<ConnectionStatus>>(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<any>(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<any>(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();