summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/storeUtil/utils
diff options
context:
space:
mode:
authorEinat Vinouze <einat.vinouze@intl.att.com>2019-08-27 16:01:01 +0300
committerIttay Stern <ittay.stern@att.com>2019-09-09 07:01:36 +0000
commite1f7974f0badbd4440d5b7ea5f1b1cb2d4973818 (patch)
tree46be9cdc44cbb475527bc3c43df23d16f7579d29 /vid-webpack-master/src/app/shared/storeUtil/utils
parente25b88b5a7a0f3bf63ca7160a441b53145484bcc (diff)
Adding feature: Replace vfmodule
Issue-ID: VID-603 Change-Id: I59068a0979d6fb733e4243c8f78921f396dc9d17 Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com> Signed-off-by: Amichai Hemli <amichai.hemli@intl.att.com> Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils')
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts9
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/service/service.actions.ts19
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.spec.ts59
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.ts153
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts33
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts88
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts37
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.actions.ts34
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.spec.ts48
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vnf/vnf.reducers.ts57
10 files changed, 440 insertions, 97 deletions
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 5722811ce..c192ece48 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/reducersHelper.ts
@@ -3,8 +3,7 @@ import {ActionOnFirstLevel} from "./firstLevel/firstLevel.actions";
import {ServiceInstanceActions} from "../../models/serviceInstanceActions";
import {ServiceState} from "./main.reducer";
-export function deleteFirstLevel(state: ServiceState, action: ActionOnFirstLevel,shouldUpdateServiceValidationCounter: boolean)
-{
+export function deleteFirstLevel(state: ServiceState, action: ActionOnFirstLevel,shouldUpdateServiceValidationCounter: boolean){
let newState = _.cloneDeep(state);
let firstLevel = newState.serviceInstance[action.serviceId][action.firstLevelName][action.storeKey];
let oldAction = firstLevel.action;
@@ -22,4 +21,10 @@ export function updateServiceValidationCounter(newState: any, oldValidationState
} else if (!oldValidationState && newValidationState) {
newState.serviceInstance[serviceUuid].validationCounter++;
}
+ resetUpgradeStatus(newState, serviceUuid);
};
+
+function resetUpgradeStatus(newState: any, serviceUuid: string){
+ newState.serviceInstance[serviceUuid].upgradedVFMSonsCounter = 0;
+ newState.serviceInstance[serviceUuid].isUpgraded = false;
+}
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.actions.ts
index e4e7e494e..069ef82e8 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.actions.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.actions.ts
@@ -10,7 +10,9 @@ export enum ServiceActions {
ADD_SERVICE_ACTION = 'ADD_SERVICE_ACTION',
DELETE_ACTION_SERVICE_INSTANCE = "DELETE_ACTION_SERVICE_INSTANCE",
UNDO_DELETE_ACTION_SERVICE_INSTANCE = "UNDO_DELETE_ACTION_SERVICE_INSTANCE",
- CHANGE_SERVICE_IS_DIRTY = "CHANGE_SERVICE_IS_DIRTY"
+ CHANGE_SERVICE_IS_DIRTY = "CHANGE_SERVICE_IS_DIRTY",
+ UPGRADE_SERVICE_ACTION = "UPGRADE_SERVICE_ACTION",
+ UNDO_UPGRADE_SERVICE_ACTION = "UNDO_UPGRADE_SERVICE_ACTION"
}
export interface CreateServiceInstanceAction extends Action {
@@ -40,6 +42,13 @@ export interface AddServiceAction extends Action{
action: ServiceInstanceActions;
}
+export interface UpgradeServiceAction extends Action{
+ serviceUuid: string;
+}
+
+export interface UndoUpgradeServiceAction extends Action{
+ serviceUuid: string;
+}
export interface DeleteActionServiceInstanceAction extends Action {
serviceId?: string;
@@ -99,4 +108,12 @@ export const changeServiceIsDirty: ActionCreator<ChangeServiceDirty> = (nodes, s
serviceId : serviceId
});
+export const upgradeService: ActionCreator<UpgradeServiceAction> = (serviceUuid : string) => ({
+ type: ServiceActions.UPGRADE_SERVICE_ACTION,
+ serviceUuid
+});
+export const undoUpgradeService: ActionCreator<UndoUpgradeServiceAction> = (serviceUuid : string) => ({
+ type: ServiceActions.UNDO_UPGRADE_SERVICE_ACTION,
+ serviceUuid
+});
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.spec.ts
index cff944563..ba8b3826e 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.spec.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.spec.ts
@@ -6,7 +6,7 @@ import {
DeleteServiceInstanceAction,
ServiceActions,
UpdateServiceInstanceAction,
- UpdateServiceModelAction
+ UpdateServiceModelAction, UpgradeServiceAction
} from "./service.actions";
import {serviceReducer} from "./service.reducers";
import {ServiceInstanceActions} from "../../../models/serviceInstanceActions";
@@ -513,7 +513,62 @@ describe('serviceReducer', () => {
expect(state.serviceInstance['serviceId'].isDirty).toBeTruthy();
});
-});
+ test('#UPGRADE_SERVICE should update service action to _Upgrade', () => {
+ const state = serviceReducer(<any>{
+ serviceInstance: {
+ 'serviceId': {
+ action: ServiceInstanceActions.None,
+ upgradedVFMSonsCounter: 0,
+ 'vnfs': {
+ 'vnf1': {
+ action: ServiceInstanceActions.None
+ },
+ 'vnf2': {
+ action: ServiceInstanceActions.Create
+ }
+ }
+
+ }
+ }
+ },
+ <UpgradeServiceAction> {
+ type: ServiceActions.UPGRADE_SERVICE_ACTION,
+ serviceUuid: 'serviceId'
+ });
+
+ expect(state.serviceInstance['serviceId'].isUpgraded).toBeTruthy();
+ expect(state.serviceInstance['serviceId'].action).toEqual(ServiceInstanceActions.None_Upgrade);
+ expect(state.serviceInstance['serviceId'].upgradedVFMSonsCounter).toEqual(1);
+ });
+ test('#UNDO_UPGRADE_SERVICE should cancel the upgrade action back to None', () => {
+ const state = serviceReducer(<any>{
+ serviceInstance: {
+ 'serviceId': {
+ isUpgraded: true,
+ upgradedVFMSonsCounter: 1,
+ action: ServiceInstanceActions.None_Upgrade,
+ 'vnfs': {
+ 'vnf1': {
+ action: ServiceInstanceActions.None_Upgrade
+ },
+ 'vnf2': {
+ action: ServiceInstanceActions.Create
+ }
+ }
+ }
+ }
+ },
+ <UpgradeServiceAction> {
+ type: ServiceActions.UNDO_UPGRADE_SERVICE_ACTION,
+ serviceUuid: 'serviceId'
+ });
+
+ expect(state.serviceInstance['serviceId'].isUpgraded).toBeFalsy();
+ expect(state.serviceInstance['serviceId'].action).toEqual(ServiceInstanceActions.None);
+ expect(state.serviceInstance['serviceId'].upgradedVFMSonsCounter).toEqual(0);
+ });
+
+});
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.ts
index c6d3da52a..811238385 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/service/service.reducers.ts
@@ -4,8 +4,10 @@ import {
ChangeServiceDirty,
CreateServiceInstanceAction,
ServiceActions,
+ UndoUpgradeServiceAction,
UpdateServiceInstanceAction,
- UpdateServiceModelAction
+ UpdateServiceModelAction,
+ UpgradeServiceAction
} from "./service.actions";
import {ServiceInstance} from "../../../models/serviceInstance";
import {ServiceState} from "../main.reducer";
@@ -13,84 +15,99 @@ import {ServiceInstanceActions} from "../../../models/serviceInstanceActions";
import * as _ from "lodash";
export function serviceReducer(state: ServiceState, action: Action) : ServiceState{
- switch (action.type) {
- case ServiceActions.UPDATE_SERVICE_INSTANCE : {
- let newState = _.cloneDeep(state);
- const updateServiceInstanceAction = <UpdateServiceInstanceAction>action;
- const uuid = updateServiceInstanceAction.serviceUuid;
- const serviceInstance = updateServiceInstanceAction.serviceInstance;
+ switch (action.type) {
+ case ServiceActions.UPDATE_SERVICE_INSTANCE : {
+ let newState = _.cloneDeep(state);
+ const updateServiceInstanceAction = <UpdateServiceInstanceAction>action;
+ const uuid = updateServiceInstanceAction.serviceUuid;
+ const serviceInstance = updateServiceInstanceAction.serviceInstance;
- updateUniqueNames(serviceInstance.instanceName, updateServiceInstanceAction.serviceInstance.instanceName, newState.serviceInstance[uuid]);
+ updateUniqueNames(serviceInstance.instanceName, updateServiceInstanceAction.serviceInstance.instanceName, newState.serviceInstance[uuid]);
- newState.serviceInstance[uuid] = _.merge(newState.serviceInstance[uuid], serviceInstance);
- return newState;
- }
- case ServiceActions.CREATE_SERVICE_INSTANCE : {
- const updateServiceInstanceAction = <CreateServiceInstanceAction>action;
- const uuid = updateServiceInstanceAction.serviceUuid;
- let newState = _.cloneDeep(state);
+ newState.serviceInstance[uuid] = _.merge(newState.serviceInstance[uuid], serviceInstance);
+ return newState;
+ }
+ case ServiceActions.CREATE_SERVICE_INSTANCE : {
+ const updateServiceInstanceAction = <CreateServiceInstanceAction>action;
+ const uuid = updateServiceInstanceAction.serviceUuid;
+ let newState = _.cloneDeep(state);
- const serviceInstance: ServiceInstance = new ServiceInstance();
- const currentInstaceName = state.serviceInstance[uuid] ? serviceInstance.instanceName : null;
+ const serviceInstance: ServiceInstance = new ServiceInstance();
+ const currentInstaceName = state.serviceInstance[uuid] ? serviceInstance.instanceName : null;
- newState.serviceInstance[uuid] = Object.assign(serviceInstance, updateServiceInstanceAction.serviceInstance);
- newState.serviceInstance[uuid].vidNotions = _.get(state,`serviceHierarchy[${uuid}].service.vidNotions`);
- if (!_.isNil(updateServiceInstanceAction.serviceInstance)) {
- updateUniqueNames(currentInstaceName, updateServiceInstanceAction.serviceInstance.instanceName, newState.serviceInstance[uuid]);
- }
- return newState;
- }
- case ServiceActions.DELETE_ALL_SERVICE_INSTANCES: {
- if (state.serviceInstance) {
- let newState = _.cloneDeep(state);
- newState.serviceInstance = {};
- return Object.assign({}, state, newState);
- }
- return Object.assign({}, state);
+ newState.serviceInstance[uuid] = Object.assign(serviceInstance, updateServiceInstanceAction.serviceInstance);
+ newState.serviceInstance[uuid].vidNotions = _.get(state,`serviceHierarchy[${uuid}].service.vidNotions`);
+ if (!_.isNil(updateServiceInstanceAction.serviceInstance)) {
+ updateUniqueNames(currentInstaceName, updateServiceInstanceAction.serviceInstance.instanceName, newState.serviceInstance[uuid]);
}
- case ServiceActions.UPDATE_MODEL: {
- let uuid = (<UpdateServiceModelAction>action).serviceHierarchy.service.uuid;
- state.serviceHierarchy[uuid] = _.cloneDeep((<UpdateServiceModelAction>action).serviceHierarchy);
- return Object.assign({}, state);
+ return newState;
+ }
+ case ServiceActions.DELETE_ALL_SERVICE_INSTANCES: {
+ if (state.serviceInstance) {
+ let newState = _.cloneDeep(state);
+ newState.serviceInstance = {};
+ return Object.assign({}, state, newState);
}
- case ServiceActions.ADD_SERVICE_ACTION: {
- const uuid: string = (<AddServiceAction>action).serviceUuid;
- const actionToAdd: ServiceInstanceActions = (<AddServiceAction>action).action;
- state.serviceInstance[uuid].action = actionToAdd;
- return Object.assign({}, state);
+ return Object.assign({}, state);
+ }
+ case ServiceActions.UPDATE_MODEL: {
+ let uuid = (<UpdateServiceModelAction>action).serviceHierarchy.service.uuid;
+ state.serviceHierarchy[uuid] = _.cloneDeep((<UpdateServiceModelAction>action).serviceHierarchy);
+ return Object.assign({}, state);
+ }
+ case ServiceActions.ADD_SERVICE_ACTION: {
+ const uuid: string = (<AddServiceAction>action).serviceUuid;
+ const actionToAdd: ServiceInstanceActions = (<AddServiceAction>action).action;
+ state.serviceInstance[uuid].action = actionToAdd;
+ return Object.assign({}, state);
+ }
+ case ServiceActions.CHANGE_SERVICE_IS_DIRTY : {
+ let newState = _.cloneDeep(state);
+ let serviceInstanceAction: ServiceInstanceActions = newState.serviceInstance[(<ChangeServiceDirty>action).serviceId].action;
+
+ if(serviceInstanceAction !== ServiceInstanceActions.None){
+ newState.serviceInstance[(<ChangeServiceDirty>action).serviceId].isDirty = true;
+ return newState;
}
- case ServiceActions.CHANGE_SERVICE_IS_DIRTY : {
- let newState = _.cloneDeep(state);
- let serviceInstanceAction: ServiceInstanceActions = newState.serviceInstance[(<ChangeServiceDirty>action).serviceId].action;
- if(serviceInstanceAction !== ServiceInstanceActions.None){
+ const nodes = (<ChangeServiceDirty>action).nodes;
+ for(let node of nodes){
+ const dirty = isDirty(node);
+ if(dirty) {
newState.serviceInstance[(<ChangeServiceDirty>action).serviceId].isDirty = true;
return newState;
}
+ }
+ newState.serviceInstance[(<ChangeServiceDirty>action).serviceId].isDirty = false;
+ return newState;
+ }
+ case ServiceActions.UPGRADE_SERVICE_ACTION: {
+ let clonedState = _.cloneDeep(state);
+ let oldServiceAction: string = ServiceInstanceActions.None;
+ const castingAction = <UpgradeServiceAction>action;
+ const uuid: string = castingAction.serviceUuid;
+ return upgradeServiceInstance(clonedState, uuid, oldServiceAction);
+ }
- const nodes = (<ChangeServiceDirty>action).nodes;
- for(let node of nodes){
- const dirty = isDirty(node);
- if(dirty) {
- newState.serviceInstance[(<ChangeServiceDirty>action).serviceId].isDirty = true;
- return newState;
- }
- }
-
- newState.serviceInstance[(<ChangeServiceDirty>action).serviceId].isDirty = false;
- return newState;
+ case ServiceActions.UNDO_UPGRADE_SERVICE_ACTION: {
+ let clonedState = _.cloneDeep(state);
+ const castingAction = <UndoUpgradeServiceAction>action;
+ const uuid: string = castingAction.serviceUuid;
+ if(!_.isNil(clonedState.serviceInstance[uuid].action) && clonedState.serviceInstance[uuid].action.includes("Upgrade")) {
+ return undoUpgradeServiceInstance(clonedState, uuid);
}
}
+ }
}
const isDirty = (node) : boolean => {
if(node.action !== ServiceInstanceActions.None) return true;
if(!_.isNil(node.children) && node.children.length > 0){
- for(let child of node.children){
- const dirty: boolean = isDirty(child);
- if(dirty) return true;
- }
+ for(let child of node.children){
+ const dirty: boolean = isDirty(child);
+ if(dirty) return true;
+ }
}
return false;
};
@@ -105,5 +122,23 @@ const updateUniqueNames = (oldName : string, newName : string, serviceInstance :
}
};
+function upgradeServiceInstance(clonedState, uuid: string, oldServiceAction: string) {
+ if(!clonedState.serviceInstance[uuid].action.includes("Upgrade")){
+ clonedState.serviceInstance[uuid].action = (`${oldServiceAction}_Upgrade`) as ServiceInstanceActions;
+ }
+ clonedState.serviceInstance[uuid].isUpgraded = true;
+ clonedState.serviceInstance[uuid].upgradedVFMSonsCounter++;
+ return clonedState;
+}
+
+function undoUpgradeServiceInstance(clonedState, uuid: string) {
+ clonedState.serviceInstance[uuid].upgradedVFMSonsCounter--;
+ if(clonedState.serviceInstance[uuid].upgradedVFMSonsCounter == 0){
+ clonedState.serviceInstance[uuid].action = ServiceInstanceActions.None;
+ clonedState.serviceInstance[uuid].isUpgraded = false;
+ }
+ return clonedState;
+}
+
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts
index a3f0f4009..59e5ee1fa 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.actions.ts
@@ -6,7 +6,9 @@ export enum VfModuleActions {
UPDATE_VF_MODULE = 'UPDATE_VF_MODULE',
DELETE_ACTION_VF_MODULE_INSTANCE = "DELETE_ACTION_VF_MODULE_INSTANCE",
UNDO_DELETE_ACTION_VF_MODULE_INSTANCE = "UNDO_DELETE_ACTION_VF_MODULE_INSTANCE",
- UPDATE_VFMODULE_POSITION = "UPDATE_VFMODULE_POSITION"
+ UPDATE_VFMODULE_POSITION = "UPDATE_VFMODULE_POSITION",
+ UPGRADE_VFMODULE = "UPGRADE_VFMODULE",
+ UNDO_UPGRADE_VFMODULE_ACTION = "UNDO_UPGRADE_VFMODULE_ACTION",
}
@@ -47,6 +49,19 @@ export interface DeleteActionVfModuleInstanceAction extends Action {
serviceId?: string;
}
+export interface UpgradeVfModuleInstanceAction extends Action {
+ modelName : string;
+ vnfStoreKey : string;
+ serviceId?: string;
+ dynamicModelName: string;
+}
+export interface UndoUpgradeVfModuleInstanceAction extends Action {
+ modelName : string;
+ vnfStoreKey : string;
+ serviceId?: string;
+ dynamicModelName: string;
+}
+
export interface UndoDeleteActionVfModuleInstanceAction extends Action {
dynamicModelName: string;
vnfStoreKey : string;
@@ -95,7 +110,6 @@ export const undoDeleteVfModuleInstance: ActionCreator<UndoDeleteActionVfModuleI
serviceId: serviceId
});
-
export const updateVFModulePosition: ActionCreator<UpdateVFModluePosition> = (node, instanceId, vnfStoreKey) => ({
type: VfModuleActions.UPDATE_VFMODULE_POSITION,
node: node,
@@ -103,3 +117,18 @@ export const updateVFModulePosition: ActionCreator<UpdateVFModluePosition> = (no
vnfStoreKey : vnfStoreKey
});
+export const upgradeVFModule: ActionCreator<UpgradeVfModuleInstanceAction> = (modelName, vnfStoreKey, serviceId, dynamicModelName) => ({
+ type: VfModuleActions.UPGRADE_VFMODULE,
+ dynamicModelName,
+ modelName,
+ vnfStoreKey,
+ serviceId
+});
+
+export const undoUgradeVFModule: ActionCreator<UndoUpgradeVfModuleInstanceAction> = (modelName, vnfStoreKey, serviceId, dynamicModelName) => ({
+ type: VfModuleActions.UNDO_UPGRADE_VFMODULE_ACTION,
+ dynamicModelName,
+ modelName,
+ vnfStoreKey,
+ serviceId
+});
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts
index de6d2142c..ee0edb0a7 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.spec.ts
@@ -1,7 +1,10 @@
import {
CreateVFModuleInstanceAction,
DeleteActionVfModuleInstanceAction,
- DeleteVfModuleInstanceAction, UndoDeleteActionVfModuleInstanceAction, UpdateVFModluePosition,
+ DeleteVfModuleInstanceAction,
+ UndoDeleteActionVfModuleInstanceAction,
+ UpdateVFModluePosition,
+ UpgradeVfModuleInstanceAction,
VfModuleActions
} from "./vfModule.actions";
import {vfModuleReducer} from "./vfModule.reducers";
@@ -102,10 +105,10 @@ describe('vfModuleReducer', () => {
vfModuleInstance.isMissingData = false;
vfModuleInstance.volumeGroupName = 'volumeGroupName';
let vfModule = vfModuleReducer(<any>{
- serviceHierarchy : {
- 'serviceModelId' : {}
- },
- serviceInstance : {
+ serviceHierarchy : {
+ 'serviceModelId' : {}
+ },
+ serviceInstance : {
'serviceModelId' : {
vnfs : {
'vfName' : {
@@ -169,16 +172,16 @@ describe('vfModuleReducer', () => {
}).serviceInstance['serviceModelId'].vnfs['vfName'].vfModules["modelName"]["dynamicModelName"];
- expect(vfModule.position).toEqual(1);
+ expect(vfModule.position).toEqual(1);
});
test('#DELETE_ACTION_VF_MODULE_INSTANCE', ()=>{
let vfModule = vfModuleReducer(<any>{
- serviceHierarchy : {
- 'serviceModelId' : {}
- },
- serviceInstance : {
+ serviceHierarchy : {
+ 'serviceModelId' : {}
+ },
+ serviceInstance : {
'serviceModelId' : {
vnfs : {
'vnfStoreKey' : {
@@ -242,7 +245,70 @@ describe('vfModuleReducer', () => {
expect(vfModule.action).toEqual(ServiceInstanceActions.None);
});
-});
+ test('#UPGRADE_VFMODULE', ()=>{
+ let vfModule = vfModuleReducer(<any>{
+ serviceHierarchy : {
+ 'serviceModelId' : {}
+ },
+ serviceInstance : {
+ 'serviceModelId' : {
+ vnfs : {
+ 'vnfStoreKey' : {
+ vfModules : {
+ 'modelName' : {
+ 'dynamicModelName1': {
+ isMissingData : true,
+ action : 'None'
+ },
+ 'dynamicModelName2': {},
+ }
+ }
+ }
+ }
+ }
+ }},
+ <UpgradeVfModuleInstanceAction>{
+ type: VfModuleActions.UPGRADE_VFMODULE,
+ dynamicModelName: 'dynamicModelName1',
+ vnfStoreKey : 'vnfStoreKey',
+ serviceId: 'serviceModelId',
+ modelName: 'modelName'
+ }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1'];
+
+ expect(vfModule.action).toEqual(ServiceInstanceActions.None_Upgrade);
+ });
+ test('#UNDO_UPGRADE_VFMODULE', ()=>{
+ let vfModule = vfModuleReducer(<any>{
+ serviceHierarchy : {
+ 'serviceModelId' : {}
+ },
+ serviceInstance : {
+ 'serviceModelId' : {
+ vnfs : {
+ 'vnfStoreKey' : {
+ vfModules : {
+ 'modelName' : {
+ 'dynamicModelName1': {
+ isMissingData : true,
+ action : 'None_Upgrade'
+ },
+ 'dynamicModelName2': {},
+ }
+ }
+ }
+ }
+ }
+ }},
+ <UpgradeVfModuleInstanceAction>{
+ type: VfModuleActions.UNDO_UPGRADE_VFMODULE_ACTION,
+ dynamicModelName: 'dynamicModelName1',
+ vnfStoreKey : 'vnfStoreKey',
+ serviceId: 'serviceModelId',
+ modelName: 'modelName'
+ }).serviceInstance['serviceModelId'].vnfs['vnfStoreKey'].vfModules['modelName']['dynamicModelName1'];
+ expect(vfModule.action).toEqual(ServiceInstanceActions.None);
+ });
+});
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts
index 05319c0fb..a7aadba41 100644
--- a/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vfModule/vfModule.reducers.ts
@@ -3,7 +3,7 @@ import * as _ from "lodash";
import {
CreateVFModuleInstanceAction, DeleteActionVfModuleInstanceAction,
DeleteVfModuleInstanceAction, UndoDeleteActionVfModuleInstanceAction, UpdateVFModluePosition,
- UpdateVFModuleInstanceAction,
+ UpdateVFModuleInstanceAction, UpgradeVfModuleInstanceAction,
VfModuleActions
} from "./vfModule.actions";
import {ServiceInstance} from "../../../models/serviceInstance";
@@ -26,6 +26,7 @@ export function vfModuleReducer(state: ServiceState , action: Action) : ServiceS
let vfModulesMap = newState.serviceInstance[serviceUuid].vnfs[vnfStoreKey].vfModules[vfModuleId] || new VfModuleMap();
let randomId = generateId();
+ vfInstance.action = ServiceInstanceActions.Create;
vfModulesMap[vfModuleId + randomId] = vfInstance;
updateUniqueNames(null, vfInstance.instanceName, newState.serviceInstance[serviceUuid]);
updateUniqueNames(null, vfInstance.volumeGroupName, newState.serviceInstance[serviceUuid]);
@@ -110,6 +111,40 @@ export function vfModuleReducer(state: ServiceState , action: Action) : ServiceS
newState.serviceInstance[serviceUuid].vnfs[updateVFModluePosition.vnfStoreKey].vfModules[modelName][dynamicModelName].position = updateVFModluePosition.node.position;
return newState;
}
+
+ case VfModuleActions.UPGRADE_VFMODULE : {
+ let clonedState = _.cloneDeep(state);
+ const upgradeAction = (<UpgradeVfModuleInstanceAction>action);
+ let oldAction = clonedState
+ .serviceInstance[upgradeAction.serviceId]
+ .vnfs[upgradeAction.vnfStoreKey]
+ .vfModules[upgradeAction.modelName][upgradeAction.dynamicModelName]
+ .action;
+ if(!_.isNil(oldAction) && oldAction.includes("Upgrade")) {
+ return clonedState;
+ }
+ clonedState.serviceInstance[upgradeAction.serviceId]
+ .vnfs[upgradeAction.vnfStoreKey]
+ .vfModules[upgradeAction.modelName][upgradeAction.dynamicModelName]
+ .action = (`${oldAction}_Upgrade`) as ServiceInstanceActions;
+ return clonedState;
+ }
+ case VfModuleActions.UNDO_UPGRADE_VFMODULE_ACTION : {
+ let clonedState = _.cloneDeep(state);
+ const upgradeAction = (<UpgradeVfModuleInstanceAction>action);
+ let oldAction = clonedState
+ .serviceInstance[upgradeAction.serviceId]
+ .vnfs[upgradeAction.vnfStoreKey]
+ .vfModules[upgradeAction.modelName][upgradeAction.dynamicModelName]
+ .action;
+ if(!_.isNil(oldAction) && oldAction.includes("Upgrade")) {
+ clonedState.serviceInstance[upgradeAction.serviceId]
+ .vnfs[upgradeAction.vnfStoreKey]
+ .vfModules[upgradeAction.modelName][upgradeAction.dynamicModelName]
+ .action = ServiceInstanceActions.None;
+ }
+ return clonedState;
+ }
}
}
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
index 25179fe2e..6fb844e52 100644
--- 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
@@ -8,7 +8,14 @@ export enum VNFActions {
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"
+ UPDATE_VNF_POSITION = "UPDATE_VNF_POISTION",
+ UPGRADE_VNF_ACTION = "UPGRADE_VNF_ACTION",
+ UNDO_UPGRADE_VNF_ACTION = "UNDO_UPGRADE_VNF_ACTION"
+}
+
+export enum VNFMethods{
+ UPGRADE = "upgrade",
+ UNDO_UPGRADE = "undoUpgrade"
}
@@ -32,6 +39,16 @@ export interface UpdateVnfInstanceAction extends Action {
vnfStoreKey?:string;
}
+export interface UpgradeVnfAction extends Action {
+ serviceUuid: string;
+ vnfStoreKey:string;
+}
+
+export interface UndoUpgradeVnfAction extends Action {
+ serviceUuid: string;
+ vnfStoreKey:string;
+}
+
export interface RemoveVnfInstanceAction extends Action {
vnfStoreKey: string;
serviceId?: string;
@@ -82,9 +99,14 @@ export const updateVnfPosition: ActionCreator<UpdateVnfPosition> = (node, instan
vnfStoreKey : vnfStoreKey
});
+export const upgradeVnf: ActionCreator<UpgradeVnfAction> = (vnfStoreKey, serviceUuid) => ({
+ type: VNFActions.UPGRADE_VNF_ACTION,
+ serviceUuid,
+ vnfStoreKey
+});
-
-
-
-
-
+export const undoUpgradeVnf: ActionCreator<UndoUpgradeVnfAction> = (vnfStoreKey, serviceUuid) => ({
+ type: VNFActions.UNDO_UPGRADE_VNF_ACTION,
+ serviceUuid,
+ 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
index a5e37fcab..502777518 100644
--- 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
@@ -2,7 +2,7 @@ import {VnfInstance} from "../../../models/vnfInstance";
import {
CreateVnfInstanceAction,
RemoveVnfInstanceAction,
- UpdateVnfPosition,
+ UpdateVnfPosition, UpgradeVnfAction,
VNFActions
} from "./vnf.actions";
import {vnfReducer} from "./vnf.reducers";
@@ -15,7 +15,7 @@ describe('vnfReducer', () => {
vnfInstance.isMissingData = false;
vnfInstance.instanceName = 'instanceName';
let vnfState = vnfReducer(<any>{
- serviceInstance : {
+ serviceInstance : {
'serviceModelId' : {
vnfs : {
"vnfStoreKey" : {
@@ -129,7 +129,49 @@ describe('vnfReducer', () => {
expect(vnfs['vnfStoreKey']).toBeUndefined();
});
-});
+ test('#UPGRADE_VNF_ACTION', () => {
+ const vnfStoreKey: string = 'vnfStoreKey';
+ const serviceModelId: string = 'serviceModelId';
+ let vnfs = vnfReducer(<any>{serviceInstance : {
+ [serviceModelId] : {
+ vnfs : {
+ [vnfStoreKey] : {
+ isMissingData : true,
+ action : 'None'
+ }
+ }
+ }
+ }},
+ <UpgradeVnfAction>{
+ type: VNFActions.UPGRADE_VNF_ACTION,
+ vnfStoreKey: vnfStoreKey,
+ serviceUuid: serviceModelId
+ }).serviceInstance[serviceModelId].vnfs[vnfStoreKey];
+ expect(vnfs).toBeDefined();
+ expect(vnfs[vnfStoreKey]).toBeUndefined();
+ });
+ test('#UNDO_UPGRADE_VNF_ACTION', () => {
+ const vnfStoreKey: string = 'vnfStoreKey';
+ const serviceModelId: string = 'serviceModelId';
+ let vnfs = vnfReducer(<any>{serviceInstance : {
+ [serviceModelId] : {
+ vnfs : {
+ [vnfStoreKey] : {
+ isMissingData : true,
+ action : 'None_Upgrade'
+ }
+ }
+ }
+ }},
+ <UpgradeVnfAction>{
+ type: VNFActions.UNDO_UPGRADE_VNF_ACTION,
+ vnfStoreKey: vnfStoreKey,
+ serviceUuid: serviceModelId
+ }).serviceInstance[serviceModelId].vnfs[vnfStoreKey];
+ 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
index 072634f2b..c5cd88aa7 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
@@ -3,7 +3,7 @@ import {VnfInstance} from "../../../models/vnfInstance";
import {
CreateVnfInstanceAction,
RemoveVnfInstanceAction,
- UpdateVnfInstanceAction, UpdateVnfPosition,
+ UpdateVnfInstanceAction, UpdateVnfPosition, UpgradeVnfAction,
VNFActions
} from "./vnf.actions";
import * as _ from "lodash";
@@ -55,7 +55,6 @@ export function vnfReducer(state: ServiceState, action: Action): ServiceState {
case VNFActions.DELETE_ACTION_VNF_INSTANCE : {
return deleteFirstLevel(state, <ActionOnFirstLevel>action,true);
-
}
case VNFActions.UNDO_DELETE_ACTION_VNF_INSTANCE : {
@@ -77,13 +76,56 @@ export function vnfReducer(state: ServiceState, action: Action): ServiceState {
case VNFActions.UPDATE_VNF_POSITION : {
let newState = _.cloneDeep(state);
- newState.serviceInstance[(<UpdateVnfPosition>action).instanceId].vnfs[(<UpdateVnfPosition>action).vnfStoreKey].position = (<UpdateVnfPosition>action).node.position;
+ newState.serviceInstance[(<UpdateVnfPosition>action).instanceId]
+ .vnfs[(<UpdateVnfPosition>action).vnfStoreKey]
+ .position = (<UpdateVnfPosition>action).node.position;
return newState;
}
- }
-}
+ case VNFActions.UPGRADE_VNF_ACTION: {
+ let clonedState = _.cloneDeep(state);
+ const castingAction = <UpgradeVnfAction>action;
+ let oldAction = clonedState
+ .serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey].action;
+ if(!oldAction.includes("Upgrade")) {
+ clonedState.serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey]
+ .action = (`${oldAction}_Upgrade`) as ServiceInstanceActions;
+ }
+
+ if(_.isNil(clonedState.serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey].upgradedVFMSonsCounter)) {
+ clonedState.serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey].upgradedVFMSonsCounter = 1;
+ return clonedState;
+ }
+ clonedState.serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey].upgradedVFMSonsCounter++;
+ return clonedState;
+ }
+ case VNFActions.UNDO_UPGRADE_VNF_ACTION: {
+ let clonedState = _.cloneDeep(state);
+ const castingAction = <UpgradeVnfAction>action;
+ if(clonedState.serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey]
+ .action.includes("Upgrade")) {
+ clonedState
+ .serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey].upgradedVFMSonsCounter--;
+ if(clonedState.serviceInstance[castingAction.serviceUuid].vnfs[castingAction.vnfStoreKey]
+ .upgradedVFMSonsCounter === 0){
+ clonedState.serviceInstance[castingAction.serviceUuid]
+ .vnfs[castingAction.vnfStoreKey]
+ .action = ServiceInstanceActions.None;
+ }
+ }
+ return clonedState;
+ }
+
+ }
+}
const updateUniqueNames = (oldName: string, newName: string, serviceInstance: ServiceInstance): void => {
@@ -108,8 +150,3 @@ export const calculateNextUniqueModelName = (vnfModelName: string, serviceId: st
}
}
};
-
-
-
-
-