9f0525db3de089d785648f83f016b00f476d644e
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / installer / VfModuleStructure.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.asdc.installer;
22
23
24 import java.util.HashMap;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.onap.sdc.api.notification.IVfModuleMetadata;
30 import org.onap.so.asdc.client.ASDCConfiguration;
31 import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
32 import org.onap.so.db.catalog.beans.VfModule;
33
34 public final class VfModuleStructure {
35
36         private final IVfModuleData vfModuleMetadata;
37
38         private final VfResourceStructure parentVfResource;
39
40         private VfModule catalogVfModule;
41         /**
42          * The list of artifact existing in this resource hashed by artifactType.
43          */
44         private final Map<String, List<VfModuleArtifact>> artifactsMap;
45
46         public VfModuleStructure(VfResourceStructure vfParentResource,IVfModuleData vfmoduleMetadata) throws ArtifactInstallerException {
47
48                 vfModuleMetadata = vfmoduleMetadata;
49                 parentVfResource = vfParentResource;
50
51                 artifactsMap = new HashMap<>();
52
53                 for (String artifactUUID:this.vfModuleMetadata.getArtifacts()) {
54                         if (vfParentResource.getArtifactsMapByUUID().containsKey(artifactUUID)) {
55                                 this.addToStructure(vfParentResource.getArtifactsMapByUUID().get(artifactUUID));
56                         } else {
57                                 throw new ArtifactInstallerException("Artifact (UUID:"+artifactUUID+ ") referenced in the VFModule UUID list has not been downloaded, cancelling the Resource deployment");
58                         }
59                 }
60         }
61
62         private void addToStructure(VfModuleArtifact vfModuleArtifact) {
63
64                 if (artifactsMap.containsKey(vfModuleArtifact.getArtifactInfo().getArtifactType())) {
65                         artifactsMap.get(vfModuleArtifact.getArtifactInfo().getArtifactType()).add(vfModuleArtifact);
66
67                 } else {
68                         List<VfModuleArtifact> nestedList = new LinkedList<>();
69                         nestedList.add(vfModuleArtifact);
70
71                         artifactsMap.put(vfModuleArtifact.getArtifactInfo().getArtifactType(), nestedList);
72                 }
73         }
74
75         public List<VfModuleArtifact> getOrderedArtifactList() {
76
77                 List <VfModuleArtifact> artifactsList = new LinkedList<>();
78
79                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT));
80                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_ENV));
81                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
82
83                 artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_NESTED)));
84
85                 artifactsList.addAll((artifactsMap.get(ASDCConfiguration.HEAT_ARTIFACT)));
86
87                 artifactsList.addAll(artifactsMap.get(ASDCConfiguration.HEAT_VOL));
88
89                 return null;
90         }
91
92         public IVfModuleData getVfModuleMetadata() {
93                 return vfModuleMetadata;
94         }
95
96         public VfResourceStructure getParentVfResource() {
97                 return parentVfResource;
98         }
99
100         public Map<String, List<VfModuleArtifact>> getArtifactsMap() {
101                 return artifactsMap;
102         }
103
104
105         public VfModule getCatalogVfModule() {
106                 return catalogVfModule;
107         }
108
109         public void setCatalogVfModule(VfModule catalogVfModule) {
110                 this.catalogVfModule = catalogVfModule;
111         }
112
113
114 }