blob: d665f81481e85725eb2f0a2cf7202062f6e26b3c [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() {
sebdet337f3662019-09-06 18:11:51 +020025 return fetch('/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) {
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
xuegaof248df62019-07-15 15:16:18 +020059 static getLoop(loopName) {
sebdet493c3832019-07-15 17:26:18 +020060 return fetch('/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
82 static getSvg(loopName) {
83 return fetch('/restservices/clds/v2/loop/svgRepresentation/' + loopName, {
84 method: 'GET',
sebdet337f3662019-09-06 18:11:51 +020085 credentials: 'same-origin'
xuegaof248df62019-07-15 15:16:18 +020086 })
sebdet493c3832019-07-15 17:26:18 +020087 .then(function (response) {
88 console.debug("svgRepresentation response received: ", response.status);
89 if (response.ok) {
90 return response.text();
91 } else {
92 console.error("svgRepresentation query failed");
93 return "";
94 }
95 })
96 .catch(function (error) {
97 console.error("svgRepresentation error received", error);
98 return "";
99 });
xuegaof248df62019-07-15 15:16:18 +0200100 }
sebdet2df6c082019-07-18 15:29:45 +0200101
102 static setMicroServiceProperties(loopName, jsonData) {
103 return fetch('/restservices/clds/v2/loop/updateMicroservicePolicy/' + loopName, {
104 method: 'POST',
105 credentials: 'same-origin',
106 headers: {
sebdet337f3662019-09-06 18:11:51 +0200107 "Content-Type": "application/json"
sebdet2df6c082019-07-18 15:29:45 +0200108 },
sebdet337f3662019-09-06 18:11:51 +0200109 body: JSON.stringify(jsonData)
sebdet2df6c082019-07-18 15:29:45 +0200110 })
111 .then(function (response) {
112 console.debug("updateMicroservicePolicy response received: ", response.status);
113 if (response.ok) {
114 return response.text();
115 } else {
116 console.error("updateMicroservicePolicy query failed");
117 return "";
118 }
119 })
120 .catch(function (error) {
121 console.error("updateMicroservicePolicy error received", error);
122 return "";
123 });
124 }
sebdetf9e2cee2019-08-09 18:36:09 +0200125
126 static setOperationalPolicyProperties(loopName, jsonData) {
127 return fetch('/restservices/clds/v2/loop/updateOperationalPolicies/' + loopName, {
128 method: 'POST',
129 credentials: 'same-origin',
130 headers: {
sebdet337f3662019-09-06 18:11:51 +0200131 "Content-Type": "application/json"
sebdetf9e2cee2019-08-09 18:36:09 +0200132 },
sebdet337f3662019-09-06 18:11:51 +0200133 body: JSON.stringify(jsonData)
sebdetf9e2cee2019-08-09 18:36:09 +0200134 })
135 .then(function (response) {
136 console.debug("updateOperationalPolicies response received: ", response.status);
137 if (response.ok) {
138 return response.text();
139 } else {
140 console.error("updateOperationalPolicies query failed");
141 return "";
142 }
143 })
144 .catch(function (error) {
145 console.error("updateOperationalPolicies error received", error);
146 return "";
147 });
148 }
xuegaob09e7df2019-07-23 14:13:06 +0200149
150 static updateGlobalProperties(loopName, jsonData) {
151 return fetch('/restservices/clds/v2/loop/updateGlobalProperties/' + loopName, {
152 method: 'POST',
153 credentials: 'same-origin',
154 headers: {
sebdet337f3662019-09-06 18:11:51 +0200155 "Content-Type": "application/json"
xuegaob09e7df2019-07-23 14:13:06 +0200156 },
sebdet337f3662019-09-06 18:11:51 +0200157 body: JSON.stringify(jsonData)
xuegaob09e7df2019-07-23 14:13:06 +0200158 })
159 .then(function (response) {
160 console.debug("updateGlobalProperties response received: ", response.status);
161 if (response.ok) {
162 return response.text();
163 } else {
164 console.error("updateGlobalProperties query failed");
165 return "";
166 }
167 })
168 .catch(function (error) {
169 console.error("updateGlobalProperties error received", error);
170 return "";
171 });
172 }
xuegao2f5b2cd2020-01-06 16:13:46 +0100173
174 static refreshOpPolicyJson(loopName) {
175 return fetch('/restservices/clds/v2/loop/refreshOpPolicyJsonSchema/' + loopName, {
176 method: 'PUT',
177 headers: {
178 "Content-Type": "application/json"
179 },
180 credentials: 'same-origin'
181 })
182 .then(function (response) {
183 console.debug("Refresh Operational Policy Json Schema response received: ", response.status);
184 if (response.ok) {
185 return response.json();
186 } else {
187 console.error("Refresh Operational Policy Json Schema query failed");
188 return {};
189 }
190 })
191 .catch(function (error) {
192 console.error("Refresh Operational Policy Json Schema error received", error);
193 return {};
194 });
195 }
sebdetaa486be2020-02-18 02:00:11 -0800196
197 static addOperationalPolicyType(loopName, policyType, policyVersion) {
198 return fetch('/restservices/clds/v2/loop/addOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion , {
199 method: 'PUT',
200 headers: {
201 "Content-Type": "application/json"
202 },
203 credentials: 'same-origin'
204 })
205 .then(function (response) {
206 console.debug("Add Operational Policy response received: ", response.status);
207 if (response.ok) {
208 return response.json();
209 } else {
210 console.error("Add Operational Policy query failed");
211 return {};
212 }
213 })
214 .catch(function (error) {
215 console.error("Add Operational Policy error received", error);
216 return {};
217 });
218 }
xuegaof248df62019-07-15 15:16:18 +0200219}