Example #1
0
        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);
        }
        protected override void SendPullRequest()
        {
            _hostState.CurrentAction = HostCurrentAction.Pulling;
            PullRequest pullRequest = new PullRequest(0, this.MachineId, LoadManager.GetPredictedHostLoadInfo());

            CommunicationModule.SendMessage(pullRequest);
        }
Example #3
0
        protected override void SendPullRequest()
        {
            Console.WriteLine($"I'm Host #{MachineId} and I am pulling a container and I have {ContainerTable.GetContainersCount()} contatiners");

            BidLock = 0;
            PullRequest pullRequest = new PullRequest(0, this.MachineId, LoadManager.GetPredictedHostLoadInfo());

            CommunicationModule.SendMessage(pullRequest);
        }
Example #4
0
        protected override void SendPullRequest()
        {
            int total = (int)SimulationSize - 1;
            var load  = LoadManager.GetPredictedHostLoadInfo();

            _currentAuction = new ForsmanPullAuction(load, total);
            BidLock         = 0;
            ForsmanPullRequest m = new ForsmanPullRequest(-1, this.MachineId, load, this.MachineId);

            CommunicationModule.SendMessage(m);
        }
Example #5
0
        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);
        }
        protected override bool SendPushRequest()
        {
            var containerLoadInfo = GetToBeRemovedContainerLoadInfo();

            if (containerLoadInfo != null)
            {
                _hostState.CurrentAction = HostCurrentAction.Pushing;
                PushRequest m = new PushRequest(0, this.MachineId, LoadManager.GetPredictedHostLoadInfo(), containerLoadInfo);
                CommunicationModule.SendMessage(m);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        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);
        }
Example #8
0
        protected override bool SendPushRequest()
        {
            BidLock = 0;
            var containerLoadInfo = GetToBeRemovedContainerLoadInfo();

            Console.WriteLine($"I'm Host #{MachineId} and I am Pushing container #{containerLoadInfo} and I have {ContainerTable.GetContainersCount()} contatiners");
            if (containerLoadInfo != null)
            {
                PushRequest m = new PushRequest(0, this.MachineId, LoadManager.GetPredictedHostLoadInfo(), containerLoadInfo);
                CommunicationModule.SendMessage(m);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #9
0
        protected override bool SendPushRequest()
        {
            var list = ContainerTable.GetAllContainersLoadInfo();
            //.Where(x=>
            //_loadManager.GetHostLoadInfoAWithoutContainer(x)
            //.CalculateTotalUtilizationState(MinUtilization,MaxUtilization)!= UtilizationStates.UnderUtilization )
            //.ToList();
            int total = (int)SimulationSize - 1;
            var load  = LoadManager.GetPredictedHostLoadInfo();

            _currentAuction = new ForsmanPushAuction(load, list, total);
            BidLock         = 0;
            ForsmanPushRequest m = new ForsmanPushRequest(-1, this.MachineId, load, this.MachineId, list);

            CommunicationModule.SendMessage(m);
            Console.WriteLine($"Host No{MachineId} send Push Request");
            return(false);
        }