public void MergeFrom(GuestCancelledReservation other) { if (other == null) { return; } if (other.PenaltyApplied != false) { PenaltyApplied = other.PenaltyApplied; } if (other.DaysBeforeReservationStart != 0) { DaysBeforeReservationStart = other.DaysBeforeReservationStart; } if (other.reservationId_ != null) { if (reservationId_ == null) { reservationId_ = new global::HOLMS.Types.Booking.Indicators.ReservationIndicator(); } ReservationId.MergeFrom(other.ReservationId); } if (other.guestId_ != null) { if (guestId_ == null) { guestId_ = new global::HOLMS.Types.CRM.Guests.GuestIndicator(); } GuestId.MergeFrom(other.GuestId); } }
public override int GetHashCode() { int hash = 1; if (checkInDate_ != null) { hash ^= CheckInDate.GetHashCode(); } if (averageRate_ != null) { hash ^= AverageRate.GetHashCode(); } if (ReservationBookingNumber.Length != 0) { hash ^= ReservationBookingNumber.GetHashCode(); } if (reservationId_ != null) { hash ^= ReservationId.GetHashCode(); } if (RoomNumber.Length != 0) { hash ^= RoomNumber.GetHashCode(); } if (guestId_ != null) { hash ^= GuestId.GetHashCode(); } if (RoomType.Length != 0) { hash ^= RoomType.GetHashCode(); } return(hash); }
public async Task <IActionResult> UpdateContactInformation( [FromBody] ContactInformationDto newContactInformation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var id = ReservationId.With(newContactInformation.ReservationId); var contactInformationUpdatedOrError = await _commandBus.PublishAsync( new UpdateContactInformation( id, newContactInformation.Name, newContactInformation.Email), CancellationToken.None); if (contactInformationUpdatedOrError.IsSuccess) { return(NoContent()); } return(BadRequest(contactInformationUpdatedOrError)); }
public virtual void TestSimple() { PrepareBasicPlan(); // create a request with a single atomic ask ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.SetArrival(5 * step); rr.SetDeadline(20 * step); ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(2048, 2), 10, 5, 10 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.SetReservationResources(Collections.SingletonList(r)); rr.SetReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); agent.CreateReservation(reservationID, "u1", plan, rr); NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", reservationID != null ); NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", plan.GetAllReservations ().Count == 3); ReservationAllocation cs = plan.GetReservationById(reservationID); System.Console.Out.WriteLine("--------AFTER SIMPLE ALLOCATION (queue: " + reservationID + ")----------"); System.Console.Out.WriteLine(plan.ToString()); System.Console.Out.WriteLine(plan.ToCumulativeString()); for (long i = 10 * step; i < 20 * step; i++) { NUnit.Framework.Assert.IsTrue("Agent-based allocation unexpected", Resources.Equals (cs.GetResourcesAtTime(i), Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (2048 * 10, 2 * 10))); } }
public async Task <ReservationOffer> GetAvailableOffersForReservation( ReservationId reservationId, DateTime arrival, DateTime departure) { var reservationOffers = await _connection .QueryAsync <ReservationOffer>( "SELECT * FROM Offer WHERE AggregateId = @ReservationId", new { ReservationId = reservationId.Value }); var offerLookup = reservationOffers.ToImmutableDictionary(_ => _.Date); // TODO ED Ported from the original example: consider just querying the database for relevant data; downside // is that it moves BL outside of the responsible object (i.e. PriceOffered.IsStillValid) var totalPriceWithHack = Enumerable .Range(0, departure.Subtract(arrival).Days) .Select(offset => arrival.AddDays(offset)) .Aggregate( Option <decimal> .Some(0.0m), (maybePrice, date) => { var a = offerLookup.ContainsKey(date); var isStillValid = a && offerLookup[date].IsStillValid(DateTime.Now); return((isStillValid) ? maybePrice.Map(p => p + offerLookup[date].Price) : Option <decimal> .None); }) .IfNone(-1); // FIXME Hack ported from the original code return(new ReservationOffer(reservationId.Value, arrival, departure, totalPriceWithHack)); }
public async Task <IActionResult> MakeReservation([FromBody] MakeReservationDto reservationDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var id = ReservationId.With(reservationDto.ReservationId); var reservationPlacedOrError = await _commandBus.PublishAsync(new MakeReservation( id, reservationDto.Name, reservationDto.Email, reservationDto.Arrival, reservationDto.Departure), CancellationToken.None); if (reservationPlacedOrError.IsSuccess) { return(NoContent()); } return(BadRequest(reservationPlacedOrError)); }
protected internal override void AssertReservationQueueDoesNotExist(ReservationId r2) { CSQueue q2 = cs.GetQueue(r2.ToString()); NUnit.Framework.Assert.IsNull(q2); }
protected internal override void AssertReservationQueueDoesNotExist(ReservationId r) { Queue q = GetReservationQueue(r.ToString()); NUnit.Framework.Assert.IsNull(q); }
public virtual void TestAddEmptyReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); int[] alloc = new int[] { }; int start = 100; IDictionary <ReservationInterval, ReservationRequest> allocations = new Dictionary <ReservationInterval, ReservationRequest>(); ReservationDefinition rDef = CreateSimpleReservationDefinition(start, start + alloc .Length, alloc.Length, allocations.Values); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID , rDef, user, planName, start, start + alloc.Length, allocations, resCalc, minAlloc ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.AddReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } }
public virtual void TestUpdateNonExistingReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); // Try to update a reservation without adding int[] alloc = new int[] { 10, 10, 10, 10, 10, 10 }; int start = 100; IDictionary <ReservationInterval, ReservationRequest> allocations = GenerateAllocation (start, alloc, false); ReservationDefinition rDef = CreateSimpleReservationDefinition(start, start + alloc .Length, alloc.Length, allocations.Values); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID , rDef, user, planName, start, start + alloc.Length, allocations, resCalc, minAlloc ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.UpdateReservation(rAllocation); NUnit.Framework.Assert.Fail("Update should fail as it does not exist in the plan" ); } catch (ArgumentException e) { NUnit.Framework.Assert.IsTrue(e.Message.EndsWith("does not exist in the plan")); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> private Plan ValidateReservation(ReservationSystem reservationSystem, ReservationId reservationId, string auditConstant) { string message = string.Empty; // check if the reservation id is valid if (reservationId == null) { message = "Missing reservation id." + " Please try again by specifying a reservation id."; RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input", "ClientRMService", message); throw RPCUtil.GetRemoteException(message); } string queueName = reservationSystem.GetQueueForReservation(reservationId); if (queueName == null) { message = "The specified reservation with ID: " + reservationId + " is unknown. Please try again with a valid reservation."; RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input", "ClientRMService", message); throw RPCUtil.GetRemoteException(message); } // check if the associated plan is valid Plan plan = reservationSystem.GetPlan(queueName); if (plan == null) { message = "The specified reservation: " + reservationId + " is not associated with any valid plan." + " Please try again with a valid reservation."; RMAuditLogger.LogFailure("UNKNOWN", auditConstant, "validate reservation input", "ClientRMService", message); throw RPCUtil.GetRemoteException(message); } return(plan); }
public override int GetHashCode() { int hash = 1; if (groupBookingId_ != null) { hash ^= GroupBookingId.GetHashCode(); } if (paymentId_ != null) { hash ^= PaymentId.GetHashCode(); } if (reservationId_ != null) { hash ^= ReservationId.GetHashCode(); } if (amount_ != null) { hash ^= Amount.GetHashCode(); } if (State != 0) { hash ^= State.GetHashCode(); } return(hash); }
public virtual void TestAddReservation() { Plan plan = new InMemoryPlan(queueMetrics, policy, agent, totalCapacity, 1L, resCalc , minAlloc, maxAlloc, planName, replanner, true); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); int[] alloc = new int[] { 10, 10, 10, 10, 10, 10 }; int start = 100; IDictionary <ReservationInterval, ReservationRequest> allocations = GenerateAllocation (start, alloc, false); ReservationDefinition rDef = CreateSimpleReservationDefinition(start, start + alloc .Length, alloc.Length, allocations.Values); ReservationAllocation rAllocation = new InMemoryReservationAllocation(reservationID , rDef, user, planName, start, start + alloc.Length, allocations, resCalc, minAlloc ); NUnit.Framework.Assert.IsNull(plan.GetReservationById(reservationID)); try { plan.AddReservation(rAllocation); } catch (PlanningException e) { NUnit.Framework.Assert.Fail(e.Message); } DoAssertions(plan, rAllocation); for (int i = 0; i < alloc.Length; i++) { NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc[i]), (alloc[i])), plan.GetTotalCommittedResources(start + i)); NUnit.Framework.Assert.AreEqual(Org.Apache.Hadoop.Yarn.Api.Records.Resource.NewInstance (1024 * (alloc[i]), (alloc[i])), plan.GetConsumptionForUser(user, start + i)); } }
public static ReservationDeleteRequest NewInstance(ReservationId reservationId) { ReservationDeleteRequest request = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord < ReservationDeleteRequest>(); request.SetReservationId(reservationId); return(request); }
public void Occupy(ReservationId reservationId, Range range) { if (IsOccupiedAt(range)) { throw new RoomAlreadyOccupiedException($"Room {Id} already occupied"); } Emit(new RoomOccupied(reservationId, range.Start, range.End)); }
protected internal override void AssertReservationQueueExists(ReservationId r2, double expectedCapacity, double expectedMaxCapacity) { CSQueue q = cs.GetQueue(r2.ToString()); NUnit.Framework.Assert.IsNotNull(q); NUnit.Framework.Assert.AreEqual(expectedCapacity, q.GetCapacity(), 0.01); NUnit.Framework.Assert.AreEqual(expectedMaxCapacity, q.GetMaximumCapacity(), 1.0); }
public async Task <ReservationReadModel> GetById(ReservationId id) { var reservations = await _connection.QueryAsync <ReservationReadModel>( "SELECT * FROM Reservation WHERE AggregateId = @ReservationId", new { ReservationId = id.GetGuid().ToString() }); return(reservations.FirstOrDefault()); }
public static ReservationSubmissionResponse NewInstance(ReservationId reservationId ) { ReservationSubmissionResponse response = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <ReservationSubmissionResponse>(); response.SetReservationId(reservationId); return(response); }
public AppAddedSchedulerEvent(ApplicationId applicationId, string queue, string user , bool isAppRecovering, ReservationId reservationID) : base(SchedulerEventType.AppAdded) { this.applicationId = applicationId; this.queue = queue; this.user = user; this.reservationID = reservationID; this.isAppRecovering = isAppRecovering; }
private bool IsSaveEnabled() { bool validReservation = ReservationId.Validate(); bool validSum = TransactionSum.Validate(true); bool validDate = TransactionDate.SelectedDate != null; bool validType = Validate(TransactionMethod); bool validRemaining = Validate(RemainingSum); return(validReservation && validSum && validDate && validType && validRemaining); }
public override void SetReservationId(ReservationId reservationId) { MaybeInitBuilder(); if (reservationId == null) { builder.ClearReservationId(); return; } this.reservationId = reservationId; }
public ReservationListData FindReservationListData(ReservationId reservationId) { var reservation = _dbContext.Reservations. Include(_ => _.accounts). Include(_ => _.equipments). Where(_ => _.id == reservationId.Value). SingleOrDefault(); return(CreateReservationListData(reservation)); }
/// <summary> /// Quick validation on the input to check some obvious fail conditions (fail /// fast) the input and returns the appropriate /// <see cref="Plan"/> /// associated with /// the specified /// <see cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Scheduler.Queue"/> /// or throws an exception message illustrating the /// details of any validation check failures /// </summary> /// <param name="reservationSystem"> /// the /// <see cref="ReservationSystem"/> /// to validate against /// </param> /// <param name="request"> /// the /// <see cref="Org.Apache.Hadoop.Yarn.Api.Protocolrecords.ReservationUpdateRequest"/> /// defining the resources /// required over time for the request /// </param> /// <returns> /// the /// <see cref="Plan"/> /// to submit the request to /// </returns> /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> public virtual Plan ValidateReservationUpdateRequest(ReservationSystem reservationSystem , ReservationUpdateRequest request) { ReservationId reservationId = request.GetReservationId(); Plan plan = ValidateReservation(reservationSystem, reservationId, RMAuditLogger.AuditConstants .UpdateReservationRequest); ValidateReservationDefinition(reservationId, request.GetReservationDefinition(), plan, RMAuditLogger.AuditConstants.UpdateReservationRequest); return(plan); }
protected internal override void AssertReservationQueueExists(ReservationId r, double expectedCapacity, double expectedMaxCapacity) { FSLeafQueue q = fs.GetQueueManager().GetLeafQueue(plan.GetQueueName() + string.Empty + "." + r, false); NUnit.Framework.Assert.IsNotNull(q); // For now we are setting both to same weight NUnit.Framework.Assert.AreEqual(expectedCapacity, q.GetWeights().GetWeight(ResourceType .Memory), 0.01); }
public override string ToString() { return("Reservation confirmation #" + ReservationId.ToString() + " is for " + Name.PadRight(7) + " \n at " + ParkName + " park and at " + CampgroundName + " campground (#" + CampgroundId + ") at site #" + SiteId.ToString().PadRight(3) + "\n from " + FromDate.ToString("D") + " to " + ToDate.ToString("D") + " and was created on " + CreateDate.ToString("D") + "\n Total Cost is of stay: " + String.Format("{0:C2}", ((ToDate - FromDate).Days * DailyFee))); }
private ReservationCreated GetValidReservationCreatedEvent(ReservationId id) { var irrelevantArrivalDate = new DateTime(2020, 02, 01); var irrelevantDepartureDate = new DateTime(2020, 02, 02); return(new ReservationCreated( id, irrelevantArrivalDate, irrelevantDepartureDate, Hotel.CreateCheckInTimeFromDate(irrelevantArrivalDate), Hotel.CreateCheckOutTimeFromDate(irrelevantDepartureDate))); }
public virtual void TestOrder() { PrepareBasicPlan(); // create a completely utilized segment around time 30 int[] f = new int[] { 100, 100 }; NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (ReservationSystemTestUtil.GetNewReservationId(), null, "u1", "dedicated", 30 * step, 30 * step + f.Length * step, ReservationSystemTestUtil.GenerateAllocation( 30 * step, step, f), res, minAlloc))); // create a chain of 4 RR, mixing gang and non-gang ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.SetArrival(0 * step); rr.SetDeadline(70 * step); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.SetInterpreter(ReservationRequestInterpreter.ROrder); ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(2048, 2), 10, 1, 10 * step); ReservationRequest r2 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(1024, 1), 10, 10, 20 * step); IList <ReservationRequest> list = new AList <ReservationRequest>(); list.AddItem(r); list.AddItem(r2); list.AddItem(r); list.AddItem(r2); reqs.SetReservationResources(list); rr.SetReservationRequests(reqs); // submit to agent ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); agent.CreateReservation(reservationID, "u1", plan, rr); // validate NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", reservationID != null ); NUnit.Framework.Assert.IsTrue("Agent-based allocation failed", plan.GetAllReservations ().Count == 4); ReservationAllocation cs = plan.GetReservationById(reservationID); NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 0 * step, 10 * step, 20, 1024 , 1)); NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 10 * step, 30 * step, 10, 1024, 1)); NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 40 * step, 50 * step, 20, 1024, 1)); NUnit.Framework.Assert.IsTrue(cs.ToString(), Check(cs, 50 * step, 70 * step, 10, 1024, 1)); System.Console.Out.WriteLine("--------AFTER ORDER ALLOCATION (queue: " + reservationID + ")----------"); System.Console.Out.WriteLine(plan.ToString()); System.Console.Out.WriteLine(plan.ToCumulativeString()); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.Reservation.Exceptions.PlanningException /// "/> public virtual bool UpdateReservation(ReservationAllocation reservation) { writeLock.Lock(); bool result = false; try { ReservationId resId = reservation.GetReservationId(); ReservationAllocation currReservation = GetReservationById(resId); if (currReservation == null) { string errMsg = "The specified Reservation with ID " + resId + " does not exist in the plan"; Log.Error(errMsg); throw new ArgumentException(errMsg); } // validate if we can accept this reservation, throws exception if // validation fails policy.Validate(this, reservation); if (!RemoveReservation(currReservation)) { Log.Error("Unable to replace reservation: {} from plan.", reservation.GetReservationId ()); return(result); } try { result = AddReservation(reservation); } catch (PlanningException e) { Log.Error("Unable to update reservation: {} from plan due to {}.", reservation.GetReservationId (), e.Message); } if (result) { Log.Info("Sucessfully updated reservation: {} in plan.", reservation.GetReservationId ()); return(result); } else { // rollback delete AddReservation(currReservation); Log.Info("Rollbacked update reservation: {} from plan.", reservation.GetReservationId ()); return(result); } } finally { writeLock.Unlock(); } }
public virtual string GetQueueForReservation(ReservationId reservationId) { readLock.Lock(); try { return(resQMap[reservationId]); } finally { readLock.Unlock(); } }
public virtual void TestOrderNoGapImpossible() { PrepareBasicPlan(); // create a completely utilized segment at time 30 int[] f = new int[] { 100, 100 }; NUnit.Framework.Assert.IsTrue(plan.ToString(), plan.AddReservation(new InMemoryReservationAllocation (ReservationSystemTestUtil.GetNewReservationId(), null, "u1", "dedicated", 30 * step, 30 * step + f.Length * step, ReservationSystemTestUtil.GenerateAllocation( 30 * step, step, f), res, minAlloc))); // create a chain of 4 RR, mixing gang and non-gang ReservationDefinition rr = new ReservationDefinitionPBImpl(); rr.SetArrival(0L); rr.SetDeadline(70L); ReservationRequests reqs = new ReservationRequestsPBImpl(); reqs.SetInterpreter(ReservationRequestInterpreter.ROrderNoGap); ReservationRequest r = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(2048, 2), 10, 1, 10); ReservationRequest r2 = ReservationRequest.NewInstance(Org.Apache.Hadoop.Yarn.Api.Records.Resource .NewInstance(1024, 1), 10, 10, 20); IList <ReservationRequest> list = new AList <ReservationRequest>(); list.AddItem(r); list.AddItem(r2); list.AddItem(r); list.AddItem(r2); reqs.SetReservationResources(list); rr.SetReservationRequests(reqs); ReservationId reservationID = ReservationSystemTestUtil.GetNewReservationId(); bool result = false; try { // submit to agent result = agent.CreateReservation(reservationID, "u1", plan, rr); NUnit.Framework.Assert.Fail(); } catch (PlanningException) { } // expected // validate NUnit.Framework.Assert.IsFalse("Agent-based allocation should have failed", result ); NUnit.Framework.Assert.IsTrue("Agent-based allocation should have failed", plan.GetAllReservations ().Count == 3); System.Console.Out.WriteLine("--------AFTER ORDER_NO_GAP IMPOSSIBLE ALLOCATION (queue: " + reservationID + ")----------"); System.Console.Out.WriteLine(plan.ToString()); System.Console.Out.WriteLine(plan.ToCumulativeString()); }
public Reservation(string reservationId) { this.reservationId = new ReservationId(reservationId); }