hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject [28/50] [abbrv] hadoop git commit: HDFS-13478. RBF: Disabled Nameservice store API. Contributed by Inigo Goiri.
Date Wed, 02 May 2018 19:22:03 GMT
http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9752503/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/proto/RouterProtocol.proto
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/proto/RouterProtocol.proto b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/proto/RouterProtocol.proto
index a4e4d65..f3a2b6e 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/proto/RouterProtocol.proto
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/proto/RouterProtocol.proto
@@ -59,4 +59,19 @@ service RouterAdminProtocolService {
    * Verify if current Router state is safe mode state.
    */
   rpc getSafeMode(GetSafeModeRequestProto) returns (GetSafeModeResponseProto);
+
+  /**
+   * Disable a name service.
+   */
+  rpc disableNameservice(DisableNameserviceRequestProto) returns (DisableNameserviceResponseProto);
+
+  /**
+   * Enable a name service.
+   */
+  rpc enableNameservice(EnableNameserviceRequestProto) returns (EnableNameserviceResponseProto);
+
+  /**
+   * Get the list of disabled name services.
+   */
+  rpc getDisabledNameservices(GetDisabledNameservicesRequestProto) returns (GetDisabledNameservicesResponseProto);
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9752503/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java
index 10b71d7..5e27173 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdmin.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.IOException;
 import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
@@ -35,9 +36,16 @@ import org.apache.hadoop.hdfs.server.federation.resolver.MountTableManager;
 import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
 import org.apache.hadoop.hdfs.server.federation.resolver.order.DestinationOrder;
 import org.apache.hadoop.hdfs.server.federation.store.StateStoreService;
+import org.apache.hadoop.hdfs.server.federation.store.impl.DisabledNameserviceStoreImpl;
 import org.apache.hadoop.hdfs.server.federation.store.impl.MountTableStoreImpl;
 import org.apache.hadoop.hdfs.server.federation.store.protocol.AddMountTableEntryRequest;
 import org.apache.hadoop.hdfs.server.federation.store.protocol.AddMountTableEntryResponse;
+import org.apache.hadoop.hdfs.server.federation.store.protocol.DisableNameserviceRequest;
+import org.apache.hadoop.hdfs.server.federation.store.protocol.DisableNameserviceResponse;
+import org.apache.hadoop.hdfs.server.federation.store.protocol.EnableNameserviceRequest;
+import org.apache.hadoop.hdfs.server.federation.store.protocol.EnableNameserviceResponse;
+import org.apache.hadoop.hdfs.server.federation.store.protocol.GetDisabledNameservicesRequest;
+import org.apache.hadoop.hdfs.server.federation.store.protocol.GetDisabledNameservicesResponse;
 import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesRequest;
 import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesResponse;
 import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest;
@@ -337,4 +345,45 @@ public class TestRouterAdmin {
         mountTable.getMountTableEntries(request);
     return response.getEntries();
   }
+
+  @Test
+  public void testNameserviceManager() throws IOException {
+
+    RouterClient client = routerContext.getAdminClient();
+    NameserviceManager nsManager = client.getNameserviceManager();
+
+    // There shouldn't be any name service disabled
+    Set<String> disabled = getDisabledNameservices(nsManager);
+    assertTrue(disabled.isEmpty());
+
+    // Disable one and see it
+    DisableNameserviceRequest disableReq =
+        DisableNameserviceRequest.newInstance("ns0");
+    DisableNameserviceResponse disableResp =
+        nsManager.disableNameservice(disableReq);
+    assertTrue(disableResp.getStatus());
+    // Refresh the cache
+    disabled = getDisabledNameservices(nsManager);
+    assertEquals(1, disabled.size());
+    assertTrue(disabled.contains("ns0"));
+
+    // Enable one and we should have no disabled name services
+    EnableNameserviceRequest enableReq =
+        EnableNameserviceRequest.newInstance("ns0");
+    EnableNameserviceResponse enableResp =
+        nsManager.enableNameservice(enableReq);
+    assertTrue(enableResp.getStatus());
+    disabled = getDisabledNameservices(nsManager);
+    assertTrue(disabled.isEmpty());
+  }
+
+  private Set<String> getDisabledNameservices(NameserviceManager nsManager)
+      throws IOException {
+    stateStore.loadCache(DisabledNameserviceStoreImpl.class, true);
+    GetDisabledNameservicesRequest getReq =
+        GetDisabledNameservicesRequest.newInstance();
+    GetDisabledNameservicesResponse response =
+        nsManager.getDisabledNameservices(getReq);
+    return response.getNameservices();
+  }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9752503/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
index b36e434..cd5edf0 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestRouterAdminCLI.java
@@ -22,20 +22,20 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.io.ByteArrayOutputStream;
-
 import java.io.PrintStream;
 import java.net.InetSocketAddress;
 import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hdfs.protocol.HdfsConstants;
-import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
 import org.apache.hadoop.hdfs.server.federation.MiniRouterDFSCluster.RouterContext;
+import org.apache.hadoop.hdfs.server.federation.RouterConfigBuilder;
 import org.apache.hadoop.hdfs.server.federation.StateStoreDFSCluster;
 import org.apache.hadoop.hdfs.server.federation.resolver.MountTableManager;
 import org.apache.hadoop.hdfs.server.federation.resolver.RemoteLocation;
 import org.apache.hadoop.hdfs.server.federation.resolver.order.DestinationOrder;
 import org.apache.hadoop.hdfs.server.federation.store.StateStoreService;
+import org.apache.hadoop.hdfs.server.federation.store.impl.DisabledNameserviceStoreImpl;
 import org.apache.hadoop.hdfs.server.federation.store.impl.MountTableStoreImpl;
 import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesRequest;
 import org.apache.hadoop.hdfs.server.federation.store.protocol.GetMountTableEntriesResponse;
@@ -65,7 +65,9 @@ public class TestRouterAdminCLI {
   private static final String TEST_USER = "test-user";
 
   private final ByteArrayOutputStream out = new ByteArrayOutputStream();
+  private final ByteArrayOutputStream err = new ByteArrayOutputStream();
   private static final PrintStream OLD_OUT = System.out;
+  private static final PrintStream OLD_ERR = System.err;
 
   @BeforeClass
   public static void globalSetUp() throws Exception {
@@ -102,8 +104,9 @@ public class TestRouterAdminCLI {
 
   @After
   public void tearDown() {
-    // set back system out
+    // set back system out/err
     System.setOut(OLD_OUT);
+    System.setErr(OLD_ERR);
   }
 
   @Test
@@ -462,6 +465,45 @@ public class TestRouterAdminCLI {
     assertEquals(-1, ToolRunner.run(admin, argv));
   }
 
+  @Test
+  public void testNameserviceManager() throws Exception {
+    // Disable a name service and check if it's disabled
+    assertEquals(0, ToolRunner.run(admin,
+        new String[] {"-nameservice", "disable", "ns0"}));
+
+    stateStore.loadCache(DisabledNameserviceStoreImpl.class, true);
+    System.setOut(new PrintStream(out));
+    assertEquals(0, ToolRunner.run(admin,
+        new String[] {"-getDisabledNameservices"}));
+    assertTrue("ns0 should be reported: " + out,
+        out.toString().contains("ns0"));
+
+    // Enable a name service and check if it's there
+    assertEquals(0, ToolRunner.run(admin,
+        new String[] {"-nameservice", "enable", "ns0"}));
+
+    out.reset();
+    stateStore.loadCache(DisabledNameserviceStoreImpl.class, true);
+    assertEquals(0, ToolRunner.run(admin,
+        new String[] {"-getDisabledNameservices"}));
+    assertFalse("ns0 should not be reported: " + out,
+        out.toString().contains("ns0"));
+
+    // Wrong commands
+    System.setErr(new PrintStream(err));
+    assertEquals(-1, ToolRunner.run(admin,
+        new String[] {"-nameservice", "enable"}));
+    String msg = "Not enough parameters specificed for cmd -nameservice";
+    assertTrue("Got error: " + err.toString(),
+        err.toString().startsWith(msg));
+
+    err.reset();
+    assertEquals(-1, ToolRunner.run(admin,
+        new String[] {"-nameservice", "wrong", "ns0"}));
+    assertTrue("Got error: " + err.toString(),
+        err.toString().startsWith("nameservice: Unknown command: wrong"));
+  }
+
   /**
    * Wait for the Router transforming to expected state.
    * @param expectedState Expected Router state.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/a9752503/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreDriverBase.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreDriverBase.java
b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreDriverBase.java
index fd29e37..d6c829b 100644
--- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreDriverBase.java
+++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/store/driver/TestStateStoreDriverBase.java
@@ -41,6 +41,7 @@ import org.apache.hadoop.hdfs.server.federation.router.RouterServiceState;
 import org.apache.hadoop.hdfs.server.federation.store.FederationStateStoreTestUtils;
 import org.apache.hadoop.hdfs.server.federation.store.StateStoreService;
 import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord;
+import org.apache.hadoop.hdfs.server.federation.store.records.DisabledNameservice;
 import org.apache.hadoop.hdfs.server.federation.store.records.MembershipState;
 import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
 import org.apache.hadoop.hdfs.server.federation.store.records.Query;
@@ -139,6 +140,11 @@ public class TestStateStoreDriverBase {
       StateStoreVersion version = generateFakeRecord(StateStoreVersion.class);
       routerState.setStateStoreVersion(version);
       return (T) routerState;
+    } else if (recordClass == DisabledNameservice.class) {
+      return (T) DisabledNameservice.newInstance(generateRandomString());
+    } else if (recordClass == StateStoreVersion.class) {
+      return (T) StateStoreVersion.newInstance(
+          generateRandomLong(), generateRandomLong());
     }
 
     return null;
@@ -186,6 +192,8 @@ public class TestStateStoreDriverBase {
   public static void removeAll(StateStoreDriver driver) throws IOException {
     driver.removeAll(MembershipState.class);
     driver.removeAll(MountTable.class);
+    driver.removeAll(RouterState.class);
+    driver.removeAll(DisabledNameservice.class);
   }
 
   public <T extends BaseRecord> void testInsert(
@@ -290,7 +298,7 @@ public class TestStateStoreDriverBase {
 
     // Verify no update occurred, all original records are unchanged
     QueryResult<T> newRecords = driver.get(clazz);
-    assertTrue(newRecords.getRecords().size() == 10);
+    assertEquals(10, newRecords.getRecords().size());
     assertEquals("A single entry was improperly updated in the store", 10,
         countMatchingEntries(records.getRecords(), newRecords.getRecords()));
 
@@ -300,9 +308,12 @@ public class TestStateStoreDriverBase {
     // Verify that one entry no longer matches the original set
     newRecords = driver.get(clazz);
     assertEquals(10, newRecords.getRecords().size());
-    assertEquals(
-        "Record of type " + clazz + " not updated in the store", 9,
-        countMatchingEntries(records.getRecords(), newRecords.getRecords()));
+    T record = records.getRecords().get(0);
+    if (record.hasOtherFields()) {
+      assertEquals(
+          "Record of type " + clazz + " not updated in the store", 9,
+          countMatchingEntries(records.getRecords(), newRecords.getRecords()));
+    }
   }
 
   private int countMatchingEntries(
@@ -379,6 +390,8 @@ public class TestStateStoreDriverBase {
       throws IllegalArgumentException, IllegalAccessException, IOException {
     testInsert(driver, MembershipState.class);
     testInsert(driver, MountTable.class);
+    testInsert(driver, RouterState.class);
+    testInsert(driver, DisabledNameservice.class);
   }
 
   public void testPut(StateStoreDriver driver)
@@ -386,18 +399,24 @@ public class TestStateStoreDriverBase {
       IOException, SecurityException {
     testPut(driver, MembershipState.class);
     testPut(driver, MountTable.class);
+    testPut(driver, RouterState.class);
+    testPut(driver, DisabledNameservice.class);
   }
 
   public void testRemove(StateStoreDriver driver)
       throws IllegalArgumentException, IllegalAccessException, IOException {
     testRemove(driver, MembershipState.class);
     testRemove(driver, MountTable.class);
+    testRemove(driver, RouterState.class);
+    testRemove(driver, DisabledNameservice.class);
   }
 
   public void testFetchErrors(StateStoreDriver driver)
       throws IllegalArgumentException, IllegalAccessException, IOException {
     testFetchErrors(driver, MembershipState.class);
     testFetchErrors(driver, MountTable.class);
+    testFetchErrors(driver, RouterState.class);
+    testFetchErrors(driver, DisabledNameservice.class);
   }
 
   public void testMetrics(StateStoreDriver driver)


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org


Mime
View raw message