xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 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() { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 25 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/getAllNames', { method: 'GET', credentials: 'same-origin' }) |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 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 | }); |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 39 | } |
| 40 | |
sebdet | d2a4df0 | 2020-02-26 15:47:30 -0800 | [diff] [blame] | 41 | static createLoop(loopName, templateName) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 42 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/create/' + loopName + '?templateName=' + templateName, { |
sebdet | d2a4df0 | 2020-02-26 15:47:30 -0800 | [diff] [blame] | 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 | |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 59 | static getLoop(loopName) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 60 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/' + loopName, { |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 61 | method: 'GET', |
| 62 | headers: { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 63 | "Content-Type": "application/json" |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 64 | }, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 65 | credentials: 'same-origin' |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 66 | }) |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 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 | |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 82 | static setMicroServiceProperties(loopName, jsonData) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 83 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateMicroservicePolicy/' + loopName, { |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 84 | method: 'POST', |
| 85 | credentials: 'same-origin', |
| 86 | headers: { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 87 | "Content-Type": "application/json" |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 88 | }, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 89 | body: JSON.stringify(jsonData) |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 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 | } |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 105 | |
| 106 | static setOperationalPolicyProperties(loopName, jsonData) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 107 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateOperationalPolicies/' + loopName, { |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 108 | method: 'POST', |
| 109 | credentials: 'same-origin', |
| 110 | headers: { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 111 | "Content-Type": "application/json" |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 112 | }, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 113 | body: JSON.stringify(jsonData) |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 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 | } |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 129 | |
| 130 | static updateGlobalProperties(loopName, jsonData) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 131 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/updateGlobalProperties/' + loopName, { |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 132 | method: 'POST', |
| 133 | credentials: 'same-origin', |
| 134 | headers: { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 135 | "Content-Type": "application/json" |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 136 | }, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 137 | body: JSON.stringify(jsonData) |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 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 | } |
xuegao | 2f5b2cd | 2020-01-06 16:13:46 +0100 | [diff] [blame] | 153 | |
sebdet | e916ac2 | 2020-03-16 11:04:34 -0700 | [diff] [blame] | 154 | static refreshOperationalPolicyJson(loopName,operationalPolicyName) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 155 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/refreshOperationalPolicyJsonSchema/' + loopName + '/' + operationalPolicyName, { |
xuegao | 2f5b2cd | 2020-01-06 16:13:46 +0100 | [diff] [blame] | 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 | } |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 176 | |
sebdet | e916ac2 | 2020-03-16 11:04:34 -0700 | [diff] [blame] | 177 | static refreshMicroServicePolicyJson(loopName,microServicePolicyName) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 178 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/refreshMicroServicePolicyJsonSchema/' + loopName + '/' + microServicePolicyName, { |
sebdet | e916ac2 | 2020-03-16 11:04:34 -0700 | [diff] [blame] | 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 | |
xuegao | fb4b25f | 2020-03-11 11:22:15 +0100 | [diff] [blame] | 200 | static addOperationalPolicyType(loopName, policyType, policyVersion) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 201 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/addOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion , { |
xuegao | fb4b25f | 2020-03-11 11:22:15 +0100 | [diff] [blame] | 202 | method: 'PUT', |
| 203 | headers: { |
| 204 | "Content-Type": "application/json" |
| 205 | }, |
| 206 | credentials: 'same-origin' |
| 207 | }) |
| 208 | .then(function (response) { |
xuegao | c656139 | 2020-04-21 13:39:50 +0200 | [diff] [blame] | 209 | console.debug("Add Operational Policy response received: ", response.status); |
xuegao | fb4b25f | 2020-03-11 11:22:15 +0100 | [diff] [blame] | 210 | if (response.ok) { |
| 211 | return response.json(); |
| 212 | } else { |
xuegao | c656139 | 2020-04-21 13:39:50 +0200 | [diff] [blame] | 213 | return response.text(); |
xuegao | fb4b25f | 2020-03-11 11:22:15 +0100 | [diff] [blame] | 214 | } |
| 215 | }) |
sebdet | 614956d | 2020-04-22 23:10:54 +0200 | [diff] [blame] | 216 | .catch(function (error) { |
xuegao | c656139 | 2020-04-21 13:39:50 +0200 | [diff] [blame] | 217 | console.error("Add Operational Policy query failed"); |
sebdet | 614956d | 2020-04-22 23:10:54 +0200 | [diff] [blame] | 218 | throw new Error(error); |
xuegao | c656139 | 2020-04-21 13:39:50 +0200 | [diff] [blame] | 219 | }) |
xuegao | fb4b25f | 2020-03-11 11:22:15 +0100 | [diff] [blame] | 220 | } |
| 221 | |
sebdet | ab3eab6 | 2020-04-16 12:09:24 +0200 | [diff] [blame] | 222 | static removeOperationalPolicyType(loopName, policyType, policyVersion, policyName) { |
Ashwin Sharma | e673a05 | 2020-07-30 16:05:02 +0000 | [diff] [blame] | 223 | return fetch(window.location.pathname + 'restservices/clds/v2/loop/removeOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion + '/' + policyName , { |
xuegao | fb4b25f | 2020-03-11 11:22:15 +0100 | [diff] [blame] | 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 | } |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 244 | } |