2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.translator.services.heattotosca.impl.unifiedcomposition;
19 import org.apache.commons.collections4.CollectionUtils;
20 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
21 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
22 import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition.UnifiedCompositionData;
23 import org.openecomp.sdc.translator.services.heattotosca.UnifiedComposition;
24 import org.openecomp.sdc.translator.services.heattotosca.UnifiedCompositionService;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Optional;
32 * The type Unified composition single substitution.
34 public class UnifiedCompositionSingleSubstitution implements UnifiedComposition {
36 private UnifiedCompositionService unifiedCompositionService = new UnifiedCompositionService();
38 // There is no consolidation in SingleSubstitution implementation.
39 // In case of single substitution, if there is more than one entry in the
40 // unifiedCompositionDataList, they all should contain the same compute type but the
41 // consolidation between them was canceled.
42 // For different compute type, this implementation will be called more than once, each time
43 // per diff compute type, while sending one entry in the unifiedCompositionDataList.
45 public void createUnifiedComposition(ServiceTemplate serviceTemplate,
46 ServiceTemplate nestedServiceTemplate,
47 List<UnifiedCompositionData> unifiedCompositionDataList,
48 TranslationContext context) {
49 if (CollectionUtils.isEmpty(unifiedCompositionDataList)
50 || context.isUnifiedHandledServiceTemplate(serviceTemplate)) {
54 unifiedCompositionService.handleComplexVfcType(serviceTemplate, context);
56 for (int i = 0; i < unifiedCompositionDataList.size(); i++) {
57 List<UnifiedCompositionData> singleSubstitutionUnifiedList = new ArrayList<>();
58 singleSubstitutionUnifiedList.add(unifiedCompositionDataList.get(i));
60 String substitutionNodeTypeId =
61 unifiedCompositionService.getSubstitutionNodeTypeId(serviceTemplate,
62 singleSubstitutionUnifiedList.get(0), null, context);
64 Optional<ServiceTemplate> substitutionServiceTemplate =
65 unifiedCompositionService.createUnifiedSubstitutionServiceTemplate(serviceTemplate,
66 singleSubstitutionUnifiedList, context, substitutionNodeTypeId, null);
68 if (!substitutionServiceTemplate.isPresent()) {
72 String abstractSubstituteNodeTemplateId = unifiedCompositionService
73 .createAbstractSubstituteNodeTemplate(serviceTemplate, substitutionServiceTemplate.get(),
74 singleSubstitutionUnifiedList, substitutionNodeTypeId, context, null);
76 unifiedCompositionService.createVfcInstanceGroup(abstractSubstituteNodeTemplateId,
77 serviceTemplate, singleSubstitutionUnifiedList, context);
79 unifiedCompositionService
80 .updateCompositionConnectivity(serviceTemplate, singleSubstitutionUnifiedList, context);
82 unifiedCompositionService
83 .cleanUnifiedCompositionEntities(serviceTemplate, singleSubstitutionUnifiedList, context);
85 unifiedCompositionService.updateSubstitutionNodeTypePrefix(substitutionServiceTemplate.get());
88 unifiedCompositionService
89 .cleanNodeTypes(serviceTemplate, unifiedCompositionDataList, context);