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; 022import org.apache.hadoop.classification.InterfaceStability; 023import org.apache.hadoop.yarn.api.ApplicationMasterProtocol; 024import org.apache.hadoop.yarn.util.Records; 025 026/** 027 * {@code UpdateContainerRequest} represents the request made by an 028 * application to the {@code ResourceManager} to update an attribute of a 029 * {@code Container} such as its Resource allocation or (@code ExecutionType} 030 * <p> 031 * It includes: 032 * <ul> 033 * <li>version for the container.</li> 034 * <li>{@link ContainerId} for the container.</li> 035 * <li> 036 * {@link Resource} capability of the container after the update request 037 * is completed. 038 * </li> 039 * </ul> 040 * 041 * @see ApplicationMasterProtocol#allocate(org.apache.hadoop.yarn.api.protocolrecords.AllocateRequest) 042 */ 043@InterfaceAudience.Public 044@InterfaceStability.Unstable 045public abstract class UpdateContainerRequest { 046 047 @InterfaceAudience.Public 048 @InterfaceStability.Unstable 049 public static UpdateContainerRequest newInstance(int version, 050 ContainerId containerId, ContainerUpdateType updateType, 051 Resource targetCapability) { 052 UpdateContainerRequest request = 053 Records.newRecord(UpdateContainerRequest.class); 054 request.setContainerVersion(version); 055 request.setContainerId(containerId); 056 request.setContainerUpdateType(updateType); 057 request.setCapability(targetCapability); 058 return request; 059 } 060 061 /** 062 * Get the <code>ContainerId</code> of the container. 063 * @return <code>ContainerId</code> of the container 064 */ 065 @InterfaceAudience.Public 066 @InterfaceStability.Unstable 067 public abstract int getContainerVersion(); 068 069 /** 070 * Set the current version of the container. 071 * @param containerVersion of the container 072 */ 073 @InterfaceAudience.Public 074 @InterfaceStability.Unstable 075 public abstract void setContainerVersion(int containerVersion); 076 077 /** 078 * Get the <code>ContainerUpdateType</code> of the container. 079 * @return <code>ContainerUpdateType</code> of the container. 080 */ 081 @InterfaceAudience.Public 082 @InterfaceStability.Unstable 083 public abstract ContainerUpdateType getContainerUpdateType(); 084 085 /** 086 * Set the <code>ContainerUpdateType</code> of the container. 087 * @param updateType of the Container 088 */ 089 @InterfaceAudience.Public 090 @InterfaceStability.Unstable 091 public abstract void setContainerUpdateType(ContainerUpdateType updateType); 092 093 /** 094 * Get the <code>ContainerId</code> of the container. 095 * @return <code>ContainerId</code> of the container 096 */ 097 @InterfaceAudience.Public 098 @InterfaceStability.Unstable 099 public abstract ContainerId getContainerId(); 100 101 /** 102 * Set the <code>ContainerId</code> of the container. 103 * @param containerId <code>ContainerId</code> of the container 104 */ 105 @InterfaceAudience.Public 106 @InterfaceStability.Unstable 107 public abstract void setContainerId(ContainerId containerId); 108 109 /** 110 * Get the <code>Resource</code> capability of the container. 111 * @return <code>Resource</code> capability of the container 112 */ 113 @InterfaceAudience.Public 114 @InterfaceStability.Unstable 115 public abstract Resource getCapability(); 116 117 /** 118 * Set the <code>Resource</code> capability of the container. 119 * @param capability <code>Resource</code> capability of the container 120 */ 121 @InterfaceAudience.Public 122 @InterfaceStability.Unstable 123 public abstract void setCapability(Resource capability); 124 125 @Override 126 public int hashCode() { 127 final int prime = 2153; 128 int result = 2459; 129 ContainerId cId = getContainerId(); 130 Resource capability = getCapability(); 131 result = 132 prime * result + ((capability == null) ? 0 : capability.hashCode()); 133 result = prime * result + ((cId == null) ? 0 : cId.hashCode()); 134 result = prime * result + getContainerVersion(); 135 return result; 136 } 137 138 @Override 139 public boolean equals(Object obj) { 140 if (this == obj) { 141 return true; 142 } 143 if (obj == null) { 144 return false; 145 } 146 if (getClass() != obj.getClass()) { 147 return false; 148 } 149 UpdateContainerRequest other = (UpdateContainerRequest) obj; 150 Resource capability = getCapability(); 151 if (capability == null) { 152 if (other.getCapability() != null) { 153 return false; 154 } 155 } else if (!capability.equals(other.getCapability())) { 156 return false; 157 } 158 ContainerId cId = getContainerId(); 159 if (cId == null) { 160 if (other.getContainerId() != null) { 161 return false; 162 } 163 } else if (!cId.equals(other.getContainerId())) { 164 return false; 165 } 166 if (getContainerVersion() != other.getContainerVersion()) { 167 return false; 168 } 169 return true; 170 } 171}