Implant vid-app-common org.onap.vid.job (main and test)
[vid.git] / vid-app-common / src / main / java / org / onap / vid / model / ServiceModel.java
index dab18d5..121c7e4 100644 (file)
@@ -7,9 +7,9 @@
  * 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.
 
 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.apache.commons.collections.MapUtils;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
 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;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 /**
  * The Class ServiceModel.
  */
@@ -40,42 +37,52 @@ 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<String, VNF> vnfs;
-       
+
        /** The networks. */
        private Map<String, Network> networks;
 
+       private Map<String, CR> collectionResources;
+
        /** Port Mirroring Configuration node templates */
        private Map<String, PortMirroringConfig> configurations;
 
+       /** Fabric Configuration node templates */
+       private Map<String, Node> fabricConfigurations;
+
        /** Service Proxy Nodes */
        private Map<String, ServiceProxy> 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 
+        * 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 
+       /**
+        * 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;
 
        /** The pnfs. */
        private Map<String, Node> pnfs;
+
+       /** Resource groups of VF (VNF) type. */
+       private Map<String, ResourceGroup> vnfGroups;
+
+       /** The vrfs */
+       private Map<String, Node> vrfs;
+
        /**
         * Instantiates a new service model.
         */
        public ServiceModel() {}
-       
+
        /**
         * Gets the service.
         *
@@ -132,6 +139,14 @@ public class ServiceModel {
                return serviceProxies;
        }
 
+       public Map<String, ResourceGroup> getVnfGroups() {
+               return vnfGroups;
+       }
+
+       public Map<String, Node> getVrfs() {
+               return vrfs;
+       }
+
        /**
         * Sets the service.
         *
@@ -218,6 +233,30 @@ public class ServiceModel {
         */
        public void setPnfs(Map<String,Node> pnfs) {this.pnfs = pnfs;}
 
+       public void setVnfGroups(Map<String, ResourceGroup> vnfGroups) {
+               this.vnfGroups = vnfGroups;
+       }
+
+       public void setVrfs(Map<String, Node> vrfs) {
+               this.vrfs = vrfs;
+       }
+
+       public Map<String, CR> getCollectionResources() {
+               return collectionResources;
+       }
+
+       public void setCollectionResources(Map<String, CR> collectionResources) {
+               this.collectionResources = collectionResources;
+       }
+
+       public Map<String, Node> getFabricConfigurations() {
+               return fabricConfigurations;
+       }
+
+       public void setFabricConfigurations(Map<String, Node> fabricConfigurations) {
+               this.fabricConfigurations = fabricConfigurations;
+       }
+
        /**
         * Extract service.
         *
@@ -226,9 +265,9 @@ public class ServiceModel {
         * @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());
@@ -246,18 +285,18 @@ public class ServiceModel {
        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<String, VfModule> vfModules = new HashMap<String, VfModule> ();
-               final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
-               
+
+               final Map<String, VfModule> vfModules = new HashMap<> ();
+               final Map<String, VolumeGroup> volumeGroups = new HashMap<> ();
+
                String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
-       String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
-       
+               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);
@@ -270,60 +309,66 @@ public class ServiceModel {
                // 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");
+               LOG.debug(EELFLoggerDelegate.debugLogger, 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())) ) {
+
+               if (!MapUtils.isEmpty(getVnfs())) {
                        for (Entry<String, VNF> vnfComponent : getVnfs().entrySet()) {
                                vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
                                normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
-                               
-                               LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + 
+
+                               LOG.debug(EELFLoggerDelegate.debugLogger, 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()))) {
+
+                               if (!MapUtils.isEmpty(getVolumeGroups())) {
                                        for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
                                                vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
-                                               
-                                               LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + 
+
+                                               LOG.debug(EELFLoggerDelegate.debugLogger, 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));
-                                                                       }
-                                                               }       
-                                                       }
+                                                       handleCustomizationName(methodName, vnfCustomizationName, vfModuleCustomizationName, vnfComponent, vfModuleComponent);
                                                }
                                        }
                                }
                        }
                }
-               
+
+       }
+
+
+
+       private void handleCustomizationName(String methodName, String vnfCustomizationName, String vfModuleCustomizationName, Entry<String, VNF> vnfComponent, Entry<String, VfModule> vfModuleComponent) {
+               VNF tmpVnf;// this vf module belongs to the VNF
+               tmpVnf = vnfComponent.getValue();
+               (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
+
+               LOG.debug(EELFLoggerDelegate.debugLogger, 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 (isVolumeGroupsContainsVfModuleCustomName(vfModuleCustomizationName)) {
+                       (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));
+               }
+       }
+       }
+
+       private boolean isVolumeGroupsContainsVfModuleCustomName(String vfModuleCustomizationName) {
+               return (!MapUtils.isEmpty(getVolumeGroups())) && (getVolumeGroups().containsKey((vfModuleCustomizationName)));
        }