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.openecomp.vid.model;
23 import java.text.DateFormat;
24 import java.text.SimpleDateFormat;
25 import java.util.HashMap;
27 import java.util.Map.Entry;
29 import org.openecomp.vid.asdc.beans.tosca.Group;
30 import org.openecomp.vid.asdc.beans.tosca.ToscaModel;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.openecomp.vid.properties.VidProperties;
34 * The Class ServiceModel.
36 public class NewServiceModel {
38 /** The Constant LOG. */
39 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(NewServiceModel.class);
41 /** The Constant dateFormat. */
42 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
44 private Service service;
47 private Map<String, VNF> vnfs;
50 private Map<String, Network> networks;
53 * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
54 * that is not present in the VNF, like the vf module customization String
56 private Map<String, VfModule> vfModules;
58 * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
61 private Map<String, VolumeGroup> volumeGroups;
63 * Instantiates a new service model.
65 public NewServiceModel() {}
72 public Service getService() {
81 public Map<String, VNF> getVnfs() {
88 * @return the networks
90 public Map<String, Network> getNetworks() {
97 * @param service the new service
99 public void setService(Service service) {
100 this.service = service;
106 * @param vnfs the vnfs
108 public void setVnfs(Map<String, VNF> vnfs) {
115 * @param networks the networks
117 public void setNetworks(Map<String, Network> networks) {
118 this.networks = networks;
121 * Gets the vf modules.
123 * @return the vf modules
125 public Map<String, VfModule> getVfModules() {
129 * Gets the volume groups.
131 * @return the volume groups
133 public Map<String, VolumeGroup> getVolumeGroups() {
137 * Sets the vf modules.
139 * @param vfModules the vf modules
141 public void setVfModules(Map<String, VfModule> vfModules) {
142 this.vfModules = vfModules;
145 * Sets the volume groups.
147 * @param volumeGroups the volume groups
149 public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
150 this.volumeGroups = volumeGroups;
155 * @param serviceToscaModel the service tosca model
156 * @param asdcServiceMetadata the asdc service metadata
157 * @return the service
159 public static Service extractService(ToscaModel serviceToscaModel, org.openecomp.vid.asdc.beans.Service asdcServiceMetadata) {
161 final Service service = new Service();
163 service.setCategory(serviceToscaModel.getMetadata().getCategory());
164 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
165 service.setName(serviceToscaModel.getMetadata().getName());
166 service.setUuid(serviceToscaModel.getMetadata().getUUID());
167 service.setDescription(serviceToscaModel.getMetadata().getDescription());
168 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
169 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
170 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
171 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
172 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
173 service.setVersion(asdcServiceMetadata.getVersion());
177 public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) {
178 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
179 // additional data like the VF module customization String>
181 final Map<String, VfModule> vfModules = new HashMap<String, VfModule> ();
182 final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
184 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
185 String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
187 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
188 final Group group = component.getValue();
189 final String type = group.getType();
190 final String customizationName = component.getKey();
192 if (type.startsWith(vfModuleTag)) {
193 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
194 vfModules.put(customizationName, vfMod);
195 if ( vfMod.isVolumeGroupAllowed() ) {
196 //volume groups have the same customization name as the vf module
197 volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
201 // add this point vfModules and volume groups are disconnected from VNF
202 serviceModel.setVfModules (vfModules);
203 serviceModel.setVolumeGroups (volumeGroups);
207 * Populate the vf modules and volume groups that we may have under the service level under each VNF.
209 // public void associateGroups() {
210 // String methodName = "associateGroups()";
211 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
212 // // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts
213 // // with vnf + ".."
214 // String vnfCustomizationName = null;
215 // String normalizedVnfCustomizationName = null;
216 // String vfModuleCustomizationName = null;
217 // NewVNF tmpVnf = null;
219 // if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) {
220 // for (Entry<String, NewVNF> vnfComponent : getVnfs().entrySet()) {
221 // vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
222 // normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
224 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
225 // " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName);
227 // // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName
229 // if (( getVfModules() != null ) && (!(getVfModules().isEmpty()))) {
230 // for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
231 // vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
233 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
234 // " VF Module customizationName=" + vfModuleCustomizationName );
235 // if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) {
237 // // this vf module belongs to the VNF
238 // tmpVnf = vnfComponent.getValue();
239 // (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
241 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
242 // " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName);
244 // // 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
245 // if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) {
246 // if (( getVolumeGroups() != null ) && (!(getVolumeGroups().isEmpty()))) {
247 // if (getVolumeGroups().containsKey((vfModuleCustomizationName))) {
248 // (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));