2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package org.openecomp.vid.model;
\r
23 import java.text.DateFormat;
\r
24 import java.text.SimpleDateFormat;
\r
25 import java.util.Date;
\r
26 import java.util.HashMap;
\r
27 import java.util.Map;
\r
28 import java.util.Map.Entry;
\r
30 import org.openecomp.vid.asdc.beans.tosca.Group;
\r
31 import org.openecomp.vid.asdc.beans.tosca.ToscaModel;
\r
32 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
\r
33 import org.openecomp.vid.properties.VidProperties;
\r
35 * The Class ServiceModel.
\r
37 @SuppressWarnings("ALL")
\r
38 public class ServiceModel {
\r
40 /** The Constant LOG. */
\r
41 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ServiceModel.class);
\r
43 /** The Constant dateFormat. */
\r
44 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
\r
46 private Service service;
\r
49 private Map<String, VNF> vnfs;
\r
51 /** The networks. */
\r
52 private Map<String, Network> networks;
\r
55 * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
\r
56 * that is not present in the VNF, like the vf module customization String
\r
58 private Map<String, VfModule> vfModules;
\r
60 * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
\r
63 private Map<String, VolumeGroup> volumeGroups;
\r
65 * Instantiates a new service model.
\r
67 public ServiceModel() {}
\r
72 * @return the service
\r
74 public Service getService() {
\r
83 public Map<String, VNF> getVnfs() {
\r
88 * Gets the networks.
\r
90 * @return the networks
\r
92 public Map<String, Network> getNetworks() {
\r
99 * @param service the new service
\r
101 public void setService(Service service) {
\r
102 this.service = service;
\r
108 * @param vnfs the vnfs
\r
110 public void setVnfs(Map<String, VNF> vnfs) {
\r
115 * Sets the networks.
\r
117 * @param networks the networks
\r
119 public void setNetworks(Map<String, Network> networks) {
\r
120 this.networks = networks;
\r
123 * Gets the vf modules.
\r
125 * @return the vf modules
\r
127 public Map<String, VfModule> getVfModules() {
\r
131 * Gets the volume groups.
\r
133 * @return the volume groups
\r
135 public Map<String, VolumeGroup> getVolumeGroups() {
\r
136 return volumeGroups;
\r
139 * Sets the vf modules.
\r
141 * @param vfModules the vf modules
\r
143 public void setVfModules(Map<String, VfModule> vfModules) {
\r
144 this.vfModules = vfModules;
\r
147 * Sets the volume groups.
\r
149 * @param volumeGroups the volume groups
\r
151 public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
\r
152 this.volumeGroups = volumeGroups;
\r
157 * @param serviceToscaModel the service tosca model
\r
158 * @param asdcServiceMetadata the asdc service metadata
\r
159 * @return the service
\r
161 public static Service extractService(ToscaModel serviceToscaModel, org.openecomp.vid.asdc.beans.Service asdcServiceMetadata) {
\r
163 final Service service = new Service();
\r
165 service.setCategory(serviceToscaModel.getMetadata().getCategory());
\r
166 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
\r
167 service.setName(serviceToscaModel.getMetadata().getName());
\r
168 service.setUuid(serviceToscaModel.getMetadata().getUUID());
\r
169 service.setDescription(serviceToscaModel.getMetadata().getDescription());
\r
170 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
\r
171 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
\r
172 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
\r
173 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
\r
174 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
\r
175 service.setVersion(asdcServiceMetadata.getVersion());
\r
179 public static void extractGroups (ToscaModel serviceToscaModel,ServiceModel serviceModel) {
\r
180 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
\r
181 // additional data like the VF module customization String>
\r
183 final Map<String, VfModule> vfModules = new HashMap<String, VfModule> ();
\r
184 final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
\r
186 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
\r
187 String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
\r
189 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
\r
190 final Group group = component.getValue();
\r
191 final String type = group.getType();
\r
192 final String customizationName = component.getKey();
\r
194 if (type.startsWith(vfModuleTag)) {
\r
195 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
\r
196 vfModules.put(customizationName, vfMod);
\r
197 if ( vfMod.isVolumeGroupAllowed() ) {
\r
198 //volume groups have the same customization name as the vf module
\r
199 volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
\r
203 // add this point vfModules and volume groups are disconnected from VNF
\r
204 serviceModel.setVfModules (vfModules);
\r
205 serviceModel.setVolumeGroups (volumeGroups);
\r
209 * Populate the vf modules and volume groups that we may have under the service level under each VNF.
\r
211 public void associateGroups() {
\r
212 String methodName = "associateGroups()";
\r
213 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
\r
214 // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts
\r
216 String vnfCustomizationName = null;
\r
217 String normalizedVnfCustomizationName = null;
\r
218 String vfModuleCustomizationName = null;
\r
221 if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) {
\r
222 for (Entry<String, VNF> vnfComponent : getVnfs().entrySet()) {
\r
223 vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
\r
224 normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
\r
226 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
\r
227 " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName);
\r
229 // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName
\r
231 if (( getVfModules() != null ) && (!(getVfModules().isEmpty()))) {
\r
232 for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
\r
233 vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
\r
235 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
\r
236 " VF Module customizationName=" + vfModuleCustomizationName );
\r
237 if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) {
\r
239 // this vf module belongs to the VNF
\r
240 tmpVnf = vnfComponent.getValue();
\r
241 (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
\r
243 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
\r
244 " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName);
\r
246 // 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
\r
247 if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) {
\r
248 if (( getVolumeGroups() != null ) && (!(getVolumeGroups().isEmpty()))) {
\r
249 if (getVolumeGroups().containsKey((vfModuleCustomizationName))) {
\r
250 (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));
\r