Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class RemoteAdmin {
final String accessToken;
final int maxRetries;
final long sleepTime;
private String pathPrefix = "/";

// This unmarshaller is necessary for getting the /version/cluster resource.
// This resource does not support protobufs. Therefore this is necessary to
Expand Down Expand Up @@ -79,6 +80,14 @@ public RemoteAdmin(Client client, Configuration conf, String accessToken) {
this.sleepTime = conf.getLong("hbase.rest.client.sleep", 1000);
}

/**
* Constructor
*/
public RemoteAdmin(Client client, Configuration conf, String accessToken, String pathPrefix) {
this(client, conf, accessToken);
this.pathPrefix = pathPrefix + "/";
}

/**
* @param tableName name of table to check
* @return true if all regions of the table are available
Expand All @@ -95,7 +104,7 @@ public boolean isTableAvailable(String tableName) throws IOException {
public VersionModel getRestVersion() throws IOException {

StringBuilder path = new StringBuilder();
path.append('/');
path.append(pathPrefix);
if (accessToken != null) {
path.append(accessToken);
path.append('/');
Expand Down Expand Up @@ -136,7 +145,7 @@ public VersionModel getRestVersion() throws IOException {
public StorageClusterStatusModel getClusterStatus() throws IOException {

StringBuilder path = new StringBuilder();
path.append('/');
path.append(pathPrefix);
if (accessToken != null) {
path.append(accessToken);
path.append('/');
Expand Down Expand Up @@ -175,7 +184,7 @@ public StorageClusterStatusModel getClusterStatus() throws IOException {
public StorageClusterVersionModel getClusterVersion() throws IOException {

StringBuilder path = new StringBuilder();
path.append('/');
path.append(pathPrefix);
if (accessToken != null) {
path.append(accessToken);
path.append('/');
Expand Down Expand Up @@ -221,7 +230,7 @@ public StorageClusterVersionModel getClusterVersion() throws IOException {
*/
public boolean isTableAvailable(byte[] tableName) throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(pathPrefix);
if (accessToken != null) {
path.append(accessToken);
path.append('/');
Expand Down Expand Up @@ -260,7 +269,7 @@ public boolean isTableAvailable(byte[] tableName) throws IOException {
public void createTable(TableDescriptor desc) throws IOException {
TableSchemaModel model = new TableSchemaModel(desc);
StringBuilder path = new StringBuilder();
path.append('/');
path.append(pathPrefix);
if (accessToken != null) {
path.append(accessToken);
path.append('/');
Expand Down Expand Up @@ -306,7 +315,7 @@ public void deleteTable(final String tableName) throws IOException {
*/
public void deleteTable(final byte[] tableName) throws IOException {
StringBuilder path = new StringBuilder();
path.append('/');
path.append(pathPrefix);
if (accessToken != null) {
path.append(accessToken);
path.append('/');
Expand Down Expand Up @@ -342,7 +351,7 @@ public void deleteTable(final byte[] tableName) throws IOException {
public TableListModel getTableList() throws IOException {

StringBuilder path = new StringBuilder();
path.append('/');
path.append(pathPrefix);
if (accessToken != null) {
path.append(accessToken);
path.append('/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ public class RemoteHTable implements Table {
final byte[] name;
final int maxRetries;
final long sleepTime;
private String pathPrefix = "/";

@SuppressWarnings("rawtypes")
protected String buildRowSpec(final byte[] row, final Map familyMap, final long startTime,
final long endTime, final int maxVersions) {
StringBuffer sb = new StringBuffer();
sb.append('/');
StringBuilder sb = new StringBuilder();
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append('/');
sb.append(toURLEncodedBytes(row));
Expand Down Expand Up @@ -159,7 +160,7 @@ protected String buildRowSpec(final byte[] row, final Map familyMap, final long

protected String buildMultiRowSpec(final byte[][] rows, int maxVersions) {
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append("/multiget/");
if (rows == null || rows.length == 0) {
Expand Down Expand Up @@ -242,6 +243,11 @@ public RemoteHTable(Client client, Configuration conf, byte[] name) {
this.sleepTime = conf.getLong("hbase.rest.client.sleep", 1000);
}

public RemoteHTable(Client client, Configuration conf, byte[] name, String pathPrefix) {
this(client, conf, name);
this.pathPrefix = pathPrefix + "/";
}

public byte[] getTableName() {
return name.clone();
}
Expand Down Expand Up @@ -359,7 +365,7 @@ public boolean[] exists(List<Get> gets) throws IOException {
public void put(Put put) throws IOException {
CellSetModel model = buildModelFromPut(put);
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append('/');
sb.append(toURLEncodedBytes(put.getRow()));
Expand Down Expand Up @@ -415,7 +421,7 @@ public void put(List<Put> puts) throws IOException {

// build path for multiput
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append("/$multiput"); // can be any nonexistent row
for (int i = 0; i < maxRetries; i++) {
Expand Down Expand Up @@ -477,7 +483,7 @@ public void flushCommits() throws IOException {
@Override
public TableDescriptor getDescriptor() throws IOException {
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append('/');
sb.append("schema");
Expand Down Expand Up @@ -516,8 +522,8 @@ public Scanner(Scan scan) throws IOException {
} catch (Exception e) {
throw new IOException(e);
}
StringBuffer sb = new StringBuffer();
sb.append('/');
StringBuilder sb = new StringBuilder();
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append('/');
sb.append("scanner");
Expand Down Expand Up @@ -688,7 +694,7 @@ private boolean doCheckAndPut(byte[] row, byte[] family, byte[] qualifier, byte[

CellSetModel model = buildModelFromPut(put);
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append('/');
sb.append(toURLEncodedBytes(put.getRow()));
Expand Down Expand Up @@ -724,7 +730,7 @@ private boolean doCheckAndDelete(byte[] row, byte[] family, byte[] qualifier, by
put.add(new KeyValue(row, family, qualifier, value));
CellSetModel model = buildModelFromPut(put);
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(pathPrefix);
sb.append(Bytes.toString(name));
sb.append('/');
sb.append(toURLEncodedBytes(row));
Expand Down