use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class RemoteHTable method doCheckAndDelete.
private boolean doCheckAndDelete(byte[] row, byte[] family, byte[] qualifier, byte[] value, Delete delete) throws IOException {
Put put = new Put(row, HConstants.LATEST_TIMESTAMP, 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 doCheckAndPut.
private boolean doCheckAndPut(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 RemoteHTable method getResults.
private Result[] getResults(String spec) throws IOException {
for (int i = 0; i < maxRetries; i++) {
Response response = client.get(spec, Constants.MIMETYPE_PROTOBUF);
int code = response.getCode();
switch(code) {
case 200:
CellSetModel model = new CellSetModel();
model.getObjectFromMessage(response.getBody());
Result[] results = buildResultFromModel(model);
if (results.length > 0) {
return results;
}
// fall through
case 404:
return new Result[0];
case 509:
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
throw (InterruptedIOException) new InterruptedIOException().initCause(e);
}
break;
default:
throw new IOException("get request returned " + code);
}
}
throw new IOException("get request timed out");
}
use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class TestSecureRESTServer method testProxy.
public void testProxy(String extraArgs, String PRINCIPAL, File keytab, int responseCode) throws Exception {
UserGroupInformation superuser = UserGroupInformation.loginUserFromKeytabAndReturnUGI(SERVICE_PRINCIPAL, serviceKeytab.getAbsolutePath());
final TableName table = TableName.valueOf("publicTable");
// Read that row as the client
Pair<CloseableHttpClient, HttpClientContext> pair = getClient();
CloseableHttpClient client = pair.getFirst();
HttpClientContext context = pair.getSecond();
HttpGet get = new HttpGet(new URL("http://localhost:" + REST_TEST.getServletPort()).toURI() + "/" + table + "/a" + extraArgs);
get.addHeader("Accept", "application/json");
UserGroupInformation user = UserGroupInformation.loginUserFromKeytabAndReturnUGI(PRINCIPAL, keytab.getAbsolutePath());
String jsonResponse = user.doAs(new PrivilegedExceptionAction<String>() {
@Override
public String run() throws Exception {
try (CloseableHttpResponse response = client.execute(get, context)) {
final int statusCode = response.getStatusLine().getStatusCode();
assertEquals(response.getStatusLine().toString(), responseCode, statusCode);
HttpEntity entity = response.getEntity();
return EntityUtils.toString(entity);
}
}
});
if (responseCode == HttpURLConnection.HTTP_OK) {
ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE);
CellSetModel model = mapper.readValue(jsonResponse, CellSetModel.class);
assertEquals(1, model.getRows().size());
RowModel row = model.getRows().get(0);
assertEquals("a", Bytes.toString(row.getKey()));
assertEquals(1, row.getCells().size());
CellModel cell = row.getCells().get(0);
assertEquals("1", Bytes.toString(cell.getValue()));
}
}
use of org.apache.hadoop.hbase.rest.model.CellSetModel in project hbase by apache.
the class MultiRowResource method get.
@GET
@Produces({ MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF, MIMETYPE_PROTOBUF_IETF })
public Response get(@Context final UriInfo uriInfo) {
MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
servlet.getMetrics().incrementRequests(1);
try {
CellSetModel model = new CellSetModel();
for (String rk : params.get(ROW_KEYS_PARAM_NAME)) {
RowSpec rowSpec = new RowSpec(rk);
if (this.versions != null) {
rowSpec.setMaxVersions(this.versions);
}
if (this.columns != null) {
for (int i = 0; i < this.columns.length; i++) {
rowSpec.addColumn(Bytes.toBytes(this.columns[i]));
}
}
ResultGenerator generator = ResultGenerator.fromRowSpec(this.tableResource.getName(), rowSpec, null, !params.containsKey(NOCACHE_PARAM_NAME));
Cell value = null;
RowModel rowModel = new RowModel(rowSpec.getRow());
if (generator.hasNext()) {
while ((value = generator.next()) != null) {
rowModel.addCell(new CellModel(CellUtil.cloneFamily(value), CellUtil.cloneQualifier(value), value.getTimestamp(), CellUtil.cloneValue(value)));
}
model.addRow(rowModel);
} else {
if (LOG.isTraceEnabled()) {
LOG.trace("The row : " + rk + " not found in the table.");
}
}
}
if (model.getRows().isEmpty()) {
// If no rows found.
servlet.getMetrics().incrementFailedGetRequests(1);
return Response.status(Response.Status.NOT_FOUND).type(MIMETYPE_TEXT).entity("No rows found." + CRLF).build();
} else {
servlet.getMetrics().incrementSucessfulGetRequests(1);
return Response.ok(model).build();
}
} catch (IOException e) {
servlet.getMetrics().incrementFailedGetRequests(1);
return processException(e);
}
}
Aggregations