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.onap.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.onap.vid.asdc.beans.tosca.Group;
30 import org.onap.vid.asdc.beans.tosca.ToscaModel;
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.onap.vid.properties.VidProperties;
34 * The Class ServiceModel.
37 public class NewServiceModel {
39 /** The Constant LOG. */
40 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(NewServiceModel.class);
42 /** The Constant dateFormat. */
43 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
45 private Service service;
48 private Map<String, VNF> vnfs;
51 private Map<String, Network> networks;
54 * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
55 * that is not present in the VNF, like the vf module customization String
57 private Map<String, VfModule> vfModules;
59 * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
62 private Map<String, VolumeGroup> volumeGroups;
64 private Map<String, PortMirroringConfig> configurations;
66 private Map<String, ServiceProxy> serviceProxies;
68 private Map<String, Node> pnfs;
71 * Instantiates a new service model.
73 public NewServiceModel() {}
80 public Service getService() {
89 public Map<String, VNF> getVnfs() {
96 * @return the networks
98 public Map<String, Network> getNetworks() {
105 * @param service the new service
107 public void setService(Service service) {
108 this.service = service;
114 * @param vnfs the vnfs
116 public void setVnfs(Map<String, VNF> vnfs) {
123 * @param networks the networks
125 public void setNetworks(Map<String, Network> networks) {
126 this.networks = networks;
129 * Gets the vf modules.
131 * @return the vf modules
133 public Map<String, VfModule> getVfModules() {
137 * Gets the volume groups.
139 * @return the volume groups
141 public Map<String, VolumeGroup> getVolumeGroups() {
145 public Map<String, PortMirroringConfig> getConfigurations() {
146 return configurations;
149 public Map<String, ServiceProxy> getServiceProxies() {
150 return serviceProxies;
154 * Sets the vf modules.
156 * @param vfModules the vf modules
160 public void setVfModules(Map<String, VfModule> vfModules) {
161 this.vfModules = vfModules;
164 * Sets the volume groups.
166 * @param volumeGroups the volume groups
168 public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
169 this.volumeGroups = volumeGroups;
173 public Map<String, Node> getPnfs() {
177 public void setPnfs(Map<String, Node> pnfs) {
184 * @param serviceToscaModel the service tosca model
185 * @param asdcServiceMetadata the asdc service metadata
186 * @return the service
188 public static Service extractService(ToscaModel serviceToscaModel, org.onap.vid.asdc.beans.Service asdcServiceMetadata) {
190 final Service service = new Service();
192 service.setCategory(serviceToscaModel.getMetadata().getCategory());
193 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
194 service.setName(serviceToscaModel.getMetadata().getName());
195 service.setUuid(serviceToscaModel.getMetadata().getUUID());
196 service.setDescription(serviceToscaModel.getMetadata().getDescription());
197 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
198 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
199 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
200 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
201 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
202 service.setVersion(asdcServiceMetadata.getVersion());
206 public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) {
207 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
208 // additional data like the VF module customization String>
210 final Map<String, VfModule> vfModules = new HashMap<String, VfModule> ();
211 final Map<String, VolumeGroup> volumeGroups = new HashMap<String, VolumeGroup> ();
213 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
214 String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
216 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
217 final Group group = component.getValue();
218 final String type = group.getType();
219 final String customizationName = component.getKey();
221 if (type.startsWith(vfModuleTag)) {
222 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
223 vfModules.put(customizationName, vfMod);
224 if ( vfMod.isVolumeGroupAllowed() ) {
225 //volume groups have the same customization name as the vf module
226 volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
230 // add this point vfModules and volume groups are disconnected from VNF
231 serviceModel.setVfModules (vfModules);
232 serviceModel.setVolumeGroups (volumeGroups);
236 * Populate the vf modules and volume groups that we may have under the service level under each VNF.
238 // public void associateGroups() {
239 // String methodName = "associateGroups()";
240 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " start");
241 // // go through the vnfs, get the vnf normalized name and look for a vf module with a customization name that starts
242 // // with vnf + ".."
243 // String vnfCustomizationName = null;
244 // String normalizedVnfCustomizationName = null;
245 // String vfModuleCustomizationName = null;
246 // NewVNF tmpVnf = null;
248 // if ( ( getVnfs() != null ) && (!(getVnfs().isEmpty())) ) {
249 // for (Entry<String, NewVNF> vnfComponent : getVnfs().entrySet()) {
250 // vnfCustomizationName = vnfComponent.getValue().getModelCustomizationName();
251 // normalizedVnfCustomizationName = VNF.normalizeName(vnfCustomizationName);
253 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
254 // " VNF customizationName=" + vnfCustomizationName + "normalized customization name=" + normalizedVnfCustomizationName);
256 // // now check to see if there is a vf module with customization name that starts with normalizedVnfCustomizationName
258 // if (( getVfModules() != null ) && (!(getVfModules().isEmpty()))) {
259 // for (Entry<String, VfModule> vfModuleComponent : getVfModules().entrySet()) {
260 // vfModuleCustomizationName = vfModuleComponent.getValue().getModelCustomizationName();
262 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
263 // " VF Module customizationName=" + vfModuleCustomizationName );
264 // if ( vfModuleCustomizationName.startsWith(normalizedVnfCustomizationName + ".." )) {
266 // // this vf module belongs to the VNF
267 // tmpVnf = vnfComponent.getValue();
268 // (tmpVnf.getVfModules()).put(vfModuleComponent.getKey(), vfModuleComponent.getValue());
270 // LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName +
271 // " Associated VF Module customizationName=" + vfModuleComponent.getKey() + " with VNF customization name=" + vnfCustomizationName);
273 // // 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
274 // if ( vfModuleComponent.getValue().isVolumeGroupAllowed() ) {
275 // if (( getVolumeGroups() != null ) && (!(getVolumeGroups().isEmpty()))) {
276 // if (getVolumeGroups().containsKey((vfModuleCustomizationName))) {
277 // (vnfComponent.getValue().getVolumeGroups()).put(vfModuleCustomizationName, (getVolumeGroups()).get(vfModuleCustomizationName));