blob: f2886b30a5378b388ae1eb1c07bf79afd8de2677 [file] [log] [blame]
sebdeteb8e3f12021-01-24 18:12:36 +01001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP POLICY-CLAMP
4 * ================================================================================
5 * Copyright (C) 2021 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 PolicyService {
24 static getPoliciesList() {
sebdeta0a3a032021-02-16 14:53:43 +010025 return fetch(window.location.pathname + 'restservices/clds/v2/policies', {
sebdeteb8e3f12021-01-24 18:12:36 +010026 method: 'GET',
27 credentials: 'same-origin'
28 })
sebdetea2969f2021-02-25 13:58:36 +010029 .then(function(response) {
30 console.debug("getPoliciesList response received: ", response.status);
31 if (response.ok) {
32 console.info("getPoliciesList query successful");
33 return response.json();
34 } else {
35 return response.text().then(responseBody => {
36 throw new Error("HTTP " + response.status + "," + responseBody);
37 })
38 }
39 })
40 .catch(function(error) {
41 console.error("getPoliciesList error occurred ", error);
42 alert("getPoliciesList error occurred " + error);
sebdetb8831e52021-03-12 19:30:22 +010043 return undefined;
sebdet42fa9f42021-03-26 18:31:08 +010044 });
sebdeteb8e3f12021-01-24 18:12:36 +010045 }
sebdet1e2760e2021-02-26 19:14:03 +010046 static createNewPolicy(policyModelType, policyModelVersion, policyName, policyVersion, policyJson) {
47 return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/'
48 + policyModelVersion + '/' + policyName + '/' + policyVersion, {
sebdetc427e642021-02-17 17:53:17 +010049 method: 'POST',
50 credentials: 'same-origin',
51 headers: {
52 "Content-Type": "application/json"
53 },
54 body: JSON.stringify(policyJson)
55 })
sebdetea2969f2021-02-25 13:58:36 +010056 .then(function (response) {
57 console.debug("createNewPolicy response received: ", response.status);
58 if (response.ok) {
59 console.info("createNewPolicy query successful");
60 return response.text();
61 } else {
62 return response.text().then(responseBody => {
63 throw new Error("HTTP " + response.status + "," + responseBody);
64 })
65 }
66 })
67 .catch(function (error) {
68 console.error("createNewPolicy error occurred ", error);
69 alert ("createNewPolicy error occurred " + error);
sebdetb8831e52021-03-12 19:30:22 +010070 return undefined;
sebdetea2969f2021-02-25 13:58:36 +010071 });
72 }
73 static deletePolicy(policyModelType, policyModelVersion, policyName, policyVersion) {
74 return fetch(window.location.pathname + 'restservices/clds/v2/policies/' + policyModelType + '/'
75 + policyModelVersion + '/' + policyName + '/' + policyVersion, {
76 method: 'DELETE',
77 credentials: 'same-origin'
78 })
79 .then(function (response) {
80 console.debug("deletePolicy response received: ", response.status);
81 if (response.ok) {
82 console.info("deletePolicy query successful");
83 return response.text();
84 } else {
85 return response.text().then(responseBody => {
86 throw new Error("HTTP " + response.status + "," + responseBody);
87 })
88 }
89 })
90 .catch(function (error) {
91 console.error("deletePolicy error occurred ", error);
92 alert ("deletePolicy error occurred " + error);
sebdetb8831e52021-03-12 19:30:22 +010093 return undefined;
sebdetea2969f2021-02-25 13:58:36 +010094 });
sebdetc427e642021-02-17 17:53:17 +010095 }
sebdet42fa9f42021-03-26 18:31:08 +010096 static updatePdpDeployment(pdpOperationsList) {
97 return fetch(window.location.pathname + 'restservices/clds/v2/policies/pdpDeployment', {
98 method: 'PUT',
99 credentials: 'same-origin',
100 headers: {
101 "Content-Type": "application/json"
102 },
103 body: JSON.stringify(pdpOperationsList)
104 })
105 .then(function (response) {
106 console.debug("updatePdpDeployment response received: ", response.status);
107 if (response.ok) {
108 console.info("updatePdpDeployment query successful");
109 return response.text();
110 } else {
111 return response.text().then(responseBody => {
112 throw new Error("HTTP " + response.status + "," + responseBody);
113 })
114 }
115 })
116 .catch(function (error) {
117 console.error("updatePdpDeployment error occurred ", error);
118 alert ("updatePdpDeployment error occurred " + error);
119 return undefined;
120 });
121 }
sebdetd1ed0a92021-04-21 16:28:33 +0200122 static sendNewPolicyModel(newPolicyModel) {
123 return fetch(window.location.pathname + 'restservices/clds/v2/policies/policytype', {
124 method: 'POST',
125 credentials: 'same-origin',
126 headers: {
127 "Content-Type": "plain/text"
128 },
129 body: newPolicyModel
130 })
131 .then(function (response) {
132 console.debug("sendNewPolicyModel response received: ", response.status);
133 if (response.ok) {
134 console.info("sendNewPolicyModel query successful");
135 return response.text();
136 } else {
137 return response.text().then(responseBody => {
138 throw new Error("HTTP " + response.status + "," + responseBody);
139 })
140 }
141 })
142 .catch(function (error) {
143 console.error("sendNewPolicyModel error occurred ", error);
144 alert ("sendNewPolicyModel error occurred " + error);
145 return undefined;
146 });
147 }
sebdeteb8e3f12021-01-24 18:12:36 +0100148}