Пример #1
0
 public override string ToString()
 {
     return(string.Format(
                "Node ({0:00}, {1:00}, {2}, {3})",
                Position.x,
                Position.y,
                Walkable ? "Walkable" : "Not Walkable",
                State == NodeState.None ? (Walkable ? "Openable" : "Wall") : State.ToString()
                ));
 }
Пример #2
0
        /// <summary>
        /// Returns a readable representation of the node, containing its state and id..
        /// </summary>
        /// <returns>String representation of the node.</returns>
        public override string ToString()
        {
            string state;

            if (NodeState == NodeState.Follower)
            {
                state = "Follower (of " + LeaderId + ")";
            }
            else
            {
                state = NodeState.ToString();
            }
            return("Node (" + NodeId + ") -- " + state);
        }
        /// <summary>
        /// Evaluates the pre and post conditions of the node.
        /// </summary>
        public static void EvaluateNode(IConditionalNode node)
        {
            //
            // Here is where we do the actual work of calling the
            // conditions.
            //
            // First, set the node into the FeatureCallContext so the
            // conditions can know
            //
            GuidanceCallContext.Current.DefaultConditionTarget = node as INode;

            //
            // Then, check the preconditions.
            // Note: We do not automatically set the result of
            // precondition calculation for Fork/Join/Decision/Merge
            // to enable them full latitude in state management
            //
            if (!EvaluateBindings(node.Preconditions))
            {
                //if (!(node is Fork) &&
                //    !(node is Join) &&
                //    !(node is Decision) &&
                //    !(node is Merge))
                if (TraceStateChanges &&
                    node.State != NodeState.Blocked)
                {
                    tracer.Verbose(Resources.GuidanceConditionsEvaluator_TraceBlockState,
                                   currentExtensionInstance.InstanceName,
                                   node.Name);
                }
                node.SetState(NodeState.Blocked, false);
            }
            else
            {
                NodeState postConditionsState = NodeState.Enabled;

                if (currentExtensionInstance != null)
                {
                    if ((currentExtensionInstance.GuidanceWorkflow != null) &&
                        ((GuidanceWorkflow)currentExtensionInstance.GuidanceWorkflow).IgnorePostConditions)
                    {
                        postConditionsState = NodeState.Enabled;
                    }
                    else
                    {
                        postConditionsState = EvaluateBindings(node.Postconditions) ? NodeState.Completed : NodeState.Enabled;
                    }
                }
                else if (GuidanceConditionsEvaluator.Current != null &&
                         GuidanceConditionsEvaluator.Current.guidanceManager != null &&
                         GuidanceConditionsEvaluator.Current.guidanceManager.ActiveGuidanceExtension != null)
                {
                    if ((GuidanceConditionsEvaluator.Current.guidanceManager.ActiveGuidanceExtension.GuidanceWorkflow != null) &&
                        ((GuidanceWorkflow)GuidanceConditionsEvaluator.Current.guidanceManager.ActiveGuidanceExtension.GuidanceWorkflow).IgnorePostConditions)
                    {
                        postConditionsState = NodeState.Enabled;
                    }
                    else
                    {
                        postConditionsState = EvaluateBindings(node.Postconditions) ? NodeState.Completed : NodeState.Enabled;
                    }
                }
                else
                {
                    postConditionsState = EvaluateBindings(node.Postconditions) ? NodeState.Completed : NodeState.Enabled;
                }

                //
                // Same rule for post condtions, let the "big guys"
                // calculate state for themselves
                //
                //if (!(node is Fork) &&
                //    !(node is Join) &&
                //    !(node is Decision) &&
                //    !(node is Merge))
                if (TraceStateChanges &&
                    node.State != postConditionsState)
                {
                    tracer.Verbose(Resources.GuidanceConditionsEvaluator_TraceStateToPostConditions + postConditionsState.ToString() + @" '{0}.{1}'.",
                                   currentExtensionInstance.InstanceName,
                                   node.Name);
                }
                node.SetState(postConditionsState, false);
            }
        }
Пример #4
0
        public void SetNodeRole(NodeState newState)
        {
            if (newState == NodeState.Candidate && !NodeOptions.EnableLeader)
            {
                Logger.LogWarning(NodeStateService.GetNodeLogId() + "Tried to promote to candidate but node has been disabled.");
                return;
            }

            if (newState != NodeStateService.Role)
            {
                Logger.LogInformation(NodeStateService.GetNodeLogId() + "Node's role changed to " + newState.ToString());
                NodeStateService.SetRole(newState);

                switch (newState)
                {
                case NodeState.Candidate:
                    ResetTimer(_electionTimeoutTimer, ClusterOptions.ElectionTimeoutMs, ClusterOptions.ElectionTimeoutMs);
                    StopTimer(_heartbeatTimer);
                    NodeStateService.InCluster = false;
                    if (NodeStateService.IsBootstrapped)
                    {
                        StartElection();
                    }
                    else
                    {
                        Logger.LogWarning("Node could not start election as bootstrapping was not complete");
                    }
                    break;

                case NodeState.Follower:
                    Random rand = new Random();
                    //On becoming a follower, wait 5 seconds to allow any other nodes to send out election time outs
                    ResetTimer(_electionTimeoutTimer, rand.Next(ClusterOptions.ElectionTimeoutMs, ClusterOptions.ElectionTimeoutMs * 2), ClusterOptions.ElectionTimeoutMs);
                    StopTimer(_heartbeatTimer);
                    TaskUtility.RestartTask(ref _commitTask, () => MonitorCommits());
                    break;

                case NodeState.Leader:
                    NodeStateService.CurrentLeader = _nodeStorage.Id;
                    NodeStateService.ResetLeaderState();
                    ResetTimer(_heartbeatTimer, 0, ClusterOptions.ElectionTimeoutMs / 4);
                    StopTimer(_electionTimeoutTimer);
                    TaskUtility.RestartTask(ref _commitTask, () => MonitorCommits());
                    NodeStateService.InCluster = true;
                    TaskUtility.RestartTask(ref _nodeDiscoveryTask, () => NodeDiscoveryLoop());
                    _clusterConnectionPool.CheckClusterConnectionPool();
                    break;

                case NodeState.Disabled:
                    StopTimer(_electionTimeoutTimer);
                    StopTimer(_heartbeatTimer);
                    break;
                }
            }
        }
 public CspPathFailure(NodeState currentState, string message = "Path Failed. You need to backtrack!") : base(
         message + $"state: {currentState.ToString()}")
 {
 }
Пример #6
0
 private void PeriodicCallback(object state)
 {
     SendBeat();
     Trace.WriteLine("SendBeat " + NodeState.ToString());
 }
Пример #7
0
 /*
  * NodeState
  */
 public static YarnProtos.NodeStateProto ConvertToProtoFormat(NodeState e)
 {
     return(YarnProtos.NodeStateProto.ValueOf(NodeStatePrefix + e.ToString()));
 }
Пример #8
0
 public virtual string ToS()
 {
     return(this.ToString() + ": " + m_nodeState.ToString());
 }
Пример #9
0
        /// <summary>
        /// Adds node to delta with recursive pass through node parents
        /// </summary>
        /// <param name="delta">Provider which will accept new nodes</param>
        /// <param name="nodeId">Node ID to add</param>
        /// <param name="nodeMapping">Mapping between (old ID)->(new ID)</param>
        private void AddNodeToAppendableTreeRecursive(DirectNodeProviderUnsafe <Guid, object, EdgeData> delta, Guid nodeId, Dictionary <Guid, Guid> nodeMapping, Dictionary <Guid, NodeState> nodeStates, IsolatedChangeSet <Guid, object, EdgeData> changeSet)
        {
            // Skip already added nodes
            if (!nodeMapping.ContainsKey(nodeId))
            {
                // Generate new ID
                Guid newId = Guid.NewGuid();
                // Check node state
                NodeState nodeState = NodeState.None;

                changeSet.NodeStates.TryGetValue(nodeId, out nodeState);

                switch (nodeState)
                {
                case NodeState.None:
                {
                    // Register in the mapping
                    nodeMapping.Add(nodeId, newId);
                    // Get undelrying node
                    var node = nodes.GetNode(nodeId, NodeAccess.Read);

                    var newNode = CloneNode(node);

                    // Set node to commited
                    newNode.Commited = true;

                    // Create edge to previous node
                    newNode.Previous = nodeId;

                    // New node is created which is copied from underlying provider
                    delta.SetNode(newId, newNode);

                    // This change is defined as modification
                    nodeStates.Add(newId, NodeState.Modified);

                    // Add node parents from the current snapshot
                    using (var enumerator = mutableParentProvider.ParentEdges(changeSet.SourceSnapshotId, nodeId))
                    {
                        if (enumerator != null)
                        {
                            while (enumerator.MoveNext())
                            {
                                AddNodeToAppendableTreeRecursive(delta, enumerator.Current.ToNodeId, nodeMapping, nodeStates, changeSet);
                            }
                        }
                    }

                    // Update parent nodes
                    UpdateParentNodes(newId, newNode, nodeState, delta, changeSet);
                }
                break;

                case NodeState.Created:
                {
                    // Read the node
                    var node = changeSet.Nodes.GetNode(nodeId, NodeAccess.ReadWrite);
                    // Set node to commited
                    node.Commited = true;
                    // There is no previous
                    node.Previous = Guid.Empty;
                    // Store to delta
                    delta.SetNode(nodeId, node);
                    // This change is defined as creation
                    nodeStates.Add(nodeId, NodeState.Created);

                    // Update parent nodes
                    UpdateParentNodes(nodeId, node, nodeState, delta, changeSet);
                }
                break;

                case NodeState.Modified:
                {
                    // Register in the mapping
                    nodeMapping.Add(nodeId, newId);
                    // Read the node
                    var node = changeSet.Nodes.GetNode(nodeId, NodeAccess.ReadWrite);
                    // Set node to commited
                    node.Commited = true;
                    // Set the previous
                    node.Previous = nodeId;
                    // Store to delta
                    delta.SetNode(newId, node);
                    // This change is defined as modification
                    nodeStates.Add(newId, NodeState.Modified);

                    // Add node parents from the current snapshot
                    using (var enumerator = mutableParentProvider.ParentEdges(changeSet.SourceSnapshotId, nodeId))
                    {
                        while (enumerator.MoveNext())
                        {
                            AddNodeToAppendableTreeRecursive(delta, enumerator.Current.ToNodeId, nodeMapping, nodeStates, changeSet);
                        }
                    }

                    // Update parent nodes
                    UpdateParentNodes(newId, node, nodeState, delta, changeSet);
                }
                break;

                case NodeState.Removed:
                {
                    // Update parent nodes
                    var node = GetNode(nodeId, changeSet);
                    UpdateParentNodes(nodeId, node, nodeState, delta, changeSet);
                }
                break;

                default:
                    throw new ArgumentException(nodeState.ToString());
                }
            }
        }