summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/model/NewServiceModel.java
blob: e55ba4a4ea3ed6e56cd8960489ccea9b5cb103b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*-
 * ============LICENSE_START=======================================================
 * VID
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.onap.vid.model;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.onap.vid.asdc.beans.tosca.Group;
import org.onap.vid.asdc.beans.tosca.ToscaModel;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.properties.VidProperties;
/**
 * The Class ServiceModel.
 */

public class NewServiceModel {

	/** The Constant LOG. */
	private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(NewServiceModel.class);
	
	/** The Constant dateFormat. */
	final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
	/** The service. */
	private Service service;
	
	/** The vnfs. */
	private Map<String, VNF> vnfs;
	
	/** The networks. */
	private Map<String, Network> networks;

	/** 
	 * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
	 * that is not present in the VNF, like the vf module customization String 
	 */
	private Map<String, VfModule> vfModules;
	/**
	 * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
	 * for newer models
	 */
	private Map<String, VolumeGroup> volumeGroups;

	private Map<String, PortMirroringConfig> configurations;

	private Map<String, ServiceProxy> serviceProxies;

	private Map<String, Node> pnfs;

	private Map<String, CR> collectionResource;


	/**
	 * Instantiates a new service model.
	 */
	public NewServiceModel() {}
	
	/**
	 * Gets the service.
	 *
	 * @return the service
	 */
	public Service getService() {
		return service;
	}

	/**
	 * Gets the vnfs.
	 *
	 * @return the vnfs
	 */
	public Map<String, VNF> getVnfs() {
		return vnfs;
	}

	/**
	 * Gets the networks.
	 *
	 * @return the networks
	 */
	public Map<String, Network> getNetworks() {
		return networks;
	}

	/**
	 * Sets the service.
	 *
	 * @param service the new service
	 */
	public void setService(Service service) {
		this.service = service;
	}

	/**
	 * Sets the vnfs.
	 *
	 * @param vnfs the vnfs
	 */
	public void setVnfs(Map<String, VNF> vnfs) {
		this.vnfs = vnfs;
	}

	/**
	 * Sets the networks.
	 *
	 * @param networks the networks
	 */
	public void setNetworks(Map<String, Network> networks) {
		this.networks = networks;
	}
	/**
	 * Gets the vf modules.
	 *
	 * @return the vf modules
	 */
	public Map<String, VfModule> getVfModules() {
		return vfModules;
	}
	/**
	 * Gets the volume groups.
	 *
	 * @return the volume groups
	 */
	public Map<String, VolumeGroup> getVolumeGroups() {
		return volumeGroups;
	}

	public Map<String, PortMirroringConfig> getConfigurations() {
		return configurations;
	}

	public Map<String, ServiceProxy> getServiceProxies() {
		return serviceProxies;
	}

	/**
	 * Sets the vf modules.
	 *
	 * @param vfModules the vf modules
	 */


	public void setVfModules(Map<String, VfModule> vfModules) {
		this.vfModules = vfModules;
	}
	/**
	 * Sets the volume groups.
	 *
	 * @param volumeGroups the volume groups
	 */
	public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
		this.volumeGroups = volumeGroups;
	}


	public Map<String, Node> getPnfs() {
		return pnfs;
	}

	public void setPnfs(Map<String, Node> pnfs) {
		this.pnfs = pnfs;
	}

	public Map<String, CR> getCollectionResource() {
		return collectionResource;
	}

	public void setCollectionResource(Map<String, CR> collectionResource) {
		this.collectionResource = collectionResource;
	}

	/**
	 * Extract service.
	 *
	 * @param serviceToscaModel the service tosca model
	 * @param asdcServiceMetadata the asdc service metadata
	 * @return the service
	 */
	public static Service extractService(ToscaModel serviceToscaModel, org.onap.vid.asdc.beans.Service asdcServiceMetadata) {
		
		final Service service = new Service();
		
		service.setCategory(serviceToscaModel.getMetadata().getCategory());
		service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
		service.setName(serviceToscaModel.getMetadata().getName());
		service.setUuid(serviceToscaModel.getMetadata().getUUID());
		service.setDescription(serviceToscaModel.getMetadata().getDescription());
		service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
		service.setInputs(serviceToscaModel.gettopology_template().getInputs());
		//FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
		//THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
		//service.setVersion(serviceToscaModel.getMetadata().getVersion());
		service.setVersion(asdcServiceMetadata.getVersion());

		return service;
	}
	public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) {
		// Get the groups. The groups may duplicate the groups that are in the VNF model and have
		// additional data like the VF module customization String>
		
		final Map<String, VfModule> vfModules = new HashMap<String, VfModule> ();
		final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
		
		String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
    	String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
    	
		for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
			final Group group = component.getValue();
			final String type = group.getType();
			final String customizationName = component.getKey();
			
			if (type.startsWith(vfModuleTag)) {
				VfModule vfMod = VfModule.extractVfModule(customizationName, group);
				vfModules.put(customizationName, vfMod);
				if ( vfMod.isVolumeGroupAllowed() ) {
					//volume groups have the same customization name as the vf module
					volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
				}
			}
		}
		// add this point vfModules and volume groups are disconnected from VNF
		serviceModel.setVfModules (vfModules);
		serviceModel.setVolumeGroups (volumeGroups);
		
	}
	/**
	 * Populate the vf modules and volume groups that we may have under the service level under each VNF.
	 */
//	public void associateGroups() {
//		String methodName = "associateGroups()";
//        LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
//		// go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts
//		// with vnf + ".."
//		String vnfCustomizationName = null;
//		String normalizedVnfCustomizationName = null;
//		String vfModuleCustomizationName = null;
//		NewVNF tmpVnf = null;
//
//		if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) {
//			for (Entry<String, NewVNF> vnfComponent : getVnfs().entrySet()) {
//				vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
//				normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
//
//				LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
//						" VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName);
//
//				// now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName
//
//				if (( getVfModules() != null ) && (!(getVfModules().isEmpty()))) {
//					for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
//						vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
//
//						LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
//								" VF Module customizationName=" + vfModuleCustomizationName );
//						if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) {
//
//							// this vf module belongs to the VNF
//							tmpVnf = vnfComponent.getValue();
//							(tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
//
//							LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
//									" Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName);
//
//							// now find if this vf module has volume groups, if so, find the volume group with the same customization name and put it under the VNF
//							if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) {
//								if (( getVolumeGroups() != null ) && (!(getVolumeGroups().isEmpty()))) {
//									if (getVolumeGroups().containsKey((vfModuleCustomizationName))) {
//										(vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));
//									}
//								}
//							}
//						}
//					}
//				}
//			}
//		}
		
//	}
}