update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / NetworkService.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 /**
19 * Created by onvelocity on 11/23/15.
20 */
21
22 'use strict';
23
24 import ColorGroups from '../../ColorGroups'
25 import DescriptorModel from '../DescriptorModel'
26 import ForwardingGraph from './ForwardingGraph'
27 import VirtualNetworkFunctionAccessPointMap from './VirtualNetworkFunctionAccessPointMap'
28 import VirtualLink from './VirtualLink'
29 import ConstituentVnfd from './ConstituentVnfd'
30 import PhysicalNetworkFunction from './PhysicalNetworkFunction'
31 import DescriptorModelFactory from '../DescriptorModelFactory'
32 import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
33
34 const indexAsInteger = d => 1 + (parseInt(d.model['member-vnf-index'], 10) || 0);
35
36 const suffixAsInteger = function (field) {
37 return (d) => 1 + (parseInt(String(d.model[field]).split('').reverse().join(''), 10) || 0);
38 };
39
40 const toBiggestValue = (newIndex, curIndex) => Math.max(newIndex, curIndex);
41
42 export default class NetworkService extends DescriptorModel {
43
44 static get type() {
45 return 'nsd';
46 }
47
48 static get className() {
49 return 'NetworkService';
50 }
51
52 constructor(model, parent) {
53 super(model, parent);
54 this.type = 'nsd';
55 this.className = 'NetworkService';
56 this._connectors = [];
57 }
58
59 get constituentVnfd() {
60 if (!this.model['constituent-vnfd']) {
61 this.model['constituent-vnfd'] = [];
62 }
63 return this.model['constituent-vnfd'].map(d => DescriptorModelFactory.newConstituentVnfd(d, this));
64 }
65
66 set constituentVnfd(obj) {
67 const updateNextVnfdIndex = (cvnfd) => {
68 const items = this.constituentVnfd;
69 const length = items.length;
70 // the default value is set to an instance count but we want it to be a sequence no
71 cvnfd.model['member-vnf-index'] = 0;
72 cvnfd.model['member-vnf-index'] = items.map(indexAsInteger).reduce(toBiggestValue, length);
73 };
74 this.updateModelList('constituent-vnfd', obj, ConstituentVnfd, updateNextVnfdIndex);
75 }
76
77 createConstituentVnfd(model) {
78 model = model || DescriptorModelMetaFactory.createModelInstanceForType('nsd.constituent-vnfd');
79 return this.constituentVnfd = DescriptorModelFactory.newConstituentVnfd(model, this);
80 }
81
82 removeConstituentVnfd(cvnfd) {
83 cvnfd = this.findChildByUid(cvnfd);
84 this.vld.forEach(vld => vld.removeVnfdConnectionPointRefForVnfdIndex(cvnfd.vnfdIndex));
85 this.vnffgd.forEach(fg => fg.removeVnfdConnectionPointRefForVnfdIndex(cvnfd.vnfdIndex));
86 return this.removeModelListItem('constituentVnfd', cvnfd);
87 }
88
89 get pnfd() {
90 if (!this.model.pnfd) {
91 this.model.pnfd = [];
92 }
93 return this.model.pnfd.map(d => DescriptorModelFactory.newPhysicalNetworkFunction(d, this));
94 }
95
96 set pnfd(obj) {
97 this.updateModelList('pnfd', obj, PhysicalNetworkFunction);
98 }
99
100 createPnfd(model) {
101 model = model || DescriptorModelMetaFactory.createModelInstanceForType('nsd.pnfd');
102 return this.pnfd = DescriptorModelFactory.newPhysicalNetworkFunction(model, this);
103 }
104
105 removePnfd(pnfd) {
106 return this.removeModelListItem('pnfd', pnfd);
107 }
108
109
110 get vld() {
111 if (!this.model.vld) {
112 this.model.vld = [];
113 }
114 return this.model.vld.map(d => DescriptorModelFactory.newVirtualLink(d, this));
115 }
116
117 set vld(obj) {
118 this.updateModelList('vld', obj, VirtualLink);
119 }
120
121 createVld() {
122 const property = DescriptorModelMetaFactory.getModelMetaForType('nsd.vld');
123 const uniqueName = DescriptorModelMetaFactory.generateItemUniqueName(this.vld, property);
124 const model = DescriptorModelMetaFactory.createModelInstanceForType('nsd.vld', uniqueName);
125 return this.vld = DescriptorModelFactory.newVirtualLink(model, this);
126 }
127
128 removeVLD(vld) {
129 return this.removeModelListItem('vld', vld);
130 }
131
132
133 // <<<<<<< Updated upstream
134 // get configParameterMap() {
135 // if (!this.model['config-parameter-map']) {
136 // this.model['config-parameter-map'] = [];
137 // }
138 // return this.model['config-parameter-map'].map(d => DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(d, this)).map((fg, i) => {
139 // return fg;
140 // });
141 // }
142
143 // set configParameterMap(obj) {
144 // const onVirtualNetworkFunctionAccessPointMap = (fg) => {
145
146 // };
147 // this.updateModelList('config-parameter-map', obj, VirtualNetworkFunctionAccessPointMap, onVirtualNetworkFunctionAccessPointMap);
148 // }
149
150 // createConfigParameterMap(model) {
151 // model = model || DescriptorModelMetaFactory.createModelInstanceForType('nsd.config-parameter-map');
152 // return this.configParameterMap = DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(model, this);
153 // }
154 // =======
155 get configParameterMap() {
156 if (!this.model['config-parameter-map']) {
157 this.model['config-parameter-map'] = [];
158 }
159 return this.model['config-parameter-map'].map(d => DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(d, this))
160 }
161
162 set configParameterMap(obj) {
163 this.updateModelList('config-parameter-map', obj, VirtualNetworkFunctionAccessPointMap);
164 }
165
166 createConfigParameterMap() {
167 const model = DescriptorModelMetaFactory.createModelInstanceForType('nsd.config-parameter-map');
168 return this.configParameterMap = DescriptorModelFactory.newVirtualNetworkFunctionAccessPointMap(model, this);
169 }
170 // >>>>>>> Stashed changes
171
172 get vnffgd() {
173 if (!this.model.vnffgd) {
174 this.model.vnffgd = [];
175 }
176 return this.model.vnffgd.map(d => DescriptorModelFactory.newForwardingGraph(d, this)).map((fg, i) => {
177 fg.uiState.colors = ColorGroups.getColorPair(i);
178 return fg;
179 });
180 }
181
182 set vnffgd(obj) {
183 this.updateModelList('vnffgd', obj, ForwardingGraph);
184 }
185
186 createVnffgd(model) {
187 const property = DescriptorModelMetaFactory.getModelMetaForType('nsd.vnffgd');
188 const uniqueName = DescriptorModelMetaFactory.generateItemUniqueName(this.vnffgd, property, 'fg');
189 model = model || DescriptorModelMetaFactory.createModelInstanceForType('nsd.vnffgd', uniqueName);
190 return this.vnffgd = DescriptorModelFactory.newForwardingGraph(model, this);
191 }
192
193 removeVnffgd(fg) {
194 return this.removeModelListItem('vnffgd', fg);
195 }
196
197 get forwardingGraphs() {
198 return this.vnffgd;
199 }
200
201
202
203 // NOTE temporarily disable NSD connection points
204 // https://trello.com/c/crVgg2A1/88-do-not-render-nsd-connection-in-the-composer
205 //get connectionPoint() {
206 // if (this.model && this.model['connection-point']) {
207 // return this.model['connection-point'];
208 // }
209 // return [];
210 //}
211 //
212 //get connectors() {
213 // const parent = this;
214 // if (!this._connectors.length) {
215 // this._connectors = this.connectionPoint.map(cp => {
216 // return DescriptorModelFactory.newConnectionPoint(parent, cp);
217 // });
218 // }
219 // return this._connectors;
220 //}
221
222 removeAnyConnectionsForConnector(cpc) {
223 // todo need to also remove connection points from related ForwardingGraph paths
224 this.vld.forEach(vldc => vldc.removeVnfdConnectionPointRefKey(cpc.key));
225 }
226
227 createConstituentVnfdForVnfd(vnfdRef) {
228 const cvnfd = this.createConstituentVnfd();
229 cvnfd.vnfdRef = vnfdRef;
230 cvnfd.vnfdId = vnfdRef.id;
231 return cvnfd;
232 }
233
234 }