Exemplo n.º 1
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Reservation.Exceptions.PlanningException
        ///     "/>
        public virtual bool AddReservation(ReservationAllocation reservation)
        {
            // Verify the allocation is memory based otherwise it is not supported
            InMemoryReservationAllocation inMemReservation = (InMemoryReservationAllocation)reservation;

            if (inMemReservation.GetUser() == null)
            {
                string errMsg = "The specified Reservation with ID " + inMemReservation.GetReservationId
                                    () + " is not mapped to any user";
                Log.Error(errMsg);
                throw new ArgumentException(errMsg);
            }
            writeLock.Lock();
            try
            {
                if (reservationTable.Contains(inMemReservation.GetReservationId()))
                {
                    string errMsg = "The specified Reservation with ID " + inMemReservation.GetReservationId
                                        () + " already exists";
                    Log.Error(errMsg);
                    throw new ArgumentException(errMsg);
                }
                // Validate if we can accept this reservation, throws exception if
                // validation fails
                policy.Validate(this, inMemReservation);
                // we record here the time in which the allocation has been accepted
                reservation.SetAcceptanceTimestamp(clock.GetTime());
                ReservationInterval searchInterval = new ReservationInterval(inMemReservation.GetStartTime
                                                                                 (), inMemReservation.GetEndTime());
                ICollection <InMemoryReservationAllocation> reservations = currentReservations[searchInterval
                                                                           ];
                if (reservations == null)
                {
                    reservations = new HashSet <InMemoryReservationAllocation>();
                }
                if (!reservations.AddItem(inMemReservation))
                {
                    Log.Error("Unable to add reservation: {} to plan.", inMemReservation.GetReservationId
                                  ());
                    return(false);
                }
                currentReservations[searchInterval] = reservations;
                reservationTable[inMemReservation.GetReservationId()] = inMemReservation;
                IncrementAllocation(inMemReservation);
                Log.Info("Sucessfully added reservation: {} to plan.", inMemReservation.GetReservationId
                             ());
                return(true);
            }
            finally
            {
                writeLock.Unlock();
            }
        }