Beispiel #1
0
 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();
         }
     }
 }
Beispiel #2
0
 protected void FailedScheduling()
 {
     powerContoller.PowerOnHost();
     Containers.Enqueue(CurrentContainer);
     if (Containers.Count > 100)
     {
     }
     CurrentContainer = null;
     inOrderProping   = 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;
        }
Beispiel #4
0
        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;
                int instanceId = Helpers.RandomNumberGenerator.GetInstanceRandomNumber();
                inOrderProping = new InOrderProping(instanceId, 0, candidates, StrategyActionType.Scheduling, container.GetContainerPredictedLoadInfo());
                TestHostForAContainer();
            }
            else
            {
                FailedScheduling();
            }
        }
        public override void HandleLoadAvailabilityResponce(LoadAvailabilityResponce message)
        {
            // var currentInOrderPrope = _currentStrategyInstance as InOrderProping;
            if (!message.HostBid.Valid)
            {
                BidCancellationRequest brequest = new BidCancellationRequest(message.SenderId, this.MachineId, _currentProping.InstanceId);
                CommunicationModule.SendMessage(brequest);

                //Should try to find another one before rejection
                if (_currentProping.OpenSession)
                {
                    int candidateHostId = _currentProping.GetNextCandidate();
                    switch (_currentProping.ActionType)
                    {
                    case StrategyActionType.PushAction:
                        var aRequest1 = new PushLoadAvailabilityRequest(candidateHostId, this.MachineId,
                                                                        _currentProping.ContainerLoadInfo, _currentProping.InstanceId, _currentProping.Owner);
                        CommunicationModule.SendMessage(aRequest1);

                        break;

                    case StrategyActionType.PullAction:
                        var aRequest2 = new PullLoadAvailabilityRequest(candidateHostId, this.MachineId,
                                                                        _currentProping.InstanceId, _currentProping.Owner);
                        CommunicationModule.SendMessage(aRequest2);

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    return;
                }
                else
                {
                    InitiateRejectAction(_currentProping.Owner, _currentProping.ActionType);
                }
            }
            else
            {
                if (message.HostBid.Reason == BidReasons.ValidBid)
                {
                }
                else if (message.HostBid.Reason == BidReasons.Evacuate)
                {
                    //EvacuatingHost = message.SenderId;
                    EvacuatingHosts.Add(message.SenderId);
                    if (EvacuatingHosts.Count > 1)
                    {
                    }
                    DataHolder.SetUtilization(message.SenderId, UtilizationStates.Evacuating);
                }
                else
                {
                    throw new NotImplementedException("from in order");
                }
                if (_currentProping.ActionType == StrategyActionType.PushAction)
                {
                    InitiateMigration(_currentProping.Owner, message.HostBid.BiddingHost, message.HostBid.ContainerId);
                }
                else
                {
                    InitiateMigration(message.HostBid.BiddingHost, _currentProping.Owner, message.HostBid.ContainerId);
                }
            }
            if (Used == 0 || _currentProping == null)
            {
                throw new NotImplementedException("");
            }
            Used            = 0;
            _currentProping = null;
        }