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 */ 018package org.apache.hadoop.hbase.replication.regionserver; 019 020import org.apache.hadoop.hbase.executor.EventType; 021import org.apache.hadoop.hbase.procedure2.RSProcedureCallable; 022import org.apache.hadoop.hbase.regionserver.HRegionServer; 023import org.apache.log4j.Logger; 024import org.apache.yetus.audience.InterfaceAudience; 025 026import org.apache.hbase.thirdparty.com.google.protobuf.InvalidProtocolBufferException; 027 028import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.PeerModificationType; 029import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.RefreshPeerParameter; 030 031/** 032 * The callable executed at RS side to refresh the peer config/state. <br/> 033 */ 034@InterfaceAudience.Private 035public class RefreshPeerCallable implements RSProcedureCallable { 036 037 private static final Logger LOG = Logger.getLogger(RefreshPeerCallable.class); 038 private HRegionServer rs; 039 040 private String peerId; 041 042 private PeerModificationType type; 043 044 private Exception initError; 045 046 @Override 047 public Void call() throws Exception { 048 if (initError != null) { 049 throw initError; 050 } 051 052 LOG.info("Received a peer change event, peerId=" + peerId + ", type=" + type); 053 PeerProcedureHandler handler = rs.getReplicationSourceService().getPeerProcedureHandler(); 054 switch (type) { 055 case ADD_PEER: 056 handler.addPeer(this.peerId); 057 break; 058 case REMOVE_PEER: 059 handler.removePeer(this.peerId); 060 break; 061 case ENABLE_PEER: 062 handler.enablePeer(this.peerId); 063 break; 064 case DISABLE_PEER: 065 handler.disablePeer(this.peerId); 066 break; 067 case UPDATE_PEER_CONFIG: 068 handler.updatePeerConfig(this.peerId); 069 break; 070 default: 071 throw new IllegalArgumentException("Unknown peer modification type: " + type); 072 } 073 return null; 074 } 075 076 @Override 077 public void init(byte[] parameter, HRegionServer rs) { 078 this.rs = rs; 079 try { 080 RefreshPeerParameter param = RefreshPeerParameter.parseFrom(parameter); 081 this.peerId = param.getPeerId(); 082 this.type = param.getType(); 083 } catch (InvalidProtocolBufferException e) { 084 initError = e; 085 } 086 } 087 088 @Override 089 public EventType getEventType() { 090 return EventType.RS_REFRESH_PEER; 091 } 092}