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);
        }
Ejemplo n.º 2
0
        private void HandlePushRequest(ForsmanPushRequest message)
        {
            ForsmanLoadAvailabilityResponce responce;

            if (BidLock == -1)
            {
                BidLock = message.SenderId;
                List <ForsmanBid> bids = new List <ForsmanBid>();
                var load = LoadManager.GetPredictedHostLoadInfo();

                foreach (var conload in message.ContainerLoads)
                {
                    var nload = LoadManager.GetHostLoadInfoAfterContainer(conload);
                    if (LoadManager.CanITakeLoad(conload))
                    //&& nload.CalculateTotalUtilizationState(MinUtilization,MaxUtilization)
                    //!=UtilizationStates.OverUtilization)
                    {
                        ForsmanBid bid = new ForsmanBid(MachineId, true, nload, message.AuctionId, conload.ContainerId,
                                                        BidReasons.ValidBid);
                        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);
        }
Ejemplo n.º 3
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);
        }
        private void HandlaCanHaveContainerRequest(CanHaveContainerRequest message)
        {
            //ContainerTable.AddContainer(message.ScheduledContainer.ContainerId, message.ScheduledContainer);
            var load     = LoadManager.GetHostLoadInfoAfterContainer(message.NewContainerLoadInfo);
            var newState = load.CalculateTotalUtilizationState(MinUtilization, MaxUtilization);
            Bid bid      = null;

            if (!_hostState.EvacuationMode &&
                LoadManager.CanITakeLoad(message.NewContainerLoadInfo) && newState != UtilizationStates.OverUtilization)
            {
                var pulls = CalculatePullsCount(message.NewContainerLoadInfo.ImageId);
                bid = new AuctionBid(this.MachineId, true, load, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.ValidBid, pulls);
            }
            else
            {
                bid = new AuctionBid(this.MachineId, false, null, message.AuctionId, message.NewContainerLoadInfo.ContainerId, BidReasons.CantBid, 0);
            }
            CanHaveContainerResponce responce = new CanHaveContainerResponce(0, MachineId, bid);

            CommunicationModule.SendMessage(responce);
        }