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.assignment;
019
020import java.io.IOException;
021import org.apache.hadoop.hbase.ServerName;
022import org.apache.hadoop.hbase.TableName;
023import org.apache.hadoop.hbase.client.RegionInfo;
024import org.apache.hadoop.hbase.master.RegionPlan;
025import org.apache.hadoop.hbase.master.procedure.AbstractStateMachineRegionProcedure;
026import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
027import org.apache.hadoop.hbase.procedure2.ProcedureStateSerializer;
028import org.apache.yetus.audience.InterfaceAudience;
029
030import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
031import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.MoveRegionState;
032import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProcedureProtos.MoveRegionStateData;
033
034/**
035 * Leave here only for checking if we can successfully start the master.
036 * @deprecated Do not use any more.
037 * @see TransitRegionStateProcedure
038 */
039@Deprecated
040@InterfaceAudience.Private
041public class MoveRegionProcedure extends AbstractStateMachineRegionProcedure<MoveRegionState> {
042  private RegionPlan plan;
043
044  public MoveRegionProcedure() {
045    super();
046  }
047
048  @Override
049  protected Flow executeFromState(final MasterProcedureEnv env, final MoveRegionState state)
050      throws InterruptedException {
051    return Flow.NO_MORE_STATE;
052  }
053
054  @Override
055  protected void rollbackState(final MasterProcedureEnv env, final MoveRegionState state)
056      throws IOException {
057    // no-op
058  }
059
060  @Override
061  public boolean abort(final MasterProcedureEnv env) {
062    return false;
063  }
064
065  @Override
066  public void toStringClassDetails(final StringBuilder sb) {
067    sb.append(getClass().getSimpleName());
068    sb.append(" ");
069    sb.append(plan);
070  }
071
072  @Override
073  protected MoveRegionState getInitialState() {
074    return MoveRegionState.MOVE_REGION_UNASSIGN;
075  }
076
077  @Override
078  protected int getStateId(final MoveRegionState state) {
079    return state.getNumber();
080  }
081
082  @Override
083  protected MoveRegionState getState(final int stateId) {
084    return MoveRegionState.forNumber(stateId);
085  }
086
087  @Override
088  public TableName getTableName() {
089    return plan.getRegionInfo().getTable();
090  }
091
092  @Override
093  public TableOperationType getTableOperationType() {
094    return TableOperationType.REGION_EDIT;
095  }
096
097  @Override
098  protected void serializeStateData(ProcedureStateSerializer serializer)
099      throws IOException {
100    super.serializeStateData(serializer);
101
102    final MoveRegionStateData.Builder state = MoveRegionStateData.newBuilder()
103        // No need to serialize the RegionInfo. The super class has the region.
104        .setSourceServer(ProtobufUtil.toServerName(plan.getSource()));
105    if (plan.getDestination() != null) {
106      state.setDestinationServer(ProtobufUtil.toServerName(plan.getDestination()));
107    }
108
109    serializer.serialize(state.build());
110  }
111
112  @Override
113  protected void deserializeStateData(ProcedureStateSerializer serializer)
114      throws IOException {
115    super.deserializeStateData(serializer);
116
117    final MoveRegionStateData state = serializer.deserialize(MoveRegionStateData.class);
118    final RegionInfo regionInfo = getRegion(); // Get it from super class deserialization.
119    final ServerName sourceServer = ProtobufUtil.toServerName(state.getSourceServer());
120    final ServerName destinationServer = state.hasDestinationServer() ?
121        ProtobufUtil.toServerName(state.getDestinationServer()) : null;
122    this.plan = new RegionPlan(regionInfo, sourceServer, destinationServer);
123  }
124}