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