1 import {ComponentState} from "../../../../utils/constants";
2 import {IDependenciesServerResponse} from "../../../services/responses/dependencies-server-response";
3 import {UiBaseObject} from "../../../../models/ui-models/ui-base-object";
6 * Created by ob0695 on 5/1/2018.
8 export enum AutomatedUpgradeInstanceType {
9 VF, SERVICE_PROXY, ALLOTTED_RESOURCE
11 export class ServiceContainerToUpgradeUiObject extends UiBaseObject {
15 isLock:boolean; // true if service is in check-out or ceritification-in-progress
16 vspInstances:Array<VspInstanceUiObject>; // list of instances of the vsp contain in the service - intances can be vf, proxy or allotted
17 isAlreadyUpgrade:boolean; // true if all instances is in latest version
19 constructor(componentToUpgrade:IDependenciesServerResponse) {
20 super(componentToUpgrade.uniqueId, componentToUpgrade.type, componentToUpgrade.name);
21 this.icon = componentToUpgrade.icon;
22 this.version = componentToUpgrade.version;
23 this.isAlreadyUpgrade = true;
24 this.isLock = componentToUpgrade.state === ComponentState.NOT_CERTIFIED_CHECKOUT;
25 this.vspInstances = [];
28 public addVfInstance = (vsp: IDependenciesServerResponse, latestVersion:string):void => {
29 let isNeededUpgrade = parseInt(vsp.version) < parseInt(latestVersion);
30 this.vspInstances.push(new VspInstanceUiObject(vsp.uniqueId, vsp.name, vsp.version, vsp.icon));
31 if (isNeededUpgrade) {
32 this.isAlreadyUpgrade = false;
36 public addProxyInstance = (vsp: IDependenciesServerResponse, isNeededUpgrade:boolean, instanceName:string):void => {
37 this.vspInstances.push(new ProxyVspInstanceUiObject(vsp.uniqueId, vsp.name, vsp.version, vsp.icon, instanceName));
38 if (isNeededUpgrade) {
39 this.isAlreadyUpgrade = false;
43 public addAllottedResourceInstance = (vsp: IDependenciesServerResponse, isNeededUpgrade:boolean, instanceName:string, vfName:string, vfId:string):void => {
44 this.vspInstances.push(new AllottedResourceInstanceUiObject(vsp.uniqueId, vsp.name, vsp.version, vsp.icon, instanceName, vfName, vfId));
45 if (isNeededUpgrade) {
46 this.isAlreadyUpgrade = false;
50 public addMultipleInstances = (vsp: IDependenciesServerResponse, vspLatestVersion:string, instancesNames:Array<string>, allottedOriginVf: IDependenciesServerResponse):void => {
51 _.forEach(instancesNames, (instanceName:string) => {
52 let isNeededUpgrade = parseInt(vsp.version) < parseInt(vspLatestVersion);
53 if (allottedOriginVf) {
54 this.addAllottedResourceInstance(vsp, isNeededUpgrade, instanceName, allottedOriginVf.name, allottedOriginVf.uniqueId);
56 this.addProxyInstance(vsp, isNeededUpgrade, instanceName);
62 export class VspInstanceUiObject {
68 instanceType:AutomatedUpgradeInstanceType;
70 constructor(uniqueId:string, vspName:string, vspVersion:string, icon:string) {
71 this.vspId = uniqueId;
72 this.vspName = vspName;
73 this.vspVersion = vspVersion;
75 this.instanceType = AutomatedUpgradeInstanceType.VF;
79 export class ProxyVspInstanceUiObject extends VspInstanceUiObject {
83 constructor(uniqueId:string, vspName:string, vspVersion:string, icon:string, instanceName: string) {
84 super(uniqueId, vspName, vspVersion, icon);
85 this.instanceName = instanceName;
86 this.instanceType = AutomatedUpgradeInstanceType.SERVICE_PROXY;
90 export class AllottedResourceInstanceUiObject extends VspInstanceUiObject {
96 constructor(uniqueId:string, vspName:string, vspVersion:string, icon:string, instanceName:string, originVfName:string, originVfId:string) {
97 super(uniqueId, vspName, vspVersion, icon)
98 this.instanceName = instanceName;
99 this.originVfId = originVfId;
100 this.originVfName = originVfName;
101 this.instanceType = AutomatedUpgradeInstanceType.ALLOTTED_RESOURCE;