218e0267d21d188fd9ea9f2d599d50317ae56a9a
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / csar / YamlTemplateParsingHandlerTest.java
1 /*-
2  * ============LICENSE_START===============================================
3  * ONAP SDC
4  * ========================================================================
5  * Modifications Copyright (c) 2019 Samsung
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.openecomp.sdc.be.components.csar;
22
23 import mockit.Deencapsulation;
24 import org.apache.commons.collections.MapUtils;
25 import org.apache.commons.lang3.StringUtils;
26 import org.assertj.core.util.Lists;
27 import org.junit.jupiter.api.BeforeAll;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.mockito.InjectMocks;
32 import org.mockito.Mock;
33 import org.mockito.junit.jupiter.MockitoExtension;
34 import org.openecomp.sdc.be.components.impl.AnnotationBusinessLogic;
35 import org.openecomp.sdc.be.components.impl.GroupTypeBusinessLogic;
36 import org.openecomp.sdc.be.components.impl.PolicyTypeBusinessLogic;
37 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
38 import org.openecomp.sdc.be.components.validation.AnnotationValidator;
39 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
40 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
41 import org.openecomp.sdc.be.model.CapabilityDefinition;
42 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
43 import org.openecomp.sdc.be.model.GroupProperty;
44 import org.openecomp.sdc.be.model.GroupTypeDefinition;
45 import org.openecomp.sdc.be.model.ParsedToscaYamlInfo;
46 import org.openecomp.sdc.be.model.PolicyDefinition;
47 import org.openecomp.sdc.be.model.PolicyTypeDefinition;
48 import org.openecomp.sdc.be.model.Resource;
49 import org.openecomp.sdc.be.model.Service;
50 import org.openecomp.sdc.be.model.UploadArtifactInfo;
51 import org.openecomp.sdc.be.model.UploadComponentInstanceInfo;
52 import org.openecomp.sdc.be.model.UploadReqInfo;
53 import org.openecomp.sdc.be.model.User;
54 import org.openecomp.sdc.be.model.operations.impl.AnnotationTypeOperations;
55 import org.openecomp.sdc.be.ui.model.OperationUi;
56 import org.openecomp.sdc.common.zip.ZipUtils;
57 import org.openecomp.sdc.common.zip.exception.ZipException;
58 import org.springframework.test.util.ReflectionTestUtils;
59
60 import java.io.File;
61 import java.net.URISyntaxException;
62 import java.util.ArrayList;
63 import java.util.Collections;
64 import java.util.HashMap;
65 import java.util.List;
66 import java.util.Map;
67 import java.util.Optional;
68 import java.util.stream.Collectors;
69
70 import static org.assertj.core.api.Assertions.assertThat;
71 import static org.junit.jupiter.api.Assertions.assertEquals;
72 import static org.junit.jupiter.api.Assertions.assertNotNull;
73 import static org.junit.jupiter.api.Assertions.assertTrue;
74 import static org.mockito.ArgumentMatchers.any;
75 import static org.mockito.ArgumentMatchers.eq;
76 import static org.mockito.Mockito.when;
77 import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
78
79 @ExtendWith(MockitoExtension.class)
80 public class YamlTemplateParsingHandlerTest {
81
82     @Mock
83     private GroupTypeBusinessLogic groupTypeBusinessLogic;
84     @Mock
85     private AnnotationTypeOperations annotationTypeOperations;
86     @Mock
87     private AnnotationValidator annotationValidator;
88     @Mock
89     private JanusGraphDao janusGraphDao;
90     @Mock
91     private User user;
92     @Mock
93     private PolicyTypeBusinessLogic policyTypeBusinessLogic;
94     @Mock
95     private ServiceBusinessLogic serviceBusinessLogic;
96     @Mock
97     private ToscaFunctionYamlParsingHandler toscaFunctionYamlParsingHandler;
98
99     private YamlTemplateParsingHandler handler;
100
101     private static Map<String, byte[]> csar;
102     private static String resourceYml;
103
104     private final static String VFC_GROUP_TYPE = "org.openecomp.groups.VfcInstanceGroup";
105     private final static String HEAT_GROUP_TYPE = "org.openecomp.groups.heat.HeatStack";
106     private final static String ROOT_GROUP_TYPE = "tosca.groups.Root";
107     private final static String OPENECOMP_ANTILOCATE_POLICY_TYPE = "org.openecomp.policies.placement.Antilocate";
108     private final static String ROOT_POLICIES_TYPE = "tosca.policies.Root";
109     private final static GroupTypeDefinition VfcInstanceGroupType = buildVfcInstanceGroupType();
110     private final static GroupTypeDefinition heatGroupType = buildHeatStackGroupType();
111     private final static GroupTypeDefinition rootGroupType = buildRootGroupType();
112     private static final PolicyTypeDefinition OPENECOMP_POLICY_TYPE = buildOpenecompPolicyType();
113     private final static String OPENECOMP_POLICY_NAME = "vepdg_server_group_policy";
114     private final static String CAPABILITY_TYPE = "org.openecomp.capabilities.VLANAssignment";
115     private final static String CAPABILITY_NAME = "vlan_assignment";
116     private static final String CSAR_FILE_PATH = "csars/with_groups.csar";
117     private static final String FILE_NAME = "MainServiceTemplate.yaml";
118     private static final String CSAR_UUID = "csarUUID";
119     private static final String RESOURCE_NAME = "resourceName";
120     private static final String MAIN_TEMPLATE_NAME = "Definitions/MainServiceTemplate.yaml";
121     private static final String NODE_NAME = "org.openecomp.resource.abstract.nodes.heat.mg";
122     private static final String MAIN_GROUP_NAME = "x_group";
123     private static final String NESTED_GROUP_NAME = "nested_mg_vepdg_group";
124
125     @InjectMocks
126     private YamlTemplateParsingHandler testSubject;
127
128     @BeforeAll
129     public static void prepareData() throws URISyntaxException, ZipException {
130         final File csarFile = new File(
131             YamlTemplateParsingHandlerTest.class.getClassLoader().getResource(CSAR_FILE_PATH).toURI());
132         csar = ZipUtils.readZip(csarFile, false);
133
134         Optional<String> keyOp = csar.keySet().stream().filter(k -> k.endsWith(FILE_NAME)).findAny();
135         byte[] mainTemplateService = keyOp.map(csar::get).orElse(null);
136         assertNotNull(mainTemplateService);
137
138         resourceYml = new String(mainTemplateService);
139     }
140
141     @BeforeEach
142     public void setup() {
143         final var annotationBusinessLogic = new AnnotationBusinessLogic(annotationTypeOperations, annotationValidator);
144         handler = new YamlTemplateParsingHandler(janusGraphDao, groupTypeBusinessLogic, annotationBusinessLogic, policyTypeBusinessLogic,
145             serviceBusinessLogic, toscaFunctionYamlParsingHandler);
146         ReflectionTestUtils.setField(handler, "policyTypeBusinessLogic", policyTypeBusinessLogic);
147     }
148
149     @Test
150     void parseResourceInfoFromOneNodeTest() {
151         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
152
153         String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
154         CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
155             MAIN_TEMPLATE_NAME, main_template_content, true);
156
157         Resource resource = new Resource();
158         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
159             csarInfo.extractTypesInfo(), NODE_NAME, resource, getInterfaceTemplateYaml(csarInfo).get());
160
161         validateParsedYaml(parsedYaml, NESTED_GROUP_NAME,
162             Lists.newArrayList("heat_file", "description"));
163     }
164
165     @Test
166     void parseServicePropertiesInfoFromYamlTest() {
167         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
168         String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
169         CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
170             MAIN_TEMPLATE_NAME, main_template_content, true);
171
172         Service service = new Service();
173         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
174             csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get());
175
176         assertThat(parsedYaml.getProperties()).isNotNull();
177         assertEquals(5, parsedYaml.getProperties().size());
178         assertTrue(parsedYaml.getProperties().containsKey("skip_post_instantiation_configuration"));
179         assertTrue(parsedYaml.getProperties().containsKey("controller_actor"));
180         assertTrue(parsedYaml.getProperties().containsKey("cds_model_version"));
181         assertTrue(parsedYaml.getProperties().containsKey("cds_model_name"));
182         assertTrue(parsedYaml.getProperties().containsKey("default_software_version"));
183     }
184
185     @Test
186     void parseRelationshipTemplateInfoFromYamlTest() {
187         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
188         String main_template_content = new String(csar.get(MAIN_TEMPLATE_NAME));
189         CsarInfo csarInfo = new OnboardedCsarInfo(user, CSAR_UUID, csar, RESOURCE_NAME,
190             MAIN_TEMPLATE_NAME, main_template_content, true);
191
192         Service service = new Service();
193         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
194             csarInfo.extractTypesInfo(), NODE_NAME, service, getInterfaceTemplateYaml(csarInfo).get());
195
196         assertThat(parsedYaml.getInstances()).isNotNull();
197         final Map<String, List<OperationUi>> operations = new HashMap<>();
198         for (UploadComponentInstanceInfo instance : parsedYaml.getInstances().values()) {
199             final Map<String, List<UploadReqInfo>> requirements = instance.getRequirements();
200             if (MapUtils.isNotEmpty(requirements)) {
201                 requirements.values()
202                     .forEach(requirementInfoList -> requirementInfoList.stream()
203                         .filter(requirement -> StringUtils.isNotEmpty(requirement.getRelationshipTemplate()))
204                         .forEach(requirement -> operations.putAll(instance.getOperations())));
205             }
206         }
207         assertEquals(1, operations.size());
208     }
209
210     @Test
211     void parseResourceInfoFromYAMLTest() {
212         stubGetGroupType();
213         stubGetPolicyType();
214
215         Resource resource = new Resource();
216         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
217             new HashMap<>(), "", resource, null);
218         validateParsedYamlWithCapability(parsedYaml);
219     }
220
221     @Test
222     void testSetArtifacts() {
223         UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo();
224         Map<String, Object> nodeTemplateJsonMap = new HashMap<>();
225         Map<String, String> nodeMap = new HashMap<>();
226         nodeMap.put("name", "test_name");
227         nodeMap.put("type", "test_type");
228         nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), nodeMap);
229         Deencapsulation.invoke(testSubject, "setArtifacts", nodeTemplateInfo, nodeTemplateJsonMap);
230         assertNotNull(nodeTemplateInfo.getArtifacts());
231     }
232
233     @Test
234     void testCreateArtifactsModuleFromYaml() {
235         Map<String, Map<String, Map<String, String>>> nodeTemplateJsonMap = new HashMap<>();
236         Map<String, Map<String, String>> map0 = new HashMap<>();
237         Map<String, String> map1 = new HashMap<>();
238         map1.put("file", "test_file");
239         map1.put("type", "test_type");
240         map0.put("test_art", map1);
241         nodeTemplateJsonMap.put(ARTIFACTS.getElementName(), map0);
242         Map<String, Map<String, UploadArtifactInfo>> result;
243         result = Deencapsulation.invoke(testSubject, "createArtifactsModuleFromYaml", nodeTemplateJsonMap);
244         assertTrue(MapUtils.isNotEmpty(result));
245         assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
246         assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
247         assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
248     }
249
250     @Test
251     void testAddModuleNodeTemplateArtifacts() {
252         Map<String, Map<String, UploadArtifactInfo>> result = new HashMap<>();
253         Map<String, String> map1 = new HashMap<>();
254         map1.put("file", "test_file");
255         map1.put("type", "test_type");
256         Deencapsulation.invoke(testSubject, "addModuleNodeTemplateArtifacts", result, map1, "test_art");
257         assertTrue(MapUtils.isNotEmpty(result));
258         assertTrue(MapUtils.isNotEmpty(result.get(ARTIFACTS.getElementName())));
259         assertEquals("test_file", result.get(ARTIFACTS.getElementName()).get("test_art").getFile());
260         assertEquals("test_type", result.get(ARTIFACTS.getElementName()).get("test_art").getType());
261     }
262
263     @Test
264     void testBuildModuleNodeTemplateArtifact() {
265         Map<String, String> map1 = new HashMap<>();
266         map1.put("file", "test_file");
267         map1.put("type", "test_type");
268         UploadArtifactInfo result;
269         result = Deencapsulation.invoke(testSubject, "buildModuleNodeTemplateArtifact", map1);
270         assertNotNull(result);
271         assertEquals("test_file", result.getFile());
272         assertEquals("test_type", result.getType());
273     }
274
275     @Test
276     void testFillArtifact() {
277         Map<String, String> map1 = new HashMap<>();
278         map1.put("file", "test_file");
279         map1.put("type", "test_type");
280         UploadArtifactInfo result = new UploadArtifactInfo();
281         Deencapsulation.invoke(testSubject, "fillArtifact", result, map1);
282         assertNotNull(result);
283         assertEquals("test_file", result.getFile());
284         assertEquals("test_type", result.getType());
285     }
286
287     @Test
288     void parseResourceWithPoliciesDefined() {
289         stubGetGroupType();
290         stubGetPolicyType();
291         Resource resource = new Resource();
292         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
293             new HashMap<>(), "", resource, "");
294         validateParsedYamlWithPolicies(parsedYaml);
295     }
296
297     @Test
298     void parseResourceInstanceWithAttributesTest() {
299         stubGetGroupType();
300         stubGetPolicyType();
301         Resource resource = new Resource();
302         ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(),
303                 new HashMap<>(), "", resource, null);
304         validateParsedYamlWithAttributes(parsedYaml);
305     }
306
307     private void validateParsedYamlWithAttributes(ParsedToscaYamlInfo parsedYaml) {
308         ArrayList<String> expectedSubnetsShowList = new ArrayList<>();
309         expectedSubnetsShowList.add("val1");
310         expectedSubnetsShowList.add("val2");
311
312         HashMap<String, String> expectedSubnetsNameMap = new HashMap<>();
313         expectedSubnetsNameMap.put("name1", "name_val1");
314         expectedSubnetsNameMap.put("name2", "name_val2");
315
316
317         assertThat(parsedYaml.getInstances().get("resource_instance_with_attributes")).isNotNull();
318         UploadComponentInstanceInfo resourceInstanceWithAttributes = parsedYaml.getInstances().get("resource_instance_with_attributes");
319         assertEquals(5, resourceInstanceWithAttributes.getAttributes().size());
320
321         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("fq_name"));
322         assertEquals("fq_name_value", resourceInstanceWithAttributes.getAttributes().get("fq_name").getValue());
323         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("tosca_name"));
324         assertEquals("tosca_name_value", resourceInstanceWithAttributes.getAttributes().get("tosca_name").getValue());
325         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_show"));
326         assertEquals(expectedSubnetsShowList, resourceInstanceWithAttributes.getAttributes().get("subnets_show").getValue());
327         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_name"));
328         assertEquals(expectedSubnetsNameMap, resourceInstanceWithAttributes.getAttributes().get("subnets_name").getValue());
329         assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("new_attribute"));
330         assertEquals("new_attribute_value", resourceInstanceWithAttributes.getAttributes().get("new_attribute").getValue());
331     }
332
333     private void validateParsedYaml(ParsedToscaYamlInfo parsedYaml, String group, List<String> expectedProp) {
334         assertThat(parsedYaml).isNotNull();
335         assertThat(parsedYaml.getGroups()).isNotNull().containsKey(group);
336         assertThat(parsedYaml.getGroups().get(group)).isNotNull();
337
338         assertThat(parsedYaml.getGroups().get(group).getProperties()).isNotNull();
339         assertThat(parsedYaml.getGroups().get(group).getProperties()
340             .stream()
341             .map(PropertyDataDefinition::getName)
342             .collect(Collectors.toList()))
343             .containsAll(expectedProp);
344
345         assertThat(parsedYaml.getGroups().get(group).getMembers()).isNotNull();
346     }
347
348     private void validateParsedYamlWithCapability(ParsedToscaYamlInfo parsedYaml) {
349
350         final List<String> expectedProp = Lists.newArrayList("vfc_parent_port_role",
351             "network_collection_function", "vfc_instance_group_function", "subinterface_role");
352
353         validateParsedYaml(parsedYaml, MAIN_GROUP_NAME, expectedProp);
354
355         assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()
356             .get(CAPABILITY_TYPE)
357             .get(0).getProperties().get(0).getValue()).isEqualTo("success");
358         assertThat(parsedYaml.getGroups().get(MAIN_GROUP_NAME).getCapabilities()).isNotNull();
359         assertThat(parsedYaml.getSubstitutionMappingNodeType()).isEqualTo("org.openecomp.resource.abstract.nodes.VF");
360     }
361
362     private void stubGetGroupType() {
363         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE), any())).thenReturn(VfcInstanceGroupType);
364         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
365         when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE), any())).thenReturn(rootGroupType);
366     }
367
368     private static GroupTypeDefinition buildRootGroupType() {
369         return createGroupTypeDefinition(ROOT_GROUP_TYPE, null,
370             "The TOSCA Group Type all other TOSCA Group Types derive from");
371     }
372
373     private static GroupTypeDefinition buildHeatStackGroupType() {
374         GroupTypeDefinition groupType = createGroupTypeDefinition(HEAT_GROUP_TYPE, "tosca.groups.Root",
375             "Grouped all heat resources which are in the same heat stack");
376
377         GroupProperty property1 = createGroupProperty("heat_file",
378             "Heat file which associate to this group/heat stack", "SUPPORTED");
379
380         GroupProperty property2 = createGroupProperty("description",
381             "Group description", "SUPPORTED");
382
383         groupType.setProperties(Lists.newArrayList(property1, property2));
384         return groupType;
385     }
386
387     private static GroupTypeDefinition buildVfcInstanceGroupType() {
388         GroupTypeDefinition groupType = createGroupTypeDefinition(VFC_GROUP_TYPE, "tosca.groups.Root",
389             "Groups of VFCs with same parent port role");
390
391         GroupProperty property1 = createGroupProperty("vfc_instance_group_function",
392             "Function of this VFC group", null);
393
394         GroupProperty property2 = createGroupProperty("vfc_parent_port_role",
395             "Common role of parent ports of VFCs in this group", null);
396
397         GroupProperty property3 = createGroupProperty("network_collection_function",
398             "Network collection function assigned to this group", null);
399
400         GroupProperty property4 = createGroupProperty("subinterface_role",
401             "Common role of subinterfaces of VFCs in this group, criteria the group is created", null);
402
403         groupType.setProperties(Lists.newArrayList(property1, property2, property3, property4));
404
405         CapabilityDefinition capability = new CapabilityDefinition();
406         capability.setType(CAPABILITY_TYPE);
407         capability.setName(CAPABILITY_NAME);
408         ComponentInstanceProperty capabilityProperty = new ComponentInstanceProperty();
409         capabilityProperty.setName("vfc_instance_group_reference");
410         capabilityProperty.setType("string");
411         capability.setProperties(Collections.singletonList(capabilityProperty));
412
413         Map<String, CapabilityDefinition> capabilityMap = new HashMap<>();
414         capabilityMap.put(CAPABILITY_NAME, capability);
415         groupType.setCapabilities(capabilityMap);
416         return groupType;
417     }
418
419     private static GroupTypeDefinition createGroupTypeDefinition(String type, String derivedFrom, String description) {
420         GroupTypeDefinition property = new GroupTypeDefinition();
421
422         if (type != null) {
423             property.setType(type);
424         }
425
426         if (derivedFrom != null) {
427             property.setDerivedFrom(derivedFrom);
428         }
429
430         if (description != null) {
431             property.setDescription(description);
432         }
433
434         return property;
435     }
436
437     private static GroupProperty createGroupProperty(String name, String description,
438                                                      String status) {
439         GroupProperty property = new GroupProperty();
440         if (name != null) {
441             property.setName(name);
442         }
443
444         if (description != null) {
445             property.setDescription(description);
446         }
447
448         if (status != null) {
449             property.setStatus(status);
450         }
451
452         property.setType("string");
453         property.setRequired(true);
454
455         return property;
456     }
457
458     private void validateParsedYamlWithPolicies(ParsedToscaYamlInfo parsedYaml) {
459         // validate  policies
460         assertThat(parsedYaml.getPolicies()).isNotNull();
461         assertThat(parsedYaml.getPolicies()).containsKey(OPENECOMP_POLICY_NAME);
462         assertThat(parsedYaml.getPolicies().get(OPENECOMP_POLICY_NAME)).isInstanceOf(PolicyDefinition.class);
463     }
464
465     private void stubGetPolicyType() {
466         when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any()))
467             .thenReturn(OPENECOMP_POLICY_TYPE);
468     }
469
470     private static PolicyTypeDefinition buildOpenecompPolicyType() {
471         return createPolicyTypeDefinition(OPENECOMP_POLICY_NAME, OPENECOMP_ANTILOCATE_POLICY_TYPE, ROOT_POLICIES_TYPE,
472             "The Openecomp Antilocate policy");
473     }
474
475     private static PolicyTypeDefinition createPolicyTypeDefinition(String policyName, String policyType, String derivedFrom, String description) {
476         PolicyTypeDefinition policyTypeDefinition = new PolicyTypeDefinition();
477         if (policyName != null && !policyName.isEmpty()) {
478             policyTypeDefinition.setName(policyName);
479         }
480         if (policyType != null) {
481             policyTypeDefinition.setType(policyType);
482         }
483         if (derivedFrom != null) {
484             policyTypeDefinition.setDerivedFrom(derivedFrom);
485         }
486         if (description != null) {
487             policyTypeDefinition.setDescription(description);
488         }
489         return policyTypeDefinition;
490     }
491
492     private Optional<String> getInterfaceTemplateYaml(CsarInfo csarInfo) {
493         String[] yamlFile;
494         String interfaceTemplateYaml = "";
495         if (csarInfo.getMainTemplateName().contains(".yml")) {
496             yamlFile = csarInfo.getMainTemplateName().split(".yml");
497             interfaceTemplateYaml = yamlFile[0] + "-interface.yml";
498         } else if (csarInfo.getMainTemplateName().contains(".yaml")) {
499             yamlFile = csarInfo.getMainTemplateName().split(".yaml");
500             interfaceTemplateYaml = yamlFile[0] + "-interface.yaml";
501         }
502         if (csarInfo.getCsar().containsKey(interfaceTemplateYaml)) {
503             return Optional.of(new String(csarInfo.getCsar().get(interfaceTemplateYaml)));
504         }
505         return Optional.empty();
506     }
507 }