Rename packages from openecomp to onap.
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / services / heattotosca / impl / unifiedcomposition / UnifiedCompositionCatalogInstance.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.translator.services.heattotosca.impl.unifiedcomposition;
18
19 import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
20 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
21 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData;
22 import org.openecomp.sdc.translator.services.heattotosca.UnifiedComposition;
23 import org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionService;
24
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Optional;
28
29 public class UnifiedCompositionCatalogInstance implements UnifiedComposition {
30
31   // There is consolidation in ScalingInstance implementation.
32   // In case of scaling instance, if there is more than one entry in the
33   // unifiedCompositionDataList, we should have consolidation between them.
34   // (all entries in the list are the once which need to be consolidated)
35   @Override
36   public void createUnifiedComposition(ServiceTemplate serviceTemplate,
37                                        ServiceTemplate nestedServiceTemplate,
38                                        List<UnifiedCompositionData> unifiedCompositionDataList,
39                                        TranslationContext context) {
40
41     UnifiedCompositionService unifiedCompositionService = new UnifiedCompositionService();
42     unifiedCompositionService.handleComplexVfcType(serviceTemplate, context);
43
44     String substitutionNodeTypeId =
45         unifiedCompositionService.getSubstitutionNodeTypeId(serviceTemplate,
46             unifiedCompositionDataList.get(0), null, context);
47     // create one substitution ST for all computes
48     Optional<ServiceTemplate> substitutionServiceTemplate =
49         unifiedCompositionService.createUnifiedSubstitutionServiceTemplate(serviceTemplate,
50             unifiedCompositionDataList, context, substitutionNodeTypeId, null);
51
52     if (!substitutionServiceTemplate.isPresent()) {
53       return;
54     }
55
56
57     // create abstract NT for each compute
58     for (int i = 0; i < unifiedCompositionDataList.size(); i++) {
59       List<UnifiedCompositionData> catalogInstanceUnifiedList = new ArrayList<>();
60       catalogInstanceUnifiedList.add(unifiedCompositionDataList.get(i));
61
62       Integer index = unifiedCompositionDataList.size() > 1 ? i : null;
63
64       String abstractSubstituteNodeTemplateId = unifiedCompositionService
65           .createAbstractSubstituteNodeTemplate(serviceTemplate, substitutionServiceTemplate.get(),
66               catalogInstanceUnifiedList, substitutionNodeTypeId, context, index);
67
68       unifiedCompositionService.createVfcInstanceGroup(abstractSubstituteNodeTemplateId,
69           serviceTemplate, catalogInstanceUnifiedList, context);
70
71       unifiedCompositionService
72           .updateCompositionConnectivity(serviceTemplate, catalogInstanceUnifiedList, context);
73
74       unifiedCompositionService
75           .cleanUnifiedCompositionEntities(serviceTemplate, catalogInstanceUnifiedList, context);
76     }
77
78     unifiedCompositionService.cleanNodeTypes(serviceTemplate, unifiedCompositionDataList, context);
79     unifiedCompositionService.updateSubstitutionNodeTypePrefix(substitutionServiceTemplate.get());
80   }
81 }