Search in sources :

Example 26 with CellSetModel

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");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 27 with CellSetModel

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");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) KeyValue(org.apache.hadoop.hbase.KeyValue) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) Put(org.apache.hadoop.hbase.client.Put)

Example 28 with CellSetModel

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");
}
Also used : InterruptedIOException(java.io.InterruptedIOException) KeyValue(org.apache.hadoop.hbase.KeyValue) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 29 with CellSetModel

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;
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with CellSetModel

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;
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)61 Response (org.apache.hadoop.hbase.rest.client.Response)44 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)42 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)37 Test (org.junit.Test)26 StringWriter (java.io.StringWriter)14 IOException (java.io.IOException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 Cell (org.apache.hadoop.hbase.Cell)9 JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)9 InterruptedIOException (java.io.InterruptedIOException)7 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 Map (java.util.Map)6 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)6 HashMap (java.util.HashMap)5 Result (org.apache.hadoop.hbase.client.Result)5 KeyValue (org.apache.hadoop.hbase.KeyValue)4 Put (org.apache.hadoop.hbase.client.Put)3