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.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;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Optional;
29 public class UnifiedCompositionCatalogInstance implements UnifiedComposition {
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)
36 public void createUnifiedComposition(ServiceTemplate serviceTemplate,
37 ServiceTemplate nestedServiceTemplate,
38 List<UnifiedCompositionData> unifiedCompositionDataList,
39 TranslationContext context) {
41 UnifiedCompositionService unifiedCompositionService = new UnifiedCompositionService();
42 unifiedCompositionService.handleComplexVfcType(serviceTemplate, context);
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);
52 if (!substitutionServiceTemplate.isPresent()) {
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));
62 Integer index = unifiedCompositionDataList.size() > 1 ? i : null;
64 String abstractSubstituteNodeTemplateId = unifiedCompositionService
65 .createAbstractSubstituteNodeTemplate(serviceTemplate, substitutionServiceTemplate.get(),
66 catalogInstanceUnifiedList, substitutionNodeTypeId, context, index);
68 unifiedCompositionService.createVfcInstanceGroup(abstractSubstituteNodeTemplateId,
69 serviceTemplate, catalogInstanceUnifiedList, context);
71 unifiedCompositionService
72 .updateCompositionConnectivity(serviceTemplate, catalogInstanceUnifiedList, context);
74 unifiedCompositionService
75 .cleanUnifiedCompositionEntities(serviceTemplate, catalogInstanceUnifiedList, context);
78 unifiedCompositionService.cleanNodeTypes(serviceTemplate, unifiedCompositionDataList, context);
79 unifiedCompositionService.updateSubstitutionNodeTypePrefix(substitutionServiceTemplate.get());