diff options
author | 2020-11-05 10:11:08 +0100 | |
---|---|---|
committer | 2020-11-12 14:21:25 +0000 | |
commit | d74f6cc4a47f4ebe94c6143f5ffb12b7f47c8fb6 (patch) | |
tree | 659d245c2d60edd94c19f06683916e0d37a9c79b /vid-webpack-master/src/app/shared/storeUtil | |
parent | 182d036de5a7d64250fc5058f3cf361b9d823282 (diff) |
Extend Modern UI for pnf usecase
Implemented functionalities to manage PNFs in modern UI:
- Adding, removing, editing PNFs
- PNF default generation based on 'min_instances' property
- FE sends proper instantiation request to BE
This is still impossible to deploy service with PNFs as VID's BE logic must be adjusted
to generate proper request to SO as described in VID-695.
Issue-ID: VID-694
Signed-off-by: Mateusz Goluchowski <mateusz.goluchowski@nokia.com>
Change-Id: I5285ac2ab5e95665244ca29c6549249d9330b1ed
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil')
8 files changed, 378 insertions, 28 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts index a135563eb..faf4aae4e 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/main.reducer.ts @@ -26,6 +26,8 @@ import {CrActions} from "./cr/cr.actions"; import {crReducer} from "./cr/cr.reducer"; import {NcfActions} from "./ncf/ncf.actions"; import {ncfReducer} from "./ncf/ncf.reducer"; +import {PNFActions} from "./pnf/pnf.actions"; +import {pnfReducer} from "./pnf/pnf.reducers"; export let initialState: ServiceState = { serviceHierarchy: {}, @@ -64,6 +66,8 @@ export const MainReducer = function (state: ServiceState = initialState, action: return vfModuleReducer(state, action); }else if (Object.values(VNFActions).includes(action.type)){ return vnfReducer(state, action); + }else if (Object.values(PNFActions).includes(action.type)){ + return pnfReducer(state, action); }else if (Object.values(VnfGroupActions).includes(action.type)){ return vnfGroupReducer(state, action); }else if(Object.values(RelatedVnfActions).includes(action.type)){ diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/network/network.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/network/network.reducers.ts index a8154e856..9c4421317 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/network/network.reducers.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/network/network.reducers.ts @@ -8,7 +8,7 @@ import { UpdateNetworkInstanceAction } from "./network.actions"; import {ServiceInstance} from "../../../models/serviceInstance"; -import {calculateNextUniqueModelName} from "../vnf/vnf.reducers"; +import {calculateNextUniqueModelName} from "../reducersHelper"; import {ServiceState} from "../main.reducer"; import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; import {deleteFirstLevel, updateServiceValidationCounter} from "../reducersHelper"; diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.actions.ts new file mode 100644 index 000000000..82ab59fb5 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.actions.ts @@ -0,0 +1,88 @@ +import {Action, ActionCreator} from "redux"; +import {PnfInstance} from "../../../models/pnfInstance"; +import {ActionOnFirstLevel} from "../firstLevel/firstLevel.actions"; + +export enum PNFActions { + CREATE_PNF_INSTANCE = "CREATE_PNF_INSTANCE", + UPDATE_PNF_INSTANCE = "UPDATE_PNF_INSTANCE", + REMOVE_PNF_INSTANCE = "REMOVE_PNF_INSTANCE", + DELETE_ACTION_PNF_INSTANCE = "DELETE_PNF_INSTANCE", + UNDO_DELETE_ACTION_PNF_INSTANCE = "UNDO_DELETE_PNF_INSTANCE", + UPDATE_PNF_POSITION = "UPDATE_PNF_POISTION" +} + +export enum PNFMethods{ + UPGRADE = "upgrade", + UNDO_UPGRADE = "undoUpgrade" +} + + +export interface CreatePnfInstanceAction extends Action { + pnfInstance?: PnfInstance; + pnfModelName?: string; + serviceUuid?: string; + pnfStoreKey?:string; +} + +export interface UpdatePnfPosition extends Action { + node: any, + instanceId : string, + pnfStoreKey?: string; +} + +export interface UpdatePnfInstanceAction extends Action { + pnfInstance?: PnfInstance; + pnfModelName?: string; + serviceUuid?: string; + pnfStoreKey?:string; +} + +export interface RemovePnfInstanceAction extends Action { + pnfStoreKey: string; + serviceId?: string; +} + +export const createPNFInstance: ActionCreator<CreatePnfInstanceAction> = (pnfInstance, pnfModelName, serviceUuid, pnfStoreKey) => ({ + type: PNFActions.CREATE_PNF_INSTANCE, + pnfInstance: pnfInstance, + pnfModelName: pnfModelName, + serviceUuid: serviceUuid, + pnfStoreKey : pnfStoreKey +}); + + +export const updatePNFInstance: ActionCreator<UpdatePnfInstanceAction> = (pnfInstance, pnfModelName, serviceUuid, pnfStoreKey) => ({ + type: PNFActions.UPDATE_PNF_INSTANCE, + pnfInstance: pnfInstance, + pnfModelName: pnfModelName, + serviceUuid: serviceUuid, + pnfStoreKey : pnfStoreKey +}); + + +export const deleteActionPnfInstance: ActionCreator<ActionOnFirstLevel> = (pnfStoreKey, serviceId) => ({ + type: PNFActions.DELETE_ACTION_PNF_INSTANCE, + firstLevelName: 'pnfs', + storeKey: pnfStoreKey, + serviceId: serviceId +}); + +export const undoDeleteActionPnfInstance: ActionCreator<ActionOnFirstLevel> = (pnfStoreKey, serviceId) => ({ + type: PNFActions.UNDO_DELETE_ACTION_PNF_INSTANCE, + firstLevelName: 'pnfs', + storeKey: pnfStoreKey, + serviceId: serviceId +}); + +export const removePnfInstance: ActionCreator<RemovePnfInstanceAction> = (pnfStoreKey, serviceId) => ({ + type: PNFActions.REMOVE_PNF_INSTANCE, + pnfStoreKey: pnfStoreKey, + serviceId: serviceId +}); + +export const updatePnfPosition: ActionCreator<UpdatePnfPosition> = (node, instanceId, pnfStoreKey) => ({ + type: PNFActions.UPDATE_PNF_POSITION, + node: node, + instanceId: instanceId, + pnfStoreKey : pnfStoreKey +}); diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.reducers.spec.ts new file mode 100644 index 000000000..b92495773 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.reducers.spec.ts @@ -0,0 +1,172 @@ +import { + CreatePnfInstanceAction, + RemovePnfInstanceAction, + UpdatePnfPosition, + UpdatePnfInstanceAction, + PNFActions +} from "./pnf.actions"; +import {pnfReducer} from "./pnf.reducers"; +import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; +import {ActionOnFirstLevel} from "../firstLevel/firstLevel.actions"; +import {PnfInstance} from "../../../models/pnfInstance"; + +describe('pnfReducer', () => { + + test('#CREATE_PNF_INSTANCE', () => { + let pnfInstance: PnfInstance = new PnfInstance(); + pnfInstance.isMissingData = false; + pnfInstance.instanceName = 'instanceName'; + let pnfState = pnfReducer(<any>{ + serviceInstance: { + 'serviceModelId': { + pnfs: {} + } + } + }, + <CreatePnfInstanceAction>{ + type: PNFActions.CREATE_PNF_INSTANCE, + pnfInstance: pnfInstance, + pnfStoreKey: null, + pnfModelName: 'pnfModelName', + serviceUuid: 'serviceModelId' + }).serviceInstance['serviceModelId'].pnfs['pnfModelName']; + + expect(pnfState).toBeDefined(); + expect(pnfState.isMissingData).toBeFalsy(); + }); + + test('#UPDATE_PNF_INSTANCE_NAME', () => { + let newInstanceName: string = "newInstanceName" + let pnfInstance: PnfInstance = new PnfInstance(); + pnfInstance.isMissingData = false; + pnfInstance.instanceName = newInstanceName; + + let pnfState = pnfReducer(<any>{ + serviceInstance: { + 'serviceModelId': { + pnfs: { + "pnfStoreKey": { + instanceName: 'oldInstanceName' + } + }, + existingNames: { + 'oldinstancename': {} + } + } + } + }, + <UpdatePnfInstanceAction>{ + type: PNFActions.UPDATE_PNF_INSTANCE, + pnfInstance: pnfInstance, + pnfStoreKey: 'pnfStoreKey', + pnfModelName: 'pnfModelName', + serviceUuid: 'serviceModelId' + }).serviceInstance['serviceModelId']; + + expect(pnfState).toBeDefined(); + expect(pnfState.pnfs['pnfStoreKey'].instanceName).toEqual(newInstanceName); + expect(newInstanceName.toLowerCase() in pnfState.existingNames).toBeTruthy(); + }); + + test('#DELETE_ACTION_PNF_INSTANCE', () => { + let pnfState = pnfReducer(<any>{ + serviceInstance: { + 'serviceModelId': { + pnfs: { + 'pnfStoreKey': { + isMissingData: true, + action: 'None' + } + } + } + } + }, + <ActionOnFirstLevel>{ + type: PNFActions.DELETE_ACTION_PNF_INSTANCE, + firstLevelName: 'pnfs', + storeKey: 'pnfStoreKey', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].pnfs['pnfStoreKey']; + + expect(pnfState).toBeDefined(); + expect(pnfState.action).toEqual(ServiceInstanceActions.None_Delete); + }); + + test('#UNDO_DELETE_ACTION_PNF_INSTANCE', () => { + let pnfState = pnfReducer(<any>{ + serviceInstance: { + 'serviceModelId': { + pnfs: { + 'pnfStoreKey': { + isMissingData: true, + action: 'Update_Delete' + } + } + } + } + }, + <ActionOnFirstLevel>{ + type: PNFActions.UNDO_DELETE_ACTION_PNF_INSTANCE, + storeKey: 'pnfStoreKey', + firstLevelName: 'pnfs', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].pnfs['pnfStoreKey']; + + expect(pnfState).toBeDefined(); + expect(pnfState.action).toEqual(ServiceInstanceActions.Update); + }); + + test('#REMOVE_PNF_INSTANCE', () => { + let pnfs = pnfReducer(<any>{ + serviceInstance: { + 'serviceModelId': { + pnfs: { + 'pnfStoreKey': { + isMissingData: true, + action: 'Update_Delete' + }, + 'pnfStoreKey_1': { + isMissingData: true, + action: 'Update_Delete' + } + } + } + } + }, + <RemovePnfInstanceAction>{ + type: PNFActions.REMOVE_PNF_INSTANCE, + pnfStoreKey: 'pnfStoreKey', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].pnfs; + + expect(pnfs).toBeDefined(); + expect(pnfs['pnfStoreKey']).toBeUndefined(); + expect(pnfs['pnfStoreKey_1']).toBeDefined(); + }); + + test('#UPDATE_PNF_POSITION', () => { + let pnfInstance: PnfInstance = new PnfInstance(); + pnfInstance.isMissingData = false; + pnfInstance.instanceName = 'instanceName'; + let pnfState = pnfReducer(<any>{ + serviceInstance: { + 'serviceModelId': { + pnfs: { + "pnfStoreKey": {} + } + } + } + }, + <UpdatePnfPosition>{ + type: PNFActions.UPDATE_PNF_POSITION, + node: <any>{ + position: 2 + }, + pnfStoreKey: 'pnfStoreKey', + instanceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].pnfs['pnfStoreKey']; + + expect(pnfState).toBeDefined(); + expect(pnfState.position).toEqual(2); + }); +}); diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.reducers.ts new file mode 100644 index 000000000..aeeae4d4e --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/pnf/pnf.reducers.ts @@ -0,0 +1,87 @@ +import {Action} from "redux"; +import {PnfInstance} from "../../../models/pnfInstance"; +import { + CreatePnfInstanceAction, + RemovePnfInstanceAction, + UpdatePnfInstanceAction, UpdatePnfPosition, + PNFActions +} from "./pnf.actions"; +import * as _ from "lodash"; +import {ServiceState} from "../main.reducer"; +import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; +import {deleteFirstLevel, updateServiceValidationCounter, calculateNextUniqueModelName, updateUniqueNames} from "../reducersHelper"; +import {ActionOnFirstLevel} from "../firstLevel/firstLevel.actions"; + +export function pnfReducer(state: ServiceState, action: Action): ServiceState { + switch (action.type) { + case PNFActions.CREATE_PNF_INSTANCE: { + const updatePnfInstanceAction = <CreatePnfInstanceAction>action; + const serviceUuid = updatePnfInstanceAction.serviceUuid; + let pnfModelName = updatePnfInstanceAction.pnfModelName; + let newState = _.cloneDeep(state); + + updatePnfInstanceAction.pnfInstance.originalName = pnfModelName; + updatePnfInstanceAction.pnfModelName = calculateNextUniqueModelName(pnfModelName, serviceUuid, newState, 'pnfs'); + + let pnfInstance: PnfInstance = newState.serviceInstance[serviceUuid].pnfs[pnfModelName]; + pnfInstance = new PnfInstance(); + updatePnfInstanceAction.pnfInstance.pnfStoreKey = updatePnfInstanceAction.pnfModelName; + updatePnfInstanceAction.pnfInstance.originalName = pnfModelName; + pnfInstance.originalName = updatePnfInstanceAction.pnfInstance.originalName; + pnfInstance.pnfStoreKey = updatePnfInstanceAction.pnfInstance.pnfStoreKey; + updateServiceValidationCounter(newState, pnfInstance['isMissingData'], updatePnfInstanceAction.pnfInstance['isMissingData'], serviceUuid); + + newState.serviceInstance[serviceUuid].pnfs[updatePnfInstanceAction.pnfModelName] = Object.assign(pnfInstance, updatePnfInstanceAction.pnfInstance); + return newState; + } + + case PNFActions.UPDATE_PNF_INSTANCE: { + const updatePnfInstanceAction = <UpdatePnfInstanceAction>action; + const serviceUuid = updatePnfInstanceAction.serviceUuid; + let pnfStoreKey = updatePnfInstanceAction.pnfStoreKey; + + let newState = _.cloneDeep(state); + let pnfInstance: PnfInstance = newState.serviceInstance[serviceUuid].pnfs[pnfStoreKey]; + let oldInstanceName = pnfInstance ? pnfInstance.instanceName : null; + updateUniqueNames(oldInstanceName, updatePnfInstanceAction.pnfInstance.instanceName, newState.serviceInstance[serviceUuid]); + + pnfInstance = pnfInstance || new PnfInstance(); + updateServiceValidationCounter(newState, pnfInstance['isMissingData'], updatePnfInstanceAction.pnfInstance['isMissingData'], serviceUuid); + + newState.serviceInstance[serviceUuid].pnfs[pnfStoreKey] = Object.assign(pnfInstance, updatePnfInstanceAction.pnfInstance); + return newState; + } + + case PNFActions.DELETE_ACTION_PNF_INSTANCE : { + return deleteFirstLevel(state, <ActionOnFirstLevel>action,true); + } + + case PNFActions.UNDO_DELETE_ACTION_PNF_INSTANCE : { + let newState = _.cloneDeep(state); + let pnf = newState.serviceInstance[(<ActionOnFirstLevel>action).serviceId].pnfs[(<ActionOnFirstLevel>action).storeKey]; + let oldState = pnf.action; + newState.serviceInstance[(<ActionOnFirstLevel>action).serviceId].pnfs[(<ActionOnFirstLevel>action).storeKey].action = (oldState.split('_')[0]) as ServiceInstanceActions; + updateServiceValidationCounter(newState, pnf['isMissingData'], false, (<ActionOnFirstLevel>action).serviceId); + return newState; + } + + case PNFActions.REMOVE_PNF_INSTANCE : { + let newState = _.cloneDeep(state); + let pnfInstance = newState.serviceInstance[(<RemovePnfInstanceAction>action).serviceId].pnfs[(<RemovePnfInstanceAction>action).pnfStoreKey]; + updateServiceValidationCounter(newState, pnfInstance['isMissingData'], false, (<RemovePnfInstanceAction>action).serviceId); + delete newState.serviceInstance[(<RemovePnfInstanceAction>action).serviceId].pnfs[(<RemovePnfInstanceAction>action).pnfStoreKey]; + return newState; + } + + case PNFActions.UPDATE_PNF_POSITION : { + let newState = _.cloneDeep(state); + newState.serviceInstance[(<UpdatePnfPosition>action).instanceId] + .pnfs[(<UpdatePnfPosition>action).pnfStoreKey] + .position = (<UpdatePnfPosition>action).node.position; + return newState; + } + } +} + + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts index c192ece48..0291a3b5c 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts @@ -2,6 +2,7 @@ import * as _ from "lodash"; import {ActionOnFirstLevel} from "./firstLevel/firstLevel.actions"; import {ServiceInstanceActions} from "../../models/serviceInstanceActions"; import {ServiceState} from "./main.reducer"; +import {ServiceInstance} from "../../models/serviceInstance"; export function deleteFirstLevel(state: ServiceState, action: ActionOnFirstLevel,shouldUpdateServiceValidationCounter: boolean){ let newState = _.cloneDeep(state); @@ -28,3 +29,26 @@ function resetUpgradeStatus(newState: any, serviceUuid: string){ newState.serviceInstance[serviceUuid].upgradedVFMSonsCounter = 0; newState.serviceInstance[serviceUuid].isUpgraded = false; } + +export const updateUniqueNames = (oldName: string, newName: string, serviceInstance: ServiceInstance): void => { + let existingNames = serviceInstance.existingNames; + if (!_.isNil(oldName) && oldName.toLowerCase() in existingNames) { + delete existingNames[oldName.toLowerCase()]; + } + if (!_.isNil(newName)) { + existingNames[newName.toLowerCase()] = ""; + } +}; + + +export const calculateNextUniqueModelName = (nfModelName: string, serviceId: string, state: any, levelName: string): string => { + let counter: number = null; + while (true) { + let pattern = !_.isNil(counter) ? ("_" + counter) : ""; + if (!_.isNil(state.serviceInstance[serviceId][levelName][nfModelName + pattern])) { + counter = counter ? (counter + 1) : 1; + } else { + return nfModelName + pattern; + } + } +}; diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.ts index c5cd88aa7..b5bcec955 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.ts @@ -7,10 +7,9 @@ import { VNFActions } from "./vnf.actions"; import * as _ from "lodash"; -import {ServiceInstance} from "../../../models/serviceInstance"; import {ServiceState} from "../main.reducer"; import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; -import {deleteFirstLevel, updateServiceValidationCounter} from "../reducersHelper"; +import {deleteFirstLevel, updateServiceValidationCounter, calculateNextUniqueModelName, updateUniqueNames} from "../reducersHelper"; import {ActionOnFirstLevel} from "../firstLevel/firstLevel.actions"; export function vnfReducer(state: ServiceState, action: Action): ServiceState { @@ -126,27 +125,3 @@ export function vnfReducer(state: ServiceState, action: Action): ServiceState { } } - - -const updateUniqueNames = (oldName: string, newName: string, serviceInstance: ServiceInstance): void => { - let existingNames = serviceInstance.existingNames; - if (!_.isNil(oldName) && oldName.toLowerCase() in existingNames) { - delete existingNames[oldName.toLowerCase()]; - } - if (!_.isNil(newName)) { - existingNames[newName.toLowerCase()] = ""; - } -}; - - -export const calculateNextUniqueModelName = (vnfModelName: string, serviceId: string, state: any, levelName: string): string => { - let counter: number = null; - while (true) { - let pattern = !_.isNil(counter) ? ("_" + counter) : ""; - if (!_.isNil(state.serviceInstance[serviceId][levelName][vnfModelName + pattern])) { - counter = counter ? (counter + 1) : 1; - } else { - return vnfModelName + pattern; - } - } -}; diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.ts index f3d81209e..33992ddfe 100644 --- a/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.ts +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.ts @@ -7,7 +7,7 @@ import { CreateVRFInstanceAction, DeleteActionVrfInstanceAction, UndoDeleteActionVrfInstanceAction, VrfActions } from "./vrf.actions"; -import {calculateNextUniqueModelName} from "../vnf/vnf.reducers"; +import {calculateNextUniqueModelName} from "../reducersHelper"; import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; export function vrfReducer(state: ServiceState, action: Action): ServiceState { |