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.openecomp.sdc.translator.services.heattotosca.helper;
23 import org.openecomp.sdc.heat.datatypes.model.Resource;
24 import org.openecomp.sdc.tosca.services.ToscaConstants;
25 import org.openecomp.sdc.translator.services.heattotosca.helper.impl.NameExtractorServiceImpl;
27 import java.util.ArrayList;
28 import java.util.Collections;
29 import java.util.List;
30 import java.util.Optional;
32 public class ContrailTranslationHelper {
34 * Gets compute node type id.
36 * @param serviceTemplateTranslatedId the service template translated id
37 * @param serviceTemplateResource the service template resource
38 * @return the compute node type id
40 public String getComputeNodeTypeId(String serviceTemplateTranslatedId,
41 Resource serviceTemplateResource) {
42 NameExtractorService nodeTypeNameExtractor = new NameExtractorServiceImpl();
43 List<PropertyRegexMatcher> propertyRegexMatchers =
44 getPropertiesAndRegexMatchers(nodeTypeNameExtractor);
45 Optional<String> extractedNodeTypeName = nodeTypeNameExtractor
46 .extractNodeTypeNameByPropertiesPriority(serviceTemplateResource.getProperties(),
47 propertyRegexMatchers);
49 return ToscaConstants.NODES_PREFIX
50 + (extractedNodeTypeName.isPresent() ? extractedNodeTypeName.get()
51 : "compute_" + serviceTemplateTranslatedId);
54 private List<PropertyRegexMatcher> getPropertiesAndRegexMatchers(
55 NameExtractorService nodeTypeNameExtractor) {
56 List<PropertyRegexMatcher> propertyRegexMatchers = new ArrayList<>();
57 propertyRegexMatchers.add(nodeTypeNameExtractor
58 .getPropertyRegexMatcher("image_name", Collections.singletonList(".+_image_name$"),
60 propertyRegexMatchers.add(nodeTypeNameExtractor
61 .getPropertyRegexMatcher("flavor", Collections.singletonList(".+_flavor_name$"),
63 return propertyRegexMatchers;