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.hdfs.server.datanode; 020 021import java.io.IOException; 022 023import org.apache.hadoop.hdfs.protocolPB.DatanodeProtocolClientSideTranslatorPB; 024import org.apache.hadoop.hdfs.server.protocol.DatanodeRegistration; 025 026 027/** 028 * A ErrorReportAction is an instruction issued by BPOfferService to 029 * BPServiceActor about a particular block encapsulated in errorMessage. 030 */ 031public class ErrorReportAction implements BPServiceActorAction { 032 033 final int errorCode; 034 final String errorMessage; 035 036 public ErrorReportAction(int errorCode, String errorMessage) { 037 this.errorCode = errorCode; 038 this.errorMessage = errorMessage; 039 } 040 041 @Override 042 public void reportTo(DatanodeProtocolClientSideTranslatorPB bpNamenode, 043 DatanodeRegistration bpRegistration) throws BPServiceActorActionException { 044 try { 045 bpNamenode.errorReport(bpRegistration, errorCode, errorMessage); 046 } catch(IOException e) { 047 throw new BPServiceActorActionException("Error reporting " 048 + "an error to namenode: "); 049 } 050 } 051 052 @Override 053 public int hashCode() { 054 final int prime = 31; 055 int result = 1; 056 result = prime * result + errorCode; 057 result = prime * result 058 + ((errorMessage == null) ? 0 : errorMessage.hashCode()); 059 return result; 060 } 061 062 @Override 063 public boolean equals(Object obj) { 064 if (this == obj) { 065 return true; 066 } 067 if (obj == null || !(obj instanceof ErrorReportAction)) { 068 return false; 069 } 070 ErrorReportAction other = (ErrorReportAction) obj; 071 if (errorCode != other.errorCode) { 072 return false; 073 } 074 if (errorMessage == null) { 075 if (other.errorMessage != null) { 076 return false; 077 } 078 } else if (!errorMessage.equals(other.errorMessage)) { 079 return false; 080 } 081 return true; 082 } 083}