Merge "RIFT-14856: launchpad UI - Logging - default category severity"
[osm/UI.git] / skyquake / plugins / logging / src / loggingSource.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 let rw = require('utils/rw.js');
19 var API_SERVER = rw.getSearchParams(window.location).api_server;
20 var loggingActions = require('./loggingActions.js');
21 var Utils = require('utils/utils.js');
22 import $ from 'jquery';
23
24 function apiUrl(endpoint) {
25 return endpoint.replace(/\/$/,'') + '?api_server=' + API_SERVER;
26 }
27
28 export default {
29 /**
30 * Retrieve the logging configuration data from the Node API server
31 */
32 getLoggingConfig: function() {
33 //console.log("LoggingSource.getLoggingConfig called");
34 return {
35 remote: function(state) {
36 return new Promise(function(resolve, reject) {
37 //console.log("loggingSource.getLoggingConfig called");
38 $.ajax({
39 url: apiUrl('api/aggregate'),
40 type: 'GET',
41 beforeSend: Utils.addAuthorizationStub,
42 success: function(data) {
43 //console.log("LoggingSource.getLoggingConfig success call. data=", data);
44 resolve(data);
45 },
46 error: function(e) {
47 console.log("Error getting logging config details");
48 }
49 });
50 });
51 },
52 success: loggingActions.getLoggingConfigSuccess,
53 error: loggingActions.getLoggingConfigError
54 }
55 },
56 /**
57 * Update the logging configuration data on the server
58 * @param {object} state - Reference to parent store state
59 * @param {object} loggingConfig - logging configuration data
60 * @return {[type]} [description]
61 }
62 */
63 updateLoggingConfig: function () {
64 return {
65 remote: function(state, nulledCategories, loggingConfig) {
66 return new Promise(function(resolve, reject) {
67 let promises = [];
68 let remove = null;
69 let change = $.ajax({
70 url: apiUrl('api/aggregate'),
71 type: 'PUT',
72 beforeSend: Utils.addAuthorizationStub,
73 data: loggingConfig,
74 success: function(data) {
75 resolve(data);
76 },
77 error: function(error) {
78 console.log("There was an error updating the logging config data",
79 error);
80 reject(error);
81 }
82 });
83 promises.push(change);
84 /* Backend bug disallows deleting: RIFT-14910
85
86 if(nulledCategories.length > 0) {
87 remove = $.ajax({
88 // url: apiUrl('api/config/default-severity'),
89 url: apiUrl('api/config/default-syslog-severity'),
90 type: 'DELETE',
91 beforeSend: Utils.addAuthorizationStub,
92 data: nulledCategories,
93 success: function(data) {
94 resolve(data);
95 },
96 error: function(error) {
97 console.log("There was an error updating the logging config data",
98 error);
99 reject(error);
100 }
101 });
102 promises.push(remove);
103 }
104 */
105
106
107 Promise.all(promises).then(function(data){
108 resolve(data)
109 }, function(){
110 reject(arguments)
111 })
112
113 });
114
115 },
116 success: loggingActions.putLoggingConfigSuccess,
117 error: loggingActions.putLoggingConfigError
118 }
119 }
120 }