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.Evolving;
024import org.apache.hadoop.yarn.util.Records;
025
026@Public
027@Evolving
028public abstract class ResourceOption {
029
030  public static ResourceOption newInstance(Resource resource,
031      int overCommitTimeout){
032    ResourceOption resourceOption = Records.newRecord(ResourceOption.class);
033    resourceOption.setResource(resource);
034    resourceOption.setOverCommitTimeout(overCommitTimeout);
035    resourceOption.build();
036    return resourceOption;
037  }
038
039  /** Negative value means no timeout. */
040  public static final int OVER_COMMIT_TIMEOUT_MILLIS_DEFAULT = -1;
041
042  /**
043   * Get the <em>resource</em> of the ResourceOption.
044   * @return <em>resource</em> of the ResourceOption
045   */
046  @Private
047  @Evolving
048  public abstract Resource getResource();
049  
050  @Private
051  @Evolving
052  protected abstract void setResource(Resource resource);
053  
054  /**
055   * Get timeout for tolerant of resource over-commitment
056   * Note: negative value means no timeout so that allocated containers will
057   * keep running until the end even under resource over-commitment cases.
058   * @return <em>overCommitTimeout</em> of the ResourceOption
059   */
060  @Private
061  @Evolving
062  public abstract int getOverCommitTimeout();
063  
064  @Private
065  @Evolving
066  protected abstract void setOverCommitTimeout(int overCommitTimeout);
067  
068  @Private
069  @Evolving
070  protected abstract void build();
071  
072  @Override
073  public String toString() {
074    return "Resource:" + getResource().toString() 
075        + ", overCommitTimeout:" + getOverCommitTimeout();
076  }
077  
078}