8a005bcaf9fc61e44f2227f683fd6055fc237396
[ccsdk/features.git] / sdnr / wt / odlux / apps / networkMapApp / src / actions / detailsAction.ts
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 import { Action } from '../../../../framework/src/flux/action';
20 import { requestRest } from '../../../../framework/src/services/restService';
21
22
23 import { site, Device } from "../model/site";
24 import { link } from '../model/link';
25 import { HistoryEntry } from "../model/historyEntry";
26 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
27 import { Dispatch } from '../../../../framework/src/flux/store';
28
29 export class SelectSiteAction extends Action {
30   constructor(public site: site){
31     super()
32   }
33 }
34
35 export class SelectLinkAction extends Action {
36  constructor(public link: link){
37    super();
38  }
39 }
40
41 export class ClearDetailsAction extends Action{
42   constructor(){
43     super();
44   }
45 }
46
47 export class AddToHistoryAction extends Action {
48  constructor(public entry: HistoryEntry){
49    super();
50  }
51 }
52
53 export class ClearHistoryAction extends Action {
54   constructor(){
55     super();
56   }
57 }
58
59 export class IsBusyCheckingDeviceListAction extends Action{
60   constructor(public isBusy: boolean){
61     super();
62   }
63 }
64
65 export class FinishedLoadingDeviceListAction extends Action{
66   constructor(public devices: Device[]){
67     super();
68   }
69 }
70
71 export class ClearLoadedDevicesAction extends Action{
72   constructor(){
73     super();
74   }
75 }
76
77 let running=false;
78
79 export const UpdateDetailsView = (nodeId: string) =>(dispatcher: Dispatch, getState: () => IApplicationStoreState) =>{
80   const {network:{details:{checkedDevices}}} = getState();
81   if(checkedDevices!==null){
82     const index = checkedDevices.findIndex(item=>item.name===nodeId)
83     if(index!==-1)
84      requestRest<any>("/rests/operational/network-topology:network-topology/topology/topology-netconf/node/"+nodeId, { method: "GET" })
85      .then(result =>{
86       if(result!==null){
87         checkedDevices[index].status = result.node[0]["netconf-node-topology:connection-status"];
88
89       }else{
90         checkedDevices[index].status = "Not connected";
91       }
92       dispatcher(new FinishedLoadingDeviceListAction(checkedDevices));
93
94      });
95
96   }
97 }
98
99 export const CheckDeviceList = (list: Device[]) => async (dispatcher: Dispatch, getState: () => IApplicationStoreState) =>{
100 if(running) return;
101 running=true;
102   dispatcher(new IsBusyCheckingDeviceListAction(true));
103
104   const promises = list.map((device)=>{
105     if(device.simulatorId){
106       return requestRest<any>("/rests/operational/network-topology:network-topology/topology/topology-netconf/node/"+device.simulatorId, { method: "GET" })
107
108     }else{
109       return requestRest<any>("/rests/operational/network-topology:network-topology/topology/topology-netconf/node/"+device.name, { method: "GET" })
110
111     }
112
113   })
114
115   Promise.all(promises).then((result)=>{
116     running=false;
117     
118
119     result.forEach((res: any, index)=>{
120       console.log("value")
121      console.log(res);
122      if(res !==null && res.node!==null){
123
124       list[index].status = res.node[0]["netconf-node-topology:connection-status"];
125      }else{
126       list[index].status = "Not connected";
127      }
128     });
129
130     dispatcher(new FinishedLoadingDeviceListAction(list));
131     dispatcher(new IsBusyCheckingDeviceListAction(false));
132
133   })
134   .catch(err=>{
135     console.error(err);
136
137   dispatcher(new IsBusyCheckingDeviceListAction(false));
138
139   });
140
141   /*  result.forEach((res: Promise<any>, index)=>{
142       console.log("value")
143      console.log(res);
144      console.log(res.value);
145      if(res.value!==null){
146       list[index].status = res.value.node[0]["netconf-node-topology:connection-status"];
147      }else{
148       list[index].status = "Not connected";
149      }*/
150     
151   
152
153
154
155
156   //get devices
157   //wait on all to finish
158   //update array
159
160
161
162
163
164 }