public override void HandleLoadAvailabilityResponce(LoadAvailabilityResponce message)
        {
            _currentAuction.AddBid(message.HostBid);
            if (!_currentAuction.OpenSession)
            {
                var winner = _currentAuction.GetWinnerBid();
                if (winner == null)
                {
                    Console.WriteLine($"\tMaster: No Winner ---------");

                    InitiateRejectAction(_currentAuction.Owner, _currentAuction.ActionType);
                }
                else
                {
                    Console.WriteLine($"\tMaster: Winner Is Host #{winner.BiddingHost}");
                    if (winner.Reason == BidReasons.ValidBid)
                    {
                    }
                    else if (winner.Reason == BidReasons.Evacuate)
                    {
                        //EvacuatingHost = message.SenderId;
                        EvacuatingHosts.Add(message.SenderId);
                        DataHolder.SetUtilization(message.SenderId, UtilizationStates.Evacuating);
                    }
                    else
                    {
                        throw new NotImplementedException("from auction");
                    }

                    //Here The Difference Exist
                    if (_currentAuction.ActionType == StrategyActionType.PushAction)
                    {
                        InitiateMigration(_currentAuction.Owner, winner.BiddingHost, winner.ContainerId);
                    }
                    else
                    {
                        InitiateMigration(winner.BiddingHost, _currentAuction.Owner, winner.ContainerId);
                    }
                }
                //Cancel All Bids
                foreach (var candidate in _currentAuction.GetAllCandidates())
                {
                    if (winner == null || candidate != winner.BiddingHost)
                    {
                        BidCancellationRequest request = new BidCancellationRequest(candidate, this.MachineId, _currentAuction.InstanceId);
                        CommunicationModule.SendMessage(request);
                        Console.WriteLine($"\tMaster: Send cancel to {candidate} on auction {_currentAuction.InstanceId}");
                    }
                }
                Console.WriteLine($"\t Master: Closing Auction #{_currentAuction.InstanceId}");
                //Auctions.Remove(currentAuction);

                _currentAuction = null;
                if (Used == 0)
                {
                    throw new NotImplementedException();
                }
                Used = 0;
            }
        }
示例#2
0
        private void HandleBidCancellationRequest(BidCancellationRequest bidCancellationRequest)
        {
            if (bidCancellationRequest.AuctionId == BidLock)
            {
                //Console.WriteLine($"I am Host #{HostId} I am not bidding any more for AuctionId{bidCancellationRequest.AuctionId}");

                BidLock = -1;
            }
            else
            {
            }
        }
 private void HandleBidCancellationRequest(BidCancellationRequest message)
 {
     //if (_hostState.CurrentAction != HostCurrentAction.Bidding)
     //    throw new NotImplementedException("How come");
     if (_hostState.AuctionId == message.AuctionId)
     {
         //Console.WriteLine($"I am Host #{HostId} I am not bidding any more for AuctionId{bidCancellationRequest.AuctionId}");
         _hostState.CurrentAction = HostCurrentAction.None;
         _hostState.AuctionId     = 0;
     }
     else
     {
         //throw new NotImplementedException("How come");
     }
 }
示例#4
0
        public void HandleLoadAvailabilityResponce(LoadAvailabilityResponce message)
        {
            _masterState.Auction.AddBid(message.HostBid);
            if (!_masterState.Auction.OpenSession)
            {
                var winner = _masterState.Auction.GetWinnerBid();
                if (winner == null)
                {
                    //Reject the request of the requester
                    InitiateRejectAction(_masterState.Auction.Owner, _masterState.Auction.ActionType);
                }
                else
                {
                    //Here The Difference Exist
                    if (_masterState.Auction.ActionType == StrategyActionType.PushAction)
                    {
                        InitiateMigration(_masterState.Auction.Owner, winner.BiddingHost, winner.ContainerId);
                    }
                    else
                    {
                        InitiateMigration(winner.BiddingHost, _masterState.Auction.Owner, winner.ContainerId);
                    }
                }
                //Cancel All Bids
                foreach (var candidate in _masterState.Auction.GetAllCandidates())
                {
                    if (winner == null || candidate != winner.BiddingHost)
                    {
                        BidCancellationRequest request = new BidCancellationRequest(candidate, this.MachineId, _masterState.Auction.InstanceId);
                        CommunicationModule.SendMessage(request);
                    }
                }

                //_masterState.CurrentAction = MasterCurrentAction.None;
                _masterState.Auction = null;
                if (_masterState.CurrentHost == 0)
                {
                    throw new Exception("How come");
                }
                _masterState.CurrentHost = 0;
            }
        }
        public override void HandleLoadAvailabilityResponce(LoadAvailabilityResponce message)
        {
            // var currentInOrderPrope = _currentStrategyInstance as InOrderProping;
            if (!message.HostBid.Valid)
            {
                BidCancellationRequest brequest = new BidCancellationRequest(message.SenderId, this.MachineId, _currentProping.InstanceId);
                CommunicationModule.SendMessage(brequest);

                //Should try to find another one before rejection
                if (_currentProping.OpenSession)
                {
                    int candidateHostId = _currentProping.GetNextCandidate();
                    switch (_currentProping.ActionType)
                    {
                    case StrategyActionType.PushAction:
                        var aRequest1 = new PushLoadAvailabilityRequest(candidateHostId, this.MachineId,
                                                                        _currentProping.ContainerLoadInfo, _currentProping.InstanceId, _currentProping.Owner);
                        CommunicationModule.SendMessage(aRequest1);

                        break;

                    case StrategyActionType.PullAction:
                        var aRequest2 = new PullLoadAvailabilityRequest(candidateHostId, this.MachineId,
                                                                        _currentProping.InstanceId, _currentProping.Owner);
                        CommunicationModule.SendMessage(aRequest2);

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    return;
                }
                else
                {
                    InitiateRejectAction(_currentProping.Owner, _currentProping.ActionType);
                }
            }
            else
            {
                if (message.HostBid.Reason == BidReasons.ValidBid)
                {
                }
                else if (message.HostBid.Reason == BidReasons.Evacuate)
                {
                    //EvacuatingHost = message.SenderId;
                    EvacuatingHosts.Add(message.SenderId);
                    if (EvacuatingHosts.Count > 1)
                    {
                    }
                    DataHolder.SetUtilization(message.SenderId, UtilizationStates.Evacuating);
                }
                else
                {
                    throw new NotImplementedException("from in order");
                }
                if (_currentProping.ActionType == StrategyActionType.PushAction)
                {
                    InitiateMigration(_currentProping.Owner, message.HostBid.BiddingHost, message.HostBid.ContainerId);
                }
                else
                {
                    InitiateMigration(message.HostBid.BiddingHost, _currentProping.Owner, message.HostBid.ContainerId);
                }
            }
            if (Used == 0 || _currentProping == null)
            {
                throw new NotImplementedException("");
            }
            Used            = 0;
            _currentProping = null;
        }