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 package org.apache.hadoop.yarn.api.records;
019
020 import java.util.List;
021 import java.util.Set;
022
023 import org.apache.hadoop.classification.InterfaceAudience.Private;
024 import org.apache.hadoop.classification.InterfaceAudience.Public;
025 import org.apache.hadoop.classification.InterfaceStability.Evolving;
026 import org.apache.hadoop.classification.InterfaceStability.Unstable;
027 import org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest;
028 import org.apache.hadoop.yarn.util.Records;
029
030 /**
031 * Description of resources requested back by the <code>ResourceManager</code>.
032 * The <code>ApplicationMaster</code> (AM) can satisfy this request according
033 * to its own priorities to prevent containers from being forcibly killed by
034 * the platform.
035 * @see PreemptionMessage
036 */
037 @Public
038 @Evolving
039 public abstract class PreemptionContract {
040
041 @Private
042 @Unstable
043 public static PreemptionContract newInstance(
044 List<PreemptionResourceRequest> req, Set<PreemptionContainer> containers) {
045 PreemptionContract contract = Records.newRecord(PreemptionContract.class);
046 contract.setResourceRequest(req);
047 contract.setContainers(containers);
048 return contract;
049 }
050
051 /**
052 * If the AM releases resources matching these requests, then the {@link
053 * PreemptionContainer}s enumerated in {@link #getContainers()} should not be
054 * evicted from the cluster. Due to delays in propagating cluster state and
055 * sending these messages, there are conditions where satisfied contracts may
056 * not prevent the platform from killing containers.
057 * @return List of {@link PreemptionResourceRequest} to update the
058 * <code>ApplicationMaster</code> about resources requested back by the
059 * <code>ResourceManager</code>.
060 * @see AllocateRequest#setAskList(List)
061 */
062 @Public
063 @Evolving
064 public abstract List<PreemptionResourceRequest> getResourceRequest();
065
066 @Private
067 @Unstable
068 public abstract void setResourceRequest(List<PreemptionResourceRequest> req);
069
070 /**
071 * Assign the set of {@link PreemptionContainer} specifying which containers
072 * owned by the <code>ApplicationMaster</code> that may be reclaimed by the
073 * <code>ResourceManager</code>. If the AM prefers a different set of
074 * containers, then it may checkpoint or kill containers matching the
075 * description in {@link #getResourceRequest}.
076 * @return Set of containers at risk if the contract is not met.
077 */
078 @Public
079 @Evolving
080 public abstract Set<PreemptionContainer> getContainers();
081
082
083 @Private
084 @Unstable
085 public abstract void setContainers(Set<PreemptionContainer> containers);
086
087 }