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.master.replication;
019
020import java.io.IOException;
021import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
022import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
023import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
024import org.apache.hadoop.hbase.replication.ReplicationException;
025import org.apache.yetus.audience.InterfaceAudience;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028
029import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.EnablePeerStateData;
030
031/**
032 * The procedure for enabling a replication peer.
033 */
034@InterfaceAudience.Private
035public class EnablePeerProcedure extends ModifyPeerProcedure {
036
037  private static final Logger LOG = LoggerFactory.getLogger(EnablePeerProcedure.class);
038
039  public EnablePeerProcedure() {
040  }
041
042  public EnablePeerProcedure(String peerId) {
043    super(peerId);
044  }
045
046  @Override
047  public PeerOperationType getPeerOperationType() {
048    return PeerOperationType.ENABLE;
049  }
050
051  @Override
052  protected void prePeerModification(MasterProcedureEnv env) throws IOException {
053    MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
054    if (cpHost != null) {
055      cpHost.preEnableReplicationPeer(peerId);
056    }
057    env.getReplicationPeerManager().preEnablePeer(peerId);
058  }
059
060  @Override
061  protected void updatePeerStorage(MasterProcedureEnv env) throws ReplicationException {
062    env.getReplicationPeerManager().enablePeer(peerId);
063  }
064
065  @Override
066  protected void postPeerModification(MasterProcedureEnv env) throws IOException {
067    LOG.info("Successfully enabled peer {}", peerId);
068    MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
069    if (cpHost != null) {
070      cpHost.postEnableReplicationPeer(peerId);
071    }
072  }
073
074  @Override
075  protected void serializeStateData(ProcedureStateSerializer serializer) throws IOException {
076    super.serializeStateData(serializer);
077    serializer.serialize(EnablePeerStateData.getDefaultInstance());
078  }
079
080  @Override
081  protected void deserializeStateData(ProcedureStateSerializer serializer) throws IOException {
082    super.deserializeStateData(serializer);
083    serializer.deserialize(EnablePeerStateData.class);
084  }
085}