public override void StopMachine() { //lock (CommunicationLock) { foreach (var container in _containerTable.GetAllContainers()) { container.StopContainer(); } Started = false; } }
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 CompareAndBalance() { var hosts = _commonLoadManager.GetAllHostLoadInfos(); Dictionary <int, double> pdis = CalculatePropDistributionForAllHosts(hosts); Random r = new Random(Guid.NewGuid().GetHashCode()); List <ContainerToHost> list = new List <ContainerToHost>(); foreach (var container in ContainerTable.GetAllContainers()) { var k = r.GetRandomFromDictionary(pdis); var cdash = _commonLoadManager.GetHostLoadInfoByHostIdAfterContainer(k, container.GetContainerNeededLoadInfo()).Volume;//Should be after adding the current container var c = LoadManager.GetNeededHostLoadInfo().Volume; if (cdash < c) { list.Add(new ContainerToHost(container.ContainerId, k, c - cdash)); } } if (list.Count == 0) { return; } var total = list.Select(x => x.Cost).Sum(); foreach (var item in list) { item.Probaility = item.Cost / total; } var result = r.GetRandomFromContainerToHost(list); MigrationContainer(result); Busy = true; }