2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
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);
29 return response.json();
31 console.error("GetLoopNames query failed");
35 .catch(function (error) {
36 console.error("GetLoopNames error received", error);
41 static createLoop(loopName, templateName) {
42 return fetch('/restservices/clds/v2/loop/create/' + loopName + '?templateName=' + templateName, {
45 "Content-Type": "application/json"
47 credentials: 'same-origin'
49 .then(function (response) {
50 console.debug("CreateLoop response received: ", response.status);
51 return response.json();
53 .catch(function (error) {
54 console.error("CreateLoop error received", error);
59 static getLoop(loopName) {
60 return fetch('/restservices/clds/v2/loop/' + loopName, {
63 "Content-Type": "application/json"
65 credentials: 'same-origin'
67 .then(function (response) {
68 console.debug("GetLoop response received: ", response.status);
70 return response.json();
72 console.error("GetLoop query failed");
76 .catch(function (error) {
77 console.error("GetLoop error received", error);
82 static setMicroServiceProperties(loopName, jsonData) {
83 return fetch('/restservices/clds/v2/loop/updateMicroservicePolicy/' + loopName, {
85 credentials: 'same-origin',
87 "Content-Type": "application/json"
89 body: JSON.stringify(jsonData)
91 .then(function (response) {
92 console.debug("updateMicroservicePolicy response received: ", response.status);
94 return response.text();
96 console.error("updateMicroservicePolicy query failed");
100 .catch(function (error) {
101 console.error("updateMicroservicePolicy error received", error);
106 static setOperationalPolicyProperties(loopName, jsonData) {
107 return fetch('/restservices/clds/v2/loop/updateOperationalPolicies/' + loopName, {
109 credentials: 'same-origin',
111 "Content-Type": "application/json"
113 body: JSON.stringify(jsonData)
115 .then(function (response) {
116 console.debug("updateOperationalPolicies response received: ", response.status);
118 return response.text();
120 console.error("updateOperationalPolicies query failed");
124 .catch(function (error) {
125 console.error("updateOperationalPolicies error received", error);
130 static updateGlobalProperties(loopName, jsonData) {
131 return fetch('/restservices/clds/v2/loop/updateGlobalProperties/' + loopName, {
133 credentials: 'same-origin',
135 "Content-Type": "application/json"
137 body: JSON.stringify(jsonData)
139 .then(function (response) {
140 console.debug("updateGlobalProperties response received: ", response.status);
142 return response.text();
144 console.error("updateGlobalProperties query failed");
148 .catch(function (error) {
149 console.error("updateGlobalProperties error received", error);
154 static refreshOperationalPolicyJson(loopName,operationalPolicyName) {
155 return fetch('/restservices/clds/v2/loop/refreshOperationalPolicyJsonSchema/' + loopName + '/' + operationalPolicyName, {
158 "Content-Type": "application/json"
160 credentials: 'same-origin'
162 .then(function (response) {
163 console.debug("Refresh Operational Policy Json Schema response received: ", response.status);
165 return response.json();
167 console.error("Refresh Operational Policy Json Schema query failed");
171 .catch(function (error) {
172 console.error("Refresh Operational Policy Json Schema error received", error);
177 static refreshMicroServicePolicyJson(loopName,microServicePolicyName) {
178 return fetch('/restservices/clds/v2/loop/refreshMicroServicePolicyJsonSchema/' + loopName + '/' + microServicePolicyName, {
181 "Content-Type": "application/json"
183 credentials: 'same-origin'
185 .then(function (response) {
186 console.debug("Refresh Operational Policy Json Schema response received: ", response.status);
188 return response.json();
190 console.error("Refresh Operational Policy Json Schema query failed");
194 .catch(function (error) {
195 console.error("Refresh Operational Policy Json Schema error received", error);
200 static addOperationalPolicyType(loopName, policyType, policyVersion) {
201 return fetch('/restservices/clds/v2/loop/addOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion , {
204 "Content-Type": "application/json"
206 credentials: 'same-origin'
208 .then(function (response) {
209 console.debug("Add Operational Policy response received: ", response.status);
211 return response.json();
213 return response.text();
216 .catch(function (error) {
217 console.error("Add Operational Policy query failed");
218 throw new Error(error);
222 static removeOperationalPolicyType(loopName, policyType, policyVersion, policyName) {
223 return fetch('/restservices/clds/v2/loop/removeOperationaPolicy/' + loopName + '/policyModel/' + policyType +'/' + policyVersion + '/' + policyName , {
226 "Content-Type": "application/json"
228 credentials: 'same-origin'
230 .then(function (response) {
231 console.debug("Remove Operational Policy response received: ", response.status);
233 return response.json();
235 console.error("Remove Operational Policy query failed");
239 .catch(function (error) {
240 console.error("Remove Operational Policy error received", error);