blob: c54e768a908276ee1d896366eaac5fd6be3f648f [file] [log] [blame]
sebdetaa486be2020-02-18 02:00:11 -08001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
sebdet3718a162021-02-12 17:18:47 +01005 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
sebdetaa486be2020-02-18 02:00:11 -08006 * ================================================================================
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 PolicyToscaService {
24 static getToscaPolicyModels() {
Ashwin Sharmae673a052020-07-30 16:05:02 +000025 return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels', { method: 'GET', credentials: 'same-origin' })
sebdetaa486be2020-02-18 02:00:11 -080026 .then(function (response) {
27 console.debug("getToscaPolicyModels response received: ", response.status);
28 if (response.ok) {
29 return response.json();
30 } else {
31 console.error("getToscaPolicyModels query failed");
32 return {};
33 }
34 })
35 .catch(function (error) {
36 console.error("getToscaPolicyModels error received", error);
37 return {};
38 });
39 }
40
41 static getToscaPolicyModelYaml(policyModelType, policyModelVersion) {
sebdet1e2760e2021-02-26 19:14:03 +010042 return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels/yaml/' + policyModelType + "/" + policyModelVersion, {
43 method: 'GET',
44 credentials: 'same-origin'
45 })
46 .then(function (response) {
47 console.debug("getToscaPolicyModelYaml response received: ", response.status);
48 if (response.ok) {
49 return response.json();
50 } else {
51 console.error("getToscaPolicyModelYaml query failed");
52 return "";
53 }
54 })
55 .catch(function (error) {
56 console.error("getToscaPolicyModelYaml error received", error);
57 return "";
58 });
sebdetaa486be2020-02-18 02:00:11 -080059 }
60
61 static getToscaPolicyModel(policyModelType, policyModelVersion) {
sebdet1e2760e2021-02-26 19:14:03 +010062 return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels/' + policyModelType + "/" + policyModelVersion, {
63 method: 'GET',
64 credentials: 'same-origin'
65 })
66 .then(function (response) {
67 console.debug("getToscaPolicyModel response received: ", response.status);
68 if (response.ok) {
69 return response.json();
70 } else {
71 console.error("getToscaPolicyModel query failed");
72 return {};
73 }
74 })
75 .catch(function (error) {
76 console.error("getToscaPolicyModel error received", error);
77 return {};
78 });
sebdetaa486be2020-02-18 02:00:11 -080079 }
80
Ashwin Sharma393bbb52020-02-27 17:24:52 +000081 static createPolicyModelFromToscaModel(jsonData) {
Ashwin Sharmae673a052020-07-30 16:05:02 +000082 return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels', {
sebdetaa486be2020-02-18 02:00:11 -080083 method: 'POST',
84 credentials: 'same-origin',
85 headers: {
86 "Content-Type": "a",
87 },
88 body: JSON.stringify(jsonData)
89 })
90 .then(function(response) {
91 console.debug("createPolicyModelFromToscaModel response received: ", response.status);
92 if (response.ok) {
93 var message = {
94 status: response.status,
95 message: 'Tosca Policy Model successfully uploaded'
96 };
97 return message;
98 } else {
99 console.error("createPolicyModelFromToscaModel failed");
100 return response.text();
101 }
102 })
103 .catch(function(error) {
104 console.error("createPolicyModelFromToscaModel error received", error);
105 return "";
106 });
107 }
108
109 static updatePolicyModelTosca(policyModelType, policyModelVersion, jsonData) {
Ashwin Sharmae673a052020-07-30 16:05:02 +0000110 return fetch(window.location.pathname + 'restservices/clds/v2/policyToscaModels/' + policyModelType + '/' + policyModelVersion, {
sebdetaa486be2020-02-18 02:00:11 -0800111 method: 'PUT',
112 credentials: 'same-origin',
113 headers: {
114 "Content-Type": "a",
115 },
116 body: JSON.stringify(jsonData)
117 })
118 .then(function(response) {
119 console.debug("updatePolicyModelTosca response received: ", response.status);
120 if (response.ok) {
121 var message = {
122 status: response.status,
123 message: 'Tosca Policy Model successfully uploaded'
124 };
125 return message;
126 } else {
127 console.error("updatePolicyModelTosca failed");
128 return response.text();
129 }
130 })
131 .catch(function(error) {
132 console.error("updatePolicyModelTosca error received", error);
133 return "";
134 });
135 }
136}