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.BaseRSProcedureCallable;
022import org.apache.yetus.audience.InterfaceAudience;
023import org.slf4j.Logger;
024import org.slf4j.LoggerFactory;
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 extends BaseRSProcedureCallable {
036
037  private static final Logger LOG = LoggerFactory.getLogger(RefreshPeerCallable.class);
038
039  private String peerId;
040
041  private PeerModificationType type;
042
043  @Override
044  protected void doCall() throws Exception {
045    LOG.info("Received a peer change event, peerId=" + peerId + ", type=" + type);
046    PeerProcedureHandler handler = rs.getReplicationSourceService().getPeerProcedureHandler();
047    switch (type) {
048      case ADD_PEER:
049        handler.addPeer(this.peerId);
050        break;
051      case REMOVE_PEER:
052        handler.removePeer(this.peerId);
053        break;
054      case ENABLE_PEER:
055        handler.enablePeer(this.peerId);
056        break;
057      case DISABLE_PEER:
058        handler.disablePeer(this.peerId);
059        break;
060      case UPDATE_PEER_CONFIG:
061        handler.updatePeerConfig(this.peerId);
062        break;
063      default:
064        throw new IllegalArgumentException("Unknown peer modification type: " + type);
065    }
066  }
067
068  @Override
069  protected void initParameter(byte[] parameter) throws InvalidProtocolBufferException {
070    RefreshPeerParameter param = RefreshPeerParameter.parseFrom(parameter);
071    this.peerId = param.getPeerId();
072    this.type = param.getType();
073  }
074
075  @Override
076  public EventType getEventType() {
077    return EventType.RS_REFRESH_PEER;
078  }
079}