diff options
author | Ittay Stern <ittay.stern@att.com> | 2018-08-29 17:01:32 +0300 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-02-18 18:35:30 +0200 |
commit | 6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch) | |
tree | 936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/shared/storeUtil/utils/vnf | |
parent | 67d99f816cc583643c35193197594cf78d8ce60a (diff) |
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378
Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/vnf')
3 files changed, 355 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.actions.ts new file mode 100644 index 000000000..b84284490 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.actions.ts @@ -0,0 +1,99 @@ +import {Action, ActionCreator} from "redux"; +import {VnfInstance} from "../../../models/vnfInstance"; + +export enum VNFActions { + CREATE_VNF_INSTANCE = "CREATE_VNF_INSTANCE", + UPDATE_VNF_INSTANCE = "UPDATE_VNF_INSTANCE", + REMOVE_VNF_INSTANCE = "REMOVE_VNF_INSTANCE", + DELETE_ACTION_VNF_INSTANCE = "DELETE_VNF_INSTANCE", + UNDO_DELETE_ACTION_VNF_INSTANCE = "UNDO_DELETE_VNF_INSTANCE", + UPDATE_VNF_POSITION = "UPDATE_VNF_POISTION" +} + + +export interface CreateVnfInstanceAction extends Action { + vnfInstance?: VnfInstance; + vnfModelName?: string; + serviceUuid?: string; + vnfStoreKey?:string; +} + +export interface UpdateVnfPosition extends Action { + node: any, + instanceId : string, + vnfStoreKey?: string; +} + +export interface UpdateVnfInstanceAction extends Action { + vnfInstance?: VnfInstance; + vnfModelName?: string; + serviceUuid?: string; + vnfStoreKey?:string; +} + + + +export interface DeleteActionVnfInstanceAction extends Action { + vnfStoreKey: string; + serviceId?: string; +} + +export interface UndoDeleteActionVnfInstanceAction extends Action { + vnfStoreKey: string; + serviceId?: string; +} + +export interface RemoveVnfInstanceAction extends Action { + vnfStoreKey: string; + serviceId?: string; +} + +export const createVNFInstance: ActionCreator<CreateVnfInstanceAction> = (vnfInstance, vnfModelName, serviceUuid, vnfStoreKey) => ({ + type: VNFActions.CREATE_VNF_INSTANCE, + vnfInstance: vnfInstance, + vnfModelName: vnfModelName, + serviceUuid: serviceUuid, + vnfStoreKey : vnfStoreKey +}); + + +export const updateVNFInstance: ActionCreator<UpdateVnfInstanceAction> = (vnfInstance, vnfModelName, serviceUuid, vnfStoreKey) => ({ + type: VNFActions.UPDATE_VNF_INSTANCE, + vnfInstance: vnfInstance, + vnfModelName: vnfModelName, + serviceUuid: serviceUuid, + vnfStoreKey : vnfStoreKey +}); + + +export const deleteActionVnfInstance: ActionCreator<DeleteActionVnfInstanceAction> = (vnfStoreKey, serviceId) => ({ + type: VNFActions.DELETE_ACTION_VNF_INSTANCE, + vnfStoreKey: vnfStoreKey, + serviceId: serviceId +}); + +export const undoDeleteActionVnfInstance: ActionCreator<UndoDeleteActionVnfInstanceAction> = (vnfStoreKey, serviceId) => ({ + type: VNFActions.UNDO_DELETE_ACTION_VNF_INSTANCE, + vnfStoreKey: vnfStoreKey, + serviceId: serviceId +}); + +export const removeVnfInstance: ActionCreator<RemoveVnfInstanceAction> = (vnfStoreKey, serviceId) => ({ + type: VNFActions.REMOVE_VNF_INSTANCE, + vnfStoreKey: vnfStoreKey, + serviceId: serviceId +}); + +export const updateVnfPosition: ActionCreator<UpdateVnfPosition> = (node, instanceId, vnfStoreKey) => ({ + type: VNFActions.UPDATE_VNF_POSITION, + node: node, + instanceId: instanceId, + vnfStoreKey : vnfStoreKey +}); + + + + + + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.spec.ts new file mode 100644 index 000000000..3241f11d9 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.spec.ts @@ -0,0 +1,132 @@ +import {VnfInstance} from "../../../models/vnfInstance"; +import { + CreateVnfInstanceAction, + DeleteActionVnfInstanceAction, RemoveVnfInstanceAction, + UndoDeleteActionVnfInstanceAction, UpdateVnfPosition, + VNFActions +} from "./vnf.actions"; +import {vnfReducer} from "./vnf.reducers"; +import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; + +describe('networkReducer', () => { + test('#UPDATE_VNF_POSITION', () => { + let vnfInstance: VnfInstance = new VnfInstance(); + vnfInstance.isMissingData = false; + vnfInstance.instanceName = 'instanceName'; + let vnfState = vnfReducer(<any>{ + serviceInstance : { + 'serviceModelId' : { + vnfs : { + "vnfStoreKey" : { + + } + } + } + }}, + <UpdateVnfPosition>{ + type: VNFActions.UPDATE_VNF_POSITION, + node : <any>{ + position : 1 + }, + vnfStoreKey : 'vnfStoreKey', + instanceId : 'serviceModelId' + }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey']; + + expect(vnfState).toBeDefined(); + expect(vnfState.position).toEqual(1); + }); + + test('#CREATE_NETWORK_INSTANCE', () => { + let vnfInstance: VnfInstance = new VnfInstance(); + vnfInstance.isMissingData = false; + vnfInstance.instanceName = 'instanceName'; + let vnfState = vnfReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + + } + } + }}, + <CreateVnfInstanceAction>{ + type: VNFActions.CREATE_VNF_INSTANCE, + vnfInstance : vnfInstance, + vnfStoreKey : null, + vnfModelName : 'vnfModelName', + serviceUuid : 'serviceModelId' + }).serviceInstance['serviceModelId'].vnfs['vnfModelName']; + + expect(vnfState).toBeDefined(); + expect(vnfState.isMissingData).toBeFalsy(); + }); + + test('#DELETE_ACTION_VNF_INSTANCE', () => { + let vnfState = vnfReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + 'vnfStoreKey' : { + isMissingData : true, + action : 'None' + } + } + } + }}, + <DeleteActionVnfInstanceAction>{ + type: VNFActions.DELETE_ACTION_VNF_INSTANCE, + vnfStoreKey: 'vnfStoreKey', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey']; + + expect(vnfState).toBeDefined(); + expect(vnfState.action).toEqual(ServiceInstanceActions.None_Delete); + }); + + test('#UNDO_DELETE_ACTION_VNF_INSTANCE', () => { + let vnfState = vnfReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + 'vnfStoreKey' : { + isMissingData : true, + action : 'Update_Delete' + } + } + } + }}, + <UndoDeleteActionVnfInstanceAction>{ + type: VNFActions.UNDO_DELETE_ACTION_VNF_INSTANCE, + vnfStoreKey: 'vnfStoreKey', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey']; + + expect(vnfState).toBeDefined(); + expect(vnfState.action).toEqual(ServiceInstanceActions.Update); + }); + + test('#REMOVE_VNF_INSTANCE', () => { + let vnfs = vnfReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + 'vnfStoreKey' : { + isMissingData : true, + action : 'Update_Delete' + }, + 'vnfStoreKey_1' : { + isMissingData : true, + action : 'Update_Delete' + } + } + } + }}, + <RemoveVnfInstanceAction>{ + type: VNFActions.REMOVE_VNF_INSTANCE, + vnfStoreKey: 'vnfStoreKey', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].vnfs; + + expect(vnfs).toBeDefined(); + expect(vnfs['vnfStoreKey']).toBeUndefined(); + }); + +}); + + + 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 new file mode 100644 index 000000000..cc24d8dc3 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.ts @@ -0,0 +1,124 @@ +import {Action} from "redux"; +import {VnfInstance} from "../../../models/vnfInstance"; +import { + CreateVnfInstanceAction, + DeleteActionVnfInstanceAction, RemoveVnfInstanceAction, UndoDeleteActionVnfInstanceAction, + UpdateVnfInstanceAction, UpdateVnfPosition, + VNFActions +} from "./vnf.actions"; +import * as _ from "lodash"; +import {ServiceInstance} from "../../../models/serviceInstance"; +import {ServiceState} from "../main.reducer"; +import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; + +export function vnfReducer(state: ServiceState, action: Action): ServiceState { + switch (action.type) { + case VNFActions.CREATE_VNF_INSTANCE: { + const updateVnfInstanceAction = <CreateVnfInstanceAction>action; + const serviceUuid = updateVnfInstanceAction.serviceUuid; + let vnfModelName = updateVnfInstanceAction.vnfModelName; + let newState = _.cloneDeep(state); + + updateVnfInstanceAction.vnfInstance.originalName = vnfModelName; + updateVnfInstanceAction.vnfModelName = calculateNextUniqueModelName(vnfModelName, serviceUuid, newState, 'vnfs'); + + let vnfInstance: VnfInstance = newState.serviceInstance[serviceUuid].vnfs[vnfModelName]; + vnfInstance = new VnfInstance(); + updateVnfInstanceAction.vnfInstance.vnfStoreKey = updateVnfInstanceAction.vnfModelName; + updateVnfInstanceAction.vnfInstance.originalName = vnfModelName; + vnfInstance.originalName = updateVnfInstanceAction.vnfInstance.originalName; + vnfInstance.vnfStoreKey = updateVnfInstanceAction.vnfInstance.vnfStoreKey; + updateServiceValidationCounter(newState, vnfInstance['isMissingData'], updateVnfInstanceAction.vnfInstance['isMissingData'], serviceUuid); + + newState.serviceInstance[serviceUuid].vnfs[updateVnfInstanceAction.vnfModelName] = Object.assign(vnfInstance, updateVnfInstanceAction.vnfInstance); + return newState; + } + + case VNFActions.UPDATE_VNF_INSTANCE: { + const updateVnfInstanceAction = <UpdateVnfInstanceAction>action; + const serviceUuid = updateVnfInstanceAction.serviceUuid; + let vnfStoreKey = updateVnfInstanceAction.vnfStoreKey; + + + let newState = _.cloneDeep(state); + let vnfInstance: VnfInstance = newState.serviceInstance[serviceUuid].vnfs[vnfStoreKey]; + updateUniqueNames(vnfInstance ? vnfInstance.instanceName : null, updateVnfInstanceAction.vnfInstance.instanceName, newState.serviceInstance[serviceUuid]); + + vnfInstance = vnfInstance || new VnfInstance(); + updateServiceValidationCounter(newState, vnfInstance['isMissingData'], updateVnfInstanceAction.vnfInstance['isMissingData'], serviceUuid); + + newState.serviceInstance[serviceUuid].vnfs[vnfStoreKey] = Object.assign(vnfInstance, updateVnfInstanceAction.vnfInstance); + return newState; + } + + case VNFActions.DELETE_ACTION_VNF_INSTANCE : { + let newState = _.cloneDeep(state); + let vnf = newState.serviceInstance[(<DeleteActionVnfInstanceAction>action).serviceId].vnfs[(<DeleteActionVnfInstanceAction>action).vnfStoreKey]; + let oldAction = vnf.action; + if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState; + newState.serviceInstance[(<DeleteActionVnfInstanceAction>action).serviceId].vnfs[(<DeleteActionVnfInstanceAction>action).vnfStoreKey].action = (oldAction + '_Delete') as ServiceInstanceActions; + updateServiceValidationCounter(newState, vnf['isMissingData'], false, (<RemoveVnfInstanceAction>action).serviceId); + return newState; + } + + case VNFActions.UNDO_DELETE_ACTION_VNF_INSTANCE : { + let newState = _.cloneDeep(state); + let vnf = newState.serviceInstance[(<UndoDeleteActionVnfInstanceAction>action).serviceId].vnfs[(<UndoDeleteActionVnfInstanceAction>action).vnfStoreKey]; + let oldState = vnf.action; + newState.serviceInstance[(<UndoDeleteActionVnfInstanceAction>action).serviceId].vnfs[(<UndoDeleteActionVnfInstanceAction>action).vnfStoreKey].action = (oldState.split('_')[0]) as ServiceInstanceActions; + updateServiceValidationCounter(newState, vnf['isMissingData'], false, (<UndoDeleteActionVnfInstanceAction>action).serviceId); + return newState; + } + + case VNFActions.REMOVE_VNF_INSTANCE : { + let newState = _.cloneDeep(state); + let vnfInstance = newState.serviceInstance[(<RemoveVnfInstanceAction>action).serviceId].vnfs[(<RemoveVnfInstanceAction>action).vnfStoreKey]; + updateServiceValidationCounter(newState, vnfInstance['isMissingData'], false, (<RemoveVnfInstanceAction>action).serviceId); + delete newState.serviceInstance[(<RemoveVnfInstanceAction>action).serviceId].vnfs[(<RemoveVnfInstanceAction>action).vnfStoreKey]; + return newState; + } + + case VNFActions.UPDATE_VNF_POSITION : { + let newState = _.cloneDeep(state); + newState.serviceInstance[(<UpdateVnfPosition>action).instanceId].vnfs[(<UpdateVnfPosition>action).vnfStoreKey].position = (<UpdateVnfPosition>action).node.position; + return newState; + } + } +} + +const updateServiceValidationCounter = (newState: any, oldValidationState: boolean, newValidationState: boolean, serviceUuid: string) => { + if (oldValidationState && !newValidationState) { + newState.serviceInstance[serviceUuid].validationCounter--; + } else if (!oldValidationState && newValidationState) { + newState.serviceInstance[serviceUuid].validationCounter++; + } +}; + + +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; + } + } +}; + + + + + |