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() { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 25 | return fetch('/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) { |
| 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 | |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 59 | static getLoop(loopName) { |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 60 | return fetch('/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 | |
| 82 | static getSvg(loopName) { |
| 83 | return fetch('/restservices/clds/v2/loop/svgRepresentation/' + loopName, { |
| 84 | method: 'GET', |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 85 | credentials: 'same-origin' |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 86 | }) |
sebdet | 493c383 | 2019-07-15 17:26:18 +0200 | [diff] [blame] | 87 | .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 | }); |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 100 | } |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 101 | |
| 102 | static setMicroServiceProperties(loopName, jsonData) { |
| 103 | return fetch('/restservices/clds/v2/loop/updateMicroservicePolicy/' + loopName, { |
| 104 | method: 'POST', |
| 105 | credentials: 'same-origin', |
| 106 | headers: { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 107 | "Content-Type": "application/json" |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 108 | }, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 109 | body: JSON.stringify(jsonData) |
sebdet | 2df6c08 | 2019-07-18 15:29:45 +0200 | [diff] [blame] | 110 | }) |
| 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 | } |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 125 | |
| 126 | static setOperationalPolicyProperties(loopName, jsonData) { |
| 127 | return fetch('/restservices/clds/v2/loop/updateOperationalPolicies/' + loopName, { |
| 128 | method: 'POST', |
| 129 | credentials: 'same-origin', |
| 130 | headers: { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 131 | "Content-Type": "application/json" |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 132 | }, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 133 | body: JSON.stringify(jsonData) |
sebdet | f9e2cee | 2019-08-09 18:36:09 +0200 | [diff] [blame] | 134 | }) |
| 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 | } |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 149 | |
| 150 | static updateGlobalProperties(loopName, jsonData) { |
| 151 | return fetch('/restservices/clds/v2/loop/updateGlobalProperties/' + loopName, { |
| 152 | method: 'POST', |
| 153 | credentials: 'same-origin', |
| 154 | headers: { |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 155 | "Content-Type": "application/json" |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 156 | }, |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 157 | body: JSON.stringify(jsonData) |
xuegao | b09e7df | 2019-07-23 14:13:06 +0200 | [diff] [blame] | 158 | }) |
| 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 | } |
xuegao | 2f5b2cd | 2020-01-06 16:13:46 +0100 | [diff] [blame] | 173 | |
| 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 | } |
sebdet | aa486be | 2020-02-18 02:00:11 -0800 | [diff] [blame] | 196 | |
| 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 | } |
xuegao | f248df6 | 2019-07-15 15:16:18 +0200 | [diff] [blame] | 219 | } |