2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.model;
23 import org.apache.commons.collections.MapUtils;
24 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
25 import org.onap.vid.asdc.beans.tosca.Group;
26 import org.onap.vid.asdc.beans.tosca.ToscaModel;
27 import org.onap.vid.properties.VidProperties;
29 import java.util.HashMap;
31 import java.util.Map.Entry;
33 * The Class ServiceModel.
35 @SuppressWarnings("ALL")
36 public class ServiceModel {
38 /** The Constant LOG. */
39 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ServiceModel.class);
42 private Service service;
45 private Map<String, VNF> vnfs;
48 private Map<String, Network> networks;
50 private Map<String, CR> collectionResources;
52 /** Port Mirroring Configuration node templates */
53 private Map<String, PortMirroringConfig> configurations;
55 /** Fabric Configuration node templates */
56 private Map<String, Node> fabricConfigurations;
58 /** Service Proxy Nodes */
59 private Map<String, ServiceProxy> serviceProxies;
62 * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
63 * that is not present in the VNF, like the vf module customization String
65 private Map<String, VfModule> vfModules;
67 * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
70 private Map<String, VolumeGroup> volumeGroups;
73 private Map<String, Node> pnfs;
75 /** Resource groups of VF (VNF) type. */
76 private Map<String, ResourceGroup> vnfGroups;
79 private Map<String, Node> vrfs;
82 * Instantiates a new service model.
84 public ServiceModel() {}
91 public Service getService() {
100 public Map<String, VNF> getVnfs() {
107 * @return the networks
109 public Map<String, Network> getNetworks() {
119 public Map<String, Node> getPnfs() {
125 * Gets the Configuration Node Templates
127 * @return the configuration type node templates
129 public Map<String, PortMirroringConfig> getConfigurations() {
130 return configurations;
134 * Gets the Service Proxy Node Templates
136 * @return the Service Proxy type node templates
138 public Map<String, ServiceProxy> getServiceProxies() {
139 return serviceProxies;
142 public Map<String, ResourceGroup> getVnfGroups() {
146 public Map<String, Node> getVrfs() {
153 * @param service the new service
155 public void setService(Service service) {
156 this.service = service;
162 * @param vnfs the vnfs
164 public void setVnfs(Map<String, VNF> vnfs) {
171 * @param networks the networks
173 public void setNetworks(Map<String, Network> networks) {
174 this.networks = networks;
178 * Sets the configuraion node templates.
180 * @param configurations
182 public void setConfigurations(Map<String, PortMirroringConfig> configurations) {
183 this.configurations = configurations;
187 * Sets the service proxy node templates.
189 * @param serviceProxies
191 public void setServiceProxies(Map<String, ServiceProxy> serviceProxies) {
192 this.serviceProxies = serviceProxies;
196 * Gets the vf modules.
198 * @return the vf modules
200 public Map<String, VfModule> getVfModules() {
206 * Gets the volume groups.
208 * @return the volume groups
210 public Map<String, VolumeGroup> getVolumeGroups() {
214 * Sets the vf modules.
216 * @param vfModules the vf modules
218 public void setVfModules(Map<String, VfModule> vfModules) {
219 this.vfModules = vfModules;
222 * Sets the volume groups.
224 * @param volumeGroups the volume groups
226 public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
227 this.volumeGroups = volumeGroups;
232 * @param pnfs the pnfs
234 public void setPnfs(Map<String,Node> pnfs) {this.pnfs = pnfs;}
236 public void setVnfGroups(Map<String, ResourceGroup> vnfGroups) {
237 this.vnfGroups = vnfGroups;
240 public void setVrfs(Map<String, Node> vrfs) {
244 public Map<String, CR> getCollectionResources() {
245 return collectionResources;
248 public void setCollectionResources(Map<String, CR> collectionResources) {
249 this.collectionResources = collectionResources;
252 public Map<String, Node> getFabricConfigurations() {
253 return fabricConfigurations;
256 public void setFabricConfigurations(Map<String, Node> fabricConfigurations) {
257 this.fabricConfigurations = fabricConfigurations;
263 * @param serviceToscaModel the service tosca model
264 * @param asdcServiceMetadata the asdc service metadata
265 * @return the service
267 public static Service extractService(ToscaModel serviceToscaModel, org.onap.vid.asdc.beans.Service asdcServiceMetadata) {
269 final Service service = new Service();
271 service.setCategory(serviceToscaModel.getMetadata().getCategory());
272 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
273 service.setName(serviceToscaModel.getMetadata().getName());
274 service.setUuid(serviceToscaModel.getMetadata().getUUID());
275 service.setDescription(serviceToscaModel.getMetadata().getDescription());
276 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
277 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
278 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
279 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
280 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
281 service.setVersion(asdcServiceMetadata.getVersion());
285 public static void extractGroups (ToscaModel serviceToscaModel,ServiceModel serviceModel) {
286 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
287 // additional data like the VF module customization String>
289 final Map<String, VfModule> vfModules = new HashMap<> ();
290 final Map<String, VolumeGroup> volumeGroups = new HashMap<> ();
292 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
293 String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
295 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
296 final Group group = component.getValue();
297 final String type = group.getType();
298 final String customizationName = component.getKey();
300 if (type.startsWith(vfModuleTag)) {
301 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
302 vfModules.put(customizationName, vfMod);
303 if ( vfMod.isVolumeGroupAllowed() ) {
304 //volume groups have the same customization name as the vf module
305 volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
309 // add this point vfModules and volume groups are disconnected from VNF
310 serviceModel.setVfModules (vfModules);
311 serviceModel.setVolumeGroups (volumeGroups);
315 * Populate the vf modules and volume groups that we may have under the service level under each VNF.
317 public void associateGroups() {
318 String methodName = "associateGroups()";
319 LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " start");
320 // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts
322 String vnfCustomizationName = null;
323 String normalizedVnfCustomizationName = null;
324 String vfModuleCustomizationName = null;
326 if (!MapUtils.isEmpty(getVnfs())) {
327 for (Entry<String, VNF> vnfComponent : getVnfs().entrySet()) {
328 vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
329 normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
331 LOG.debug(EELFLoggerDelegate.debugLogger, methodName +
332 " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName);
334 // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName
336 if (!MapUtils.isEmpty(getVfModules())) {
337 for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
338 vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
340 LOG.debug(EELFLoggerDelegate.debugLogger, methodName +
341 " VF Module customizationName=" + vfModuleCustomizationName );
342 if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) {
343 handleCustomizationName(methodName, vnfCustomizationName, vfModuleCustomizationName, vnfComponent, vfModuleComponent);
354 private void handleCustomizationName(String methodName, String vnfCustomizationName, String vfModuleCustomizationName, Entry<String, VNF> vnfComponent, Entry<String, VfModule> vfModuleComponent) {
355 VNF tmpVnf;// this vf module belongs to the VNF
356 tmpVnf = vnfComponent.getValue();
357 (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
359 LOG.debug(EELFLoggerDelegate.debugLogger, methodName +
360 " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName);
362 // 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
363 if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) {
364 if (isVolumeGroupsContainsVfModuleCustomName(vfModuleCustomizationName)) {
365 (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));
370 private boolean isVolumeGroupsContainsVfModuleCustomName(String vfModuleCustomizationName) {
371 return (!MapUtils.isEmpty(getVolumeGroups())) && (getVolumeGroups().containsKey((vfModuleCustomizationName)));