xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 1 | /*- |
| 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 | */ |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 23 | |
| 24 | export 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', |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 31 | credentials: 'same-origin' |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 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 | } |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 49 | |
sebdet | 4946e5b | 2019-07-10 12:32:36 +0200 | [diff] [blame] | 50 | |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 51 | static refreshStatus(cl_name) { |
| 52 | console.log("Refresh the status for closedloopName=" + cl_name); |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 53 | |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 54 | return fetch("/restservices/clds/v2/loop/getstatus/" + cl_name, { |
| 55 | method: 'GET', |
sebdet | 337f366 | 2019-09-06 18:11:51 +0200 | [diff] [blame] | 56 | credentials: 'same-origin' |
xuegao | 5fe750c | 2019-08-06 13:03:53 +0200 | [diff] [blame] | 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 | } |
xuegao | 7c7323d | 2019-07-09 11:52:20 +0200 | [diff] [blame] | 74 | } |