Search in sources :

Example 1 with InstanceRequiredPropertiesException

use of org.alien4cloud.alm.service.exceptions.InstanceRequiredPropertiesException in project alien4cloud by alien4cloud.

the class NodeInstanceService method checkRequired.

/**
 * Performs validation of the node instance. Note that based on the actual node state the validation is more or less strict.
 *
 * When the node state is initial the validation checks that all elements defined in the node template or node instance attributes matches the definition of
 * the node
 * type. It however does not check if the type has all required properties configured.
 *
 * When the node state is anything else the validation performs above validation and also checks that all required properties are defined.
 *
 * @param nodeType The node type against which to perform validation of the node instance.
 * @param nodeInstance The actual node instance to validate
 */
@ToscaContextual
public void checkRequired(NodeType nodeType, NodeInstance nodeInstance) {
    List<PropertiesTask> errors = Lists.newArrayList();
    topologyPropertiesValidationService.validateNodeTemplate(errors, nodeType, nodeInstance.getNodeTemplate(), "", false);
    if (!errors.isEmpty()) {
        Set<String> errorProperties = Sets.newHashSet();
        for (PropertiesTask task : errors) {
            for (List<String> properties : task.getProperties().values()) {
                errorProperties.addAll(properties);
            }
        }
        throw new InstanceRequiredPropertiesException("Some required properties are not defined.", errorProperties);
    }
}
Also used : InstanceRequiredPropertiesException(org.alien4cloud.alm.service.exceptions.InstanceRequiredPropertiesException) PropertiesTask(alien4cloud.topology.task.PropertiesTask) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Aggregations

PropertiesTask (alien4cloud.topology.task.PropertiesTask)1 ToscaContextual (alien4cloud.tosca.context.ToscaContextual)1 InstanceRequiredPropertiesException (org.alien4cloud.alm.service.exceptions.InstanceRequiredPropertiesException)1