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.tosca.services;
23 import org.apache.commons.collections4.CollectionUtils;
24 import org.apache.commons.collections4.MapUtils;
25 import org.openecomp.core.utilities.CommonMethods;
26 import org.openecomp.sdc.common.errors.CoreException;
27 import org.openecomp.sdc.datatypes.error.ErrorLevel;
28 import org.openecomp.sdc.logging.api.Logger;
29 import org.openecomp.sdc.logging.api.LoggerFactory;
30 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
31 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
32 import org.openecomp.sdc.logging.types.LoggerConstants;
33 import org.openecomp.sdc.logging.types.LoggerErrorCode;
34 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
35 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
36 import org.openecomp.sdc.tosca.datatypes.ToscaCapabilityType;
37 import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
38 import org.openecomp.sdc.tosca.datatypes.ToscaRelationshipType;
39 import org.openecomp.sdc.tosca.datatypes.model.AttributeDefinition;
40 import org.openecomp.sdc.tosca.datatypes.model.CapabilityAssignment;
41 import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition;
42 import org.openecomp.sdc.tosca.datatypes.model.Constraint;
43 import org.openecomp.sdc.tosca.datatypes.model.EntrySchema;
44 import org.openecomp.sdc.tosca.datatypes.model.GroupDefinition;
45 import org.openecomp.sdc.tosca.datatypes.model.Import;
46 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
47 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
48 import org.openecomp.sdc.tosca.datatypes.model.ParameterDefinition;
49 import org.openecomp.sdc.tosca.datatypes.model.PolicyDefinition;
50 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
51 import org.openecomp.sdc.tosca.datatypes.model.RelationshipTemplate;
52 import org.openecomp.sdc.tosca.datatypes.model.RequirementAssignment;
53 import org.openecomp.sdc.tosca.datatypes.model.RequirementDefinition;
54 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
55 import org.openecomp.sdc.tosca.datatypes.model.Status;
56 import org.openecomp.sdc.tosca.datatypes.model.SubstitutionMapping;
57 import org.openecomp.sdc.tosca.datatypes.model.TopologyTemplate;
58 import org.openecomp.sdc.tosca.datatypes.model.heatextend.ParameterDefinitionExt;
59 import org.openecomp.sdc.tosca.errors.InvalidAddActionNullEntityErrorBuilder;
60 import org.openecomp.sdc.tosca.errors.InvalidRequirementAssignmentErrorBuilder;
61 import org.openecomp.sdc.tosca.services.impl.ToscaAnalyzerServiceImpl;
63 import java.io.ByteArrayInputStream;
64 import java.io.ByteArrayOutputStream;
65 import java.io.IOException;
66 import java.io.NotSerializableException;
67 import java.io.ObjectInputStream;
68 import java.io.ObjectOutputStream;
69 import java.util.ArrayList;
70 import java.util.Collections;
71 import java.util.HashMap;
72 import java.util.List;
73 import java.util.ListIterator;
75 import java.util.Objects;
76 import java.util.Optional;
79 * The type Data model util.
81 public class DataModelUtil {
84 * Add substitution mapping.
87 private static final MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
88 private static final Logger logger = LoggerFactory.getLogger(DataModelUtil.class);
89 private static final String SERVICE_TEMPLATE = "Service Template";
90 private static final String NODE_TYPE = "Node Type";
93 * Add substitution mapping.
95 * @param serviceTemplate the service template
96 * @param substitutionMapping the substitution mapping
98 public static void addSubstitutionMapping(ServiceTemplate serviceTemplate,
99 SubstitutionMapping substitutionMapping) {
100 mdcDataDebugMessage.debugEntryMessage(null);
102 if (serviceTemplate == null) {
103 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
104 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
105 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
106 throw new CoreException(
107 new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping", SERVICE_TEMPLATE)
111 if (serviceTemplate.getTopology_template() == null) {
112 serviceTemplate.setTopology_template(new TopologyTemplate());
114 serviceTemplate.getTopology_template().setSubstitution_mappings(substitutionMapping);
116 mdcDataDebugMessage.debugExitMessage(null);
119 public static List<String> getDirectives(NodeTemplate nodeTemplate) {
120 if (Objects.isNull(nodeTemplate)
121 || Objects.isNull(nodeTemplate.getDirectives())) {
122 return Collections.emptyList();
125 return nodeTemplate.getDirectives();
129 * Add substitution mapping req.
131 * @param serviceTemplate the service template
132 * @param substitutionMappingRequirementId the substitution mapping requirement id
133 * @param substitutionMappingRequirementList the substitution mapping requirement list
135 public static void addSubstitutionMappingReq(ServiceTemplate serviceTemplate,
136 String substitutionMappingRequirementId,
137 List<String> substitutionMappingRequirementList) {
140 mdcDataDebugMessage.debugEntryMessage(null);
142 if (serviceTemplate == null) {
143 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
144 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
145 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
146 throw new CoreException(
147 new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Requirements",
148 SERVICE_TEMPLATE).build());
151 if (serviceTemplate.getTopology_template() == null) {
152 serviceTemplate.setTopology_template(new TopologyTemplate());
154 if (serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
155 serviceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
157 if (serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
159 serviceTemplate.getTopology_template().getSubstitution_mappings()
160 .setRequirements(new HashMap<>());
163 serviceTemplate.getTopology_template().getSubstitution_mappings().getRequirements()
164 .put(substitutionMappingRequirementId, substitutionMappingRequirementList);
166 mdcDataDebugMessage.debugExitMessage(null);
170 * Add substitution mapping capability.
172 * @param serviceTemplate the service template
173 * @param substitutionMappingCapabilityId the substitution mapping capability id
174 * @param substitutionMappingCapabilityList the substitution mapping capability list
176 public static void addSubstitutionMappingCapability(ServiceTemplate serviceTemplate,
177 String substitutionMappingCapabilityId,
178 List<String> substitutionMappingCapabilityList) {
181 mdcDataDebugMessage.debugEntryMessage(null);
183 if (serviceTemplate == null) {
184 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
185 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
186 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
187 throw new CoreException(
188 new InvalidAddActionNullEntityErrorBuilder("Substitution Mapping Capabilities",
189 SERVICE_TEMPLATE).build());
192 if (serviceTemplate.getTopology_template() == null) {
193 serviceTemplate.setTopology_template(new TopologyTemplate());
195 if (serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
196 serviceTemplate.getTopology_template().setSubstitution_mappings(new SubstitutionMapping());
198 if (serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
200 serviceTemplate.getTopology_template().getSubstitution_mappings()
201 .setCapabilities(new HashMap<>());
204 serviceTemplate.getTopology_template().getSubstitution_mappings().getCapabilities()
205 .putIfAbsent(substitutionMappingCapabilityId, substitutionMappingCapabilityList);
207 mdcDataDebugMessage.debugExitMessage(null);
210 public static Map<String, NodeTemplate> getNodeTemplates(ServiceTemplate serviceTemplate) {
211 if (Objects.isNull(serviceTemplate)
212 || Objects.isNull(serviceTemplate.getTopology_template())
213 || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates())) {
214 return new HashMap<>();
217 return serviceTemplate.getTopology_template().getNode_templates();
223 * @param serviceTemplate the service template
224 * @param nodeTemplateId the node template id
225 * @param nodeTemplate the node template
227 public static void addNodeTemplate(ServiceTemplate serviceTemplate, String nodeTemplateId,
228 NodeTemplate nodeTemplate) {
231 mdcDataDebugMessage.debugEntryMessage(null);
233 if (serviceTemplate == null) {
234 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
235 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
236 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
237 throw new CoreException(
238 new InvalidAddActionNullEntityErrorBuilder("Node Template", SERVICE_TEMPLATE).build());
240 TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
241 if (Objects.isNull(topologyTemplate)) {
242 topologyTemplate = new TopologyTemplate();
243 serviceTemplate.setTopology_template(topologyTemplate);
245 if (topologyTemplate.getNode_templates() == null) {
246 topologyTemplate.setNode_templates(new HashMap<>());
248 topologyTemplate.getNode_templates().put(nodeTemplateId, nodeTemplate);
250 mdcDataDebugMessage.debugExitMessage(null);
255 * Add capabilities def to node type.
257 * @param nodeType the node type
258 * @param capabilities the capability definitions
260 public static void addNodeTypeCapabilitiesDef(NodeType nodeType,
261 Map<String, CapabilityDefinition> capabilities) {
262 mdcDataDebugMessage.debugEntryMessage(null);
264 if (MapUtils.isEmpty(capabilities) || capabilities.entrySet().isEmpty()) {
268 if (nodeType == null) {
269 throw new CoreException(
270 new InvalidAddActionNullEntityErrorBuilder("Capability Definition", NODE_TYPE).build());
273 if (MapUtils.isEmpty(nodeType.getCapabilities())) {
274 nodeType.setCapabilities(new HashMap<>());
276 if (capabilities.size() > 0) {
277 nodeType.setCapabilities(new HashMap<>());
279 for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
280 nodeType.getCapabilities().put(entry.getKey(), entry.getValue());
283 mdcDataDebugMessage.debugExitMessage(null);
287 * Add policy definition.
289 * @param serviceTemplate the service template
290 * @param policyId the policy id
291 * @param policyDefinition the policy definition
293 public static void addPolicyDefinition(ServiceTemplate serviceTemplate, String policyId,
294 PolicyDefinition policyDefinition) {
297 mdcDataDebugMessage.debugEntryMessage(null);
299 if (serviceTemplate == null) {
300 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
301 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
302 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
303 throw new CoreException(
304 new InvalidAddActionNullEntityErrorBuilder("Policy Definition", SERVICE_TEMPLATE)
307 TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
308 if (Objects.isNull(topologyTemplate)) {
309 topologyTemplate = new TopologyTemplate();
310 serviceTemplate.setTopology_template(topologyTemplate);
312 if (topologyTemplate.getPolicies() == null) {
313 topologyTemplate.setPolicies(new HashMap<>());
315 topologyTemplate.getPolicies().put(policyId, policyDefinition);
317 mdcDataDebugMessage.debugExitMessage(null);
323 * @param serviceTemplate the service template
324 * @param nodeTypeId the node type id
325 * @param nodeType the node type
327 public static void addNodeType(ServiceTemplate serviceTemplate, String nodeTypeId,
331 mdcDataDebugMessage.debugEntryMessage(null);
333 if (serviceTemplate == null) {
334 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
335 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
336 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
337 throw new CoreException(
338 new InvalidAddActionNullEntityErrorBuilder(NODE_TYPE, SERVICE_TEMPLATE).build());
340 if (serviceTemplate.getNode_types() == null) {
341 serviceTemplate.setNode_types(new HashMap<>());
343 serviceTemplate.getNode_types().put(nodeTypeId, nodeType);
345 mdcDataDebugMessage.debugExitMessage(null);
348 public static void removeNodeType(ServiceTemplate serviceTemplate,
350 if (serviceTemplate == null) {
351 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
352 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
353 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
354 throw new CoreException(
355 new InvalidAddActionNullEntityErrorBuilder(NODE_TYPE, SERVICE_TEMPLATE).build());
357 if (serviceTemplate.getNode_types() == null) {
358 serviceTemplate.setNode_types(new HashMap<>());
360 serviceTemplate.getNode_types().remove(nodeTypeId);
362 mdcDataDebugMessage.debugExitMessage(null);
366 * Add relationship template.
368 * @param serviceTemplate the service template
369 * @param relationshipTemplateId the relationship template id
370 * @param relationshipTemplate the relationship template
372 public static void addRelationshipTemplate(ServiceTemplate serviceTemplate,
373 String relationshipTemplateId,
374 RelationshipTemplate relationshipTemplate) {
377 mdcDataDebugMessage.debugEntryMessage(null);
379 if (serviceTemplate == null) {
380 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
381 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
382 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
383 throw new CoreException(
384 new InvalidAddActionNullEntityErrorBuilder("Relationship Template", SERVICE_TEMPLATE)
387 if (serviceTemplate.getTopology_template() == null) {
388 serviceTemplate.setTopology_template(new TopologyTemplate());
390 if (serviceTemplate.getTopology_template().getRelationship_templates() == null) {
391 serviceTemplate.getTopology_template().setRelationship_templates(new HashMap<>());
393 serviceTemplate.getTopology_template().getRelationship_templates()
394 .put(relationshipTemplateId, relationshipTemplate);
396 mdcDataDebugMessage.debugExitMessage(null);
400 * Add requirement assignment.
402 * @param nodeTemplate the node template
403 * @param requirementId the requirement id
404 * @param requirementAssignment the requirement assignment
406 public static void addRequirementAssignment(NodeTemplate nodeTemplate, String requirementId,
407 RequirementAssignment requirementAssignment) {
410 mdcDataDebugMessage.debugEntryMessage(null);
412 if (nodeTemplate == null) {
413 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
414 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
415 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
416 throw new CoreException(
417 new InvalidAddActionNullEntityErrorBuilder("Requirement Assignment", "Node Template")
420 if (requirementAssignment.getNode() == null) {
421 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
422 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
423 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
424 throw new CoreException(new InvalidRequirementAssignmentErrorBuilder(requirementId).build());
427 if (nodeTemplate.getRequirements() == null) {
428 nodeTemplate.setRequirements(new ArrayList<>());
430 Map<String, RequirementAssignment> requirement = new HashMap<>();
431 requirement.put(requirementId, requirementAssignment);
432 nodeTemplate.getRequirements().add(requirement);
434 mdcDataDebugMessage.debugExitMessage(null);
438 * Gets node template.
440 * @param serviceTemplate the service template
441 * @param nodeTemplateId the node template id
442 * @return the node template
444 public static NodeTemplate getNodeTemplate(ServiceTemplate serviceTemplate,
445 String nodeTemplateId) {
447 mdcDataDebugMessage.debugEntryMessage(null);
449 if (serviceTemplate == null
450 || serviceTemplate.getTopology_template() == null
451 || serviceTemplate.getTopology_template().getNode_templates() == null) {
455 mdcDataDebugMessage.debugExitMessage(null);
456 return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId);
462 * @param serviceTemplate the service template
463 * @param nodeTypeId the node type id
464 * @return the node type
466 public static NodeType getNodeType(ServiceTemplate serviceTemplate, String nodeTypeId) {
469 mdcDataDebugMessage.debugEntryMessage(null);
470 if (serviceTemplate == null || serviceTemplate.getNode_types() == null) {
474 mdcDataDebugMessage.debugExitMessage(null);
475 return serviceTemplate.getNode_types().get(nodeTypeId);
479 * Gets requirement definition.
481 * @param nodeType the node type
482 * @param requirementDefinitionId the requirement definition id
483 * @return the requirement definition
485 public static Optional<RequirementDefinition> getRequirementDefinition(
487 String requirementDefinitionId) {
490 mdcDataDebugMessage.debugEntryMessage(null);
492 if (nodeType == null || nodeType.getRequirements() == null || requirementDefinitionId == null) {
493 return Optional.empty();
495 for (Map<String, RequirementDefinition> reqMap : nodeType.getRequirements()) {
496 if (reqMap.containsKey(requirementDefinitionId)) {
497 return Optional.of(reqMap.get(requirementDefinitionId));
501 mdcDataDebugMessage.debugExitMessage(null);
502 return Optional.empty();
506 * get requirement definition from requirement definition list by req key.
508 * @param requirementsDefinitionList requirement definition list
509 * @param requirementKey requirement key
511 public static Optional<RequirementDefinition> getRequirementDefinition(
512 List<Map<String, RequirementDefinition>> requirementsDefinitionList,
513 String requirementKey) {
514 mdcDataDebugMessage.debugEntryMessage(null);
515 if (CollectionUtils.isEmpty(requirementsDefinitionList)) {
516 return Optional.empty();
519 for (Map<String, RequirementDefinition> requirementMap : requirementsDefinitionList) {
520 if (requirementMap.containsKey(requirementKey)) {
521 mdcDataDebugMessage.debugExitMessage(null);
522 return Optional.of(requirementMap.get(requirementKey));
526 mdcDataDebugMessage.debugExitMessage(null);
527 return Optional.empty();
531 * Gets capability definition.
533 * @param nodeType the node type
534 * @param capabilityDefinitionId the capability definition id
535 * @return the capability definition
537 public static Optional<CapabilityDefinition> getCapabilityDefinition(
539 String capabilityDefinitionId) {
542 mdcDataDebugMessage.debugEntryMessage(null);
544 if (nodeType == null || nodeType.getCapabilities() == null || capabilityDefinitionId == null) {
545 return Optional.empty();
548 mdcDataDebugMessage.debugExitMessage(null);
549 return Optional.ofNullable(nodeType.getCapabilities().get(capabilityDefinitionId));
553 * Add group definition to topology template.
555 * @param serviceTemplate the service template
556 * @param groupName the group name
557 * @param group the group
559 public static void addGroupDefinitionToTopologyTemplate(ServiceTemplate serviceTemplate,
560 String groupName, GroupDefinition group) {
563 mdcDataDebugMessage.debugEntryMessage(null);
565 if (serviceTemplate == null) {
566 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
567 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
568 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
569 throw new CoreException(
570 new InvalidAddActionNullEntityErrorBuilder("Group Definition", SERVICE_TEMPLATE)
574 TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
575 if (Objects.isNull(topologyTemplate)) {
576 topologyTemplate = new TopologyTemplate();
577 serviceTemplate.setTopology_template(topologyTemplate);
579 if (topologyTemplate.getGroups() == null) {
580 topologyTemplate.setGroups(new HashMap<>());
582 if (serviceTemplate.getTopology_template().getGroups() == null) {
583 Map<String, GroupDefinition> groups = new HashMap<>();
584 serviceTemplate.getTopology_template().setGroups(groups);
587 serviceTemplate.getTopology_template().getGroups().put(groupName, group);
588 mdcDataDebugMessage.debugExitMessage(null);
592 * Create parameter definition property definition.
594 * @param type the type
595 * @param description the description
596 * @param value the value
597 * @param required the required
598 * @param constraints the constraints
599 * @param status the status
600 * @param entrySchema the entry schema
601 * @param defaultVal the default val
602 * @return the property definition
604 public static ParameterDefinition createParameterDefinition(String type, String description,
605 Object value, boolean required,
606 List<Constraint> constraints,
608 EntrySchema entrySchema,
612 mdcDataDebugMessage.debugEntryMessage(null);
614 ParameterDefinition paramDef = new ParameterDefinition();
615 paramDef.setType(type);
616 paramDef.setDescription(description);
617 paramDef.setValue(value);
618 paramDef.setRequired(required);
619 paramDef.setConstraints(constraints);
620 if (status != null) {
621 paramDef.setStatus(status);
623 paramDef.setEntry_schema(entrySchema == null ? null : entrySchema.clone());
624 paramDef.set_default(defaultVal);
626 mdcDataDebugMessage.debugExitMessage(null);
631 * Create requirement requirement definition.
633 * @param capability the capability
634 * @param node the node
635 * @param relationship the relationship
636 * @param occurrences the occurrences
637 * @return the requirement definition
639 public static RequirementDefinition createRequirement(String capability, String node,
640 String relationship, Object[] occurrences) {
643 mdcDataDebugMessage.debugEntryMessage(null);
645 RequirementDefinition requirementDefinition = new RequirementDefinition();
646 requirementDefinition.setCapability(capability);
647 requirementDefinition.setNode(node);
648 requirementDefinition.setRelationship(relationship);
649 if (occurrences != null) {
650 requirementDefinition.setOccurrences(occurrences);
653 mdcDataDebugMessage.debugExitMessage(null);
654 return requirementDefinition;
658 * Create entry schema entry schema.
660 * @param type the type
661 * @param description the description
662 * @param constraints the constraints
663 * @return the entry schema
665 public static EntrySchema createEntrySchema(String type, String description,
666 List<Constraint> constraints) {
669 mdcDataDebugMessage.debugEntryMessage(null);
671 if (Objects.isNull(type) && Objects.isNull(description) &&
672 CollectionUtils.isEmpty(constraints)) {
676 EntrySchema entrySchema = new EntrySchema();
677 entrySchema.setType(type);
678 entrySchema.setDescription(description);
679 entrySchema.setConstraints(constraints);
681 mdcDataDebugMessage.debugExitMessage(null);
686 * Create get input property value from list parameter map.
688 * @param inputPropertyListName the input property list name
689 * @param indexInTheList the index in the list
690 * @param nestedPropertyName the nested property name
693 public static Map createGetInputPropertyValueFromListParameter(String inputPropertyListName,
695 String... nestedPropertyName) {
698 mdcDataDebugMessage.debugEntryMessage(null);
700 List propertyList = new ArrayList<>();
701 propertyList.add(inputPropertyListName);
702 propertyList.add(indexInTheList);
703 if (nestedPropertyName != null) {
704 Collections.addAll(propertyList, nestedPropertyName);
706 Map getInputProperty = new HashMap<>();
707 getInputProperty.put(ToscaFunctions.GET_INPUT.getDisplayName(), propertyList);
709 mdcDataDebugMessage.debugExitMessage(null);
710 return getInputProperty;
714 * Convert property def to parameter def parameter definition ext.
716 * @param propertyDefinition the property definition
717 * @return the parameter definition ext
719 public static ParameterDefinitionExt convertPropertyDefToParameterDef(
720 PropertyDefinition propertyDefinition) {
723 mdcDataDebugMessage.debugEntryMessage(null);
725 if (propertyDefinition == null) {
729 ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
730 parameterDefinition.setType(propertyDefinition.getType());
731 parameterDefinition.setDescription(propertyDefinition.getDescription());
732 parameterDefinition.setRequired(propertyDefinition.getRequired());
733 parameterDefinition.set_default(propertyDefinition.get_default());
734 parameterDefinition.setStatus(propertyDefinition.getStatus());
735 parameterDefinition.setConstraints(propertyDefinition.getConstraints());
736 parameterDefinition.setEntry_schema(Objects.isNull(propertyDefinition.getEntry_schema()) ? null
737 : propertyDefinition.getEntry_schema().clone());
738 parameterDefinition.setHidden(false);
739 parameterDefinition.setImmutable(false);
741 mdcDataDebugMessage.debugExitMessage(null);
742 return parameterDefinition;
746 * Convert attribute def to parameter def parameter definition ext.
748 * @param attributeDefinition the attribute definition
749 * @param outputValue the output value
750 * @return the parameter definition ext
752 public static ParameterDefinitionExt convertAttributeDefToParameterDef(
753 AttributeDefinition attributeDefinition, Map<String, List> outputValue) {
756 mdcDataDebugMessage.debugEntryMessage(null);
758 if (attributeDefinition == null) {
761 ParameterDefinitionExt parameterDefinition = new ParameterDefinitionExt();
762 parameterDefinition.setDescription(attributeDefinition.getDescription());
763 parameterDefinition.setValue(outputValue);
765 mdcDataDebugMessage.debugExitMessage(null);
766 return parameterDefinition;
769 public static boolean isNodeTemplate(String entryId, ServiceTemplate serviceTemplate) {
770 return serviceTemplate.getTopology_template().getNode_templates() != null
771 && serviceTemplate.getTopology_template().getNode_templates().get(entryId) != null;
775 * Add Input parameter.
777 * @param serviceTemplate the service template
778 * @param parameterDefinitionId the parameter definition id
779 * @param parameterDefinition the parameter definition
781 public static void addInputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
782 String parameterDefinitionId,
783 ParameterDefinition parameterDefinition) {
786 mdcDataDebugMessage.debugEntryMessage(null);
788 if (Objects.isNull(serviceTemplate)) {
789 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
790 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
791 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
792 throw new CoreException(
793 new InvalidAddActionNullEntityErrorBuilder("Topology Template Input Parameter",
794 SERVICE_TEMPLATE).build());
796 TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
797 if (Objects.isNull(topologyTemplate)) {
798 topologyTemplate = new TopologyTemplate();
799 serviceTemplate.setTopology_template(topologyTemplate);
801 if (topologyTemplate.getInputs() == null) {
802 topologyTemplate.setInputs(new HashMap<>());
804 topologyTemplate.getInputs().put(parameterDefinitionId, parameterDefinition);
806 mdcDataDebugMessage.debugExitMessage(null);
811 * Add Output parameter.
813 * @param serviceTemplate the service template
814 * @param parameterDefinitionId the parameter definition id
815 * @param parameterDefinition the parameter definition
817 public static void addOutputParameterToTopologyTemplate(ServiceTemplate serviceTemplate,
818 String parameterDefinitionId,
819 ParameterDefinition parameterDefinition) {
822 mdcDataDebugMessage.debugEntryMessage(null);
824 if (Objects.isNull(serviceTemplate)) {
825 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
826 LoggerTragetServiceName.ADD_ENTITIES_TO_TOSCA, ErrorLevel.ERROR.name(),
827 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_ADD_ACTION);
828 throw new CoreException(
829 new InvalidAddActionNullEntityErrorBuilder("Topology Template Output Parameter",
830 SERVICE_TEMPLATE).build());
832 TopologyTemplate topologyTemplate = serviceTemplate.getTopology_template();
833 if (Objects.isNull(topologyTemplate)) {
834 topologyTemplate = new TopologyTemplate();
835 serviceTemplate.setTopology_template(topologyTemplate);
837 if (topologyTemplate.getOutputs() == null) {
838 topologyTemplate.setOutputs(new HashMap<>());
840 topologyTemplate.getOutputs().put(parameterDefinitionId, parameterDefinition);
842 mdcDataDebugMessage.debugExitMessage(null);
847 * Add requirement def to requirement def list.
849 * @param requirementList requirement list
850 * @param requirementDef added requirement def
852 public static void addRequirementToList(List<Map<String, RequirementDefinition>> requirementList,
853 Map<String, RequirementDefinition> requirementDef) {
854 if (requirementDef == null) {
857 if (requirementList == null) {
858 requirementList = new ArrayList<>();
861 for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
862 CommonMethods.mergeEntryInList(entry.getKey(), entry.getValue(), requirementList);
867 * get node template requirement.
869 * @param nodeTemplate node template
871 public static Map<String, RequirementAssignment> getNodeTemplateRequirements(
872 NodeTemplate nodeTemplate) {
873 mdcDataDebugMessage.debugEntryMessage(null);
875 if (Objects.isNull(nodeTemplate)) {
878 List<Map<String, RequirementAssignment>> templateRequirements = nodeTemplate.getRequirements();
880 Map<String, RequirementAssignment> nodeTemplateRequirementsAssignment = new HashMap<>();
881 if (CollectionUtils.isEmpty(templateRequirements)) {
882 return nodeTemplateRequirementsAssignment;
884 YamlUtil yamlUtil = new YamlUtil();
885 for (Map<String, RequirementAssignment> requirementAssignmentMap : templateRequirements) {
886 for (Map.Entry<String, RequirementAssignment> requirementEntry : requirementAssignmentMap
888 RequirementAssignment requirementAssignment = (yamlUtil
889 .yamlToObject(yamlUtil.objectToYaml(requirementEntry.getValue()),
890 RequirementAssignment.class));
891 nodeTemplateRequirementsAssignment
892 .put(requirementEntry.getKey(), requirementAssignment);
896 mdcDataDebugMessage.debugExitMessage(null);
897 return nodeTemplateRequirementsAssignment;
901 * Gets the list of requirements for the node template.
903 * @param nodeTemplate the node template
904 * @return the node template requirement list and null if the node has no requirements
906 public static List<Map<String, RequirementAssignment>> getNodeTemplateRequirementList(
907 NodeTemplate nodeTemplate) {
908 mdcDataDebugMessage.debugEntryMessage(null);
909 ToscaExtensionYamlUtil toscaExtensionYamlUtil = new ToscaExtensionYamlUtil();
910 //Creating concrete objects
911 List<Map<String, RequirementAssignment>> requirements = nodeTemplate.getRequirements();
912 List<Map<String, RequirementAssignment>> concreteRequirementList = null;
913 if (requirements != null) {
914 concreteRequirementList = new ArrayList<>();
915 ListIterator<Map<String, RequirementAssignment>> reqListIterator = requirements
917 while (reqListIterator.hasNext()) {
918 Map<String, RequirementAssignment> requirement = reqListIterator.next();
919 Map<String, RequirementAssignment> concreteRequirement = new HashMap<>();
920 for (Map.Entry<String, RequirementAssignment> reqEntry : requirement.entrySet()) {
921 RequirementAssignment requirementAssignment = (toscaExtensionYamlUtil
922 .yamlToObject(toscaExtensionYamlUtil.objectToYaml(reqEntry.getValue()),
923 RequirementAssignment.class));
924 concreteRequirement.put(reqEntry.getKey(), requirementAssignment);
925 concreteRequirementList.add(concreteRequirement);
926 reqListIterator.remove();
929 requirements.clear();
930 requirements.addAll(concreteRequirementList);
931 nodeTemplate.setRequirements(requirements);
933 mdcDataDebugMessage.debugExitMessage(null);
934 return concreteRequirementList;
938 * get requirement assignment from requirement assignment list by req key.
940 * @param requirementsAssignmentList requirement definition list
941 * @param requirementKey requirement key
943 public static Optional<List<RequirementAssignment>> getRequirementAssignment(
944 List<Map<String, RequirementAssignment>> requirementsAssignmentList,
945 String requirementKey) {
947 mdcDataDebugMessage.debugEntryMessage(null);
948 if (CollectionUtils.isEmpty(requirementsAssignmentList)) {
949 return Optional.empty();
952 List<RequirementAssignment> matchRequirementAssignmentList = new ArrayList<>();
953 for (Map<String, RequirementAssignment> requirementMap : requirementsAssignmentList) {
954 if (requirementMap.containsKey(requirementKey)) {
955 YamlUtil yamlUtil = new YamlUtil();
956 RequirementAssignment requirementAssignment = (yamlUtil
957 .yamlToObject(yamlUtil.objectToYaml(requirementMap.get(requirementKey)),
958 RequirementAssignment.class));
959 matchRequirementAssignmentList.add(requirementAssignment);
963 mdcDataDebugMessage.debugExitMessage(null);
964 return Optional.of(matchRequirementAssignmentList);
968 * remove requirement definition from requirement definition list by req key.
970 * @param requirementsDefinitionList requirement definition list
971 * @param requirementKey requirement key
973 public static void removeRequirementsDefinition(
974 List<Map<String, RequirementDefinition>> requirementsDefinitionList,
975 String requirementKey) {
976 mdcDataDebugMessage.debugEntryMessage(null);
977 if (requirementsDefinitionList == null) {
981 List<Map<String, RequirementDefinition>> mapToBeRemoved = new ArrayList<>();
982 for (Map<String, RequirementDefinition> reqMap : requirementsDefinitionList) {
983 reqMap.remove(requirementKey);
984 if (reqMap.isEmpty()) {
985 mapToBeRemoved.add(reqMap);
988 for (Map<String, RequirementDefinition> removeMap : mapToBeRemoved) {
989 requirementsDefinitionList.remove(removeMap);
992 mdcDataDebugMessage.debugExitMessage(null);
996 * remove requirement assignment from requirement definition list by req key.
998 * @param requirementsAssignmentList requirement Assignment list
999 * @param requirementKey requirement key
1001 public static void removeRequirementsAssignment(
1002 List<Map<String, RequirementAssignment>> requirementsAssignmentList,
1003 String requirementKey) {
1004 mdcDataDebugMessage.debugEntryMessage(null);
1005 if (requirementsAssignmentList == null) {
1009 List<Map<String, RequirementAssignment>> mapToBeRemoved = new ArrayList<>();
1010 for (Map<String, RequirementAssignment> reqMap : requirementsAssignmentList) {
1011 reqMap.remove(requirementKey);
1012 if (reqMap.isEmpty()) {
1013 mapToBeRemoved.add(reqMap);
1016 for (Map<String, RequirementAssignment> removeMap : mapToBeRemoved) {
1017 requirementsAssignmentList.remove(removeMap);
1020 mdcDataDebugMessage.debugExitMessage(null);
1025 * Remove requirement assignment.
1027 * @param nodeTemplate the node template
1028 * @param requirementKey the requirement key
1029 * @param requirementAssignmentToBeDeleted the requirement assignment to be deleted
1031 public static void removeRequirementAssignment(
1032 NodeTemplate nodeTemplate,
1033 String requirementKey,
1034 RequirementAssignment requirementAssignmentToBeDeleted) {
1035 mdcDataDebugMessage.debugEntryMessage(null);
1036 ToscaAnalyzerService toscaAnalyzerService = new ToscaAnalyzerServiceImpl();
1037 List<Map<String, RequirementAssignment>> nodeTemplateRequirements = nodeTemplate
1039 if (nodeTemplateRequirements == null) {
1043 ListIterator<Map<String, RequirementAssignment>> iter = nodeTemplateRequirements.listIterator();
1044 while (iter.hasNext()) {
1045 Map<String, RequirementAssignment> reqMap = iter.next();
1046 RequirementAssignment requirementAssignment = reqMap.get(requirementKey);
1047 if (requirementAssignment != null) {
1048 boolean isDesiredRequirementAssignment = toscaAnalyzerService
1049 .isDesiredRequirementAssignment(requirementAssignment,
1050 requirementAssignmentToBeDeleted.getCapability(),
1051 requirementAssignmentToBeDeleted.getNode(),
1052 requirementAssignmentToBeDeleted.getRelationship());
1053 if (isDesiredRequirementAssignment) {
1059 mdcDataDebugMessage.debugExitMessage(null);
1063 * Return the suffix of the input namespace For an exampale - for abc.sdf.vsrx, return vsrx
1065 * @param namespace namespace
1066 * @return String namespace suffix
1068 public static String getNamespaceSuffix(String namespace) {
1069 if (namespace == null) {
1072 String delimiterChar = ".";
1073 if (namespace.contains(delimiterChar)) {
1074 return namespace.substring(namespace.lastIndexOf(delimiterChar) + 1);
1080 * Return true if the input import exist in the input imports list.
1082 * @param imports namespace
1083 * @param importId namespace
1084 * @return true if exist, false if not exist
1086 public static boolean isImportAddedToServiceTemplate(List<Map<String, Import>> imports,
1088 for (Map<String, Import> anImport : imports) {
1089 if (anImport.containsKey(importId)) {
1097 * Get output parameter according to the input outputParameterId.
1099 * @param serviceTemplate service template
1100 * @param outputParameterId output parameter id
1101 * @return ParameterDefinition - output parameter
1103 public static ParameterDefinition getOuputParameter(ServiceTemplate serviceTemplate,
1104 String outputParameterId) {
1105 mdcDataDebugMessage.debugEntryMessage(null);
1107 if (serviceTemplate == null
1108 || serviceTemplate.getTopology_template() == null
1109 || serviceTemplate.getTopology_template().getOutputs() == null) {
1113 mdcDataDebugMessage.debugExitMessage(null);
1114 return serviceTemplate.getTopology_template().getOutputs().get(outputParameterId);
1118 * Gets input parameters in a service template.
1120 * @param serviceTemplate the service template
1121 * @return the input parameters
1123 public static Map<String, ParameterDefinition> getInputParameters(ServiceTemplate
1125 if (serviceTemplate == null
1126 || serviceTemplate.getTopology_template() == null
1127 || serviceTemplate.getTopology_template().getInputs() == null) {
1130 return serviceTemplate.getTopology_template().getInputs();
1134 * Gets relationship templates in a service template.
1136 * @param serviceTemplate the service template
1137 * @return the relationship template
1139 public static Map<String, RelationshipTemplate> getRelationshipTemplates(ServiceTemplate
1141 if (serviceTemplate == null
1142 || serviceTemplate.getTopology_template() == null
1143 || serviceTemplate.getTopology_template().getRelationship_templates() == null) {
1146 return serviceTemplate.getTopology_template().getRelationship_templates();
1150 * Get property value according to the input propertyId.
1152 * @param nodeTemplate node template
1153 * @param propertyId property id
1154 * @return Object property Value
1156 public static Object getPropertyValue(NodeTemplate nodeTemplate,
1157 String propertyId) {
1158 mdcDataDebugMessage.debugEntryMessage(null);
1160 if (nodeTemplate == null
1161 || nodeTemplate.getProperties() == null) {
1165 mdcDataDebugMessage.debugExitMessage(null);
1166 return nodeTemplate.getProperties().get(propertyId);
1170 * Get node template properties according to the input node template id.
1172 * @param serviceTemplate service template
1173 * @param nodeTemplateId node template id
1174 * @return node template properties
1176 public static Map<String, Object> getNodeTemplateProperties(ServiceTemplate serviceTemplate,
1177 String nodeTemplateId) {
1178 mdcDataDebugMessage.debugEntryMessage(null);
1180 if (serviceTemplate == null
1181 || serviceTemplate.getTopology_template() == null
1182 || serviceTemplate.getTopology_template().getNode_templates() == null
1183 || serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId) == null) {
1187 mdcDataDebugMessage.debugExitMessage(null);
1188 return serviceTemplate.getTopology_template().getNode_templates().get(nodeTemplateId)
1193 * Gets substitution mappings in a service template.
1195 * @param serviceTemplate the service template
1196 * @return the substitution mappings
1198 public static SubstitutionMapping getSubstitutionMappings(ServiceTemplate serviceTemplate) {
1199 mdcDataDebugMessage.debugEntryMessage(null);
1201 if (serviceTemplate == null
1202 || serviceTemplate.getTopology_template() == null
1203 || serviceTemplate.getTopology_template().getSubstitution_mappings() == null) {
1207 mdcDataDebugMessage.debugExitMessage(null);
1208 return serviceTemplate.getTopology_template().getSubstitution_mappings();
1213 * Compare two requirement assignment objects for equality.
1215 * @param first the first requirement assignment object
1216 * @param second the second requirement assignment object
1217 * @return true if objects are equal and false otherwise
1219 public static boolean compareRequirementAssignment(RequirementAssignment first,
1220 RequirementAssignment second) {
1221 return (first.getCapability().equals(second.getCapability())
1222 && first.getNode().equals(second.getNode())
1223 && first.getRelationship().equals(second.getRelationship()));
1227 * Gets a deep copy clone of the input object.
1229 * @param <T> the type parameter
1230 * @param objectValue the object value
1231 * @param clazz the clazz
1232 * @return the cloned object
1234 public static <T> Object getClonedObject(Object objectValue, Class<T> clazz) {
1235 YamlUtil yamlUtil = new ToscaExtensionYamlUtil();
1236 Object clonedObjectValue;
1237 String objectToYaml = yamlUtil.objectToYaml(objectValue);
1238 clonedObjectValue = yamlUtil.yamlToObject(objectToYaml, clazz);
1239 return clonedObjectValue;
1243 * Gets a deep copy clone of the input object.
1245 * @param obj the object to be cloned
1246 * @return the cloned object
1248 public static Object getClonedObject(Object obj) {
1249 Object clonedObjectValue;
1252 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
1253 ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
1254 objectOutputStream.writeObject(obj);
1255 //Deserialize object
1256 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream
1258 ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
1259 clonedObjectValue = objectInputStream.readObject();
1260 } catch (NotSerializableException ex) {
1261 logger.debug(ex.getMessage(), ex);
1262 return getClonedObject(obj, obj.getClass());
1263 } catch (IOException | ClassNotFoundException ex) {
1264 logger.debug(ex.getMessage(), ex);
1267 return clonedObjectValue;
1271 * Add substitution filtering property.
1273 * @param templateName the substitution service template name
1274 * @param nodeTemplate the node template
1275 * @param count the count
1277 public static void addSubstitutionFilteringProperty(String templateName,
1278 NodeTemplate nodeTemplate, int count) {
1279 Map<String, Object> serviceTemplateFilterPropertyValue = new HashMap<>();
1280 Map<String, Object> properties = nodeTemplate.getProperties();
1281 serviceTemplateFilterPropertyValue.put(ToscaConstants
1282 .SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, templateName);
1283 serviceTemplateFilterPropertyValue.put(ToscaConstants.COUNT_PROPERTY_NAME, count);
1284 properties.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME,
1285 serviceTemplateFilterPropertyValue);
1286 nodeTemplate.setProperties(properties);
1290 * Adding binding requirement from port node template to compute node template.
1292 * @param computeNodeTemplateId compute node template id
1293 * @param portNodeTemplate port node template
1295 public static void addBindingReqFromPortToCompute(String computeNodeTemplateId,
1296 NodeTemplate portNodeTemplate) {
1299 mdcDataDebugMessage.debugEntryMessage(null);
1300 RequirementAssignment requirementAssignment = new RequirementAssignment();
1301 requirementAssignment.setCapability(ToscaCapabilityType.NATIVE_NETWORK_BINDABLE);
1302 requirementAssignment.setRelationship(ToscaRelationshipType.NATIVE_NETWORK_BINDS_TO);
1303 requirementAssignment.setNode(computeNodeTemplateId);
1304 addRequirementAssignment(portNodeTemplate, ToscaConstants.BINDING_REQUIREMENT_ID,
1305 requirementAssignment);
1306 mdcDataDebugMessage.debugExitMessage(null);
1309 public static SubstitutionMapping createSubstitutionTemplateSubMapping(
1311 NodeType substitutionNodeType,
1312 Map<String, Map<String, List<String>>> mapping) {
1313 mdcDataDebugMessage.debugEntryMessage(null);
1314 SubstitutionMapping substitutionMapping = new SubstitutionMapping();
1315 substitutionMapping.setNode_type(nodeTypeKey);
1316 substitutionMapping.setCapabilities(
1317 manageCapabilityMapping(substitutionNodeType.getCapabilities(), mapping.get("capability")));
1318 substitutionMapping.setRequirements(
1319 manageRequirementMapping(substitutionNodeType.getRequirements(),
1320 mapping.get("requirement")));
1322 mdcDataDebugMessage.debugExitMessage(null);
1323 return substitutionMapping;
1327 * Add node template capability.
1329 * @param nodeTemplate the node template
1330 * @param capabilityId the capability id
1331 * @param capabilityProperties the capability properties
1332 * @param capabilityAttributes the capability attributes
1334 public static void addNodeTemplateCapability(NodeTemplate nodeTemplate, String capabilityId,
1335 Map<String, Object> capabilityProperties,
1336 Map<String, Object> capabilityAttributes) {
1337 List<Map<String, CapabilityAssignment>> capabilities = nodeTemplate.getCapabilities();
1338 if (Objects.isNull(capabilities)) {
1339 capabilities = new ArrayList<>();
1341 CapabilityAssignment capabilityAssignment = new CapabilityAssignment();
1342 capabilityAssignment.setProperties(capabilityProperties);
1343 capabilityAssignment.setAttributes(capabilityAttributes);
1344 Map<String, CapabilityAssignment> nodeTemplateCapability = new HashMap<>();
1345 nodeTemplateCapability.put(capabilityId, capabilityAssignment);
1346 capabilities.add(nodeTemplateCapability);
1347 nodeTemplate.setCapabilities(capabilities);
1350 private static Map<String, List<String>> manageRequirementMapping(
1351 List<Map<String, RequirementDefinition>> requirementList,
1352 Map<String, List<String>> requirementSubstitutionMapping) {
1353 mdcDataDebugMessage.debugEntryMessage(null);
1355 if (requirementList == null) {
1358 Map<String, List<String>> requirementMapping = new HashMap<>();
1359 String requirementKey;
1360 List<String> requirementMap;
1361 for (Map<String, RequirementDefinition> requirementDefMap : requirementList) {
1362 for (Map.Entry<String, RequirementDefinition> entry : requirementDefMap.entrySet()) {
1363 requirementKey = entry.getKey();
1364 requirementMap = requirementSubstitutionMapping.get(requirementKey);
1365 requirementMapping.put(requirementKey, requirementMap);
1369 mdcDataDebugMessage.debugExitMessage(null);
1370 return requirementMapping;
1373 private static Map<String, List<String>> manageCapabilityMapping(
1374 Map<String, CapabilityDefinition> capabilities,
1375 Map<String, List<String>> capabilitySubstitutionMapping) {
1376 mdcDataDebugMessage.debugEntryMessage(null);
1378 if (capabilities == null) {
1379 mdcDataDebugMessage.debugExitMessage(null);
1383 Map<String, List<String>> capabilityMapping = new HashMap<>();
1384 String capabilityKey;
1385 List<String> capabilityMap;
1386 for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) {
1387 capabilityKey = entry.getKey();
1388 capabilityMap = capabilitySubstitutionMapping.get(capabilityKey);
1389 capabilityMapping.put(capabilityKey, capabilityMap);
1392 mdcDataDebugMessage.debugExitMessage(null);
1393 return capabilityMapping;
1396 public static void addSubstitutionNodeTypeRequirements(NodeType substitutionNodeType,
1397 List<Map<String, RequirementDefinition>>
1399 String templateName) {
1400 mdcDataDebugMessage.debugEntryMessage(null);
1402 if (CollectionUtils.isEmpty(requirementsList)) {
1406 if (substitutionNodeType.getRequirements() == null) {
1407 substitutionNodeType.setRequirements(new ArrayList<>());
1410 for (Map<String, RequirementDefinition> requirementDef : requirementsList) {
1411 for (Map.Entry<String, RequirementDefinition> entry : requirementDef.entrySet()) {
1412 Map<String, RequirementDefinition> requirementMap = new HashMap<>();
1413 requirementMap.put(entry.getKey() + "_" + templateName, entry.getValue().clone());
1414 substitutionNodeType.getRequirements().add(requirementMap);
1418 mdcDataDebugMessage.debugExitMessage(null);
1421 public static boolean isNodeTemplateSectionMissingFromServiceTemplate(
1422 ServiceTemplate serviceTemplate) {
1423 return Objects.isNull(serviceTemplate.getTopology_template())
1424 || MapUtils.isEmpty(serviceTemplate.getTopology_template().getNode_templates());