2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import i18n from 'nfvo-utils/i18n/i18n.js';
17 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
18 import Configuration from 'sdc-app/config/Configuration.js';
19 import SoftwareProductComponentsMonitoringConstants, {actionTypes} from './SoftwareProductComponentsMonitoringConstants.js';
20 import {actionTypes as modalActionTypes} from 'nfvo-components/modal/GlobalModalConstants.js';
24 function baseUrl(vspId, version, componentId) {
25 const versionId = version.id;
26 const restPrefix = Configuration.get('restPrefix');
27 return `${restPrefix}/v1.0/vendor-software-products/${vspId}/versions/${versionId}/components/${componentId}/monitors`;
30 function snmpTrapUrl(vspId, version, componentId, isUpload) {
31 return `${baseUrl(vspId, version, componentId)}/snmp-trap${isUpload ? '/upload' : ''}`;
34 function snmpPollUrl(vspId, version, componentId, isUpload) {
35 return `${baseUrl(vspId, version, componentId)}/snmp${isUpload ? '/upload' : ''}`;
38 let onInvalidFileSizeUpload = (dispatch) => dispatch({
39 type: modalActionTypes.GLOBAL_MODAL_ERROR,
41 title: i18n('Upload Failed'),
42 msg: i18n('no zip file was uploaded or zip file doesn\'t exist')
46 let uploadSnmpTrapFile = (dispatch, {softwareProductId, version, componentId, formData}) => {
47 RestAPIUtil.post(snmpTrapUrl(softwareProductId, version, componentId, UPLOAD), formData).then(()=> dispatch({
48 type: actionTypes.SNMP_TRAP_UPLOADED, data: {filename: formData.get('upload').name}
52 let uploadSnmpPollFile = (dispatch, {softwareProductId, version, componentId, formData}) => {
53 RestAPIUtil.post(snmpPollUrl(softwareProductId, version, componentId, UPLOAD), formData).then(()=> dispatch({
54 type: actionTypes.SNMP_POLL_UPLOADED, data: {filename: formData.get('upload').name}
58 let deleteSnmpTrapFile = (dispatch, {softwareProductId, version, componentId}) => {
59 RestAPIUtil.destroy(snmpTrapUrl(softwareProductId, version, componentId, !UPLOAD)).then(()=> dispatch({
60 type: actionTypes.SNMP_TRAP_DELETED
64 let deleteSnmpPollFile = (dispatch, {softwareProductId, version, componentId}) => {
65 RestAPIUtil.destroy(snmpPollUrl(softwareProductId, version, componentId, !UPLOAD)).then(()=> dispatch({
66 type: actionTypes.SNMP_POLL_DELETED
70 const SoftwareProductComponentsMonitoringAction = {
72 fetchExistingFiles(dispatch, {softwareProductId, version, componentId}){
73 RestAPIUtil.fetch(`${baseUrl(softwareProductId, version, componentId)}/snmp`).then(response =>
75 type: actionTypes.SNMP_FILES_DATA_CHANGE,
76 data: {trapFilename: response.snmpTrap, pollFilename: response.snmpPoll}
81 uploadSnmpFile(dispatch, {softwareProductId, version, componentId, formData, type}){
82 if (formData.get('upload').size) {
83 if (type === SoftwareProductComponentsMonitoringConstants.SNMP_TRAP) {
84 uploadSnmpTrapFile(dispatch, {softwareProductId, version, componentId, formData});
87 uploadSnmpPollFile(dispatch, {softwareProductId, version, componentId, formData});
91 onInvalidFileSizeUpload(dispatch);
95 deleteSnmpFile(dispatch, {softwareProductId, version, componentId, type}){
96 if (type === SoftwareProductComponentsMonitoringConstants.SNMP_TRAP) {
97 deleteSnmpTrapFile(dispatch, {softwareProductId, version, componentId});
100 deleteSnmpPollFile(dispatch, {softwareProductId, version, componentId});
106 export default SoftwareProductComponentsMonitoringAction;