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.so.asdc.installer;
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.List;
28 import org.onap.sdc.api.notification.IVfModuleMetadata;
29 import org.onap.so.asdc.client.ASDCConfiguration;
30 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
31 import org.onap.so.db.catalog.beans.VfModule;
33 public final class VfModuleStructure {
35 private final IVfModuleData vfModuleMetadata;
37 private final VfResourceStructure parentVfResource;
39 private VfModule catalogVfModule;
41 * The list of artifact existing in this resource hashed by artifactType.
43 private final Map<String, List<VfModuleArtifact>> artifactsMap;
45 public VfModuleStructure(VfResourceStructure vfParentResource, IVfModuleData vfmoduleMetadata)
46 throws ArtifactInstallerException {
48 vfModuleMetadata = vfmoduleMetadata;
49 parentVfResource = vfParentResource;
51 artifactsMap = new HashMap<>();
53 for (String artifactUUID : this.vfModuleMetadata.getArtifacts()) {
54 if (vfParentResource.getArtifactsMapByUUID().containsKey(artifactUUID)) {
55 this.addToStructure(vfParentResource.getArtifactsMapByUUID().get(artifactUUID));
57 throw new ArtifactInstallerException("Artifact (UUID:" + artifactUUID
58 + ") referenced in the VFModule UUID list has not been downloaded, cancelling the Resource deployment");
63 private void addToStructure(VfModuleArtifact vfModuleArtifact) {
65 if (artifactsMap.containsKey(vfModuleArtifact.getArtifactInfo().getArtifactType())) {
66 artifactsMap.get(vfModuleArtifact.getArtifactInfo().getArtifactType()).add(vfModuleArtifact);
69 List<VfModuleArtifact> nestedList = new LinkedList<>();
70 nestedList.add(vfModuleArtifact);
72 artifactsMap.put(vfModuleArtifact.getArtifactInfo().getArtifactType(), nestedList);
76 public List<VfModuleArtifact> getOrderedArtifactList() {
78 List<VfModuleArtifact> artifactsList = new LinkedList<>();
80 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT));
81 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_ENV));
82 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
84 artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_NESTED)));
86 artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_ARTIFACT)));
88 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
93 public IVfModuleData getVfModuleMetadata() {
94 return vfModuleMetadata;
97 public VfResourceStructure getParentVfResource() {
98 return parentVfResource;
101 public Map<String, List<VfModuleArtifact>> getArtifactsMap() {
106 public VfModule getCatalogVfModule() {
107 return catalogVfModule;
110 public void setCatalogVfModule(VfModule catalogVfModule) {
111 this.catalogVfModule = catalogVfModule;