예제 #1
0
 public ForsmanHostHandler(NetworkInterfaceCard communicationModule, ContainerTable containerTable, ILoadManager loadManager, StrategyActionType currentActionType,
                           SimulationSize simulationSize) : base(communicationModule, containerTable, loadManager)
 {
     _currentActionType = currentActionType;
     SimulationSize     = simulationSize;
     MaxUtilization     = Global.OtherMaxUtilization;
     MinUtilization     = Global.OtherMinUtilization;
 }
 protected LocationStrategy(int auctionId, int owner, List <int> candidates, StrategyActionType actionType)
 {
     InstanceId    = auctionId;
     Owner         = owner;
     ActionType    = actionType;
     ExpectedBids  = candidates.Count;
     _remaningBids = candidates.Count;
     _candidates   = candidates;
 }
예제 #3
0
        public InOrderProping(int auctionId, int owner, List <int> candidates, StrategyActionType actionType, ContainerLoadInfo loadInfo)
            : base(auctionId, owner, candidates, actionType)
        {
            if (actionType == StrategyActionType.PullAction && ContainerLoadInfo != null)
            {
                throw new NotImplementedException();
            }

            ContainerLoadInfo = loadInfo;
        }
예제 #4
0
        /// <summary>
        /// Should Be Optimized for the reasons to add new host or remove one
        /// </summary>
        /// <param name="hostId"></param>
        /// <param name="atype"></param>
        protected void InitiateRejectAction(int hostId, StrategyActionType atype)
        {
            var action = RejectActions.Nothing;

            switch (atype)
            {
            case StrategyActionType.PushAction:
                if (DataHolder.GetUtilization(hostId) == UtilizationStates.UnderUtilization ||
                    DataHolder.GetUtilization(hostId) == UtilizationStates.Normal)
                {
                    //throw new NotImplementedException("How come");
                    action = RejectActions.TestWalid;
                }
                else if (DataHolder.GetUtilization(hostId) == UtilizationStates.Evacuating)
                {
                    action = RejectActions.CancelEvacuation;
                    //UpdateSate(hostId, UtilizationStates.UnderUtilization,"Master");
                    DataHolder.SetUtilization(hostId, UtilizationStates.UnderUtilization);
                }
                else if (DataHolder.GetCandidateHosts(UtilizationStates.UnderUtilization, hostId).Count == 0 &&
                         DataHolder.GetCandidateHosts(UtilizationStates.Evacuating, hostId).Count == 0)
                {
                    PowerController.PowerOnHost();
                }
                else
                {
                    //Should I cancell all evacuations
                }
                break;

            case StrategyActionType.PullAction:
                //Evacuate Host

                if (DataHolder.GetCandidateHosts(UtilizationStates.OverUtilization, hostId).Count == 0)
                {
                    action = RejectActions.Evacuate;
                    //UpdateSate(hostId, UtilizationStates.Evacuating, "Master");
                    DataHolder.SetUtilization(hostId, UtilizationStates.Evacuating);
                    //evacuating.Add(hostId, DateTime.Now);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            RejectRequest request = new RejectRequest(hostId, this.MachineId, atype, action);

            CommunicationModule.SendMessage(request);
        }
예제 #5
0
 public LeastFullAuction(int auctionId, int auctionOwner, List <int> candidates, StrategyActionType strategyActionType)
     : base(auctionId, auctionOwner, candidates, strategyActionType)
 {
 }
예제 #6
0
 public LeastPullsAuction(int instanceId, int owner, List <int> candidates, StrategyActionType actionType)
     : base(instanceId, owner, candidates, actionType)
 {
 }
예제 #7
0
        /// <summary>
        /// Should Be Optimized for the reasons to add new host or remove one
        /// </summary>
        /// <param name="hostId"></param>
        /// <param name="atype"></param>
        protected void InitiateRejectAction(int hostId, StrategyActionType atype)
        {
            //Implement Conditions for How to Add New Nodes or Remove
            //Implement Add Host and Evacuation System Locks
            var action = RejectActions.Nothing;

            switch (atype)
            {
            case StrategyActionType.PushAction:
                //Create New Host
                //if (hostId != EvacuatingHost)
                //if (EvacuatingHost == 0)

                if (EvacuatingHosts.Count == 0)
                {
                    //if (_pushFailures > Global.GetNoOfFailures)
                    if (!DataHolder.GetCandidateHosts(UtilizationStates.UnderUtilization, 0).Any())
                    {
                        PowerController.PowerOnHost();
                    }
                    //_pushFailures = 0;

                    //else
                    //{
                    //    //_pushFailures++;
                    //}
                }
                //else if (hostId == EvacuatingHost)
                else if (EvacuatingHosts.Contains(hostId))
                {
                    action = RejectActions.CancelEvacuation;
                    Console.WriteLine($"Cancel Evacuation for {hostId}");
                    //EvacuatingHost = 0;
                    EvacuatingHosts.Remove(hostId);
                    DataHolder.SetUtilization(hostId, UtilizationStates.UnderUtilization);
                }
                else
                {
                    //throw new Exception("Evacuting Host with Push Request, What to Do");
                    //Options (Cancel Evacuation Mode @All Hosts)
                    foreach (var ehost in EvacuatingHosts)
                    {
                        DataHolder.SetUtilization(ehost, UtilizationStates.UnderUtilization);
                        var cem = new CancelEvacuation(ehost, this.MachineId);
                        CommunicationModule.SendMessage(cem);
                    }
                    EvacuatingHosts.Clear();
                }
                break;

            case StrategyActionType.PullAction:
                //Evacuate Host
                if (EvacuatingHosts.Contains(hostId))
                {
                    throw new NotImplementedException();
                }
                if (    //(EvacuatingHost == 0 &&
                    !DataHolder.GetCandidateHosts(UtilizationStates.OverUtilization, 0).Any())
                {
                    DataHolder.SetUtilization(hostId, UtilizationStates.Evacuating);
                    //EvacuatingHost = hostId;
                    EvacuatingHosts.Add(hostId);
                    if (EvacuatingHosts.Count > 1)
                    {
                    }
                    action = RejectActions.Evacuate;
                    Console.WriteLine($"Start Evacuation for {hostId}");
                }
                //else if (hostId == EvacuatingHost)
                //{
                //    throw new NotImplementedException();
                //}

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            RejectRequest request = new RejectRequest(hostId, this.MachineId, atype, action);

            CommunicationModule.SendMessage(request);
        }
예제 #8
0
 public RejectRequest(int target, int sender, StrategyActionType type, RejectActions action) : base(target, sender, MessageTypes.RejectRequest)
 {
     Auctiontype  = type;
     RejectAction = action;
 }
예제 #9
0
        private Auction CreateAuctionInstance(AuctionTypes auctionType, int auctionOwner, List <int> candidates, StrategyActionType strategyActionType)
        {
            int instanceId = Helpers.RandomNumberGenerator.GetInstanceRandomNumber();

            switch (auctionType)
            {
            case AuctionTypes.MostFull:
                return(new MostFullAuction(instanceId, auctionOwner, candidates, strategyActionType));

            case AuctionTypes.LeastFull:
                return(new LeastFullAuction(instanceId, auctionOwner, candidates, strategyActionType));

            case AuctionTypes.Random:
                return(new RandomAuction(instanceId, auctionOwner, candidates, strategyActionType));

            case AuctionTypes.LeastPulls:
                return(new LeastPullsAuction(instanceId, auctionOwner, candidates, strategyActionType));

            //case AuctionTypes.MaxEntropy:
            //    break;
            //case AuctionTypes.LeastEnergy:
            //    break;
            default:
                throw new ArgumentOutOfRangeException("auctionType");
            }
        }