Search in sources :

Example 1 with Client

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

the class TestMultiRowResource method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    conf = TEST_UTIL.getConfiguration();
    conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled);
    if (csrfEnabled) {
        conf.set(RESTServer.REST_CSRF_BROWSER_USERAGENTS_REGEX_KEY, ".*");
    }
    extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, "");
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(conf);
    context = JAXBContext.newInstance(CellModel.class, CellSetModel.class, RowModel.class);
    marshaller = context.createMarshaller();
    unmarshaller = context.createUnmarshaller();
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    Admin admin = TEST_UTIL.getAdmin();
    if (admin.tableExists(TABLE)) {
        return;
    }
    TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder.newBuilder(TABLE);
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFA)).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    columnFamilyDescriptor = ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFB)).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
    admin.createTable(tableDescriptorBuilder.build());
}
Also used : CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) Cluster(org.apache.hadoop.hbase.rest.client.Cluster) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) TableDescriptorBuilder(org.apache.hadoop.hbase.client.TableDescriptorBuilder) Client(org.apache.hadoop.hbase.rest.client.Client) Admin(org.apache.hadoop.hbase.client.Admin) ColumnFamilyDescriptor(org.apache.hadoop.hbase.client.ColumnFamilyDescriptor) BasicHeader(org.apache.http.message.BasicHeader) BeforeClass(org.junit.BeforeClass)

Example 2 with Client

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

the class TestNamespacesResource method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    conf = TEST_UTIL.getConfiguration();
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(conf);
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    testNamespacesModel = new TestNamespacesModel();
    context = JAXBContext.newInstance(NamespacesModel.class);
}
Also used : NamespacesModel(org.apache.hadoop.hbase.rest.model.NamespacesModel) TestNamespacesModel(org.apache.hadoop.hbase.rest.model.TestNamespacesModel) Cluster(org.apache.hadoop.hbase.rest.client.Cluster) TestNamespacesModel(org.apache.hadoop.hbase.rest.model.TestNamespacesModel) Client(org.apache.hadoop.hbase.rest.client.Client) BeforeClass(org.junit.BeforeClass)

Example 3 with Client

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

the class TestResourceFilter method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.getConfiguration().set(Constants.FILTER_CLASSES, DummyFilter.class.getName());
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
}
Also used : Cluster(org.apache.hadoop.hbase.rest.client.Cluster) Client(org.apache.hadoop.hbase.rest.client.Client) BeforeClass(org.junit.BeforeClass)

Example 4 with Client

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

the class TestScannersWithFilters method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    TEST_UTIL.startMiniCluster(3);
    REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
    context = JAXBContext.newInstance(CellModel.class, CellSetModel.class, RowModel.class, ScannerModel.class);
    marshaller = context.createMarshaller();
    unmarshaller = context.createUnmarshaller();
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    Admin admin = TEST_UTIL.getAdmin();
    if (!admin.tableExists(TABLE)) {
        TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(TABLE).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILIES[0])).setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILIES[1])).build();
        admin.createTable(tableDescriptor);
        Table table = TEST_UTIL.getConnection().getTable(TABLE);
        // Insert first half
        for (byte[] ROW : ROWS_ONE) {
            Put p = new Put(ROW);
            p.setDurability(Durability.SKIP_WAL);
            for (byte[] QUALIFIER : QUALIFIERS_ONE) {
                p.addColumn(FAMILIES[0], QUALIFIER, VALUES[0]);
            }
            table.put(p);
        }
        for (byte[] ROW : ROWS_TWO) {
            Put p = new Put(ROW);
            p.setDurability(Durability.SKIP_WAL);
            for (byte[] QUALIFIER : QUALIFIERS_TWO) {
                p.addColumn(FAMILIES[1], QUALIFIER, VALUES[1]);
            }
            table.put(p);
        }
        // Insert second half (reverse families)
        for (byte[] ROW : ROWS_ONE) {
            Put p = new Put(ROW);
            p.setDurability(Durability.SKIP_WAL);
            for (byte[] QUALIFIER : QUALIFIERS_ONE) {
                p.addColumn(FAMILIES[1], QUALIFIER, VALUES[0]);
            }
            table.put(p);
        }
        for (byte[] ROW : ROWS_TWO) {
            Put p = new Put(ROW);
            p.setDurability(Durability.SKIP_WAL);
            for (byte[] QUALIFIER : QUALIFIERS_TWO) {
                p.addColumn(FAMILIES[0], QUALIFIER, VALUES[1]);
            }
            table.put(p);
        }
        // Delete the second qualifier from all rows and families
        for (byte[] ROW : ROWS_ONE) {
            Delete d = new Delete(ROW);
            d.addColumns(FAMILIES[0], QUALIFIERS_ONE[1]);
            d.addColumns(FAMILIES[1], QUALIFIERS_ONE[1]);
            table.delete(d);
        }
        for (byte[] ROW : ROWS_TWO) {
            Delete d = new Delete(ROW);
            d.addColumns(FAMILIES[0], QUALIFIERS_TWO[1]);
            d.addColumns(FAMILIES[1], QUALIFIERS_TWO[1]);
            table.delete(d);
        }
        colsPerRow -= 2;
        // Delete the second rows from both groups, one column at a time
        for (byte[] QUALIFIER : QUALIFIERS_ONE) {
            Delete d = new Delete(ROWS_ONE[1]);
            d.addColumns(FAMILIES[0], QUALIFIER);
            d.addColumns(FAMILIES[1], QUALIFIER);
            table.delete(d);
        }
        for (byte[] QUALIFIER : QUALIFIERS_TWO) {
            Delete d = new Delete(ROWS_TWO[1]);
            d.addColumns(FAMILIES[0], QUALIFIER);
            d.addColumns(FAMILIES[1], QUALIFIER);
            table.delete(d);
        }
        numRows -= 2;
        table.close();
    }
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) Table(org.apache.hadoop.hbase.client.Table) CellSetModel(org.apache.hadoop.hbase.rest.model.CellSetModel) Cluster(org.apache.hadoop.hbase.rest.client.Cluster) CellModel(org.apache.hadoop.hbase.rest.model.CellModel) RowModel(org.apache.hadoop.hbase.rest.model.RowModel) Client(org.apache.hadoop.hbase.rest.client.Client) Admin(org.apache.hadoop.hbase.client.Admin) ScannerModel(org.apache.hadoop.hbase.rest.model.ScannerModel) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) Put(org.apache.hadoop.hbase.client.Put) BeforeClass(org.junit.BeforeClass)

Example 5 with Client

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

the class TestSecurityHeadersFilter method testDefaultValues.

@Test
public void testDefaultValues() throws Exception {
    TEST_UTIL.startMiniCluster();
    REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
    client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
    String path = "/version/cluster";
    Response response = client.get(path);
    assertThat(response.getCode(), equalTo(200));
    assertThat("Header 'X-Content-Type-Options' is missing from Rest response", response.getHeader("X-Content-Type-Options"), is(not((String) null)));
    assertThat("Header 'X-Content-Type-Options' has invalid default value", response.getHeader("X-Content-Type-Options"), equalTo("nosniff"));
    assertThat("Header 'X-XSS-Protection' is missing from Rest response", response.getHeader("X-XSS-Protection"), is(not((String) null)));
    assertThat("Header 'X-XSS-Protection' has invalid default value", response.getHeader("X-XSS-Protection"), equalTo("1; mode=block"));
    assertThat("Header 'Strict-Transport-Security' should be missing from Rest response," + "but it's present", response.getHeader("Strict-Transport-Security"), is((String) null));
    assertThat("Header 'Content-Security-Policy' should be missing from Rest response," + "but it's present", response.getHeader("Content-Security-Policy"), is((String) null));
}
Also used : Response(org.apache.hadoop.hbase.rest.client.Response) Cluster(org.apache.hadoop.hbase.rest.client.Cluster) Client(org.apache.hadoop.hbase.rest.client.Client) Test(org.junit.Test)

Aggregations

Client (org.apache.hadoop.hbase.rest.client.Client)21 Cluster (org.apache.hadoop.hbase.rest.client.Cluster)19 BeforeClass (org.junit.BeforeClass)14 Admin (org.apache.hadoop.hbase.client.Admin)6 ColumnFamilyDescriptor (org.apache.hadoop.hbase.client.ColumnFamilyDescriptor)5 TableDescriptorBuilder (org.apache.hadoop.hbase.client.TableDescriptorBuilder)5 CellModel (org.apache.hadoop.hbase.rest.model.CellModel)5 CellSetModel (org.apache.hadoop.hbase.rest.model.CellSetModel)5 RowModel (org.apache.hadoop.hbase.rest.model.RowModel)5 ScannerModel (org.apache.hadoop.hbase.rest.model.ScannerModel)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 Put (org.apache.hadoop.hbase.client.Put)2 Table (org.apache.hadoop.hbase.client.Table)2 RemoteAdmin (org.apache.hadoop.hbase.rest.client.RemoteAdmin)2 Response (org.apache.hadoop.hbase.rest.client.Response)2 TableListModel (org.apache.hadoop.hbase.rest.model.TableListModel)2 JacksonJaxbJsonProvider (org.apache.hbase.thirdparty.com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)2 BasicHeader (org.apache.http.message.BasicHeader)2 ArrayList (java.util.ArrayList)1