2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
23 import NotificationConstants from 'nfvo-components/notifications/NotificationConstants.js';
24 import Configuration from 'sdc-app/config/Configuration.js';
25 import SoftwareProductComponentsMonitoringConstants, {actionTypes} from './SoftwareProductComponentsMonitoringConstants.js';
29 function baseUrl(vspId, componentId) {
30 const restPrefix = Configuration.get('restPrefix');
31 return `${restPrefix}/v1.0/vendor-software-products/${vspId}/components/${componentId}/monitors`;
34 function snmpTrapUrl(vspId, componentId, isUpload) {
35 return `${baseUrl(vspId, componentId)}/snmp-trap${isUpload ? '/upload' : ''}`;
38 function snmpPollUrl(vspId, componentId, isUpload) {
39 return `${baseUrl(vspId, componentId)}/snmp${isUpload ? '/upload' : ''}`;
42 let onInvalidFileSizeUpload = (dispatch) => dispatch({
43 type: NotificationConstants.NOTIFY_ERROR,
45 title: i18n('Upload Failed'),
46 msg: i18n('no zip file was uploaded or zip file doesn\'t exist')
50 let uploadSnmpTrapFile = (dispatch, {softwareProductId, componentId, formData}) => {
51 RestAPIUtil.create(snmpTrapUrl(softwareProductId, componentId, UPLOAD), formData).then(()=> dispatch({
52 type: actionTypes.SNMP_TRAP_UPLOADED, data: {filename: formData.get('upload').name}
56 let uploadSnmpPollFile = (dispatch, {softwareProductId, componentId, formData}) => {
57 RestAPIUtil.create(snmpPollUrl(softwareProductId, componentId, UPLOAD), formData).then(()=> dispatch({
58 type: actionTypes.SNMP_POLL_UPLOADED, data: {filename: formData.get('upload').name}
62 let deleteSnmpTrapFile = (dispatch, {softwareProductId, componentId}) => {
63 RestAPIUtil.destroy(snmpTrapUrl(softwareProductId, componentId, !UPLOAD)).then(()=> dispatch({
64 type: actionTypes.SNMP_TRAP_DELETED
68 let deleteSnmpPollFile = (dispatch, {softwareProductId, componentId}) => {
69 RestAPIUtil.destroy(snmpPollUrl(softwareProductId, componentId, !UPLOAD)).then(()=> dispatch({
70 type: actionTypes.SNMP_POLL_DELETED
74 const SoftwareProductComponentsMonitoringAction = {
76 fetchExistingFiles(dispatch, {softwareProductId, componentId}){
77 RestAPIUtil.fetch(`${baseUrl(softwareProductId, componentId)}/snmp`).then(response =>
79 type: actionTypes.SNMP_FILES_DATA_CHANGE,
80 data: {trapFilename: response.snmpTrap, pollFilename: response.snmpPoll}
85 uploadSnmpFile(dispatch, {softwareProductId, componentId, formData, type}){
86 if (formData.get('upload').size) {
87 if (type === SoftwareProductComponentsMonitoringConstants.SNMP_TRAP) {
88 uploadSnmpTrapFile(dispatch, {softwareProductId, componentId, formData});
91 uploadSnmpPollFile(dispatch, {softwareProductId, componentId, formData});
95 onInvalidFileSizeUpload(dispatch);
99 deleteSnmpFile(dispatch, {softwareProductId, componentId, type}){
100 if (type === SoftwareProductComponentsMonitoringConstants.SNMP_TRAP) {
101 deleteSnmpTrapFile(dispatch, {softwareProductId, componentId});
104 deleteSnmpPollFile(dispatch, {softwareProductId, componentId});
110 export default SoftwareProductComponentsMonitoringAction;