blob: 7cea3ff9f2cf030cef4de7670c19a684a00b7ba7 [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) {
xuegao0efeb6b2019-10-07 14:36:34 +020027 console.info("LoopActionService perform action: " + uiAction + " closedloopName=" + cl_name);
xuegao5fe750c2019-08-06 13:03:53 +020028 const svcAction = uiAction.toLowerCase();
29 return fetch("/restservices/clds/v2/loop/" + svcAction + "/" + cl_name, {
30 method: 'PUT',
sebdet337f3662019-09-06 18:11:51 +020031 credentials: 'same-origin'
xuegao5fe750c2019-08-06 13:03:53 +020032 })
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) {
xuegao0efeb6b2019-10-07 14:36:34 +020041 console.info("Action Successful: " + uiAction);
xuegao5fe750c2019-08-06 13:03:53 +020042 return data;
43 })
44 .catch(function(error) {
xuegao0efeb6b2019-10-07 14:36:34 +020045 console.info("Action Failure: " + uiAction);
xuegao5fe750c2019-08-06 13:03:53 +020046 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) {
xuegao0efeb6b2019-10-07 14:36:34 +020052 console.info("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',
sebdet337f3662019-09-06 18:11:51 +020056 credentials: 'same-origin'
xuegao5fe750c2019-08-06 13:03:53 +020057 })
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}