HBASE-9849 [REST] Forbidden schema delete in read only mode (Julian Zhou)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1541644 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fe5865d9e3
commit
feca3e26c4
|
@ -236,6 +236,10 @@ public class SchemaResource extends ResourceBase {
|
||||||
LOG.debug("DELETE " + uriInfo.getAbsolutePath());
|
LOG.debug("DELETE " + uriInfo.getAbsolutePath());
|
||||||
}
|
}
|
||||||
servlet.getMetrics().incrementRequests(1);
|
servlet.getMetrics().incrementRequests(1);
|
||||||
|
if (servlet.isReadOnly()) {
|
||||||
|
return Response.status(Response.Status.FORBIDDEN).type(MIMETYPE_TEXT)
|
||||||
|
.entity("Forbidden" + CRLF).build();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
HBaseAdmin admin = servlet.getAdmin();
|
HBaseAdmin admin = servlet.getAdmin();
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
|
@ -123,14 +123,17 @@ public class TestSchemaResource {
|
||||||
model = testTableSchemaModel.fromJSON(Bytes.toString(response.getBody()));
|
model = testTableSchemaModel.fromJSON(Bytes.toString(response.getBody()));
|
||||||
testTableSchemaModel.checkModel(model, TABLE1);
|
testTableSchemaModel.checkModel(model, TABLE1);
|
||||||
|
|
||||||
// delete the table
|
// test delete schema operation is forbidden in read-only mode
|
||||||
client.delete(schemaPath);
|
response = client.delete(schemaPath);
|
||||||
|
assertEquals(response.getCode(), 403);
|
||||||
// make sure HBase concurs
|
|
||||||
assertFalse(admin.tableExists(TABLE1));
|
|
||||||
|
|
||||||
// return read-only setting back to default
|
// return read-only setting back to default
|
||||||
conf.set("hbase.rest.readonly", "false");
|
conf.set("hbase.rest.readonly", "false");
|
||||||
|
|
||||||
|
// delete the table and make sure HBase concurs
|
||||||
|
response = client.delete(schemaPath);
|
||||||
|
assertEquals(response.getCode(), 200);
|
||||||
|
assertFalse(admin.tableExists(TABLE1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -171,14 +174,17 @@ public class TestSchemaResource {
|
||||||
model.getObjectFromMessage(response.getBody());
|
model.getObjectFromMessage(response.getBody());
|
||||||
testTableSchemaModel.checkModel(model, TABLE2);
|
testTableSchemaModel.checkModel(model, TABLE2);
|
||||||
|
|
||||||
// delete the table
|
// test delete schema operation is forbidden in read-only mode
|
||||||
client.delete(schemaPath);
|
response = client.delete(schemaPath);
|
||||||
|
assertEquals(response.getCode(), 403);
|
||||||
// make sure HBase concurs
|
|
||||||
assertFalse(admin.tableExists(TABLE2));
|
|
||||||
|
|
||||||
// return read-only setting back to default
|
// return read-only setting back to default
|
||||||
conf.set("hbase.rest.readonly", "false");
|
conf.set("hbase.rest.readonly", "false");
|
||||||
|
|
||||||
|
// delete the table and make sure HBase concurs
|
||||||
|
response = client.delete(schemaPath);
|
||||||
|
assertEquals(response.getCode(), 200);
|
||||||
|
assertFalse(admin.tableExists(TABLE2));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue