HBASE-795 More Table operation in TableHandler for REST interface
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@686657 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c17ecdb420
commit
6cb9d9ff7f
|
@ -37,7 +37,9 @@ Release 0.3.0 - Unreleased
|
||||||
HBASE-812 Compaction needs little better skip algo (Daniel Leffel via Stack)
|
HBASE-812 Compaction needs little better skip algo (Daniel Leffel via Stack)
|
||||||
HBASE-806 Change HbaseMapWritable and RowResult to implement SortedMap
|
HBASE-806 Change HbaseMapWritable and RowResult to implement SortedMap
|
||||||
instead of Map (Jonathan Gray via Stack)
|
instead of Map (Jonathan Gray via Stack)
|
||||||
HBASE-795 More Table operation in TableHandler for REST interface
|
HBASE-795 More Table operation in TableHandler for REST interface: part 1
|
||||||
|
(Sishen Freecity via Stack)
|
||||||
|
HBASE-795 More Table operation in TableHandler for REST interface: part 2
|
||||||
(Sishen Freecity via Stack)
|
(Sishen Freecity via Stack)
|
||||||
HBASE-830 Debugging HCM.locateRegionInMeta is painful
|
HBASE-830 Debugging HCM.locateRegionInMeta is painful
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ implements javax.servlet.Servlet {
|
||||||
private RowHandler rowHandler;
|
private RowHandler rowHandler;
|
||||||
private ScannerHandler scannerHandler;
|
private ScannerHandler scannerHandler;
|
||||||
|
|
||||||
private static final String TABLES = "tables";
|
|
||||||
private static final String SCANNER = "scanner";
|
private static final String SCANNER = "scanner";
|
||||||
private static final String ROW = "row";
|
private static final String ROW = "row";
|
||||||
|
|
||||||
|
@ -117,12 +116,13 @@ implements javax.servlet.Servlet {
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
String [] pathSegments = getPathSegments(request);
|
String [] pathSegments = getPathSegments(request);
|
||||||
|
|
||||||
if (pathSegments.length == 1 && pathSegments[0].toLowerCase().equals(TABLES)) {
|
if (pathSegments.length == 0 || pathSegments[0].length() <= 0) {
|
||||||
|
// if it was a root request, it must be a create table request
|
||||||
tableHandler.doPost(request, response, pathSegments);
|
tableHandler.doPost(request, response, pathSegments);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// there should be at least two path segments (table name and row or
|
// there should be at least two path segments (table name and row or
|
||||||
// scanner)
|
// scanner or disable/enable operation)
|
||||||
if (pathSegments.length >= 2 && pathSegments[0].length() > 0) {
|
if (pathSegments.length >= 2 && pathSegments[0].length() > 0) {
|
||||||
if (pathSegments[1].toLowerCase().equals(SCANNER)
|
if (pathSegments[1].toLowerCase().equals(SCANNER)
|
||||||
&& pathSegments.length >= 2) {
|
&& pathSegments.length >= 2) {
|
||||||
|
@ -132,8 +132,8 @@ implements javax.servlet.Servlet {
|
||||||
&& pathSegments.length >= 3) {
|
&& pathSegments.length >= 3) {
|
||||||
rowHandler.doPost(request, response, pathSegments);
|
rowHandler.doPost(request, response, pathSegments);
|
||||||
return;
|
return;
|
||||||
} else if (pathSegments[0].toLowerCase().equals(TABLES) && pathSegments[1].length() > 0
|
} else if ((pathSegments[1].toLowerCase().equals(TableHandler.DISABLE) || pathSegments[1].toLowerCase().equals(TableHandler.ENABLE))
|
||||||
&& (pathSegments[2].toLowerCase().equals(TableHandler.DISABLE) || pathSegments[2].toLowerCase().equals(TableHandler.ENABLE))) {
|
&& pathSegments.length == 2) {
|
||||||
tableHandler.doPost(request, response, pathSegments);
|
tableHandler.doPost(request, response, pathSegments);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -147,12 +147,13 @@ implements javax.servlet.Servlet {
|
||||||
|
|
||||||
protected void doPut(HttpServletRequest request, HttpServletResponse response)
|
protected void doPut(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
// Equate PUT with a POST.
|
|
||||||
String [] pathSegments = getPathSegments(request);
|
String [] pathSegments = getPathSegments(request);
|
||||||
|
|
||||||
if (pathSegments.length == 2 && pathSegments[0].toLowerCase().equals(TABLES) && pathSegments[1].length() > 0) {
|
if (pathSegments.length == 1 && pathSegments[0].length() > 0) {
|
||||||
|
// if it has only table name
|
||||||
tableHandler.doPut(request, response, pathSegments);
|
tableHandler.doPut(request, response, pathSegments);
|
||||||
} else {
|
} else {
|
||||||
|
// Equate PUT with a POST.
|
||||||
doPost(request, response);
|
doPost(request, response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +163,8 @@ implements javax.servlet.Servlet {
|
||||||
throws IOException, ServletException {
|
throws IOException, ServletException {
|
||||||
String [] pathSegments = getPathSegments(request);
|
String [] pathSegments = getPathSegments(request);
|
||||||
|
|
||||||
if (pathSegments.length == 2 && pathSegments[0].toLowerCase().equals(TABLES) && pathSegments[1].length() > 0) {
|
if (pathSegments.length == 1 && pathSegments[0].length() > 0) {
|
||||||
|
// if it only has only table name
|
||||||
tableHandler.doDelete(request, response, pathSegments);
|
tableHandler.doDelete(request, response, pathSegments);
|
||||||
return;
|
return;
|
||||||
} else if (pathSegments.length >= 3 && pathSegments[0].length() > 0) {
|
} else if (pathSegments.length >= 3 && pathSegments[0].length() > 0) {
|
||||||
|
|
|
@ -55,7 +55,6 @@ public abstract class GenericHandler {
|
||||||
protected static final String CONTENT_TYPE = "content-type";
|
protected static final String CONTENT_TYPE = "content-type";
|
||||||
protected static final String ROW = "row";
|
protected static final String ROW = "row";
|
||||||
protected static final String REGIONS = "regions";
|
protected static final String REGIONS = "regions";
|
||||||
protected static final String TABLES = "tables";
|
|
||||||
|
|
||||||
protected final Log LOG = LogFactory.getLog(this.getClass());
|
protected final Log LOG = LogFactory.getLog(this.getClass());
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,6 @@ import java.io.IOException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.SortedMap;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
@ -39,7 +37,6 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.apache.hadoop.hbase.util.JenkinsHash;
|
import org.apache.hadoop.hbase.util.JenkinsHash;
|
||||||
import org.apache.hadoop.hbase.io.Cell;
|
import org.apache.hadoop.hbase.io.Cell;
|
||||||
import org.apache.hadoop.hbase.io.RowResult;
|
import org.apache.hadoop.hbase.io.RowResult;
|
||||||
import org.apache.hadoop.io.Text;
|
|
||||||
import org.mortbay.servlet.MultiPartResponse;
|
import org.mortbay.servlet.MultiPartResponse;
|
||||||
import org.znerd.xmlenc.XMLOutputter;
|
import org.znerd.xmlenc.XMLOutputter;
|
||||||
|
|
||||||
|
|
|
@ -78,15 +78,15 @@ public class TableHandler extends GenericHandler {
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response,
|
public void doPost(HttpServletRequest request, HttpServletResponse response,
|
||||||
String[] pathSegments)
|
String[] pathSegments)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
if (pathSegments.length == 1) {
|
if (pathSegments.length == 0 || pathSegments[0].length() <= 0) {
|
||||||
// if it's a creation operation
|
// if it's a creation operation
|
||||||
putTable(request, response, pathSegments);
|
putTable(request, response, pathSegments);
|
||||||
} else {
|
} else {
|
||||||
// if it's a disable operation or enable operation
|
// if it's a disable operation or enable operation
|
||||||
String tableName = pathSegments[1];
|
String tableName = pathSegments[0];
|
||||||
if (pathSegments[2].toLowerCase().equals(DISABLE)) {
|
if (pathSegments[1].toLowerCase().equals(DISABLE)) {
|
||||||
admin.disableTable(tableName);
|
admin.disableTable(tableName);
|
||||||
} else if (pathSegments[2].toLowerCase().equals(ENABLE)) {
|
} else if (pathSegments[1].toLowerCase().equals(ENABLE)) {
|
||||||
admin.enableTable(tableName);
|
admin.enableTable(tableName);
|
||||||
}
|
}
|
||||||
response.setStatus(202);
|
response.setStatus(202);
|
||||||
|
@ -240,7 +240,7 @@ public class TableHandler extends GenericHandler {
|
||||||
|
|
||||||
private void deleteTable(HttpServletRequest request,
|
private void deleteTable(HttpServletRequest request,
|
||||||
HttpServletResponse response, String[] pathSegments) throws IOException {
|
HttpServletResponse response, String[] pathSegments) throws IOException {
|
||||||
String tableName = pathSegments[1];
|
String tableName = pathSegments[0];
|
||||||
admin.deleteTable(tableName);
|
admin.deleteTable(tableName);
|
||||||
response.setStatus(202);
|
response.setStatus(202);
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ public class TableHandler extends GenericHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String tableName = pathSegments[1];
|
String tableName = pathSegments[0];
|
||||||
|
|
||||||
NodeList columnfamily_nodes = doc.getElementsByTagName("columnfamily");
|
NodeList columnfamily_nodes = doc.getElementsByTagName("columnfamily");
|
||||||
for (int i = 0; i < columnfamily_nodes.getLength(); i++) {
|
for (int i = 0; i < columnfamily_nodes.getLength(); i++) {
|
||||||
|
|
Loading…
Reference in New Issue