/** * Send a DELETE request * @param path the path or URI * @return a Response object with response detail * @throws IOException */ public Response delete(String path) throws IOException { return delete(cluster, path); }
/** * Send a DELETE request * @param path the path or URI * @param extraHdr additional Header to send * @return a Response object with response detail * @throws IOException */ public Response delete(String path, Header extraHdr) throws IOException { return delete(cluster, path, extraHdr); }
@Override public void close() { try { client.delete(uri); } catch (IOException e) { LOG.warn(StringUtils.stringifyException(e)); } }
int code = 0; for (int i = 0; i < maxRetries; i++) { Response response = client.delete(path.toString()); code = response.getCode(); switch (code) {
protected static Response deleteRow(String table, String row) throws IOException { StringBuilder path = new StringBuilder(); path.append('/'); path.append(table); path.append('/'); path.append(row); Response response = client.delete(path.toString()); Thread.yield(); return response; }
protected static Response deleteValue(String table, String row, String column) throws IOException { StringBuilder path = new StringBuilder(); path.append('/'); path.append(table); path.append('/'); path.append(row); path.append('/'); path.append(column); Response response = client.delete(path.toString()); Thread.yield(); return response; }
@Override public void delete(Delete delete) throws IOException { String spec = buildRowSpec(delete.getRow(), delete.getFamilyCellMap(), delete.getTimestamp(), delete.getTimestamp(), 1); for (int i = 0; i < maxRetries; i++) { Response response = client.delete(spec); 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("delete request failed with " + code); } } throw new IOException("delete request timed out"); }
@Test public void testDelete() throws Exception { testTimedOutCall(new CallExecutor() { @Override public void run() throws Exception { Delete delete = new Delete(Bytes.toBytes("delete")); remoteTable.delete(delete); } }); verify(client, times(RETRIES)).delete(anyString()); }
@Test public void testFailingDeleteTable() throws Exception { testTimedOutCall(new CallExecutor() { @Override public void run() throws Exception { remoteAdmin.deleteTable("TestTable"); } }); verify(client, times(RETRIES)).delete(anyString()); }
@Before public void setup() throws Exception { client = mock(Client.class); Response response = new Response(509); when(client.get(anyString(), anyString())).thenReturn(response); when(client.delete(anyString())).thenReturn(response); when(client.put(anyString(), anyString(), any())).thenReturn(response); when(client.post(anyString(), anyString(), any())).thenReturn(response); Configuration configuration = TEST_UTIL.getConfiguration(); configuration.setInt("hbase.rest.client.max.retries", RETRIES); configuration.setInt("hbase.rest.client.sleep", SLEEP_TIME); remoteAdmin = new RemoteAdmin(client, TEST_UTIL.getConfiguration(), "MyTable"); }
@Before public void setup() throws Exception { client = mock(Client.class); Response response = new Response(509); when(client.get(anyString(), anyString())).thenReturn(response); when(client.delete(anyString())).thenReturn(response); when(client.put(anyString(), anyString(), any())).thenReturn( response); when(client.post(anyString(), anyString(), any())).thenReturn( response); Configuration configuration = TEST_UTIL.getConfiguration(); configuration.setInt("hbase.rest.client.max.retries", RETRIES); configuration.setInt("hbase.rest.client.sleep", SLEEP_TIME); remoteTable = new RemoteHTable(client, TEST_UTIL.getConfiguration(), "MyTable"); }
@Test public void testMultiCellGetXML() throws IOException, JAXBException { String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1; String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2; StringBuilder path = new StringBuilder(); path.append("/"); path.append(TABLE); path.append("/multiget/?row="); path.append(ROW_1); path.append("&row="); path.append(ROW_2); client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1), extraHdr); client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2), extraHdr); Response response = client.get(path.toString(), Constants.MIMETYPE_XML); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_XML, response.getHeader("content-type")); client.delete(row_5_url, extraHdr); client.delete(row_6_url, extraHdr); }
@Test public void testMultiCellGetJSON() throws IOException, JAXBException { String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1; String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2; StringBuilder path = new StringBuilder(); path.append("/"); path.append(TABLE); path.append("/multiget/?row="); path.append(ROW_1); path.append("&row="); path.append(ROW_2); if (csrfEnabled) { Response response = client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1)); assertEquals(400, response.getCode()); } client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1), extraHdr); client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2), extraHdr); Response response = client.get(path.toString(), Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); assertEquals(Constants.MIMETYPE_JSON, response.getHeader("content-type")); client.delete(row_5_url, extraHdr); client.delete(row_6_url, extraHdr); }
@Test public void testMultiCellGetJSONNotFound() throws IOException, JAXBException { String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1; StringBuilder path = new StringBuilder(); path.append("/"); path.append(TABLE); path.append("/multiget/?row="); path.append(ROW_1); path.append("&row="); path.append(ROW_2); client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1), extraHdr); Response response = client.get(path.toString(), Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE); CellSetModel cellSet = (CellSetModel) mapper.readValue(response.getBody(), CellSetModel.class); assertEquals(1, cellSet.getRows().size()); assertEquals(ROW_1, Bytes.toString(cellSet.getRows().get(0).getKey())); assertEquals(VALUE_1, Bytes.toString(cellSet.getRows().get(0).getCells().get(0).getValue())); client.delete(row_5_url, extraHdr); }
@Test public void testMultiCellGetWithColsJSON() throws IOException, JAXBException { String row_5_url = "/" + TABLE + "/" + ROW_1 + "/" + COLUMN_1; String row_6_url = "/" + TABLE + "/" + ROW_2 + "/" + COLUMN_2; StringBuilder path = new StringBuilder(); path.append("/"); path.append(TABLE); path.append("/multiget"); path.append("/" + COLUMN_1 + "," + CFB); path.append("?row="); path.append(ROW_1); path.append("&row="); path.append(ROW_2); client.post(row_5_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_1), extraHdr); client.post(row_6_url, Constants.MIMETYPE_BINARY, Bytes.toBytes(VALUE_2), extraHdr); Response response = client.get(path.toString(), Constants.MIMETYPE_JSON); assertEquals(200, response.getCode()); ObjectMapper mapper = new JacksonJaxbJsonProvider().locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE); CellSetModel cellSet = mapper.readValue(response.getBody(), CellSetModel.class); assertEquals(2, cellSet.getRows().size()); assertEquals(ROW_1, Bytes.toString(cellSet.getRows().get(0).getKey())); assertEquals(VALUE_1, Bytes.toString(cellSet.getRows().get(0).getCells().get(0).getValue())); assertEquals(ROW_2, Bytes.toString(cellSet.getRows().get(1).getKey())); assertEquals(VALUE_2, Bytes.toString(cellSet.getRows().get(1).getCells().get(0).getValue())); client.delete(row_5_url, extraHdr); client.delete(row_6_url, extraHdr); }
response = client.delete(scannerURI); assertEquals(200, response.getCode());
@Test public void testCannotDeleteDefaultAndHbaseNamespaces() throws IOException { String defaultPath = "/namespaces/default"; String hbasePath = "/namespaces/hbase"; Response response; // Check that doesn't exist via non-REST call. Admin admin = TEST_UTIL.getAdmin(); assertNotNull(findNamespace(admin, "default")); assertNotNull(findNamespace(admin, "hbase")); // Try (but fail) to delete namespaces via REST. response = client.delete(defaultPath); assertEquals(503, response.getCode()); response = client.delete(hbasePath); assertEquals(503, response.getCode()); assertNotNull(findNamespace(admin, "default")); assertNotNull(findNamespace(admin, "hbase")); }
response = client.delete(scannerURI); assertEquals(200, response.getCode()); return count;