Esempio n. 1
0
        private FabricTestAction GetMoveSecondaryReplicaAction(MoveSecondaryReplicaStateTransitionAction ragAction)
        {
            Requires.Argument("moveSecondaryReplicaStateTransitionAction", ragAction).NotNull();

            Uri    serviceUri      = ragAction.ServiceUri;
            Guid   guid            = ragAction.PartitionId;
            string currentNodeName = ragAction.NodeFrom;
            string newNodeName     = ragAction.NodeTo;

            string report = StringHelper.Format(
                "Generating Action: {0}\n\t\tService: {1}\n\t\tPartition: {2}\n\t\tFrom: {3} To: {4}",
                ragAction.ActionType,
                serviceUri,
                guid,
                currentNodeName,
                newNodeName);

            Log.WriteInfo(TraceType, report);
            if (this.reportFunction != null)
            {
                this.reportFunction(report);
            }

            var partitionSelector = PartitionSelector.PartitionIdOf(serviceUri, guid);

            return(new MoveSecondaryAction(currentNodeName, newNodeName, partitionSelector, ragAction.ForceMove));
        }
        private StateTransitionAction GenerateOneMoveSecondaryAction(Guid activityId = default(Guid))
        {
            var availableSecondaryReplicas = this.stateSnapshot.GetFaultableReplicas(true /*IsStateful*/).Where(r => this.SelectReadySecondary(r));

            if (availableSecondaryReplicas.Count() <= 0)
            {
                return(null);
            }

            var secondaryChosen      = availableSecondaryReplicas.ElementAt(this.Random.Next(availableSecondaryReplicas.Count()));
            var partitionEntities    = secondaryChosen.ParentPartitionEntity.ReplicaList.Select <ReplicaEntity, string>(r => r.Replica.NodeName);
            var availableNodesToMove = this.stateSnapshot.GetFaultableNodes().Where(n => !partitionEntities.Contains(n.CurrentNodeInfo.NodeName));

            if (availableNodesToMove.Count() <= 0)
            {
                return(null);
            }

            var newSecondaryNode = availableNodesToMove.ElementAt(this.Random.Next(availableNodesToMove.Count()));

            TestabilityTrace.TraceSource.WriteInfo(
                this.TraceType,
                "{0}: Replica '{1}' has been chosen for MoveSecondary to '{2}'.",
                activityId,
                secondaryChosen,
                newSecondaryNode.CurrentNodeInfo.NodeName);

            secondaryChosen.MoveReplica(newSecondaryNode.CurrentNodeInfo.NodeName, activityId);

            var replicaAction = new MoveSecondaryReplicaStateTransitionAction(
                secondaryChosen.ParentPartitionEntity.ParentServiceEntity.ServiceName(),
                secondaryChosen.ParentPartitionEntity.Guid,
                secondaryChosen.Replica.NodeName,
                newSecondaryNode.CurrentNodeInfo.NodeName,
                this.stateSnapshot.ClusterSnapshotId);

            return(replicaAction);
        }