2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 import { Action } from '../../../../framework/src/flux/action';
20 import { Dispatch } from '../../../../framework/src/flux/store';
22 import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions';
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
25 import mediatorService from '../services/mediatorService';
26 import { MediatorConfig, MediatorConfigResponse } from '../models/mediatorServer';
28 /** Represents the base action. */
29 export class BaseAction extends Action { }
31 export class SetMediatorBusyByName extends BaseAction {
32 constructor(public name: string, public isBusy: boolean) {
37 export class AddMediatorConfig extends BaseAction {
38 constructor(public mediatorConfig: MediatorConfigResponse) {
43 export class UpdateMediatorConfig extends BaseAction {
44 constructor(public name: string, public mediatorConfig: MediatorConfigResponse) {
49 export class RemoveMediatorConfig extends BaseAction {
50 constructor(public name: string) {
56 export const startMediatorByNameAsyncActionCreator = (name: string) => (dispatch: Dispatch, getState: () => IApplicationStoreState) => {
57 dispatch(new SetMediatorBusyByName(name, true));
58 const { mediator: { mediatorServerState: { id } } } = getState();
60 mediatorService.startMediatorByName(id, name).then(msg => {
61 dispatch(new AddSnackbarNotification({ message: msg + ' ' + name, options: { variant: 'info' } }));
62 // since there is no notification, a timeout will be need here
63 window.setTimeout(() => {
64 mediatorService.getMediatorServerConfigByName(id, name).then(config => {
66 dispatch(new UpdateMediatorConfig(name, config));
68 dispatch(new AddSnackbarNotification({ message: `Error: reading mediator config for ${name}.`, options: { variant: 'error' } }));
70 dispatch(new SetMediatorBusyByName(name, false));
75 dispatch(new AddSnackbarNotification({ message: `Error: currently no mediator server selected.`, options: { variant: 'error' } }));
76 dispatch(new SetMediatorBusyByName(name, false));
80 export const stopMediatorByNameAsyncActionCreator = (name: string) => (dispatch: Dispatch, getState: () => IApplicationStoreState) => {
81 dispatch(new SetMediatorBusyByName(name, true));
82 const { mediator: { mediatorServerState: { id } } } = getState();
84 mediatorService.stopMediatorByName(id, name).then(msg => {
85 dispatch(new AddSnackbarNotification({ message: msg + ' ' + name, options: { variant: 'info' } }));
86 // since there is no notification, a timeout will be need here
87 window.setTimeout(() => {
88 mediatorService.getMediatorServerConfigByName(id, name).then(config => {
90 dispatch(new UpdateMediatorConfig(name, config));
92 dispatch(new AddSnackbarNotification({ message: `Error: reading mediator config for ${name}.`, options: { variant: 'error' } }));
94 dispatch(new SetMediatorBusyByName(name, false));
99 dispatch(new AddSnackbarNotification({ message: `Error: currently no mediator server selected.`, options: { variant: 'error' } }));
100 dispatch(new SetMediatorBusyByName(name, false));
104 export const addMediatorConfigAsyncActionCreator = (config: MediatorConfig) => (dispatch: Dispatch, getState: () => IApplicationStoreState) => {
105 const { Name: name } = config;
106 const { mediator: { mediatorServerState: { id } } } = getState();
108 mediatorService.createMediatorConfig(id, config).then(msg => {
109 dispatch(new AddSnackbarNotification({ message: msg + ' ' + name, options: { variant: 'info' } }));
110 // since there is no notification, a timeout will be need here
111 window.setTimeout(() => {
112 mediatorService.getMediatorServerConfigByName(id, name).then(config => {
114 dispatch(new AddMediatorConfig(config));
116 dispatch(new AddSnackbarNotification({ message: `Error: reading mediator config for ${name}.`, options: { variant: 'error' } }));
122 dispatch(new AddSnackbarNotification({ message: `Error: currently no mediator server selected.`, options: { variant: 'error' } }));
126 export const updateMediatorConfigAsyncActionCreator = (config: MediatorConfig) => (dispatch: Dispatch) => {
127 // currently not supported be backend
130 export const removeMediatorConfigAsyncActionCreator = (config: MediatorConfig) => (dispatch: Dispatch, getState: () => IApplicationStoreState) => {
131 const { Name: name } = config;
132 const { mediator: { mediatorServerState: { id } } } = getState();
134 mediatorService.deleteMediatorConfigByName(id, name).then(msg => {
135 dispatch(new AddSnackbarNotification({ message: msg + ' ' + name, options: { variant: 'info' } }));
136 // since there is no notification, a timeout will be need here
137 window.setTimeout(() => {
138 mediatorService.getMediatorServerConfigByName(id, config.Name).then(config => {
140 dispatch(new RemoveMediatorConfig(name));
142 dispatch(new AddSnackbarNotification({ message: `Error: deleting mediator config for ${name}.`, options: { variant: 'error' } }));
148 dispatch(new AddSnackbarNotification({ message: `Error: currently no mediator server selected.`, options: { variant: 'error' } }));
149 dispatch(new SetMediatorBusyByName(name, false));