001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.hadoop.yarn.api.records;
020
021import org.apache.hadoop.classification.InterfaceAudience.Private;
022import org.apache.hadoop.classification.InterfaceAudience.Public;
023import org.apache.hadoop.classification.InterfaceStability.Unstable;
024import org.apache.hadoop.classification.InterfaceStability.Stable;
025import org.apache.hadoop.yarn.util.Records;
026
027/**
028 * {@code ResourceAllocationRequest} represents an allocation
029 * made for a reservation for the current state of the plan. This can be
030 * changed for reasons such as re-planning, but will always be subject to the
031 * constraints of the user contract as described by
032 * {@link ReservationDefinition}
033 * {@link Resource}
034 *
035 * <p>
036 * It includes:
037 * <ul>
038 *   <li>StartTime of the allocation.</li>
039 *   <li>EndTime of the allocation.</li>
040 *   <li>{@link Resource} reserved for the allocation.</li>
041 * </ul>
042 *
043 * @see Resource
044 */
045@Public
046@Stable
047public abstract class ResourceAllocationRequest {
048
049  /**
050   * @param startTime The start time that the capability is reserved for.
051   * @param endTime The end time that the capability is reserved for.
052   * @param capability {@link Resource} representing the capability of the
053   *                                   resource allocation.
054   * @return {ResourceAllocationRequest} which represents the capability of
055   * the resource allocation for a time interval.
056   */
057  @Public
058  @Stable
059  public static ResourceAllocationRequest newInstance(long startTime,
060                                     long endTime, Resource capability) {
061    ResourceAllocationRequest ra = Records.newRecord(
062            ResourceAllocationRequest.class);
063    ra.setEndTime(endTime);
064    ra.setStartTime(startTime);
065    ra.setCapability(capability);
066    return ra;
067  }
068
069  /**
070   * Get the start time that the resource is allocated.
071   *
072   * @return the start time that the resource is allocated.
073   */
074  @Public
075  @Unstable
076  public abstract long getStartTime();
077
078  /**
079   * Set the start time that the resource is allocated.
080   *
081   * @param startTime The start time that the capability is reserved for.
082   */
083  @Private
084  @Unstable
085  public abstract void setStartTime(long startTime);
086
087  /**
088   * Get the end time that the resource is allocated.
089   *
090   * @return the end time that the resource is allocated.
091   */
092  @Public
093  @Unstable
094  public abstract long getEndTime();
095
096  /**
097   * Set the end time that the resource is allocated.
098   *
099   * @param endTime The end time that the capability is reserved for.
100   */
101  @Private
102  @Unstable
103  public abstract void setEndTime(long endTime);
104
105  /**
106   * Get the allocated resource.
107   *
108   * @return the allocated resource.
109   */
110  @Public
111  @Unstable
112  public abstract Resource getCapability();
113
114  /**
115   * Set the allocated resource.
116   *
117   * @param resource {@link Resource} representing the capability of the
118   *                                   resource allocation.
119   */
120  @Private
121  @Unstable
122  public abstract void setCapability(Resource resource);
123}