Removal of Svg api
[clamp.git] / ui-react / src / api / LoopService.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END============================================
19  * ===================================================================
20  *
21  */
22
23 export default class LoopService {
24         static getLoopNames() {
25                 return fetch('/restservices/clds/v2/loop/getAllNames', { method: 'GET', credentials: 'same-origin' })
26                         .then(function (response) {
27                                 console.debug("GetLoopNames response received: ", response.status);
28                                 if (response.ok) {
29                                         return response.json();
30                                 } else {
31                                         console.error("GetLoopNames query failed");
32                                         return {};
33                                 }
34                         })
35                         .catch(function (error) {
36                                 console.error("GetLoopNames error received", error);
37                                 return {};
38                         });
39         }
40
41         static createLoop(loopName, templateName) {
42                 return fetch('/restservices/clds/v2/loop/create/' + loopName + '?templateName=' + templateName, {
43                         method: 'POST',
44                         headers: {
45                                 "Content-Type": "application/json"
46                         },
47                         credentials: 'same-origin'
48                 })
49                         .then(function (response) {
50                                 console.debug("CreateLoop response received: ", response.status);
51                                 return response.json();
52                         })
53                         .catch(function (error) {
54                                 console.error("CreateLoop error received", error);
55                                 return "";
56                         });
57         }
58
59         static getLoop(loopName) {
60                 return fetch('/restservices/clds/v2/loop/' + loopName, {
61                         method: 'GET',
62                         headers: {
63                                 "Content-Type": "application/json"
64                         },
65                         credentials: 'same-origin'
66                 })
67                         .then(function (response) {
68                                 console.debug("GetLoop response received: ", response.status);
69                                 if (response.ok) {
70                                         return response.json();
71                                 } else {
72                                         console.error("GetLoop query failed");
73                                         return {};
74                                 }
75                         })
76                         .catch(function (error) {
77                                 console.error("GetLoop error received", error);
78                                 return {};
79                         });
80         }
81
82         static setMicroServiceProperties(loopName, jsonData) {
83                 return fetch('/restservices/clds/v2/loop/updateMicroservicePolicy/' + loopName, {
84                         method: 'POST',
85                         credentials: 'same-origin',
86                         headers: {
87                                 "Content-Type": "application/json"
88                         },
89                         body: JSON.stringify(jsonData)
90                 })
91                         .then(function (response) {
92                                 console.debug("updateMicroservicePolicy response received: ", response.status);
93                                 if (response.ok) {
94                                         return response.text();
95                                 } else {
96                                         console.error("updateMicroservicePolicy query failed");
97                                         return "";
98                                 }
99                         })
100                         .catch(function (error) {
101                                 console.error("updateMicroservicePolicy error received", error);
102                                 return "";
103                         });
104         }
105         
106         static setOperationalPolicyProperties(loopName, jsonData) {
107                 return fetch('/restservices/clds/v2/loop/updateOperationalPolicies/' + loopName, {
108                         method: 'POST',
109                         credentials: 'same-origin',
110                         headers: {
111                                 "Content-Type": "application/json"
112                         },
113                         body: JSON.stringify(jsonData)
114                 })
115                         .then(function (response) {
116                                 console.debug("updateOperationalPolicies response received: ", response.status);
117                                 if (response.ok) {
118                                         return response.text();
119                                 } else {
120                                         console.error("updateOperationalPolicies query failed");
121                                         return "";
122                                 }
123                         })
124                         .catch(function (error) {
125                                 console.error("updateOperationalPolicies error received", error);
126                                 return "";
127                         });
128         }
129
130         static updateGlobalProperties(loopName, jsonData) {
131                 return fetch('/restservices/clds/v2/loop/updateGlobalProperties/' + loopName, {
132                         method: 'POST',
133                         credentials: 'same-origin',
134                         headers: {
135                                 "Content-Type": "application/json"
136                         },
137                         body: JSON.stringify(jsonData)
138                 })
139                         .then(function (response) {
140                                 console.debug("updateGlobalProperties response received: ", response.status);
141                                 if (response.ok) {
142                                         return response.text();
143                                 } else {
144                                         console.error("updateGlobalProperties query failed");
145                                         return "";
146                                 }
147                         })
148                         .catch(function (error) {
149                                 console.error("updateGlobalProperties error received", error);
150                                 return "";
151                         });
152         }
153
154         static refreshOperationalPolicyJson(loopName,operationalPolicyName) {
155                 return fetch('/restservices/clds/v2/loop/refreshOperationalPolicyJsonSchema/' + loopName + '/' + operationalPolicyName, {
156                         method: 'PUT',
157                         headers: {
158                                 "Content-Type": "application/json"
159                         },
160                         credentials: 'same-origin'
161                 })
162                         .then(function (response) {
163                                 console.debug("Refresh Operational Policy Json Schema response received: ", response.status);
164                                 if (response.ok) {
165                                         return response.json();
166                                 } else {
167                                         console.error("Refresh Operational Policy Json Schema query failed");
168                                         return {};
169                                 }
170                         })
171                         .catch(function (error) {
172                                 console.error("Refresh Operational Policy Json Schema error received", error);
173                                 return {};
174                         });
175         }
176
177                 static refreshMicroServicePolicyJson(loopName,microServicePolicyName) {
178                 return fetch('/restservices/clds/v2/loop/refreshMicroServicePolicyJsonSchema/' + loopName + '/' + microServicePolicyName, {
179                         method: 'PUT',
180                         headers: {
181                                 "Content-Type": "application/json"
182                         },
183                         credentials: 'same-origin'
184                 })
185                         .then(function (response) {
186                                 console.debug("Refresh Operational Policy Json Schema response received: ", response.status);
187                                 if (response.ok) {
188                                         return response.json();
189                                 } else {
190                                         console.error("Refresh Operational Policy Json Schema query failed");
191                                         return {};
192                                 }
193                         })
194                         .catch(function (error) {
195                                 console.error("Refresh Operational Policy Json Schema error received", error);
196                                 return {};
197                         });
198     }
199
200         static addOperationalPolicyType(loopName, policyType, policyVersion) {
201                 return fetch('/restservices/clds/v2/loop/addOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion , {
202                         method: 'PUT',
203                         headers: {
204                                 "Content-Type": "application/json"
205                         },
206                         credentials: 'same-origin'
207                 })
208                                 .then(function (response) {
209                                 console.debug("Add Operational Policy response received: ", response.status);
210                                 if (response.ok) {
211                                         return response.json();
212                                 } else {
213                                         return response.text();
214                                 }
215                         })
216                         .catch(function (error) {
217                                 console.error("Add Operational Policy query failed");
218                                 throw new Error(error);
219                         })
220         }
221
222         static removeOperationalPolicyType(loopName, policyType, policyVersion, policyName) {
223                 return fetch('/restservices/clds/v2/loop/removeOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion + '/' + policyName , {
224                         method: 'PUT',
225                         headers: {
226                                 "Content-Type": "application/json"
227                         },
228                         credentials: 'same-origin'
229                 })
230                                 .then(function (response) {
231                                         console.debug("Remove Operational Policy response received: ", response.status);
232                                 if (response.ok) {
233                                         return response.json();
234                                 } else {
235                                         console.error("Remove Operational Policy query failed");
236                                         return {};
237                                 }
238                         })
239                         .catch(function (error) {
240                                 console.error("Remove Operational Policy error received", error);
241                                 return {};
242                         });
243         }
244 }