From 1cfb08779ea0e00be69e072a940b3063e049fe6b Mon Sep 17 00:00:00 2001 From: Ofir Sonsino Date: Wed, 31 Jan 2018 17:19:00 +0200 Subject: org.onap migration Change-Id: I52f0b2851f2c765752b6d21f49b32136d7d72a3d Issue-ID: VID-86 Signed-off-by: Ofir Sonsino --- .../main/java/org/onap/vid/model/ServiceModel.java | 330 +++++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java (limited to 'vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java') diff --git a/vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java b/vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java new file mode 100644 index 000000000..dab18d518 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/model/ServiceModel.java @@ -0,0 +1,330 @@ +/*- + * ============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.Date; +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.NodeTemplate; +import org.onap.vid.asdc.beans.tosca.ToscaModel; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.properties.VidProperties; +/** + * The Class ServiceModel. + */ +@SuppressWarnings("ALL") +public class ServiceModel { + + /** The Constant LOG. */ + private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ServiceModel.class); + + /** The Constant dateFormat. */ + final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS"); + /** The service. */ + private Service service; + + /** The vnfs. */ + private Map vnfs; + + /** The networks. */ + private Map networks; + + /** Port Mirroring Configuration node templates */ + private Map configurations; + + /** Service Proxy Nodes */ + private Map serviceProxies; + + /** + * 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 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 volumeGroups; + + /** The pnfs. */ + private Map pnfs; + /** + * Instantiates a new service model. + */ + public ServiceModel() {} + + /** + * Gets the service. + * + * @return the service + */ + public Service getService() { + return service; + } + + /** + * Gets the vnfs. + * + * @return the vnfs + */ + public Map getVnfs() { + return vnfs; + } + + /** + * Gets the networks. + * + * @return the networks + */ + public Map getNetworks() { + return networks; + } + + + /** + * Gets the pnfs. + * + * @return the pnfs + */ + public Map getPnfs() { + return pnfs; + } + + + /** + * Gets the Configuration Node Templates + * + * @return the configuration type node templates + */ + public Map getConfigurations() { + return configurations; + } + + /** + * Gets the Service Proxy Node Templates + * + * @return the Service Proxy type node templates + */ + public Map getServiceProxies() { + return serviceProxies; + } + + /** + * 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 vnfs) { + this.vnfs = vnfs; + } + + /** + * Sets the networks. + * + * @param networks the networks + */ + public void setNetworks(Map networks) { + this.networks = networks; + } + + /** + * Sets the configuraion node templates. + * + * @param configurations + */ + public void setConfigurations(Map configurations) { + this.configurations = configurations; + } + + /** + * Sets the service proxy node templates. + * + * @param serviceProxies + */ + public void setServiceProxies(Map serviceProxies) { + this.serviceProxies = serviceProxies; + } + + /** + * Gets the vf modules. + * + * @return the vf modules + */ + public Map getVfModules() { + return vfModules; + } + + + /** + * Gets the volume groups. + * + * @return the volume groups + */ + public Map getVolumeGroups() { + return volumeGroups; + } + /** + * Sets the vf modules. + * + * @param vfModules the vf modules + */ + public void setVfModules(Map vfModules) { + this.vfModules = vfModules; + } + /** + * Sets the volume groups. + * + * @param volumeGroups the volume groups + */ + public void setVolumeGroups(Map volumeGroups) { + this.volumeGroups = volumeGroups; + } + /** + * Sets the pnfs. + * + * @param pnfs the pnfs + */ + public void setPnfs(Map pnfs) {this.pnfs = pnfs;} + + /** + * 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,ServiceModel 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 vfModules = new HashMap (); + final Map volumeGroups = new HashMap (); + + String asdcModelNamespace = VidProperties.getAsdcModelNamespace(); + String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE; + + for (Entry 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; + VNF tmpVnf = null; + + if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) { + for (Entry 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 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)); + } + } + } + } + } + } + } + } + + } + + +} -- cgit 1.2.3-korg