summaryrefslogtreecommitdiffstats
path: root/sdnr/wt/odlux/apps/performanceHistoryApp/src/services/performanceHistoryService.tsx
blob: a1cdcffcc2d08be92ab440ffe5c3e6b09e19c93a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { requestRest } from '../../../../framework/src/services/restService';
import { Result } from '../../../../framework/src/models/elasticSearch';

import { ConnectedNetworkElements } from '../models/connectedNetworkElements';
import { DistinctLtp, Ltp } from '../models/availableLtps';
import { Topology, TopologyNode } from '../models/topologyNetConf';

/** 
 * Represents a web api accessor service for Network elements actions.
 */
class PerformanceService {

  private static networkElementTopology = (mountPoint: TopologyNode) => {
    const mountId = mountPoint["node-id"];
    return {
      mountId: mountId,
    }
  }

  /**
   * Get all connected network elements from restconf.
   */
  public async getConnectedNetworkElementsList(): Promise<ConnectedNetworkElements[] | null> {
    const path = "restconf/operational/network-topology:network-topology/topology/topology-netconf";
    const topologyRequestPomise = requestRest<{ topology: Topology[] | null }>(path, { method: "GET" }, true);
    const [netconfResponse] = await Promise.all([topologyRequestPomise]);
    const topologyNetconf = netconfResponse && netconfResponse.topology && netconfResponse.topology.find(topology => topology["topology-id"] === "topology-netconf");
    let mountPoints = topologyNetconf && topologyNetconf.node && topologyNetconf.node.filter(
      mountPoint => mountPoint["netconf-node-topology:connection-status"] == "connected").map(mountedElement => {
        return PerformanceService.networkElementTopology(mountedElement);
      });
    return mountPoints || [];
  }

  /**
   * Get distinct ltps based on the selected network element and time period from the historicalperformance15min database table.
   */
  public async getDistinctLtpsFrom15minDatabase(networkElement: string): Promise<Ltp[] | null> {
    const path = 'database/sdnperformance/historicalperformance15min/_search';
    const query = {
      "size": 0,
      "query": {
        "match": {
          "node-name": networkElement
        }
      },
      "aggs": {
        "uuid-interface": {
          "terms": {
            "field": "uuid-interface"
          }
        }
      }
    };
    const result = await requestRest<Result<DistinctLtp>>(path, { method: "POST", body: JSON.stringify(query) });
    if(result && result.aggregations) {
    }
    return result && result.aggregations && result.aggregations["uuid-interface"].buckets.map(ne=>({
      key:ne.key
    }))|| null;
  }

  /**
   * Get distinct ltps based on the selected network element and time period from the historicalperformance24h database table.
   */
  public async getDistinctLtpsFrom24hoursDatabase(networkElement: string): Promise<Ltp[] | null> {
    const path = 'database/sdnperformance/historicalperformance24h/_search';
    const query = {
      "size": 0,
      "query": {
        "match": {
          "node-name": networkElement
        }
      },
      "aggs": {
        "uuid-interface": {
          "terms": {
            "field": "uuid-interface"
          }
        }
      }
    };
    const result = await requestRest<Result<DistinctLtp>>(path, { method: "POST", body: JSON.stringify(query) });
    if(result && result.aggregations) {
    }
    return result && result.aggregations && result.aggregations["uuid-interface"].buckets.map(ne=>({
      key:ne.key
    }))|| null;
  }
}

export const PerformanceHistoryService = new PerformanceService();
export default PerformanceHistoryService;