Esempio n. 1
0
        /// <summary>
        ///     Traverses node types starting from nodeTypeNameToStart, then to its requirements nodes types and so on
        /// </summary>
        /// <param name="nodeTypeNameToStart">Name of a node type to start the traversal</param>
        /// <param name="action">Action to be executed on each node type when visiting a node type</param>
        /// <exception cref="ToscaNodeTypeNotFoundException">Thrown when nodeTypeNameToStart is not found in NodeTypes dictionary.</exception>
        public void TraverseNodeTypesByRequirements(string nodeTypeNameToStart, Action <string, ToscaNodeType> action)
        {
            if (!NodeTypes.ContainsKey(nodeTypeNameToStart))
            {
                throw new ToscaNodeTypeNotFoundException(string.Format("Node type '{0}' not found", nodeTypeNameToStart));
            }
            var serviceArchiveWalker = new ToscaNodeTypeRequirementsGraph(this);

            serviceArchiveWalker.Walk(nodeTypeNameToStart, action);
        }
Esempio n. 2
0
        /// <summary>
        ///     Implements Validate method from <see cref="IValidatableObject" /> interface
        /// </summary>
        /// <param name="validationContext">Context the validation runs in</param>
        /// <returns>List of validation results if any</returns>
        IEnumerable <ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
        {
            var validationResults = new List <ValidationResult>();

            foreach (var nodeTypeKeyValue in NodeTypes)
            {
                nodeTypeKeyValue.Value.SetDerivedFromToRoot(nodeTypeKeyValue.Key);

                foreach (var requirementKeyValue in nodeTypeKeyValue.Value.Requirements.SelectMany(r => r).ToArray())
                {
                    if (!string.IsNullOrEmpty(requirementKeyValue.Value.Node) &&
                        !NodeTypes.ContainsKey(requirementKeyValue.Value.Node))
                    {
                        validationResults.Add(CreateRequirementValidationResult(requirementKeyValue, nodeTypeKeyValue));
                    }
                }

                foreach (var capabilityKeyValue in nodeTypeKeyValue.Value.Capabilities)
                {
                    if (!CapabilityTypes.ContainsKey(capabilityKeyValue.Value.Type))
                    {
                        validationResults.Add(CreateCapabilityTypeValidationResult(nodeTypeKeyValue.Key,
                                                                                   capabilityKeyValue.Value.Type, capabilityKeyValue.Key));
                    }
                }

                foreach (var complexDataTypeKeyValue in DataTypes)
                {
                    foreach (var basicDatatypeKeyValue in complexDataTypeKeyValue.Value.Properties)
                    {
                        var basicType = basicDatatypeKeyValue.Value.Type;
                        if (!DataTypes.ContainsKey(basicType))
                        {
                            validationResults.Add(new ValidationResult(
                                                      string.Format("Data type '{0}' specified as part of data type '{1}' not found.",
                                                                    basicType,
                                                                    complexDataTypeKeyValue.Key)));
                        }
                    }
                }

                var circularDependencyValidationResults = nodeTypeKeyValue.Value.ValidateCircularDependency().ToList();
                if (circularDependencyValidationResults.Any())
                {
                    return(validationResults.Concat(circularDependencyValidationResults));
                }
            }

            var importCircularValidationResults = ValidateImportsCircularDependency();

            if (importCircularValidationResults.Any())
            {
                return(validationResults.Concat(importCircularValidationResults));
            }

            if (!validationResults.Any())
            {
                var requirementsGraph = new ToscaNodeTypeRequirementsGraph(this);
                if (requirementsGraph.ContainsCyclicLoop())
                {
                    validationResults.Add(new ValidationResult("Circular dependency detected by requirements on node type"));
                }
            }
            return(validationResults);
        }