예제 #1
0
 public DrivenNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     visualNotificationDeferrals = 0;
     visualsNeedNotification = false;
     handlingLongMessage = false;
 }
예제 #2
0
 public void Add(NodeDefinition nd)
 {
     if (NodeDefinitions != null)
     {
         NodeDefinitions.Add(nd);
     }
 }
예제 #3
0
        /// <summary>
        /// Generates the PowerDNS Recursor hosts file for a node.  This will be uploaded
        /// to <b>/etc/powerdns/hosts</b>.
        /// </summary>
        /// <param name="hiveDefinition">The hive definition.</param>
        /// <param name="nodeDefinition">The target node definition.</param>
        /// <returns>The host definitions.</returns>
        private static string GetPowerDnsHosts(HiveDefinition hiveDefinition, NodeDefinition nodeDefinition)
        {
            var sbHosts = new StringBuilder();

            sbHosts.AppendLineLinux("# PowerDNS Recursor authoritatively answers for [*.HIVENAME.nhive.io] hostnames.");
            sbHosts.AppendLineLinux("# on the local node using these mappings.");

            sbHosts.AppendLineLinux();
            sbHosts.AppendLineLinux("# Internal hive Consul mappings:");
            sbHosts.AppendLineLinux();

            sbHosts.AppendLineLinux($"{GetHostsFormattedAddress(nodeDefinition)} {hiveDefinition.Hostnames.Consul}");

            foreach (var manager in hiveDefinition.Managers)
            {
                sbHosts.AppendLineLinux($"{GetHostsFormattedAddress(manager)} {manager.Name}.{hiveDefinition.Hostnames.Consul}");
            }

            sbHosts.AppendLineLinux();
            sbHosts.AppendLineLinux("# Internal hive Vault mappings:");
            sbHosts.AppendLineLinux();
            sbHosts.AppendLineLinux($"{GetHostsFormattedAddress(nodeDefinition)} {hiveDefinition.Hostnames.Vault}");

            foreach (var manager in hiveDefinition.Managers)
            {
                sbHosts.AppendLineLinux($"{GetHostsFormattedAddress(manager)} {manager.Name}.{hiveDefinition.Hostnames.Vault}");
            }

            if (hiveDefinition.Docker.RegistryCache)
            {
                sbHosts.AppendLineLinux();
                sbHosts.AppendLineLinux("# Internal hive registry cache related mappings:");
                sbHosts.AppendLineLinux();

                foreach (var manager in hiveDefinition.Managers)
                {
                    sbHosts.AppendLineLinux($"{GetHostsFormattedAddress(manager)} {manager.Name}.{hiveDefinition.Hostnames.RegistryCache}");
                }
            }

            if (hiveDefinition.Log.Enabled)
            {
                sbHosts.AppendLineLinux();
                sbHosts.AppendLineLinux("# Internal hive log pipeline related mappings:");
                sbHosts.AppendLineLinux();

                sbHosts.AppendLineLinux($"{GetHostsFormattedAddress(nodeDefinition)} {hiveDefinition.Hostnames.LogEsData}");
            }

            sbHosts.AppendLineLinux();
            sbHosts.AppendLineLinux("# Internal hive RabbitMQ related mappings:");
            sbHosts.AppendLineLinux();

            foreach (var node in hiveDefinition.SortedNodes.Where(n => n.Labels.HiveMQ))
            {
                sbHosts.AppendLineLinux($"{GetHostsFormattedAddress(node)} {node.Name}.{hiveDefinition.Hostnames.HiveMQ}");
            }

            return(sbHosts.ToString());
        }
예제 #4
0
        /// <summary>
        /// Map the implementations of an alias to a tree-defintion builder.
        /// </summary>
        /// <remarks>
        /// If nodes do not yet exist in the builder they are pushed, otherwise this will verify that
        /// the existing nodes match the fields of the new types.
        /// </remarks>
        /// <param name="builder">Builder to push the node definitions to</param>
        /// <param name="context">Context object with dependencies for the mapping</param>
        /// <param name="alias">Alias whose nodes to map</param>
        /// <exception cref="Exceptions.MissingTypeException">
        /// Thrown when a type for a node of the alias cannot be found in the context.
        /// </exception>
        /// <exception cref="Exceptions.DuplicateNodeException">
        /// Thrown when a node with the same identifier is already pushed but fields do not match.
        /// </exception>
        /// <returns>Definitions that the alias types are mapped to</returns>
        public static NodeDefinition[] MapNodes(
            this TreeDefinitionBuilder builder,
            Context context,
            AliasDefinition alias)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (alias == null)
            {
                throw new ArgumentNullException(nameof(alias));
            }

            var nodes = new NodeDefinition[alias.Values.Length];

            for (int i = 0; i < nodes.Length; i++)
            {
                var identifier = alias.Values[i];
                if (!context.Types.TryGetType(identifier, out var nodeType))
                {
                    throw new Exceptions.MissingTypeException(identifier);
                }

                nodes[i] = MapNode(builder, context, nodeType);
            }

            return(nodes);
        }
예제 #5
0
        /// <summary>
        /// Connects to the specified controller.
        /// </summary>
        /// <param name="def">The controller to connect to.</param>
        /// <returns>True if the connection failed or return a JoinSuccess, false if it returned a JoinFailure.</returns>
        private bool ConnectToController(NodeDefinition def)
        {
            Message message = new Message(def, new JoinAttempt(NodeType.Query, _settings.NodeName, _settings.Port, _settings.ToString()), true)
            {
                SendWithoutConfirmation = true
            };

            SendMessage(message);
            message.BlockUntilDone();

            if (message.Success)
            {
                if (message.Response.Data is JoinFailure)
                {
                    Logger.Log("Failed to join controllers: " + ((JoinFailure)message.Response.Data).Reason, LogLevel.Error);
                    AfterStop();
                    return(false);
                }

                // success
                JoinSuccess successData = (JoinSuccess)message.Response.Data;
                Connections[def].ConnectionEstablished(def, NodeType.Controller);
                if (successData.Data["PrimaryController"].ValueAsBoolean)
                {
                    Logger.Log("Setting the primary controller to " + message.Address.ConnectionName, LogLevel.Info);
                    Primary = message.Address;
                }

                SendMessage(new Message(message.Response, new Acknowledgement(), false));
            }

            return(true);
        }
예제 #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="nodeDefinition">NodeDefinition</param>
        /// <param name="nodeConfiguration">NodeConfiguration</param>
        public NodeViewModel(NodeDefinition nodeDefinition, NodeConfiguration nodeConfiguration)
        {
            this.nodeDefinition    = nodeDefinition;
            this.nodeConfiguration = nodeConfiguration;

            FlowPins      = new ObservableCollection <FlowConnectorViewModel>();
            DataPins      = new ObservableCollection <DataConnectorViewModel>();
            defaultValues = new ObservableCollection <DataPinDefaultValueViewModel>();

            FillPins();

            foreach (var inPin in DataPins.Where(x => x.PinDirection == PinDirectionDefinition.In))
            {
                // Skip if array

                var configuration = new NodePinConfiguration
                {
                    Name         = inPin.Name,
                    DefaultValue = nodeConfiguration.Pins.FirstOrDefault(x => x.Name == inPin.Name)?.DefaultValue
                };

                defaultValues.Add(new DataPinDefaultValueViewModel(configuration, inPin.DisplayName)
                {
                    Parent = this
                });
            }

            if (nodeConfiguration == null)
            {
                nodeConfiguration = new NodeConfiguration();
            }
        }
        /// <summary>
        /// Add an node to the scheme.
        /// </summary>
        /// <remarks>Identifier has to be unique across all nodes.</remarks>
        /// <exception cref="Exceptions.DuplicateNodeTypeException">
        /// Thrown when node-type is not unique.
        /// </exception>
        /// <param name="typeIdentifier">Identifier of the node-type</param>
        /// <param name="build">Callback to add content to the node</param>
        /// <returns>Newly created definition</returns>
        public NodeDefinition PushNode(string typeIdentifier, Action <NodeDefinitionBuilder> build = null)
        {
            if (string.IsNullOrEmpty(typeIdentifier))
            {
                throw new ArgumentException($"Invalid type-identifier: '{typeIdentifier}'", nameof(typeIdentifier));
            }

            // Verify that node-types are unique
            if (this.nodes.Any(n => n.Type == typeIdentifier))
            {
                throw new Exceptions.DuplicateNodeTypeException(typeIdentifier);
            }

            NodeDefinition definition;

            if (build == null)
            {
                definition = new NodeDefinition(typeIdentifier, comment: null, ImmutableArray <INodeField> .Empty);
            }
            else
            {
                var builder = new NodeDefinitionBuilder(typeIdentifier);
                build(builder);
                definition = builder.Build();
            }

            this.nodes.Add(definition);
            return(definition);
        }
예제 #8
0
        public bool FindPath(List <NodeDefinition> nodeDefinitions, NodeDefinition currentNode, List <List <string> > Paths, List <string> path)
        {
            // If node exists then loop is detected
            if (path.Contains(currentNode.Name))
            {
                return(false);
            }

            // Add current node
            path.Add(currentNode.Name);

            // Output probe reached
            if (currentNode.Outputs == null || currentNode.Outputs.Count == 0)
            {
                Paths.Add(path);
                return(true);
            }

            // Loop find path for all outputs
            foreach (string nodeOutput in currentNode.Outputs)
            {
                NodeDefinition nextNode = nodeDefinitions.FirstOrDefault(def => def.Name == nodeOutput);
                if (nextNode != null)
                {
                    List <string> tempPath = new List <string>(path);
                    bool          valid    = FindPath(nodeDefinitions, nextNode, Paths, tempPath);
                    if (!valid)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
예제 #9
0
        public Circuit Build(List <NodeDefinition> nodeDefinitions)
        {
            _logger.Log("Building circuit...");

            ObservableCollection <INode> nodes = new ObservableCollection <INode>();

            nodeDefinitions.ForEach(nodeDefinition =>
            {
                nodes.Add(_nodeFactory.CreateNode(nodeDefinition));
            });

            foreach (INode node in nodes)
            {
                NodeDefinition nodeDefinition = nodeDefinitions.FirstOrDefault(tempNodeDefinition => tempNodeDefinition.Name.Equals(node.Name));

                if (nodeDefinition != null)
                {
                    nodeDefinition.Inputs.ForEach(inputName =>
                    {
                        node.ConnectInput(nodes.FirstOrDefault(inputNode => inputNode.Name.Equals(inputName)));
                    });

                    nodeDefinition.Outputs.ForEach(outputName =>
                    {
                        node.ConnectOutput(nodes.FirstOrDefault(outputNode => outputNode.Name.Equals(outputName)));
                    });
                }
            }

            _logger.LogSuccess("Circuit building successful");

            return(new Circuit(nodes));
        }
예제 #10
0
        public void ThreeRowsSimple()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var counterWrapper = new TestCounterWrapper();
            var nodeRegistry   = new NodeRegistry <string>();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{counterWrapper.Counter++}";
                }
                else
                {
                    p.Stop();
                }
            }), definitionA));
            nodeRegistry.Register("B",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "BBB"; }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner  = new DataNodeRunner <string>(provider, nodeRegistry);
            var wrapper = new DataItemWrapper <string>();

            runner.Step(wrapper);
            Assert.AreEqual("AAA0BBBCCC", wrapper.Item);
            runner.Step(wrapper);
            Assert.AreEqual("AAA1BBBCCC", wrapper.Item);
            runner.Step(wrapper);
            Assert.AreEqual("AAA2BBBCCC", wrapper.Item);
        }
예제 #11
0
        public void CreateNodeFromDefinitionTest()
        {
            var def  = new NodeDefinition("id", "OR");
            var node = this.nodeFactory.CreateNode(def);

            Assert.Equal("id", node.NodeId);
            Assert.IsType <OrNode>(node);
        }
예제 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkTransfer"/> class.
        /// </summary>
        /// <param name="data">The data to read from.</param>
        /// <param name="index">The index at which to start reading from.</param>
        internal ChunkTransfer(byte[] data, int index)
        {
            string node = ByteArrayHelper.ToString(data, ref index);

            _node  = new NodeDefinition(node.Split(':')[0], int.Parse(node.Split(':')[1]));
            _start = ChunkMarker.ConvertFromString(ByteArrayHelper.ToString(data, ref index));
            _end   = ChunkMarker.ConvertFromString(ByteArrayHelper.ToString(data, ref index));
        }
예제 #13
0
 public SelectionNode(NodeDefinition nd, Network net, int instnc, bool alwaysEnlistOutputs)
     : base(nd, net, instnc)
 {
     optionCount = 0;
     this.alwaysEnlistOutputs = alwaysEnlistOutputs;
     deferNewOptionInstallation = new DeferrableAction(
         SelectionNode.InstallNewOptions, this);
 }
예제 #14
0
 public Type GetRegisteredNodeType(NodeDefinition nodeDefinition)
 {
     if (IsNodeRegistered(nodeDefinition.Type))
     {
         return(RegisteredNodes[nodeDefinition.Type]);
     }
     return(null);
 }
예제 #15
0
 /// <inheritdoc />
 protected override void ConnectionLost(NodeDefinition node, NodeType type)
 {
     if (Equals(Primary, node))
     {
         Primary = null;
         Logger.Log("Primary controller unreachable.", LogLevel.Info);
     }
 }
예제 #16
0
        public void ThreeRowsSimpleRunAllNodesMustBeDisposed()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var counterWrapper = new TestCounterWrapper();
            var nodeRegistry   = new NodeRegistry <string>();
            var a = new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{counterWrapper.Counter++}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            });
            var b = new TestActionProcess(p => { p.Item = p.Item += "BBB"; });
            var c = new TestActionProcess(p => { p.Item = p.Item += "CCC"; });

            nodeRegistry.Register("A", new BaseNode <string>(a, definitionA));
            nodeRegistry.Register("B", new BaseNode <string>(b, definitionB));
            nodeRegistry.Register("C", new BaseNode <string>(c, definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            runner.Dispose();
            Assert.IsTrue(a.IsDisposed);
            Assert.IsTrue(b.IsDisposed);
            Assert.IsTrue(c.IsDisposed);
        }
예제 #17
0
 public NodeDescriptor(
     IDescriptorContext context,
     NodeDefinition definition,
     Func <IObjectFieldDescriptor> configureNodeField)
 {
     Context             = context;
     Definition          = definition;
     _configureNodeField = configureNodeField;
 }
예제 #18
0
        public ESNode(NodeDefinition nodeDefinition)
        {
            Enabled = nodeDefinition.Enabled;
            Host    = nodeDefinition.Host;
            Port    = nodeDefinition.Port;
//			Framed = nodeDefinition.IsFramed;
            DangerZoneThreshold = nodeDefinition.DangerZoneThreshold;
            DangerZoneSeconds   = nodeDefinition.DangerZoneSeconds;
            ConnectionProvider  = new ConnectionPool(nodeDefinition.Host, nodeDefinition.Port, nodeDefinition.ConnectionPool ?? ElasticSearchConfig.Instance.ConnectionPool, nodeDefinition.IsFramed);
        }
예제 #19
0
        public INode CreateNode(NodeDefinition nodeDefinition)
        {
            if (IsNodeRegistered(nodeDefinition.Type) && Activator.CreateInstance(RegisteredNodes[nodeDefinition.Type]) is INode node)
            {
                node.Init(nodeDefinition.Name, nodeDefinition.Inputs.Count, nodeDefinition.Outputs.Count);
                return(node);
            }

            return(null);
        }
예제 #20
0
        public void CommitThrowsTest()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var nodeRegistry = new NodeRegistry <string>();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{p.Number}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            }, () => throw new Exception("Houston we have a problem")), definitionA));
            nodeRegistry.Register("B",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "BBB"; }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            var current = runner.Current;

            Assert.AreEqual(1, current.CommitExceptions.Count);
        }
예제 #21
0
        public Node MakeNewNode(NodeDefinition nodeDefinition)
        {
            var nNode = new Node
            {
                Guid           = new ShortGuid("NODE_" + (_nextNodeId++).ToSymbolString()),
                NodeDefinition = nodeDefinition
            };

            Nodes.Add(nNode.Guid, nNode);
            return(nNode);
        }
예제 #22
0
        public void CommitTest()
        {
            var definitionC = new NodeDefinition
            {
                Name      = "C",
                DependsOn = new List <string>
                {
                    "B"
                }
            };

            var definitionB = new NodeDefinition
            {
                Name      = "B",
                DependsOn = new List <string>
                {
                    "A"
                }
            };

            var definitionA = new NodeDefinition
            {
                Name = "A"
            };
            var nodeRegistry = new NodeRegistry <string>();
            var flag         = new TestFlag();

            nodeRegistry.Register("A", new BaseNode <string>(new TestActionProcess(p =>
            {
                if (p.Number < 3)
                {
                    p.Item = $"AAA{p.Number}";
                }
                if (p.Number == 2)
                {
                    p.Stop();
                }
            }, () => { flag.Flag = true; }), definitionA));
            nodeRegistry.Register("B",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "BBB"; }), definitionB));
            nodeRegistry.Register("C",
                                  new BaseNode <string>(new TestActionProcess(p => { p.Item = p.Item += "CCC"; }), definitionC));

            var provider = new NodeDefinitionProvider("C");

            provider.Register("C", definitionC);
            provider.Register("B", definitionB);
            provider.Register("A", definitionA);

            var runner = new DataNodeRunner <string>(provider, nodeRegistry);

            runner.Run();
            Assert.IsTrue(flag.Flag);
        }
예제 #23
0
        /// <inheritdoc />
        public override void Run()
        {
            BeforeStart();

            _controllerNodes = NodeDefinition.ParseConnectionString(_settings.ConnectionString);

            // Find yourself
            _self = null;
            foreach (var def in _controllerNodes)
            {
                if (def.IsSelf(_settings.Port))
                {
                    _self = def;
                    break;
                }
            }

            if (_self == null)
            {
                Logger.Log("Could not find myself in the connection string, shutting down.", LogLevel.Error);
                AfterStop();
                return;
            }

            // If you get a JoinFailure from any other node, stop because this node's settings are wrong.
            foreach (var def in _controllerNodes)
            {
                if (!Equals(def, Self) && !ConnectToController(def))
                {
                    AfterStop();
                    return;
                }
            }

            if (_controllerNodes.Count == 1)
            {
                Logger.Log("Only controller in the network, becoming primary.", LogLevel.Info);
                Primary = Self;
            }

            _reconnectionThread = new Thread(ReconnectionThreadRun);
            _reconnectionThread.Start();

            _maintenanceThread = new Thread(MaintenanceThreadRun);
            _maintenanceThread.Start();

            while (Running)
            {
                Thread.Sleep(1);
            }

            AfterStop();
        }
예제 #24
0
        private NodeDefinition Attach(NodeDefinition nodeDefinition)
        {
            if (_current != null)
            {
                nodeDefinition.DependsOn.Add(_current.Name);
            }

            _current = nodeDefinition;

            _nodeDefinitionProvider.SetRoot(nodeDefinition.Name);
            return(nodeDefinition);
        }
        private static JObject CreateNodeJsonObject(NodeDefinition node)
        {
            var obj = new JObject();

            obj["nodeType"] = node.Type;
            if (!string.IsNullOrEmpty(node.Comment))
            {
                obj["comment"] = node.Comment;
            }
            obj["fields"] = new JArray(node.Fields.Select(CreateFieldJsonObject).ToArray());
            return(obj);
        }
예제 #26
0
        /// <summary>
        /// Returns the IP address for a node suitable for including in the
        /// <b>/etc/hosts</b> file.
        /// </summary>
        /// <param name="nodeDefinition">The target node definition.</param>
        /// <returns>
        /// The IP address, left adjusted with necessary spaces so that the
        /// host definitions will align nicely.
        /// </returns>
        private static string GetHostsFormattedAddress(NodeDefinition nodeDefinition)
        {
            const string ip4Max = "255.255.255.255";

            var address = nodeDefinition.PrivateAddress.ToString();

            if (address.Length < ip4Max.Length)
            {
                address += new string(' ', ip4Max.Length - address.Length);
            }

            return(address);
        }
예제 #27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChunkListResponse"/> class.
        /// </summary>
        /// <param name="data">The data to read from.</param>
        /// <param name="index">The index at which to start reading from.</param>
        internal ChunkListResponse(byte[] data, int index)
        {
            _chunks = new List <ChunkDefinition>();
            string s = ByteArrayHelper.ToString(data, ref index);

            string[] defs = s.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (var item in defs)
            {
                string[]       def     = item.Split(',');
                NodeDefinition nodeDef = new NodeDefinition(def[2].Split(':')[0], int.Parse(def[2].Split(':')[1]));
                _chunks.Add(new ChunkDefinition(ChunkMarker.ConvertFromString(def[0]), ChunkMarker.ConvertFromString(def[1]), nodeDef));
            }
        }
예제 #28
0
        public DisplayNode(NodeDefinition nd, Network net, int instnc)
            : base(nd, net, instnc)
        {
            xpos = ypos = Utils.UnspecifiedPosition;
            width = height = Utils.UnspecifiedDimension;
            image = null;

            // It's makes no sense to even think about creating an image window
            // for a Display node in a macro.

            userSpecifiedWhere = net.IsMacro;
            title = null;
            panelAccessManager = null;
        }
예제 #29
0
        /// <inheritdoc />
        protected override void ConnectionLost(NodeDefinition node, NodeType type)
        {
            if (type == NodeType.Controller)
            {
                if (Equals(Primary, node))
                {
                    Logger.Log("Primary controller unreachable, searching for new primary.", LogLevel.Info);
                    Primary = null;
                }

                // start at 1 because GetConnectedNodes doesn't include the current node.
                var connectedNodes        = GetConnectedNodes();
                int controllerActiveCount = 1 + _controllerNodes.Count(def => connectedNodes.Any(e => Equals(e.Item1, def)));

                if (controllerActiveCount <= _controllerNodes.Count / 2)
                {
                    Logger.Log("Not enough connected nodes to remain primary.", LogLevel.Info);
                    Primary = null;
                }
            }
            else if (type == NodeType.Storage)
            {
                lock (_storageNodes)
                {
                    _storageNodes.RemoveAll(e => e.Item1.Equals(node));
                }

                lock (_chunkList)
                {
                    _chunkList.RemoveAll(e => Equals(e.Node, node));
                }

                lock (_balancingLockObject)
                {
                    if (Equals(node, _nodeManagingChunk))
                    {
                        _balancing         = BalancingState.None;
                        _nodeManagingChunk = null;
                    }

                    if (Equals(node, _nodeTransferingChunk))
                    {
                        _balancing            = BalancingState.None;
                        _nodeTransferingChunk = null;
                        _chunkBeingTransfered = null;
                        Logger.Log("Chunk transfer failed.", LogLevel.Info);
                    }
                }
            }
        }
예제 #30
0
        /// <summary>
        /// Gets a list of the chunks from the internal document.
        /// </summary>
        /// <returns>A list of the chunks from the internal document.</returns>
        private List <ChunkDefinition> GetList()
        {
            List <ChunkDefinition> returnValue = new List <ChunkDefinition>();

            for (int i = 0; i < _chunkList.Count; ++i)
            {
                var array = _chunkList[i.ToString()].ValueAsArray;
                var start = ChunkMarker.ConvertFromString(array[0].ValueAsString);
                var end   = ChunkMarker.ConvertFromString(array[1].ValueAsString);
                var node  = new NodeDefinition(array[2].ValueAsString.Split(':')[0], int.Parse(array[2].ValueAsString.Split(':')[1]));
                returnValue.Add(new ChunkDefinition(start, end, node));
            }

            return(returnValue);
        }
        public NodesViewModel(IBlueprintDefinitionsRegistry registry)
        {
            _allItems.AddRange(registry.GetAllDefinitions());

            _items = new CollectionViewSource
            {
                Source = _allItems
            };
            _items.GroupDescriptions.Add(new PropertyGroupDescription("NodeType"));
            _items.Filter += ItemsOnFilter;

            if (_items.View.MoveCurrentToFirst())
            {
                SelectedItem = _items.View.CurrentItem as NodeDefinition;
            }
        }
예제 #32
0
        public ScalarNode(NodeDefinition nd, Network net, int instnc /*, false, 1 */)
            : base(nd, net, instnc)
        {
            isContinuousUpdate = false;
            vectorType = false;
            numComponents = 1;
            rangeCheckDeferrals = 0;
            needsRangeCheck = false;

            if (verifyInputCount())
                return;

            AttributeParameter ap = (AttributeParameter) getInputParameter((int)Params.INCR);
            Debug.Assert(ap != null);
            ap.setSyncOnTypeMatch(false);
        }
예제 #33
0
        /// <inheritdoc />
        protected override void ConnectionLost(NodeDefinition node, NodeType type)
        {
            if (Equals(Primary, node))
            {
                Logger.Log("Primary controller unreachable.", LogLevel.Info);
                Primary = null;
            }

            lock (_connectedStorageNodes)
            {
                if (_connectedStorageNodes.Contains(node))
                {
                    _connectedStorageNodes.Remove(node);
                }
            }
        }
예제 #34
0
        /// <summary>
        /// Processes an update operation.
        /// </summary>
        /// <param name="dataOperation">The document that represents the operation.</param>
        /// <param name="message">The original message.</param>
        private void ProcessUpdateOperation(Document dataOperation, Message message)
        {
            UpdateOperation updateOperation = new UpdateOperation(dataOperation["update"].ValueAsDocument);

            if (!updateOperation.Valid)
            {
                SendMessage(new Message(message, updateOperation.ErrorMessage, false));
                return;
            }

            _chunkListLock.EnterReadLock();
            var chunk = _chunkList.SingleOrDefault(e => ChunkMarker.IsBetween(e.Start, e.End, updateOperation.DocumentId.ToString()));

            _chunkListLock.ExitReadLock();

            NodeDefinition node = chunk == null ? null : chunk.Node;

            if (node == null)
            {
                SendMessage(new Message(message, new DataOperationResult(ErrorCodes.FailedMessage, "No storage node up for the specified id range."), false));
                return;
            }

            Message operationMessage = new Message(node, message.Data, true);

            operationMessage.SetResponseCallback(delegate(Message originalOperationMessage)
            {
                if (originalOperationMessage.Success)
                {
                    DataOperationResult result = (DataOperationResult)originalOperationMessage.Response.Data;
                    Document resultDocument    = new Document(result.Result);
                    if (!resultDocument["success"].ValueAsBoolean && (ErrorCodes)Enum.Parse(typeof(ErrorCodes), resultDocument["errorcode"].ValueAsString) == ErrorCodes.ChunkMoved)
                    {
                        ProcessUpdateOperation(dataOperation, message);
                        return;
                    }

                    SendMessage(new Message(message, result, false));
                    return;
                }

                SendMessage(new Message(message, new DataOperationResult(ErrorCodes.FailedMessage, "Failed to send message to storage node."), false));
            });
            SendMessage(operationMessage);
        }
예제 #35
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="mdf"></param>
        /// <param name="module"></param>
        /// <returns>true if the module was added to the mdf dictionary</returns>
        public static bool FinishNodeDefinition(ref Dictionary<Symbol, NodeDefinition> mdf,
            ref NodeDefinition module)
        {
            Debug.Assert(mdf != null);
            Debug.Assert(module != null);

            Symbol nameSym = module.NameSymbol;

            if (module.Category != Symbol.zero ||
            (nameSym == NDAllocatorDictionary.GetNodeNameSymbol) ||
            (nameSym == NDAllocatorDictionary.SetNodeNameSymbol))
            {
                module.completeDefinition();
                mdf.Add(nameSym, module);
                return true;
            }
            else
                return false;
        }
예제 #36
0
 public ComputeNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     expression = "";
     exposedExpression = false;
 }
예제 #37
0
 public ProbeNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #38
0
        public static bool ParseOutboardLine(ref NodeDefinition module, String line,
            int lineNumber)
        {
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);

            line = line.Trim();
            List<String> toks = Utils.StringTokenizer(line, ";", null);
            if (toks.Count < 1)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Encountered an erroneous OUTBOARD specification on line {0}", lineNumber);
                return false;
            }
            module.OutboardCommand = toks[0];
            if (toks.Count > 1)
                module.DefaultOutboardHost = toks[1];

            return true;
        }
예제 #39
0
        public static bool ParseLoadableLine(ref NodeDefinition module, String line,
            int lineNumber)
        {
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);

            line = line.Trim();
            int sem = line.IndexOf(';');
            if (sem >= 0)
                line = line.Substring(0, sem);

            if (line.Length == 0)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Encountered an erroneous LOADABLE specification on line {0}.", lineNumber);
                return false;
            }
            module.DynamicLoadFile = line;
            return true;
        }
예제 #40
0
 public Node(NodeDefinition nd, Network net, int inst)
 {
     network = net;
     instanceNumber = inst;
     setDefinition(nd);
     vpe_xpos = vpe_ypos = 0;
     labelSymbol = Symbol.zero;
     standin = null;
     cdb = null;
     moduleMessageId = null;
     nodeCacheability = nd.DefaultCacheability;
     buildParameterLists();
     marked = false;
     layout_information = null;
 }
예제 #41
0
 public ValueListNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #42
0
        public ImageNode(NodeDefinition nd, Network net, int instnc)
            : base(nd, net, instnc)
        {
            initializeParams();
            ImageDefinition imnd = (ImageDefinition)nd;
            macroDirty = true;
            translating = false;

            // Anything below here also belongs in this->setDefaultCfgState().
            saveInteractionMode = DirectInteractionMode.NONE;
            internalCache = imnd.DefaultInternalCacheability;
        }
예제 #43
0
 public TransmitterNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #44
0
 public MacroParameterNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     index = -1;
 }
예제 #45
0
 //
 // Constructor:
 //
 public SequencerNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     throw new Exception("not implemented yet");
 }
예제 #46
0
 public ColormapNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     throw new Exception("Not Yet Implemented");
 }
예제 #47
0
 public ScalarListNode(NodeDefinition nd, Network net, int instnc,
     bool isvector, int dimensions)
     : base(nd, net, instnc, isvector, dimensions)
 {
 }
 public ModuleMessagingNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #49
0
 public MacroNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #50
0
 public FileSelectorNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #51
0
 public StreaklineNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     setInputValue(1, getModuleMessageIdString(), DXTypeVals.StringType, false);
 }
 public NondrivenInteractorNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #53
0
        public static bool ParseInputLine(Dictionary<Symbol, NodeDefinition> mdf,
            ref NodeDefinition module, String line, int lineNumber)
        {
            Debug.Assert(mdf != null);
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);
            ParameterDefinition input = null;
            Symbol symbol;

            List<String> toks = Utils.StringTokenizer(line, ";", new String[] { "" });

            if (toks.Count < 3)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Encountered an erroneous INPUT specification on line {0}.", lineNumber);
                return false;
            }

            // Parse the first substring: NAME and optional attributes
            String iname;
            int bracketStart = toks[0].IndexOf('[');
            if (bracketStart >= 0)
                iname = toks[0].Substring(0, bracketStart);
            else
                iname = toks[0];

            iname = iname.Trim();
            Regex rx = new Regex(@"^([a-zA-Z_]\w*)$");
            Match m = rx.Match(iname);
            if (!m.Success)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Invalid input name: {0} line {1}",
                    iname, lineNumber);
                return false;
            }

            symbol = SymbolManager.theSymbolManager.registerSymbol(iname);
            input = new ParameterDefinition(symbol);
            input.markAsInput();
            input.setDefaultVisibility();

            if (toks[0].Contains("["))
            {
                int begin_att = toks[0].IndexOf('[');
                int end_att = toks[0].Substring(begin_att).IndexOf(']');
                String atts = null;
                if (end_att > 0)
                    atts = toks[0].Substring(begin_att, end_att);
                if (atts != null)
                    if (!ParseParameterAttributes(ref input, atts))
                    {
                        ErrorDialog ed = new ErrorDialog();
                        ed.post("Unrecognized input attribute(s) ({0}) in MDF line {1}",
                            atts, lineNumber);
                        return false;
                    }
            }

            // Parse the second substring: TYPE.
            if (!ParseMDFTypes(ref input, toks[1], lineNumber))
                return false;

            // Parse the third substring:  DEFAULT VALUE.

            // If the value is equal to "(none)", then mark this parameter
            // as a required parameter.

            toks[2] = toks[2].Trim();
            if (toks[2].StartsWith("("))
            { // A descriptive value
                if (toks[2] == "(none)")
                    input.setRequired();
                else
                    input.setNotRequired();
                input.setDescriptiveValue(toks[2]);
            }
            else if (!input.setDefaultValue(toks[2]))
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Default value given on line {0} not one of given types.", lineNumber);
                return false;
            }

            // Add the fourth substring:  DESCRIPTION
            // Description can be blank
            if (toks.Count == 3)
                input.setDescription("");
            else
                input.setDescription(toks[3]);

            module.addInput(input);
            return true;
        }
예제 #54
0
 public ToggleNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     outputType = DXTypeVals.UndefinedType;
     is_set = false;
 }
예제 #55
0
        public static bool ParseOptionsLine(Dictionary<Symbol, NodeDefinition> mdf,
            ref NodeDefinition module, String line, int lineNumber)
        {
            Debug.Assert(mdf != null);
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);

            int inum = module.InputCount;

            // assumes we're working on the most recently added param.
            ParameterDefinition pd = module.getInputDefinition(inum);

            List<String> toks = Utils.StringTokenizer(line, ";", new string[] { "" });
            foreach (string tok in toks)
            {
                String tokt = tok.Trim();
                if (tokt.Length > 0)
                    pd.addValueOption(tokt);
            }
            return true;
        }
예제 #56
0
 public ShadowedOutputNode(NodeDefinition nd, Network net, int instc)
     : base(nd, net, instc)
 {
 }
예제 #57
0
        public static bool ParseOutputLine(Dictionary<Symbol, NodeDefinition> mdf,
            ref NodeDefinition module, String line, int lineNumber)
        {
            Debug.Assert(mdf != null);
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);

            Symbol symbol;
            ParameterDefinition output;

            List<String> toks = Utils.StringTokenizer(line, ";", new String[] { "" });

            if (toks.Count < 3)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Encountered an erroneous OUTPUT specification on line {0}.", lineNumber);
                return false;
            }

            // Parse the first substring: NAME and optional attributes
            String iname;
            int bracketStart = toks[0].IndexOf('[');
            if (bracketStart >= 0)
                iname = toks[0].Substring(0, bracketStart);
            else
                iname = toks[0];

            iname = iname.Trim();
            Regex rx = new Regex(@"^([a-zA-Z_][0-9a-zA-Z_]*)$");
            Match m = rx.Match(iname);
            if (!m.Success)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Invalid output name: {0} line {1}",
                    iname, lineNumber);
                return false;
            }

            symbol = SymbolManager.theSymbolManager.registerSymbol(iname);
            output = new ParameterDefinition(symbol);
            output.markAsOutput();
            output.setDefaultVisibility();

            if (toks[0].Contains("["))
            {
                int begin_att = toks[0].IndexOf('[');
                int end_att = toks[0].Substring(begin_att).IndexOf(']');
                String atts = null;
                if (end_att > 0)
                    atts = toks[0].Substring(begin_att, end_att);
                if (atts != null)
                    if (!ParseParameterAttributes(ref output, atts))
                    {
                        ErrorDialog ed = new ErrorDialog();
                        ed.post("Unrecognized input attribute(s) ({0}) in MDF line {1}",
                            atts, lineNumber);
                        return false;
                    }
            }

            // Parse the second substring: TYPE.
            if (!ParseMDFTypes(ref output, toks[1], lineNumber))
                return false;

            // Parse the third substring:  DESCRIPTION

            output.setDescription(toks[2]);

            module.addOutput(output);
            return true;
        }
예제 #58
0
 public ReceiverNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
 }
예제 #59
0
        private static bool ParseRepeatLine(Dictionary<Symbol, NodeDefinition> mdf,
            ref NodeDefinition module, String line, int lineNumber, StateConstants io_state)
        {
            Debug.Assert(mdf != null);
            Debug.Assert(module != null);
            Debug.Assert(line != null);
            Debug.Assert(lineNumber > 0);
            Debug.Assert(io_state == StateConstants.Input || io_state == StateConstants.Output);

            line = line.Trim();
            Regex rx = new Regex(@"^([0-9]+)$");
            Match m = rx.Match(line);
            if (!m.Success)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("Encountered error when expecting a repeat value on line {0}.",
                    lineNumber);
                return false;
            }

            int value = Int32.Parse(line);

            int cnt;
            String ioname;

            if (io_state == StateConstants.Input)
            {
                cnt = module.InputCount;
                ioname = "input";
                module.InputRepeatCount = value;
            }
            else
            {
                cnt = module.OutputCount;
                ioname = "output";
                module.OutputRepeatCount = value;
            }

            if (value > cnt)
            {
                ErrorDialog ed = new ErrorDialog();
                ed.post("The repeat value on line {0} is greater than the number of prior {1} paramaters.",
                    lineNumber, ioname);
                if (io_state == StateConstants.Input)
                    module.InputRepeatCount = 0;
                else
                    module.OutputRepeatCount = 0;
                return false;
            }
            return true;
        }
예제 #60
0
 public InteractorNode(NodeDefinition nd, Network net, int instnc)
     : base(nd, net, instnc)
 {
     numComponents = 1;
     lastInteractorLabel = null;
     java_variable = null;
 }