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.util.Records; 024 025/** 026 * {@code UpdateContainerError} is used by the Scheduler to notify the 027 * ApplicationMaster of an UpdateContainerRequest it cannot satisfy due to 028 * an error in the request. It includes the update request as well as 029 * a reason for why the request was not satisfiable. 030 */ 031@InterfaceAudience.Public 032@InterfaceStability.Unstable 033public abstract class UpdateContainerError { 034 035 @InterfaceAudience.Public 036 @InterfaceStability.Unstable 037 public static UpdateContainerError newInstance(String reason, 038 UpdateContainerRequest updateContainerRequest) { 039 UpdateContainerError error = Records.newRecord(UpdateContainerError.class); 040 error.setReason(reason); 041 error.setUpdateContainerRequest(updateContainerRequest); 042 return error; 043 } 044 045 /** 046 * Get reason why the update request was not satisfiable. 047 * @return Reason 048 */ 049 @InterfaceAudience.Public 050 @InterfaceStability.Unstable 051 public abstract String getReason(); 052 053 /** 054 * Set reason why the update request was not satisfiable. 055 * @param reason Reason 056 */ 057 @InterfaceAudience.Public 058 @InterfaceStability.Unstable 059 public abstract void setReason(String reason); 060 061 /** 062 * Get the {@code UpdateContainerRequest} that was not satisfiable. 063 * @return UpdateContainerRequest 064 */ 065 @InterfaceAudience.Public 066 @InterfaceStability.Unstable 067 public abstract UpdateContainerRequest getUpdateContainerRequest(); 068 069 /** 070 * Set the {@code UpdateContainerRequest} that was not satisfiable. 071 * @param updateContainerRequest Update Container Request 072 */ 073 @InterfaceAudience.Public 074 @InterfaceStability.Unstable 075 public abstract void setUpdateContainerRequest( 076 UpdateContainerRequest updateContainerRequest); 077 078 @Override 079 public int hashCode() { 080 final int prime = 2153; 081 int result = 2459; 082 String reason = getReason(); 083 UpdateContainerRequest updateReq = getUpdateContainerRequest(); 084 result = prime * result + ((reason == null) ? 0 : reason.hashCode()); 085 result = prime * result + ((updateReq == null) ? 0 : updateReq.hashCode()); 086 return result; 087 } 088 089 @Override 090 public boolean equals(Object obj) { 091 if (this == obj) { 092 return true; 093 } 094 if (obj == null) { 095 return false; 096 } 097 if (getClass() != obj.getClass()) { 098 return false; 099 } 100 UpdateContainerError other = (UpdateContainerError) obj; 101 String reason = getReason(); 102 if (reason == null) { 103 if (other.getReason() != null) { 104 return false; 105 } 106 } else if (!reason.equals(other.getReason())) { 107 return false; 108 } 109 UpdateContainerRequest req = getUpdateContainerRequest(); 110 if (req == null) { 111 if (other.getUpdateContainerRequest() != null) { 112 return false; 113 } 114 } else if (!req.equals(other.getUpdateContainerRequest())) { 115 return false; 116 } 117 return true; 118 } 119}