Esempio n. 1
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Reservation.Exceptions.ContractValidationException
 ///     "/>
 private void ValidateInput(Plan plan, ReservationRequest rr, Resource totalCapacity
                            )
 {
     if (rr.GetConcurrency() < 1)
     {
         throw new ContractValidationException("Gang Size should be >= 1");
     }
     if (rr.GetNumContainers() <= 0)
     {
         throw new ContractValidationException("Num containers should be >= 0");
     }
     // check that gangSize and numContainers are compatible
     if (rr.GetNumContainers() % rr.GetConcurrency() != 0)
     {
         throw new ContractValidationException("Parallelism must be an exact multiple of gang size"
                                               );
     }
     // check that the largest container request does not exceed
     // the cluster-wide limit for container sizes
     if (Resources.GreaterThan(plan.GetResourceCalculator(), totalCapacity, rr.GetCapability
                                   (), plan.GetMaximumAllocation()))
     {
         throw new ContractValidationException("Individual" + " capability requests should not exceed cluster's maxAlloc"
                                               );
     }
 }
Esempio n. 2
0
        /// <summary>
        /// This method actually perform the placement of an atomic stage of the
        /// reservation.
        /// </summary>
        /// <remarks>
        /// This method actually perform the placement of an atomic stage of the
        /// reservation. The key idea is to traverse the plan backward for a
        /// "lease-duration" worth of time, and compute what is the maximum multiple of
        /// our concurrency (gang) parameter we can fit. We do this and move towards
        /// previous instant in time until the time-window is exhausted or we placed
        /// all the user request.
        /// </remarks>
        private IDictionary <ReservationInterval, ReservationRequest> PlaceSingleStage(Plan
                                                                                       plan, RLESparseResourceAllocation tempAssigned, ReservationRequest rr, long earliestStart
                                                                                       , long curDeadline, ReservationAllocation oldResAllocation, Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                                       totalCapacity)
        {
            IDictionary <ReservationInterval, ReservationRequest> allocationRequests = new Dictionary
                                                                                       <ReservationInterval, ReservationRequest>();

            // compute the gang as a resource and get the duration
            Org.Apache.Hadoop.Yarn.Api.Records.Resource gang = Resources.Multiply(rr.GetCapability
                                                                                      (), rr.GetConcurrency());
            long dur  = rr.GetDuration();
            long step = plan.GetStep();

            // ceil the duration to the next multiple of the plan step
            if (dur % step != 0)
            {
                dur += (step - (dur % step));
            }
            // we know for sure that this division has no remainder (part of contract
            // with user, validate before
            int gangsToPlace = rr.GetNumContainers() / rr.GetConcurrency();
            int maxGang      = 0;

            // loop trying to place until we are done, or we are considering
            // an invalid range of times
            while (gangsToPlace > 0 && curDeadline - dur >= earliestStart)
            {
                // as we run along we remember how many gangs we can fit, and what
                // was the most constraining moment in time (we will restart just
                // after that to place the next batch)
                maxGang = gangsToPlace;
                long minPoint   = curDeadline;
                int  curMaxGang = maxGang;
                // start placing at deadline (excluded due to [,) interval semantics and
                // move backward
                for (long t = curDeadline - plan.GetStep(); t >= curDeadline - dur && maxGang > 0
                     ; t = t - plan.GetStep())
                {
                    // As we run along we will logically remove the previous allocation for
                    // this reservation
                    // if one existed
                    Org.Apache.Hadoop.Yarn.Api.Records.Resource oldResCap = Org.Apache.Hadoop.Yarn.Api.Records.Resource
                                                                            .NewInstance(0, 0);
                    if (oldResAllocation != null)
                    {
                        oldResCap = oldResAllocation.GetResourcesAtTime(t);
                    }
                    // compute net available resources
                    Org.Apache.Hadoop.Yarn.Api.Records.Resource netAvailableRes = Resources.Clone(totalCapacity
                                                                                                  );
                    Resources.AddTo(netAvailableRes, oldResCap);
                    Resources.SubtractFrom(netAvailableRes, plan.GetTotalCommittedResources(t));
                    Resources.SubtractFrom(netAvailableRes, tempAssigned.GetCapacityAtTime(t));
                    // compute maximum number of gangs we could fit
                    curMaxGang = (int)Math.Floor(Resources.Divide(plan.GetResourceCalculator(), totalCapacity
                                                                  , netAvailableRes, gang));
                    // pick the minimum between available resources in this instant, and how
                    // many gangs we have to place
                    curMaxGang = Math.Min(gangsToPlace, curMaxGang);
                    // compare with previous max, and set it. also remember *where* we found
                    // the minimum (useful for next attempts)
                    if (curMaxGang <= maxGang)
                    {
                        maxGang  = curMaxGang;
                        minPoint = t;
                    }
                }
                // if we were able to place any gang, record this, and decrement
                // gangsToPlace
                if (maxGang > 0)
                {
                    gangsToPlace -= maxGang;
                    ReservationInterval reservationInt = new ReservationInterval(curDeadline - dur, curDeadline
                                                                                 );
                    ReservationRequest reservationRes = ReservationRequest.NewInstance(rr.GetCapability
                                                                                           (), rr.GetConcurrency() * maxGang, rr.GetConcurrency(), rr.GetDuration());
                    // remember occupied space (plan is read-only till we find a plausible
                    // allocation for the entire request). This is needed since we might be
                    // placing other ReservationRequest within the same
                    // ReservationDefinition,
                    // and we must avoid double-counting the available resources
                    tempAssigned.AddInterval(reservationInt, reservationRes);
                    allocationRequests[reservationInt] = reservationRes;
                }
                // reset our new starting point (curDeadline) to the most constraining
                // point so far, we will look "left" of that to find more places where
                // to schedule gangs (for sure nothing on the "right" of this point can
                // fit a full gang.
                curDeadline = minPoint;
            }
            // if no gangs are left to place we succeed and return the allocation
            if (gangsToPlace == 0)
            {
                return(allocationRequests);
            }
            else
            {
                // If we are here is becasue we did not manage to satisfy this request.
                // So we need to remove unwanted side-effect from tempAssigned (needed
                // for ANY).
                foreach (KeyValuePair <ReservationInterval, ReservationRequest> tempAllocation in
                         allocationRequests)
                {
                    tempAssigned.RemoveInterval(tempAllocation.Key, tempAllocation.Value);
                }
                // and return null to signal failure in this allocation
                return(null);
            }
        }