Search in sources :

Example 66 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestScannerResource method testTableScanWithTableDisable.

// performs table scan during which the underlying table is disabled
// assert that we get 410 (Gone)
@Test
public void testTableScanWithTableDisable() throws IOException {
    ScannerModel model = new ScannerModel();
    model.addColumn(Bytes.toBytes(COLUMN_1));
    model.setCaching(1);
    Response response = client.put("/" + TABLE_TO_BE_DISABLED + "/scanner", Constants.MIMETYPE_PROTOBUF, model.createProtobufOutput());
    assertEquals(response.getCode(), 201);
    String scannerURI = response.getLocation();
    assertNotNull(scannerURI);
    TEST_UTIL.getAdmin().disableTable(TABLE_TO_BE_DISABLED);
    response = client.get(scannerURI, Constants.MIMETYPE_PROTOBUF);
    assertTrue("got " + response.getCode(), response.getCode() == 410);
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) Test(org.junit.Test)

Example 67 with Response

use of org.apache.hadoop.hbase.rest.client.Response 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, JAXBException {
    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)

Example 68 with Response

use of org.apache.hadoop.hbase.rest.client.Response 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)

Example 69 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestDeleteRow method testDeleteNonExistentColumn.

@Test
public void testDeleteNonExistentColumn() throws Exception {
    Response response = putValueJson(TABLE, ROW_1, COLUMN_1, VALUE_1);
    assertEquals(response.getCode(), 200);
    response = checkAndDeleteJson(TABLE, ROW_1, COLUMN_1, VALUE_2);
    assertEquals(304, response.getCode());
    assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
    response = checkAndDeleteJson(TABLE, ROW_2, COLUMN_1, VALUE_2);
    assertEquals(304, response.getCode());
    assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
    response = checkAndDeleteJson(TABLE, ROW_1, "dummy", VALUE_1);
    assertEquals(400, response.getCode());
    assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
    response = checkAndDeleteJson(TABLE, ROW_1, "dummy:test", VALUE_1);
    assertEquals(404, response.getCode());
    assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
    response = checkAndDeleteJson(TABLE, ROW_1, "a:test", VALUE_1);
    assertEquals(304, response.getCode());
    assertEquals(200, getValueJson(TABLE, ROW_1, COLUMN_1).getCode());
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Test(org.junit.Test)

Example 70 with Response

use of org.apache.hadoop.hbase.rest.client.Response in project hbase by apache.

the class TestTableScan method testScanUsingListenerUnmarshallerXML.

/**
   * An example to scan using listener in unmarshaller for XML.
   * @throws Exception the exception
   */
@Test
public void testScanUsingListenerUnmarshallerXML() throws Exception {
    StringBuilder builder = new StringBuilder();
    builder.append("/*");
    builder.append("?");
    builder.append(Constants.SCAN_COLUMN + "=" + COLUMN_1);
    builder.append("&");
    builder.append(Constants.SCAN_LIMIT + "=10");
    Response response = client.get("/" + TABLE + builder.toString(), Constants.MIMETYPE_XML);
    assertEquals(200, response.getCode());
    assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type"));
    JAXBContext context = JAXBContext.newInstance(ClientSideCellSetModel.class, RowModel.class, CellModel.class);
    Unmarshaller unmarshaller = context.createUnmarshaller();
    final ClientSideCellSetModel.Listener listener = new ClientSideCellSetModel.Listener() {

        @Override
        public void handleRowModel(ClientSideCellSetModel helper, RowModel row) {
            assertTrue(row.getKey() != null);
            assertTrue(row.getCells().size() > 0);
        }
    };
    // install the callback on all ClientSideCellSetModel instances
    unmarshaller.setListener(new Unmarshaller.Listener() {

        public void beforeUnmarshal(Object target, Object parent) {
            if (target instanceof ClientSideCellSetModel) {
                ((ClientSideCellSetModel) target).setCellSetModelListener(listener);
            }
        }

        public void afterUnmarshal(Object target, Object parent) {
            if (target instanceof ClientSideCellSetModel) {
                ((ClientSideCellSetModel) target).setCellSetModelListener(null);
            }
        }
    });
    // create a new XML parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    XMLReader reader = factory.newSAXParser().getXMLReader();
    reader.setContentHandler(unmarshaller.getUnmarshallerHandler());
    assertFalse(ClientSideCellSetModel.listenerInvoked);
    reader.parse(new InputSource(response.getStream()));
    assertTrue(ClientSideCellSetModel.listenerInvoked);
}
Also used : InputSource(org.xml.sax.InputSource) JAXBContext(javax.xml.bind.JAXBContext) Response(org.apache.hadoop.hbase.rest.client.Response) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Aggregations

Response (org.apache.hadoop.hbase.rest.client.Response)91 Test (org.junit.Test)73 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)39 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)30 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)24 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StringWriter (java.io.StringWriter)16 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)10 Admin (org.apache.hadoop.hbase.client.Admin)9 JAXBContext (javax.xml.bind.JAXBContext)7 Unmarshaller (javax.xml.bind.Unmarshaller)7 JacksonJaxbJsonProvider (org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider)6 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)6 HashMap (java.util.HashMap)4 NamespaceDescriptor (org.apache.hadoop.hbase.NamespaceDescriptor)4 NamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.NamespacesInstanceModel)4 TestNamespacesInstanceModel (org.apache.hadoop.hbase.rest.model.TestNamespacesInstanceModel)4 Header (org.apache.http.Header)4 StorageClusterVersionModel (org.apache.hadoop.hbase.rest.model.StorageClusterVersionModel)3 TableListModel (org.apache.hadoop.hbase.rest.model.TableListModel)3