org.apache.hadoop.hbase.NamespaceDescriptor#setConfiguration ( )源码实例Demo

下面列出了org.apache.hadoop.hbase.NamespaceDescriptor#setConfiguration ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hbase   文件: TestModifyNamespaceProcedure.java
@Test
public void testModifyNamespaceWithInvalidRegionCount() throws Exception {
  final NamespaceDescriptor nsd =
      NamespaceDescriptor.create("testModifyNamespaceWithInvalidRegionCount").build();
  final String nsKey = "hbase.namespace.quota.maxregions";
  final String nsValue = "-1";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  createNamespaceForTesting(nsd);

  // Modify
  nsd.setConfiguration(nsKey, nsValue);

  long procId = procExec.submitProcedure(
    new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
  // Wait the completion
  ProcedureTestingUtility.waitProcedure(procExec, procId);
  Procedure<?> result = procExec.getResult(procId);
  assertTrue(result.isFailed());
  LOG.debug("Modify namespace failed with exception: " + result.getException());
  assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
 
源代码2 项目: hbase   文件: TestModifyNamespaceProcedure.java
@Test
public void testModifyNamespaceWithInvalidTableCount() throws Exception {
  final NamespaceDescriptor nsd =
      NamespaceDescriptor.create("testModifyNamespaceWithInvalidTableCount").build();
  final String nsKey = "hbase.namespace.quota.maxtables";
  final String nsValue = "-1";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  createNamespaceForTesting(nsd);

  // Modify
  nsd.setConfiguration(nsKey, nsValue);

  long procId = procExec.submitProcedure(
    new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
  // Wait the completion
  ProcedureTestingUtility.waitProcedure(procExec, procId);
  Procedure<?> result = procExec.getResult(procId);
  assertTrue(result.isFailed());
  LOG.debug("Modify namespace failed with exception: " + result.getException());
  assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
 
源代码3 项目: hbase   文件: TestCreateNamespaceProcedure.java
@Test
public void testCreateNamespaceWithInvalidRegionCount() throws Exception {
  final NamespaceDescriptor nsd =
      NamespaceDescriptor.create("testCreateNamespaceWithInvalidRegionCount").build();
  final String nsKey = "hbase.namespace.quota.maxregions";
  final String nsValue = "-1";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  nsd.setConfiguration(nsKey, nsValue);

  long procId = procExec.submitProcedure(
    new CreateNamespaceProcedure(procExec.getEnvironment(), nsd));
  // Wait the completion
  ProcedureTestingUtility.waitProcedure(procExec, procId);
  Procedure<?> result = procExec.getResult(procId);
  assertTrue(result.isFailed());
  LOG.debug("Create namespace failed with exception: " + result.getException());
  assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
 
源代码4 项目: hbase   文件: TestCreateNamespaceProcedure.java
@Test
public void testCreateNamespaceWithInvalidTableCount() throws Exception {
  final NamespaceDescriptor nsd =
      NamespaceDescriptor.create("testCreateNamespaceWithInvalidTableCount").build();
  final String nsKey = "hbase.namespace.quota.maxtables";
  final String nsValue = "-1";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  nsd.setConfiguration(nsKey, nsValue);

  long procId = procExec.submitProcedure(
    new CreateNamespaceProcedure(procExec.getEnvironment(), nsd));
  // Wait the completion
  ProcedureTestingUtility.waitProcedure(procExec, procId);
  Procedure<?> result = procExec.getResult(procId);
  assertTrue(result.isFailed());
  LOG.debug("Create namespace failed with exception: " + result.getException());
  assertTrue(ProcedureTestingUtility.getExceptionCause(result) instanceof ConstraintException);
}
 
源代码5 项目: hbase   文件: TestModifyNamespaceProcedure.java
@Test
public void testModifyNamespace() throws Exception {
  final NamespaceDescriptor nsd = NamespaceDescriptor.create("testModifyNamespace").build();
  final String nsKey1 = "hbase.namespace.quota.maxregions";
  final String nsValue1before = "1111";
  final String nsValue1after = "9999";
  final String nsKey2 = "hbase.namespace.quota.maxtables";
  final String nsValue2 = "10";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  nsd.setConfiguration(nsKey1, nsValue1before);
  createNamespaceForTesting(nsd);

  // Before modify
  NamespaceDescriptor currentNsDescriptor =
      UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
  assertEquals(nsValue1before, currentNsDescriptor.getConfigurationValue(nsKey1));
  assertNull(currentNsDescriptor.getConfigurationValue(nsKey2));

  // Update
  nsd.setConfiguration(nsKey1, nsValue1after);
  nsd.setConfiguration(nsKey2, nsValue2);

  long procId1 = procExec.submitProcedure(
    new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));
  // Wait the completion
  ProcedureTestingUtility.waitProcedure(procExec, procId1);
  ProcedureTestingUtility.assertProcNotFailed(procExec, procId1);

  // Verify the namespace is updated.
  currentNsDescriptor =
      UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
  assertEquals(nsValue1after, nsd.getConfigurationValue(nsKey1));
  assertEquals(nsValue2, currentNsDescriptor.getConfigurationValue(nsKey2));
}
 
源代码6 项目: hbase   文件: TestModifyNamespaceProcedure.java
@Test
public void testRecoveryAndDoubleExecution() throws Exception {
  final NamespaceDescriptor nsd =
      NamespaceDescriptor.create("testRecoveryAndDoubleExecution").build();
  final String nsKey = "foo";
  final String nsValue = "bar";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  createNamespaceForTesting(nsd);
  ProcedureTestingUtility.waitNoProcedureRunning(procExec);
  ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);

  // Modify
  nsd.setConfiguration(nsKey, nsValue);

  // Start the Modify procedure && kill the executor
  long procId = procExec.submitProcedure(
    new ModifyNamespaceProcedure(procExec.getEnvironment(), nsd));

  // Restart the executor and execute the step twice
  MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);

  ProcedureTestingUtility.assertProcNotFailed(procExec, procId);
  // Validate
  NamespaceDescriptor currentNsDescriptor =
      UTIL.getAdmin().getNamespaceDescriptor(nsd.getName());
  assertEquals(nsValue, currentNsDescriptor.getConfigurationValue(nsKey));
}
 
源代码7 项目: hbase   文件: TestAsyncNamespaceAdminApi.java
@Test
public void testNamespaceOperations() throws Exception {
  admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join();
  admin.createNamespace(NamespaceDescriptor.create(prefix + "ns2").build()).join();

  // create namespace that already exists
  runWithExpectedException(new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      admin.createNamespace(NamespaceDescriptor.create(prefix + "ns1").build()).join();
      return null;
    }
  }, NamespaceExistException.class);

  // create a table in non-existing namespace
  runWithExpectedException(new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      TableDescriptorBuilder tableDescriptorBuilder =
        TableDescriptorBuilder.newBuilder(TableName.valueOf("non_existing_namespace",
          "table1"));
      ColumnFamilyDescriptor columnFamilyDescriptor =
        ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("family1")).build();
      tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
      admin.createTable(tableDescriptorBuilder.build()).join();
      return null;
    }
  }, NamespaceNotFoundException.class);

  // get descriptor for existing namespace
  NamespaceDescriptor ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
  assertEquals(prefix + "ns1", ns1.getName());

  // get descriptor for non-existing namespace
  runWithExpectedException(new Callable<NamespaceDescriptor>() {
    @Override
    public NamespaceDescriptor call() throws Exception {
      return admin.getNamespaceDescriptor("non_existing_namespace").get();
    }
  }, NamespaceNotFoundException.class);

  // delete descriptor for existing namespace
  admin.deleteNamespace(prefix + "ns2").join();

  // delete descriptor for non-existing namespace
  runWithExpectedException(new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      admin.deleteNamespace("non_existing_namespace").join();
      return null;
    }
  }, NamespaceNotFoundException.class);

  // modify namespace descriptor for existing namespace
  ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
  ns1.setConfiguration("foo", "bar");
  admin.modifyNamespace(ns1).join();
  ns1 = admin.getNamespaceDescriptor(prefix + "ns1").get();
  assertEquals("bar", ns1.getConfigurationValue("foo"));

  // modify namespace descriptor for non-existing namespace
  runWithExpectedException(new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      admin.modifyNamespace(NamespaceDescriptor.create("non_existing_namespace").build()).join();
      return null;
    }
  }, NamespaceNotFoundException.class);

  admin.deleteNamespace(prefix + "ns1").join();
}
 
源代码8 项目: hbase   文件: TestNamespaceAuditor.java
@Test
public void testRestoreSnapshotQuotaExceed() throws Exception {
  String nsp = prefix + "_testRestoreSnapshotQuotaExceed";
  NamespaceDescriptor nspDesc =
      NamespaceDescriptor.create(nsp)
          .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").build();
  ADMIN.createNamespace(nspDesc);
  NamespaceDescriptor ndesc = ADMIN.getNamespaceDescriptor(nsp);
  assertNotNull("Namespace descriptor found null.", ndesc);
  TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
  TableDescriptorBuilder tableDescOne = TableDescriptorBuilder
    .newBuilder(tableName1);
  tableDescOne.setColumnFamily(columnFamilyDescriptor);

  ADMIN.createTable(tableDescOne.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);

  NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
  assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());

  String snapshot = "snapshot_testRestoreSnapshotQuotaExceed";
  // snapshot has 4 regions
  ADMIN.snapshot(snapshot, tableName1);
  // recreate table with 1 region and set max regions to 3 for namespace
  ADMIN.disableTable(tableName1);
  ADMIN.deleteTable(tableName1);
  ADMIN.createTable(tableDescOne.build());
  ndesc.setConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "3");
  ADMIN.modifyNamespace(ndesc);

  ADMIN.disableTable(tableName1);
  try {
    ADMIN.restoreSnapshot(snapshot);
    fail("Region quota is exceeded so QuotaExceededException should be thrown but HBaseAdmin"
        + " wraps IOException into RestoreSnapshotException");
  } catch (RestoreSnapshotException ignore) {
    assertTrue(ignore.getCause() instanceof QuotaExceededException);
  }
  assertEquals(1, getNamespaceState(nsp).getRegionCount());
  ADMIN.enableTable(tableName1);
  ADMIN.deleteSnapshot(snapshot);
}
 
源代码9 项目: hbase   文件: TestNamespacesInstanceResource.java
@Test
public void testGetNamespaceTablesAndCannotDeleteNamespace() throws IOException, JAXBException {
  Admin admin = TEST_UTIL.getAdmin();
  String nsName = "TestNamespacesInstanceResource5";
  Response response;

  // Create namespace via admin.
  NamespaceDescriptor.Builder nsBuilder = NamespaceDescriptor.create(nsName);
  NamespaceDescriptor nsd = nsBuilder.build();
  nsd.setConfiguration("key1", "value1");
  admin.createNamespace(nsd);

  // Create two tables via admin.
  TableName tn1 = TableName.valueOf(nsName + ":table1");
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tn1);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
  TableName tn2 = TableName.valueOf(nsName + ":table2");
  tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(tn2);
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());

  Map<String, String> nsProperties = new HashMap<>();
  nsProperties.put("key1", "value1");
  List<String> nsTables = Arrays.asList("table1", "table2");

  // Check get namespace properties as XML, JSON and Protobuf.
  String namespacePath = "/namespaces/" + nsName;
  response = client.get(namespacePath);
  assertEquals(200, response.getCode());

  response = client.get(namespacePath, Constants.MIMETYPE_XML);
  assertEquals(200, response.getCode());
  NamespacesInstanceModel model = fromXML(response.getBody());
  checkNamespaceProperties(model.getProperties(), nsProperties);

  response = client.get(namespacePath, Constants.MIMETYPE_JSON);
  assertEquals(200, response.getCode());
  model = jsonMapper.readValue(response.getBody(), NamespacesInstanceModel.class);
  checkNamespaceProperties(model.getProperties(), nsProperties);

  response = client.get(namespacePath, Constants.MIMETYPE_PROTOBUF);
  assertEquals(200, response.getCode());
  model.getObjectFromMessage(response.getBody());
  checkNamespaceProperties(model.getProperties(), nsProperties);

  // Check get namespace tables as XML, JSON and Protobuf.
  namespacePath = "/namespaces/" + nsName + "/tables";
  response = client.get(namespacePath);
  assertEquals(200, response.getCode());

  response = client.get(namespacePath, Constants.MIMETYPE_XML);
  assertEquals(200, response.getCode());
  TableListModel tablemodel = fromXML(response.getBody());
  checkNamespaceTables(tablemodel.getTables(), nsTables);

  response = client.get(namespacePath, Constants.MIMETYPE_JSON);
  assertEquals(200, response.getCode());
  tablemodel = jsonMapper.readValue(response.getBody(), TableListModel.class);
  checkNamespaceTables(tablemodel.getTables(), nsTables);

  response = client.get(namespacePath, Constants.MIMETYPE_PROTOBUF);
  assertEquals(200, response.getCode());
  tablemodel.setTables(new ArrayList<>());
  tablemodel.getObjectFromMessage(response.getBody());
  checkNamespaceTables(tablemodel.getTables(), nsTables);

  // Check cannot delete namespace via REST because it contains tables.
  response = client.delete(namespacePath);
  namespacePath = "/namespaces/" + nsName;
  assertEquals(503, response.getCode());
}