blob: 6e45ce4b932a8747862d07aefbefa77b064fb04d [file] [log] [blame]
xuegao7c7323d2019-07-09 11:52:20 +02001/*-
2 * ============LICENSE_START=======================================================
3 * ONAP CLAMP
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights
6 * reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
20 * ===================================================================
21 *
22 */
xuegao5fe750c2019-08-06 13:03:53 +020023
24export default class LoopActionService{
25
26 static performAction(cl_name, uiAction) {
27 console.log("LoopActionService perform action: " + uiAction + " closedloopName=" + cl_name);
28 const svcAction = uiAction.toLowerCase();
29 return fetch("/restservices/clds/v2/loop/" + svcAction + "/" + cl_name, {
30 method: 'PUT',
31 credentials: 'same-origin',
32 })
33 .then(function (response) {
34 if (response.ok) {
35 return response.json();
36 } else {
37 return Promise.reject("Perform action failed with code:" + response.status);
38 }
39 })
40 .then(function (data) {
41 alert("Action Successful: " + uiAction);
42 return data;
43 })
44 .catch(function(error) {
45 console.log("Action Failure: " + uiAction);
46 return Promise.reject(error);
47 });
48 }
xuegao7c7323d2019-07-09 11:52:20 +020049
sebdet4946e5b2019-07-10 12:32:36 +020050
xuegao5fe750c2019-08-06 13:03:53 +020051 static refreshStatus(cl_name) {
52 console.log("Refresh the status for closedloopName=" + cl_name);
xuegao7c7323d2019-07-09 11:52:20 +020053
xuegao5fe750c2019-08-06 13:03:53 +020054 return fetch("/restservices/clds/v2/loop/getstatus/" + cl_name, {
55 method: 'GET',
56 credentials: 'same-origin',
57 })
58 .then(function (response) {
59 if (response.ok) {
60 return response.json();
61 } else {
62 return Promise.reject("Refresh status failed with code:" + response.status);
63 }
64 })
65 .then(function (data) {
66 console.info ("Refresh status Successful");
67 return data;
68 })
69 .catch(function(error) {
70 console.info ("Refresh status failed:", error);
71 return Promise.reject(error);
72 });
73 }
xuegao7c7323d2019-07-09 11:52:20 +020074}