2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 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> collectionResource;
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 * Instantiates a new service model.
81 public ServiceModel() {}
88 public Service getService() {
97 public Map<String, VNF> getVnfs() {
104 * @return the networks
106 public Map<String, Network> getNetworks() {
116 public Map<String, Node> getPnfs() {
122 * Gets the Configuration Node Templates
124 * @return the configuration type node templates
126 public Map<String, PortMirroringConfig> getConfigurations() {
127 return configurations;
131 * Gets the Service Proxy Node Templates
133 * @return the Service Proxy type node templates
135 public Map<String, ServiceProxy> getServiceProxies() {
136 return serviceProxies;
139 public Map<String, ResourceGroup> getVnfGroups() {
146 * @param service the new service
148 public void setService(Service service) {
149 this.service = service;
155 * @param vnfs the vnfs
157 public void setVnfs(Map<String, VNF> vnfs) {
164 * @param networks the networks
166 public void setNetworks(Map<String, Network> networks) {
167 this.networks = networks;
171 * Sets the configuraion node templates.
173 * @param configurations
175 public void setConfigurations(Map<String, PortMirroringConfig> configurations) {
176 this.configurations = configurations;
180 * Sets the service proxy node templates.
182 * @param serviceProxies
184 public void setServiceProxies(Map<String, ServiceProxy> serviceProxies) {
185 this.serviceProxies = serviceProxies;
189 * Gets the vf modules.
191 * @return the vf modules
193 public Map<String, VfModule> getVfModules() {
199 * Gets the volume groups.
201 * @return the volume groups
203 public Map<String, VolumeGroup> getVolumeGroups() {
207 * Sets the vf modules.
209 * @param vfModules the vf modules
211 public void setVfModules(Map<String, VfModule> vfModules) {
212 this.vfModules = vfModules;
215 * Sets the volume groups.
217 * @param volumeGroups the volume groups
219 public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
220 this.volumeGroups = volumeGroups;
225 * @param pnfs the pnfs
227 public void setPnfs(Map<String,Node> pnfs) {this.pnfs = pnfs;}
229 public void setVnfGroups(Map<String, ResourceGroup> vnfGroups) {
230 this.vnfGroups = vnfGroups;
233 public Map<String, CR> getCollectionResource() {
234 return collectionResource;
237 public void setCollectionResource(Map<String, CR> collectionResource) {
238 this.collectionResource = collectionResource;
241 public Map<String, Node> getFabricConfigurations() {
242 return fabricConfigurations;
245 public void setFabricConfigurations(Map<String, Node> fabricConfigurations) {
246 this.fabricConfigurations = fabricConfigurations;
252 * @param serviceToscaModel the service tosca model
253 * @param asdcServiceMetadata the asdc service metadata
254 * @return the service
256 public static Service extractService(ToscaModel serviceToscaModel, org.onap.vid.asdc.beans.Service asdcServiceMetadata) {
258 final Service service = new Service();
260 service.setCategory(serviceToscaModel.getMetadata().getCategory());
261 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
262 service.setName(serviceToscaModel.getMetadata().getName());
263 service.setUuid(serviceToscaModel.getMetadata().getUUID());
264 service.setDescription(serviceToscaModel.getMetadata().getDescription());
265 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
266 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
267 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
268 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
269 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
270 service.setVersion(asdcServiceMetadata.getVersion());
274 public static void extractGroups (ToscaModel serviceToscaModel,ServiceModel serviceModel) {
275 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
276 // additional data like the VF module customization String>
278 final Map<String, VfModule> vfModules = new HashMap<> ();
279 final Map<String, VolumeGroup> volumeGroups = new HashMap<> ();
281 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
282 String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
284 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
285 final Group group = component.getValue();
286 final String type = group.getType();
287 final String customizationName = component.getKey();
289 if (type.startsWith(vfModuleTag)) {
290 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
291 vfModules.put(customizationName, vfMod);
292 if ( vfMod.isVolumeGroupAllowed() ) {
293 //volume groups have the same customization name as the vf module
294 volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
298 // add this point vfModules and volume groups are disconnected from VNF
299 serviceModel.setVfModules (vfModules);
300 serviceModel.setVolumeGroups (volumeGroups);
304 * Populate the vf modules and volume groups that we may have under the service level under each VNF.
306 public void associateGroups() {
307 String methodName = "associateGroups()";
308 LOG.debug(EELFLoggerDelegate.debugLogger, methodName + " start");
309 // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts
311 String vnfCustomizationName = null;
312 String normalizedVnfCustomizationName = null;
313 String vfModuleCustomizationName = null;
315 if (!MapUtils.isEmpty(getVnfs())) {
316 for (Entry<String, VNF> vnfComponent : getVnfs().entrySet()) {
317 vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
318 normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
320 LOG.debug(EELFLoggerDelegate.debugLogger, methodName +
321 " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName);
323 // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName
325 if (!MapUtils.isEmpty(getVolumeGroups())) {
326 for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
327 vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
329 LOG.debug(EELFLoggerDelegate.debugLogger, methodName +
330 " VF Module customizationName=" + vfModuleCustomizationName );
331 if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) {
332 handleCustomizationName(methodName, vnfCustomizationName, vfModuleCustomizationName, vnfComponent, vfModuleComponent);
343 private void handleCustomizationName(String methodName, String vnfCustomizationName, String vfModuleCustomizationName, Entry<String, VNF> vnfComponent, Entry<String, VfModule> vfModuleComponent) {
344 VNF tmpVnf;// this vf module belongs to the VNF
345 tmpVnf = vnfComponent.getValue();
346 (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
348 LOG.debug(EELFLoggerDelegate.debugLogger, methodName +
349 " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName);
351 // 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
352 if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) {
353 if (isVolumeGroupsContainsVfModuleCustomName(vfModuleCustomizationName)) {
354 (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));
359 private boolean isVolumeGroupsContainsVfModuleCustomName(String vfModuleCustomizationName) {
360 return (!MapUtils.isEmpty(getVolumeGroups())) && (getVolumeGroups().containsKey((vfModuleCustomizationName)));