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; } }
/// <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); }
private void HandleEvacuationDone(EvacuationDone message) { PowerController.PowerOffHost(message.SenderId); //EvacuatingHost = 0; EvacuatingHosts.Remove(message.SenderId); }
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; }