use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class RemoteHTable method put.
@Override
public void put(Put put) throws IOException {
CellSetModel model = buildModelFromPut(put);
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(Bytes.toString(name));
sb.append('/');
sb.append(toURLEncodedBytes(put.getRow()));
for (int i = 0; i < maxRetries; i++) {
Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
int code = response.getCode();
switch(code) {
case 200:
return;
case 509:
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
break;
default:
throw new IOException("put request failed with " + code);
}
}
throw new IOException("put request timed out");
}
use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class RemoteHTable method checkAndDelete.
@Override
public boolean checkAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value, Delete delete) throws IOException {
Put put = new Put(row);
put.setFamilyCellMap(delete.getFamilyCellMap());
// column to check-the-value
put.add(new KeyValue(row, family, qualifier, value));
CellSetModel model = buildModelFromPut(put);
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(Bytes.toString(name));
sb.append('/');
sb.append(toURLEncodedBytes(row));
sb.append("?check=delete");
for (int i = 0; i < maxRetries; i++) {
Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
int code = response.getCode();
switch(code) {
case 200:
return true;
case // NOT-MODIFIED
304:
return false;
case 509:
try {
Thread.sleep(sleepTime);
} catch (final InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
break;
default:
throw new IOException("checkAndDelete request failed with " + code);
}
}
throw new IOException("checkAndDelete request timed out");
}
use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class RemoteHTable method checkAndPut.
@Override
public boolean checkAndPut(byte[] row, byte[] family, byte[] qualifier, byte[] value, Put put) throws IOException {
// column to check-the-value
put.add(new KeyValue(row, family, qualifier, value));
CellSetModel model = buildModelFromPut(put);
StringBuilder sb = new StringBuilder();
sb.append('/');
sb.append(Bytes.toString(name));
sb.append('/');
sb.append(toURLEncodedBytes(put.getRow()));
sb.append("?check=put");
for (int i = 0; i < maxRetries; i++) {
Response response = client.put(sb.toString(), Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
int code = response.getCode();
switch(code) {
case 200:
return true;
case // NOT-MODIFIED
304:
return false;
case 509:
try {
Thread.sleep(sleepTime);
} catch (final InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
break;
default:
throw new IOException("checkAndPut request failed with " + code);
}
}
throw new IOException("checkAndPut request timed out");
}
use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class RowResourceBase method checkAndPutValuePB.
protected static Response checkAndPutValuePB(String url, String table, String row, String column, String valueToCheck, String valueToPut, HashMap<String, String> otherCells) throws IOException {
RowModel rowModel = new RowModel(row);
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToPut)));
if (otherCells != null) {
for (Map.Entry<String, String> entry : otherCells.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
}
}
// This Cell need to be added as last cell.
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
CellSetModel cellSetModel = new CellSetModel();
cellSetModel.addRow(rowModel);
Response response = client.put(url, Constants.MIMETYPE_PROTOBUF, cellSetModel.createProtobufOutput());
Thread.yield();
return response;
}
use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class RowResourceBase method checkAndDeleteJson.
protected static Response checkAndDeleteJson(String url, String table, String row, String column, String valueToCheck, HashMap<String, String> cellsToDelete) throws IOException {
RowModel rowModel = new RowModel(row);
if (cellsToDelete != null) {
for (Map.Entry<String, String> entry : cellsToDelete.entrySet()) {
rowModel.addCell(new CellModel(Bytes.toBytes(entry.getKey()), Bytes.toBytes(entry.getValue())));
}
}
// Add this at the end
rowModel.addCell(new CellModel(Bytes.toBytes(column), Bytes.toBytes(valueToCheck)));
CellSetModel cellSetModel = new CellSetModel();
cellSetModel.addRow(rowModel);
String jsonString = jsonMapper.writeValueAsString(cellSetModel);
Response response = client.put(url, Constants.MIMETYPE_JSON, Bytes.toBytes(jsonString));
Thread.yield();
return response;
}
Aggregations