private void HandlePullRequest(ForsmanPullRequest message) { ForsmanLoadAvailabilityResponce responce; if (BidLock == -1) { BidLock = message.SenderId; List <ForsmanBid> bids = new List <ForsmanBid>(); var load = LoadManager.GetPredictedHostLoadInfo(); foreach (var cont in ContainerTable.GetAllContainers()) { var conload = cont.GetContainerPredictedLoadInfo(); var nload = LoadManager.GetHostLoadInfoAWithoutContainer(conload); if (LoadManager.CanITakeLoad(conload)) //&& nload.CalculateTotalUtilizationState(MinUtilization, MaxUtilization) != UtilizationStates.UnderUtilization) { ForsmanBid bid = new ForsmanBid(MachineId, true, nload, message.AuctionId, conload.ContainerId, BidReasons.ValidBid, conload); bids.Add(bid); } } responce = new ForsmanLoadAvailabilityResponce(message.SenderId, this.MachineId, load, true, bids); } else { responce = new ForsmanLoadAvailabilityResponce(message.SenderId, this.MachineId, null, false, null); //Resources are locked in the first place } CommunicationModule.SendMessage(responce); }
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); }