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