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
019 package org.apache.hadoop.yarn.api.records;
020
021 import org.apache.hadoop.classification.InterfaceAudience.Private;
022 import org.apache.hadoop.classification.InterfaceAudience.Public;
023 import org.apache.hadoop.classification.InterfaceStability.Evolving;
024 import org.apache.hadoop.yarn.util.Records;
025
026 @Public
027 @Evolving
028 public 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 /**
040 * Get the <em>resource</em> of the ResourceOption.
041 * @return <em>resource</em> of the ResourceOption
042 */
043 @Private
044 @Evolving
045 public abstract Resource getResource();
046
047 @Private
048 @Evolving
049 protected abstract void setResource(Resource resource);
050
051 /**
052 * Get timeout for tolerant of resource over-commitment
053 * Note: negative value means no timeout so that allocated containers will
054 * keep running until the end even under resource over-commitment cases.
055 * @return <em>overCommitTimeout</em> of the ResourceOption
056 */
057 @Private
058 @Evolving
059 public abstract int getOverCommitTimeout();
060
061 @Private
062 @Evolving
063 protected abstract void setOverCommitTimeout(int overCommitTimeout);
064
065 @Private
066 @Evolving
067 protected abstract void build();
068
069 @Override
070 public String toString() {
071 return "Resource:" + getResource().toString()
072 + ", overCommitTimeout:" + getOverCommitTimeout();
073 }
074
075 }