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 AddContainer(Container container) { if (CurrentContainer != null) { throw new NotImplementedException("How come"); } List <int> candidates = new List <int>(Holder.GetCandidateHosts(UtilizationStates.Normal, 0)); var under = Holder.GetCandidateHosts(UtilizationStates.UnderUtilization, 0); candidates.AddRange(under); if (candidates.Count > 0) { CurrentContainer = container; AuctionFactory(candidates); foreach (var id in candidates) { Message m = new CanHaveContainerRequest(id, 0, auction.InstanceId, CurrentContainer.GetContainerPredictedLoadInfo()); CommunicationModule.SendMessage(m); } } else { FailedScheduling(); } }
public override void MachineAction() { BidLock = -1; EvacuateMode = false; //inital sleep before push or pull //Thread.Sleep(10*Global.Second); while (Started) { //change to time based on backoff algorithm var bft = GetBackOffTime(); Thread.Sleep(bft); lock (_hostLock) { var s = LoadManager.CheckSystemState(true, MinUtilization, MaxUtilization); //can this be up if (BidLock == -1 && !EvacuateMode) { TryToChangeSystemState(s); } else if (EvacuateMode && BidLock == -1) { if (!SendPushRequest()) { break; } } } } var message = new EvacuationDone(0, this.MachineId); CommunicationModule.SendMessage(message); //Console.WriteLine("Hahahahha"); }
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); }
protected override void SendPullRequest() { _hostState.CurrentAction = HostCurrentAction.Pulling; PullRequest pullRequest = new PullRequest(0, this.MachineId, LoadManager.GetPredictedHostLoadInfo()); CommunicationModule.SendMessage(pullRequest); }
protected override void HandlePullRequest(PullRequest message, List <int> candidates) { var ncandidates = candidates.Take((int)TestedHostsCount).ToList(); int instanceId = RandomNumberGenerator.GetInstanceRandomNumber(); // int count = candidates.Count(); MostFullAuction pullAuction = new MostFullAuction(instanceId, message.SenderId, ncandidates, StrategyActionType.PullAction); Console.WriteLine($"\tMaster: Initiate a Pull Auction of Host#{message.SenderId} with #{instanceId}"); foreach (var candidateHostId in ncandidates) { if (candidateHostId == 0) { throw new NotImplementedException(); } PullLoadAvailabilityRequest request = new PullLoadAvailabilityRequest(candidateHostId, this.MachineId, instanceId, pullAuction.Owner); CommunicationModule.SendMessage(request); } if (_currentAuction != null) { throw new NotImplementedException(); } //Auctions.Add(pushAuction); Used = message.SenderId; _currentAuction = pullAuction; }
private void HandleInitiateMigration(InitiateMigration message) { //Case Docker if (ContainerTable.ContainerType == ContainersType.D) { var container = ContainerTable.GetContainerById(message.ContainerId) as DockerContainer; var imageId = container.ImageId; var request = new ImageLoadRequest(message.TargetHost, this.MachineId, imageId, message.ContainerId); CommunicationModule.SendMessage(request); } //Case Normal else { Task t = new Task(() => { var container = ContainerTable.GetContainerById(message.ContainerId); ContainerTable.LockContainer(message.ContainerId); container.Checkpoint(this.MachineId); var size = (int)container.GetContainerNeededLoadInfo().CurrentLoad.MemorySize; MigrateContainerRequest request = new MigrateContainerRequest(message.TargetHost, this.MachineId, container, size); CommunicationModule.SendMessage(request); ResetBackOff(); }); t.Start(); } //GlobalEnviromentVariables.ResetCheckRate(); }
private void HandlePullRequest(PullRequest message, List <int> candidates) { var ncandidates = candidates.Take(calculateCountFromPercent(candidates.Count, TestedHostsCount)).ToList(); // int count = candidates.Count(); Auction pullAuction = CreateAuctionInstance(PullAuctionType, message.SenderId, ncandidates, StrategyActionType.PullAction); foreach (var candidateHostId in ncandidates) { if (candidateHostId == 0) { throw new NotImplementedException(); } PullLoadAvailabilityRequest request = new PullLoadAvailabilityRequest(candidateHostId, this.MachineId, pullAuction.InstanceId, pullAuction.Owner); CommunicationModule.SendMessage(request); } if (_masterState.Auction != null) { throw new NotImplementedException(); } //Auctions.Add(pushAuction); //_masterState.CurrentAction = MasterCurrentAction.PullAuction; _masterState.CurrentHost = message.SenderId; _masterState.Auction = pullAuction; }
protected override void HandleCanHaveContainerResponce(CanHaveContainerResponce message) { if (message.Bid.AuctionId != inOrderProping.InstanceId) { throw new NotImplementedException("How come"); } if (message.Bid.Valid) { AddContainerRequest request = new AddContainerRequest(message.SenderId, 0, CurrentContainer); CommunicationModule.SendMessage(request); CurrentContainer = null; inOrderProping = null; } else { if (inOrderProping.OpenSession) { TestHostForAContainer(); } else { FailedScheduling(); } } }
private void TestHostForAContainer() { var id = inOrderProping.GetNextCandidate(); Message m = new CanHaveContainerRequest(id, 0, inOrderProping.InstanceId, CurrentContainer.GetContainerPredictedLoadInfo()); CommunicationModule.SendMessage(m); }
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; } }
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); }
private void HelloMessage(ChatUser cu = null) { if (cu != null) { UserProfile.Destination = cu.Sender; } SignedMessage signedUserProfileMessage = new SignedMessage(UserProfile.ToJson()); userModule.SendMessage <string>(signedUserProfileMessage.ToJson(), messageModule.Id.ToString()); }
protected void InitiateMigration(int source, int target, int containerId) { //Console.WriteLine($"\n\n ------------------- Initiate Push from {source} to {target} on contianer {containerId} in auction Id = {auctionId}"); //migratedIds.Add(containerId,source); var initMigration = new InitiateMigration(this.MachineId, source, target, containerId); CommunicationModule.SendMessage(initMigration); //Should Release All Locks }
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 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); }
private void HandleImageLoadRequest(ImageLoadRequest message) { Task t = new Task(async() => { var table = ContainerTable as DockerContainerTable; await table.LoadImage(message.ImageId); var responce = new ImageLoadResponce(message.SenderId, this.MachineId, message.ContainerId, true); CommunicationModule.SendMessage(responce); }); t.Start(); }
private void HandleInitiateMigrationRequest(InitiateMigration message) { var con = ContainerTable.GetContainerById(message.ContainerId); var size = (int)con.GetContainerNeededLoadInfo().CurrentLoad.MemorySize; ContainerTable.LockContainer(con.ContainerId); con.Checkpoint(this.MachineId); MigrateContainerRequest request = new MigrateContainerRequest(message.SenderId, this.MachineId, con, size); CommunicationModule.SendMessage(request); }
private void MigrationContainer(ContainerToHost result) { var con = ContainerTable.GetContainerById(result.ConId); var size = (int)con.GetContainerNeededLoadInfo().CurrentLoad.MemorySize; ContainerTable.LockContainer(con.ContainerId); con.Checkpoint(this.MachineId); MigrateContainerRequest request = new MigrateContainerRequest(result.HostId, this.MachineId, con, size); CommunicationModule.SendMessage(request); }
/// <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) { var action = RejectActions.Nothing; switch (atype) { case StrategyActionType.PushAction: if (DataHolder.GetUtilization(hostId) == UtilizationStates.UnderUtilization || DataHolder.GetUtilization(hostId) == UtilizationStates.Normal) { //throw new NotImplementedException("How come"); action = RejectActions.TestWalid; } else if (DataHolder.GetUtilization(hostId) == UtilizationStates.Evacuating) { action = RejectActions.CancelEvacuation; //UpdateSate(hostId, UtilizationStates.UnderUtilization,"Master"); DataHolder.SetUtilization(hostId, UtilizationStates.UnderUtilization); } else if (DataHolder.GetCandidateHosts(UtilizationStates.UnderUtilization, hostId).Count == 0 && DataHolder.GetCandidateHosts(UtilizationStates.Evacuating, hostId).Count == 0) { PowerController.PowerOnHost(); } else { //Should I cancell all evacuations } break; case StrategyActionType.PullAction: //Evacuate Host if (DataHolder.GetCandidateHosts(UtilizationStates.OverUtilization, hostId).Count == 0) { action = RejectActions.Evacuate; //UpdateSate(hostId, UtilizationStates.Evacuating, "Master"); DataHolder.SetUtilization(hostId, UtilizationStates.Evacuating); //evacuating.Add(hostId, DateTime.Now); } break; default: throw new ArgumentOutOfRangeException(); } RejectRequest request = new RejectRequest(hostId, this.MachineId, atype, action); CommunicationModule.SendMessage(request); }
private void HandleLoadAvailabilityResponse(ForsmanLoadAvailabilityResponce message) { _currentAuction.EndWaitFor(message.SenderId, message.OldLoadInfo); if (message.Valid) { foreach (var bid in message.Bids) { _currentAuction.AddBid(bid, MinUtilization, MaxUtilization); } } if (!_currentAuction.OpenSession) { var winner = _currentAuction.GetWinnerBid(); if (winner != null) { WinnerAnnouncementMessage responce = new WinnerAnnouncementMessage(-1, this.MachineId, winner.BiddingHost); CommunicationModule.SendMessage(responce); if (_currentActionType == StrategyActionType.PushAction) { var con = ContainerTable.GetContainerById(winner.ContainerId); var size = (int)con.GetContainerNeededLoadInfo().CurrentLoad.MemorySize; ContainerTable.LockContainer(con.ContainerId); con.Checkpoint(this.MachineId); MigrateContainerRequest request = new MigrateContainerRequest(winner.BiddingHost, this.MachineId, con, size); CommunicationModule.SendMessage(request); } else { InitiateMigration request = new InitiateMigration(this.MachineId, winner.BiddingHost, winner.BiddingHost, winner.ContainerId); CommunicationModule.SendMessage(request); } ResetBackOff(); //_lastDelay = 5; } else //No winner { WinnerAnnouncementMessage responce = new WinnerAnnouncementMessage(-1, this.MachineId, 0); CommunicationModule.SendMessage(responce); MaxUtilization = Global.OtherMaxUtilization; MinUtilization = Global.OtherMinUtilization; IncreaseBackOffTime(); BidLock = -1; //_lastDelay = 5; } _currentAuction = null; } }
protected override void HandlePullRequest(PullRequest message, List <int> candidates) { int instanceId = Helpers.RandomNumberGenerator.GetInstanceRandomNumber(); var inOrderInstance = new InOrderProping(instanceId, message.SenderId, candidates, StrategyActionType.PullAction, null); var candidateHostId = inOrderInstance.GetNextCandidate(); PullLoadAvailabilityRequest request = new PullLoadAvailabilityRequest(candidateHostId, this.MachineId, instanceId, inOrderInstance.Owner); CommunicationModule.SendMessage(request); if (_currentProping != null) { throw new NotImplementedException(); } Used = message.SenderId; _currentProping = inOrderInstance; }
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 HandleMigrateContainerRequest(MigrateContainerRequest message) { Task t = new Task(() => { ContainerTable.AddContainer(message.MigratedContainer.ContainerId, message.MigratedContainer); message.MigratedContainer.Restore(this.MachineId); var responce = new MigrateContainerResponse(message.SenderId, this.MachineId, message.MigratedContainer.ContainerId, true); CommunicationModule.SendMessage(responce); BidLock = -1; ResetBackOff(); }); t.Start(); }
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); }
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); } }
private void HandleMigrateContainerRequest(MigrateContainerRequest message) { message.MigratedContainer.Restore(this.MachineId); if (message.MigratedContainer.ContainerType == ContainersType.D) { var table = ContainerTable as DockerContainerTable; var container = message.MigratedContainer as DockerContainer; var t = table.LoadImage(container.ImageId); t.Wait(); } ContainerTable.AddContainer(message.MigratedContainer.ContainerId, message.MigratedContainer); var responce = new MigrateContainerResponse(message.SenderId, this.MachineId, message.MigratedContainer.ContainerId, true); CommunicationModule.SendMessage(responce); }
private void HandleMigrateContainerRequest(MigrateContainerRequest message) { Task t = new Task(() => { ContainerTable.AddContainer(message.MigratedContainer.ContainerId, message.MigratedContainer); //var nd = Global.GetNetworkDelay(message.MessageSize); //await Task.Delay(nd*Global.Second); message.MigratedContainer.Restore(this.MachineId); var responce = new MigrateContainerResponse(message.SenderId, this.MachineId, message.MigratedContainer.ContainerId, true); CommunicationModule.SendMessage(responce); _hostState.CurrentAction = HostCurrentAction.None; ResetBackOff(); }); t.Start(); }
private void HandleInitiateMigration(InitiateMigration message) { //Console.WriteLine($" \n\n\n\n \t\t\t From Push with Love{message.ContainerId}"); Task t = new Task(() => { var container = ContainerTable.GetContainerById(message.ContainerId); ContainerTable.LockContainer(message.ContainerId); container.Checkpoint(this.MachineId); var size = (int)container.GetContainerNeededLoadInfo().CurrentLoad.MemorySize; MigrateContainerRequest request = new MigrateContainerRequest(message.TargetHost, this.MachineId, container, size); CommunicationModule.SendMessage(request); ResetBackOff(); }); t.Start(); //GlobalEnviromentVariables.ResetCheckRate(); }
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); }