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 org.onap.vid.asdc.beans.tosca.Group;
24 import org.onap.vid.asdc.beans.tosca.ToscaModel;
25 import org.onap.vid.properties.VidProperties;
27 import java.util.HashMap;
29 import java.util.Map.Entry;
31 * The Class ServiceModel.
34 public class NewServiceModel {
36 private Service service;
39 private Map<String, VNF> vnfs;
42 private Map<String, Network> networks;
45 * The vf modules. The VNF also has vfmodules but the vfmodules at the service level may have additional info
46 * that is not present in the VNF, like the vf module customization String
48 private Map<String, VfModule> vfModules;
50 * The volume groups. The VNF also has volume groups but the volume groups will be populated at the service level
53 private Map<String, VolumeGroup> volumeGroups;
55 private Map<String, PortMirroringConfig> configurations;
57 private Map<String, Node> fabricConfigurations;
59 private Map<String, ServiceProxy> serviceProxies;
61 private Map<String, Node> pnfs;
63 private Map<String, CR> collectionResource;
65 private Map<String, ResourceGroup> vnfGroups;
68 * Instantiates a new service model.
70 public NewServiceModel() {}
77 public Service getService() {
86 public Map<String, VNF> getVnfs() {
93 * @return the networks
95 public Map<String, Network> getNetworks() {
102 * @param service the new service
104 public void setService(Service service) {
105 this.service = service;
111 * @param vnfs the vnfs
113 public void setVnfs(Map<String, VNF> vnfs) {
120 * @param networks the networks
122 public void setNetworks(Map<String, Network> networks) {
123 this.networks = networks;
126 * Gets the vf modules.
128 * @return the vf modules
130 public Map<String, VfModule> getVfModules() {
134 * Gets the volume groups.
136 * @return the volume groups
138 public Map<String, VolumeGroup> getVolumeGroups() {
142 public Map<String, PortMirroringConfig> getConfigurations() {
143 return configurations;
146 public Map<String, ServiceProxy> getServiceProxies() {
147 return serviceProxies;
151 * Sets the vf modules.
153 * @param vfModules the vf modules
157 public void setVfModules(Map<String, VfModule> vfModules) {
158 this.vfModules = vfModules;
161 * Sets the volume groups.
163 * @param volumeGroups the volume groups
165 public void setVolumeGroups(Map<String, VolumeGroup> volumeGroups) {
166 this.volumeGroups = volumeGroups;
170 public Map<String, Node> getPnfs() {
174 public void setPnfs(Map<String, Node> pnfs) {
178 public Map<String, CR> getCollectionResource() {
179 return collectionResource;
182 public void setCollectionResource(Map<String, CR> collectionResource) {
183 this.collectionResource = collectionResource;
186 public Map<String, Node> getFabricConfigurations() {
187 return fabricConfigurations;
190 public void setFabricConfigurations(Map<String, Node> fabricConfigurations) {
191 this.fabricConfigurations = fabricConfigurations;
197 * @param serviceToscaModel the service tosca model
198 * @param asdcServiceMetadata the asdc service metadata
199 * @return the service
201 public static Service extractService(ToscaModel serviceToscaModel, org.onap.vid.asdc.beans.Service asdcServiceMetadata) {
203 final Service service = new Service();
205 service.setCategory(serviceToscaModel.getMetadata().getCategory());
206 service.setInvariantUuid(serviceToscaModel.getMetadata().getInvariantUUID());
207 service.setName(serviceToscaModel.getMetadata().getName());
208 service.setUuid(serviceToscaModel.getMetadata().getUUID());
209 service.setDescription(serviceToscaModel.getMetadata().getDescription());
210 service.setServiceEcompNaming(serviceToscaModel.getMetadata().getServiceEcompNaming());
211 service.setInputs(serviceToscaModel.gettopology_template().getInputs());
212 //FIXME: SDC is not sending the Version with the Tosca Model for 1610 - they should send it in 1702
213 //THIS IS A TEMPORARY FIX, AT SOME POINT UNCOMMENT ME
214 //service.setVersion(serviceToscaModel.getMetadata().getVersion());
215 service.setVersion(asdcServiceMetadata.getVersion());
218 public static void extractGroups (ToscaModel serviceToscaModel,NewServiceModel serviceModel) {
219 // Get the groups. The groups may duplicate the groups that are in the VNF model and have
220 // additional data like the VF module customization String>
222 final Map<String, VfModule> vfModules = new HashMap<> ();
223 final Map<String, VolumeGroup> volumeGroups = new HashMap<> ();
225 String asdcModelNamespace = VidProperties.getAsdcModelNamespace();
226 String vfModuleTag = asdcModelNamespace + ModelConstants.VF_MODULE;
228 for (Entry<String, Group> component : serviceToscaModel.gettopology_template().getGroups().entrySet()) {
229 final Group group = component.getValue();
230 final String type = group.getType();
231 final String customizationName = component.getKey();
233 if (type.startsWith(vfModuleTag)) {
234 VfModule vfMod = VfModule.extractVfModule(customizationName, group);
235 vfModules.put(customizationName, vfMod);
236 if ( vfMod.isVolumeGroupAllowed() ) {
237 //volume groups have the same customization name as the vf module
238 volumeGroups.put(customizationName, VolumeGroup.extractVolumeGroup(customizationName,group));
242 // add this point vfModules and volume groups are disconnected from VNF
243 serviceModel.setVfModules (vfModules);
244 serviceModel.setVolumeGroups (volumeGroups);
248 public Map<String, ResourceGroup> getVnfGroups() {
252 public void setVnfGroups(Map<String, ResourceGroup> vnfGroups) {
253 this.vnfGroups = vnfGroups;
256 * Populate the vf modules and volume groups that we may have under the service level under each VNF.