Search in sources :

Example 1 with IncompatiblePropertyDefinitionException

use of alien4cloud.model.components.IncompatiblePropertyDefinitionException in project alien4cloud by alien4cloud.

the class EditorInputHelperService method getInputCandidates.

/**
 * Utility method to get the list of inputs (ids) that are compatible with the given property definition (no constraint conflicts)..
 *
 * @param topologyId The id of the topology for which to find input candidates.
 * @param nodeTemplateName The name of the node template for which to get input candidates.
 * @param propertyDefinitionGetter Implementation on how to get the property definition (from node properties, capabilities properties, relationships
 *            properties).
 * @return A list of input candidates that are compatible with the requested property definition.
 */
public List<String> getInputCandidates(String topologyId, String nodeTemplateName, IPropertyDefinitionGetter propertyDefinitionGetter) {
    try {
        editionContextManager.init(topologyId);
        // check authorization to update a topology
        topologyService.checkEditionAuthorizations(EditionContextManager.getTopology());
        Topology topology = EditionContextManager.getTopology();
        NodeTemplate nodeTemplate = topology.getNodeTemplates().get(nodeTemplateName);
        PropertyDefinition pd = propertyDefinitionGetter.get(nodeTemplate);
        if (pd == null) {
            throw new NotFoundException("Unexpected error, property definition cannot be found for node <" + nodeTemplateName + ">");
        }
        Map<String, PropertyDefinition> inputs = topology.getInputs();
        List<String> inputIds = new ArrayList<String>();
        if (inputs != null && !inputs.isEmpty()) {
            // iterate overs existing inputs and filter them by checking constraint compatibility
            for (Map.Entry<String, PropertyDefinition> inputEntry : inputs.entrySet()) {
                try {
                    inputEntry.getValue().checkIfCompatibleOrFail(pd);
                    inputIds.add(inputEntry.getKey());
                } catch (IncompatiblePropertyDefinitionException e) {
                // Nothing to do here, the id won't be added to the list
                }
            }
        }
        return inputIds;
    } finally {
        editionContextManager.destroy();
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ArrayList(java.util.ArrayList) NotFoundException(alien4cloud.exception.NotFoundException) Topology(org.alien4cloud.tosca.model.templates.Topology) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Map(java.util.Map) IncompatiblePropertyDefinitionException(alien4cloud.model.components.IncompatiblePropertyDefinitionException)

Aggregations

NotFoundException (alien4cloud.exception.NotFoundException)1 IncompatiblePropertyDefinitionException (alien4cloud.model.components.IncompatiblePropertyDefinitionException)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1