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; } }
private void HandlePushLoadAvailabilityRequest(PushLoadAvailabilityRequest message) { Bid bid; if (_hostState.CurrentAction == HostCurrentAction.None && !_hostState.EvacuationMode && LoadManager.CanITakeLoad(message.NewContainerLoadInfo)) { var load = LoadManager.GetHostLoadInfoAfterContainer(message.NewContainerLoadInfo); var newState = load.CalculateTotalUtilizationState(MinUtilization, MaxUtilization); if (newState == UtilizationStates.OverUtilization) { bid = new AuctionBid(MachineId, false, load, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.FullLoad, 0); } else { int pulls = CalculatePullsCount(message.NewContainerLoadInfo.ImageId); bid = new AuctionBid(MachineId, true, load, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.ValidBid, pulls); _hostState.CurrentAction = HostCurrentAction.Bidding; _hostState.AuctionId = message.AuctionId; } } else { bid = new AuctionBid(MachineId, false, null, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.CantBid, 0); } LoadAvailabilityResponce availabilityResponce = new LoadAvailabilityResponce(message.SenderId, this.MachineId, message.AuctionId, bid); CommunicationModule.SendMessage(availabilityResponce); }
private void HandlePullLoadAvailabilityRequest(PullLoadAvailabilityRequest message) { Console.WriteLine($"Pull : I'm Host #{MachineId}: I've got message from # {message.SenderId}" + $" for auction # {message.AuctionId}"); Bid bid; if (BidLock == -1 && !EvacuateMode) { ContainerLoadInfo selectedContainerload = GetToBeRemovedContainerLoadInfo(); if (selectedContainerload != null) { var oldstate = LoadManager.GetPredictedHostLoadInfo().CalculateTotalUtilizationState(MinUtilization, MaxUtilization); var load = LoadManager.GetHostLoadInfoAWithoutContainer(selectedContainerload); var newState = load.CalculateTotalUtilizationState(MinUtilization, MaxUtilization); if (oldstate == UtilizationStates.Normal && newState == UtilizationStates.UnderUtilization) { bid = new Bid(MachineId, false, load, message.AuctionId, selectedContainerload.ContainerId, BidReasons.MinimumLoad); } else { var breason = BidReasons.ValidBid; if (oldstate == UtilizationStates.UnderUtilization) { EvacuateMode = true; breason = BidReasons.Evacuate; } bid = new Bid(MachineId, true, load, message.AuctionId, selectedContainerload.ContainerId, breason); BidLock = bid.AuctionId; } Console.WriteLine($"I am Host #{MachineId} I am bidding for AuctionId {bid.AuctionId}"); } else { bid = new Bid(MachineId, false, null, message.AuctionId, -1, BidReasons.Empty); } } else { Console.WriteLine($"I am Host #{MachineId} I am Not I'm not Bidlocked {BidLock}"); bid = new Bid(MachineId, false, null, message.AuctionId, -1, BidReasons.CantBid); } Console.WriteLine($"I am Host #{MachineId} for Pull Auction {message.AuctionId} with {bid.Valid}"); LoadAvailabilityResponce availabilityResponce = new LoadAvailabilityResponce(message.SenderId, this.MachineId, message.AuctionId, bid); // var responce = new GetHostLoadInfoResponce(this.HostId, load); CommunicationModule.SendMessage(availabilityResponce); }
private void HandlePullLoadAvailabilityRequest(PullLoadAvailabilityRequest message) { Bid bid; if (_hostState.CurrentAction == HostCurrentAction.None && !_hostState.EvacuationMode) { ContainerLoadInfo selectedContainerload = GetToBeRemovedContainerLoadInfo(); if (selectedContainerload != null) { var oldstate = LoadManager.GetPredictedHostLoadInfo().CalculateTotalUtilizationState(MinUtilization, MaxUtilization); var load = LoadManager.GetHostLoadInfoAWithoutContainer(selectedContainerload); var newState = load.CalculateTotalUtilizationState(MinUtilization, MaxUtilization); //Comment this condition if (oldstate == UtilizationStates.Normal && newState == UtilizationStates.UnderUtilization) { bid = new AuctionBid(MachineId, false, load, message.AuctionId, -1, BidReasons.MinimumLoad, 0); } else { //try to find how many pulls the target will need !!! var pullsCountRequest = new PullsCountRequest(message.RequestOwner, this.MachineId, selectedContainerload.ImageId); var t = CommunicationModule.RequestData(pullsCountRequest); t.Wait(); var pullsCountResponce = t.Result as PullsCountResponce; bid = new AuctionBid(MachineId, true, load, message.AuctionId, selectedContainerload.ContainerId, BidReasons.ValidBid, pullsCountResponce.PullsCount); _hostState.CurrentAction = HostCurrentAction.Bidding; _hostState.AuctionId = message.AuctionId; } } else { bid = new AuctionBid(MachineId, false, null, message.AuctionId, -1, BidReasons.Empty, 0); } } else { bid = new AuctionBid(MachineId, false, null, message.AuctionId, -1, BidReasons.CantBid, 0); } LoadAvailabilityResponce availabilityResponce = new LoadAvailabilityResponce(message.SenderId, this.MachineId, message.AuctionId, bid); CommunicationModule.SendMessage(availabilityResponce); }
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; } }
private void HandlePushLoadAvailabilityRequest(PushLoadAvailabilityRequest message) { Console.WriteLine($"Push : I'm Host #{MachineId}: I've got message from # {message.SenderId}" + $" for auction # {message.AuctionId}"); Bid bid; if (BidLock == -1 && !EvacuateMode && LoadManager.CanITakeLoad(message.NewContainerLoadInfo)) { var load = LoadManager.GetHostLoadInfoAfterContainer(message.NewContainerLoadInfo); var newState = load.CalculateTotalUtilizationState(MinUtilization, MaxUtilization); if (newState == UtilizationStates.OverUtilization) { bid = new Bid(MachineId, false, load, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.FullLoad); } else { bid = new Bid(MachineId, true, load, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.ValidBid); BidLock = bid.AuctionId; } Console.WriteLine($"I am Host #{MachineId} I am bidding for AuctionId {bid.AuctionId}"); } else { Console.WriteLine($"I am Host #{MachineId} I am Not I'm not Bidlocked {BidLock}"); bid = new Bid(MachineId, false, null, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.CantBid); } //Console.WriteLine($"I am Host #{HostId} bidding Push Auction {message.AuctionId} with {bid.Valid}"); LoadAvailabilityResponce availabilityResponce = new LoadAvailabilityResponce(message.SenderId, this.MachineId, message.AuctionId, bid); // var responce = new GetHostLoadInfoResponce(this.HostId, load); CommunicationModule.SendMessage(availabilityResponce); }
public abstract void HandleLoadAvailabilityResponce(LoadAvailabilityResponce message);
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; }