blob: 96bb8a0a705636acfed6277ad4e9be5f9265488f [file] [log] [blame]
xuegaof248df62019-07-15 15:16:18 +02001/*-
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
23export default class LoopService {
24 static getLoopNames() {
Ashwin Sharmae673a052020-07-30 16:05:02 +000025 return fetch(window.location.pathname + 'restservices/clds/v2/loop/getAllNames', { method: 'GET', credentials: 'same-origin' })
sebdet493c3832019-07-15 17:26:18 +020026 .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 });
xuegaof248df62019-07-15 15:16:18 +020039 }
40
sebdetd2a4df02020-02-26 15:47:30 -080041 static createLoop(loopName, templateName) {
Ashwin Sharmae673a052020-07-30 16:05:02 +000042 return fetch(window.location.pathname + 'restservices/clds/v2/loop/create/' + loopName + '?templateName=' + templateName, {
sebdetd2a4df02020-02-26 15:47:30 -080043 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
xuegaof248df62019-07-15 15:16:18 +020059 static getLoop(loopName) {
Ashwin Sharmae673a052020-07-30 16:05:02 +000060 return fetch(window.location.pathname + 'restservices/clds/v2/loop/' + loopName, {
xuegaof248df62019-07-15 15:16:18 +020061 method: 'GET',
62 headers: {
sebdet337f3662019-09-06 18:11:51 +020063 "Content-Type": "application/json"
sebdet493c3832019-07-15 17:26:18 +020064 },
sebdet337f3662019-09-06 18:11:51 +020065 credentials: 'same-origin'
xuegaof248df62019-07-15 15:16:18 +020066 })
sebdet493c3832019-07-15 17:26:18 +020067 .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
sebdet2df6c082019-07-18 15:29:45 +020082 static setMicroServiceProperties(loopName, jsonData) {
Ashwin Sharmae673a052020-07-30 16:05:02 +000083 return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateMicroservicePolicy/' + loopName, {
sebdet2df6c082019-07-18 15:29:45 +020084 method: 'POST',
85 credentials: 'same-origin',
86 headers: {
sebdet337f3662019-09-06 18:11:51 +020087 "Content-Type": "application/json"
sebdet2df6c082019-07-18 15:29:45 +020088 },
sebdet337f3662019-09-06 18:11:51 +020089 body: JSON.stringify(jsonData)
sebdet2df6c082019-07-18 15:29:45 +020090 })
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 }
sebdetf9e2cee2019-08-09 18:36:09 +0200105
106 static setOperationalPolicyProperties(loopName, jsonData) {
Ashwin Sharmae673a052020-07-30 16:05:02 +0000107 return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateOperationalPolicies/' + loopName, {
sebdetf9e2cee2019-08-09 18:36:09 +0200108 method: 'POST',
109 credentials: 'same-origin',
110 headers: {
sebdet337f3662019-09-06 18:11:51 +0200111 "Content-Type": "application/json"
sebdetf9e2cee2019-08-09 18:36:09 +0200112 },
sebdet337f3662019-09-06 18:11:51 +0200113 body: JSON.stringify(jsonData)
sebdetf9e2cee2019-08-09 18:36:09 +0200114 })
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 }
xuegaob09e7df2019-07-23 14:13:06 +0200129
130 static updateGlobalProperties(loopName, jsonData) {
Ashwin Sharmae673a052020-07-30 16:05:02 +0000131 return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateGlobalProperties/' + loopName, {
xuegaob09e7df2019-07-23 14:13:06 +0200132 method: 'POST',
133 credentials: 'same-origin',
134 headers: {
sebdet337f3662019-09-06 18:11:51 +0200135 "Content-Type": "application/json"
xuegaob09e7df2019-07-23 14:13:06 +0200136 },
sebdet337f3662019-09-06 18:11:51 +0200137 body: JSON.stringify(jsonData)
xuegaob09e7df2019-07-23 14:13:06 +0200138 })
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 }
xuegao2f5b2cd2020-01-06 16:13:46 +0100153
sebdete916ac22020-03-16 11:04:34 -0700154 static refreshOperationalPolicyJson(loopName,operationalPolicyName) {
Ashwin Sharmae673a052020-07-30 16:05:02 +0000155 return fetch(window.location.pathname + 'restservices/clds/v2/loop/refreshOperationalPolicyJsonSchema/' + loopName + '/' + operationalPolicyName, {
xuegao2f5b2cd2020-01-06 16:13:46 +0100156 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 }
sebdetaa486be2020-02-18 02:00:11 -0800176
sebdete916ac22020-03-16 11:04:34 -0700177 static refreshMicroServicePolicyJson(loopName,microServicePolicyName) {
Ashwin Sharmae673a052020-07-30 16:05:02 +0000178 return fetch(window.location.pathname + 'restservices/clds/v2/loop/refreshMicroServicePolicyJsonSchema/' + loopName + '/' + microServicePolicyName, {
sebdete916ac22020-03-16 11:04:34 -0700179 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
xuegaofb4b25f2020-03-11 11:22:15 +0100200 static addOperationalPolicyType(loopName, policyType, policyVersion) {
Ashwin Sharmae673a052020-07-30 16:05:02 +0000201 return fetch(window.location.pathname + 'restservices/clds/v2/loop/addOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion , {
xuegaofb4b25f2020-03-11 11:22:15 +0100202 method: 'PUT',
203 headers: {
204 "Content-Type": "application/json"
205 },
206 credentials: 'same-origin'
207 })
208 .then(function (response) {
xuegaoc6561392020-04-21 13:39:50 +0200209 console.debug("Add Operational Policy response received: ", response.status);
xuegaofb4b25f2020-03-11 11:22:15 +0100210 if (response.ok) {
211 return response.json();
212 } else {
xuegaoc6561392020-04-21 13:39:50 +0200213 return response.text();
xuegaofb4b25f2020-03-11 11:22:15 +0100214 }
215 })
sebdet614956d2020-04-22 23:10:54 +0200216 .catch(function (error) {
xuegaoc6561392020-04-21 13:39:50 +0200217 console.error("Add Operational Policy query failed");
sebdet614956d2020-04-22 23:10:54 +0200218 throw new Error(error);
xuegaoc6561392020-04-21 13:39:50 +0200219 })
xuegaofb4b25f2020-03-11 11:22:15 +0100220 }
221
sebdetab3eab62020-04-16 12:09:24 +0200222 static removeOperationalPolicyType(loopName, policyType, policyVersion, policyName) {
Ashwin Sharmae673a052020-07-30 16:05:02 +0000223 return fetch(window.location.pathname + 'restservices/clds/v2/loop/removeOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion + '/' + policyName , {
xuegaofb4b25f2020-03-11 11:22:15 +0100224 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 }
xuegaof248df62019-07-15 15:16:18 +0200244}