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.client;
019
020import static org.junit.Assert.*;
021
022import java.util.ArrayList;
023import java.util.EnumSet;
024import java.util.List;
025import org.apache.hadoop.hbase.ClusterMetrics;
026import org.apache.hadoop.hbase.HBaseClassTestRule;
027import org.apache.hadoop.hbase.ServerName;
028import org.apache.hadoop.hbase.testclassification.ClientTests;
029import org.apache.hadoop.hbase.testclassification.MediumTests;
030import org.apache.hadoop.hbase.zookeeper.ZKUtil;
031import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
032import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
033import org.junit.ClassRule;
034import org.junit.Test;
035import org.junit.experimental.categories.Category;
036import org.slf4j.Logger;
037import org.slf4j.LoggerFactory;
038
039@Category({ MediumTests.class, ClientTests.class })
040public class TestAdmin4 extends TestAdminBase {
041  @ClassRule
042  public static final HBaseClassTestRule CLASS_RULE =
043    HBaseClassTestRule.forClass(TestAdmin4.class);
044
045  // For HBASE-24208
046  @Test
047  public void testDecommissionAndStopRegionServers() throws Exception {
048    List<ServerName> decommissionedRegionServers = ADMIN.listDecommissionedRegionServers();
049    assertTrue(decommissionedRegionServers.isEmpty());
050
051    ArrayList<ServerName> clusterRegionServers =
052      new ArrayList<>(ADMIN.getRegionServers(true));
053
054    List<ServerName> serversToDecommission = new ArrayList<ServerName>();
055    serversToDecommission.add(clusterRegionServers.get(0));
056
057    // Decommission
058    ADMIN.decommissionRegionServers(serversToDecommission, true);
059    assertEquals(1, ADMIN.listDecommissionedRegionServers().size());
060
061    // Stop decommissioned region server and verify it is removed from draining znode
062    ServerName serverName = serversToDecommission.get(0);
063    ADMIN.stopRegionServer(serverName.getHostname()+":"+serverName.getPort());
064    assertNotEquals("RS not removed from decommissioned list", -1,
065      TEST_UTIL.waitFor(10000, () -> ADMIN.listDecommissionedRegionServers().isEmpty()));
066    ZKWatcher zkw = TEST_UTIL.getZooKeeperWatcher();
067    assertEquals(-1, ZKUtil.checkExists(zkw,
068      ZNodePaths.joinZNode(zkw.getZNodePaths().drainingZNode, serverName.getServerName())));
069  }
070}