public void run() throws Exception { Cluster cluster = new Cluster(); cluster.add(host, port); Client restClient = new Client(cluster, conf.getBoolean(Constants.REST_SSL_ENABLED, false)); try (RemoteHTable remoteTable = new RemoteHTable(restClient, conf, "example")) { // Write data to the table String rowKey = "row1"; Put p = new Put(rowKey.getBytes()); p.addColumn("family1".getBytes(), "qualifier1".getBytes(), "value1".getBytes()); remoteTable.put(p); // Get the data from the table Get g = new Get(rowKey.getBytes()); Result result = remoteTable.get(g); Preconditions.checkArgument(result != null, Bytes.toString(remoteTable.getTableName()) + " should have a row with key as " + rowKey); System.out.println("row = " + new String(result.getRow())); for (Cell cell : result.rawCells()) { System.out.print("family = " + Bytes.toString(CellUtil.cloneFamily(cell)) + "\t"); System.out.print("qualifier = " + Bytes.toString(CellUtil.cloneQualifier(cell)) + "\t"); System.out.print("value = " + Bytes.toString(CellUtil.cloneValue(cell)) + "\t"); System.out.println("timestamp = " + Long.toString(cell.getTimestamp())); } } }
private void runNIsMoreThanOne(final Class<? extends Test> cmd) throws IOException, InterruptedException, ClassNotFoundException { RemoteAdmin remoteAdmin = new RemoteAdmin(new Client(cluster), getConf()); checkTable(remoteAdmin); if (nomapred) { doMultipleClients(cmd); } else { doMapReduce(cmd); } }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled); 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; } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); }
private void runNIsOne(final Class<? extends Test> cmd) { Status status = new Status() { @Override public void setStatus(String msg) throws IOException { LOG.info(msg); } }; RemoteAdmin admin = null; try { Client client = new Client(cluster); admin = new RemoteAdmin(client, getConf()); checkTable(admin); runOneClient(cmd, 0, this.R, this.R, this.flushCommits, this.writeToWAL, this.useTags, this.noOfTags, this.connection, status); } catch (Exception e) { LOG.error("Failed", e); } }
@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())); testNamespacesInstanceModel = new TestNamespacesInstanceModel(); context = JAXBContext.newInstance(NamespacesInstanceModel.class, TableListModel.class); jsonMapper = new JacksonJaxbJsonProvider() .locateMapper(NamespacesInstanceModel.class, MediaType.APPLICATION_JSON_TYPE); NAMESPACE1_PROPS.put("key1", "value1"); NAMESPACE2_PROPS.put("key2a", "value2a"); NAMESPACE2_PROPS.put("key2b", "value2b"); NAMESPACE3_PROPS.put("key3", "value3"); NAMESPACE4_PROPS.put("key4a", "value4a"); NAMESPACE4_PROPS.put("key4b", "value4b"); }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled); extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, ""); TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(conf); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); testTableSchemaModel = new TestTableSchemaModel(); context = JAXBContext.newInstance( ColumnSchemaModel.class, TableSchemaModel.class); }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); TEST_UTIL.startMiniCluster(); TEST_UTIL.createTable(TableName.valueOf("TestStatusResource"), Bytes.toBytes("D")); TEST_UTIL.createTable(TableName.valueOf("TestStatusResource2"), Bytes.toBytes("D")); REST_TEST_UTIL.startServletContainer(conf); Cluster cluster = new Cluster(); cluster.add("localhost", REST_TEST_UTIL.getServletPort()); client = new Client(cluster); context = JAXBContext.newInstance(StorageClusterStatusModel.class); TEST_UTIL.waitFor(6000, new Waiter.Predicate<IOException>() { @Override public boolean evaluate() throws IOException { return TEST_UTIL.getMiniHBaseCluster().getClusterStatus().getAverageLoad() > 0; } }); }
@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())); context = JAXBContext.newInstance( CellModel.class, CellSetModel.class, RowModel.class, ScannerModel.class); marshaller = context.createMarshaller(); unmarshaller = context.createUnmarshaller(); Admin admin = TEST_UTIL.getAdmin(); if (admin.tableExists(TABLE)) { return; } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); expectedRows1 = insertData(TEST_UTIL.getConfiguration(), TABLE, COLUMN_1, 1.0); expectedRows2 = insertData(TEST_UTIL.getConfiguration(), TABLE, COLUMN_2, 0.5); htd = new HTableDescriptor(TABLE_TO_BE_DISABLED); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); }
@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())); }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); conf.set(Constants.CUSTOM_FILTERS, "CustomFilter:" + CustomFilter.class.getName()); TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(conf); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); Admin admin = TEST_UTIL.getAdmin(); if (!admin.tableExists(TABLE)) { HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); htd.addFamily(new HColumnDescriptor(CFB)); admin.createTable(htd); expectedRows1 = TestScannerResource.insertData(conf, TABLE, COLUMN_1, 1.0); expectedRows2 = TestScannerResource.insertData(conf, TABLE, COLUMN_2, 0.5); expectedRows3 = TestScannerResource.insertData(conf, TABLE, COLUMN_EMPTY, 1.0); } }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration()); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); Admin admin = TEST_UTIL.getAdmin(); if (admin.tableExists(TABLE)) { return; } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(CFA)); admin.createTable(htd); }
@BeforeClass public static void setUpBeforeClass() throws Exception { TEST_UTIL.startMiniCluster(); REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration()); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); context = JAXBContext.newInstance( VersionModel.class, StorageClusterVersionModel.class); }
@BeforeClass public static void setUpBeforeClass() throws Exception { conf = TEST_UTIL.getConfiguration(); TEST_UTIL.startMiniCluster(3); REST_TEST_UTIL.startServletContainer(conf); context = JAXBContext.newInstance( CellModel.class, CellSetModel.class, RowModel.class); xmlMarshaller = context.createMarshaller(); xmlUnmarshaller = context.createUnmarshaller(); jsonMapper = new JacksonJaxbJsonProvider() .locateMapper(CellSetModel.class, MediaType.APPLICATION_JSON_TYPE); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); }
@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); }
@Before public void before() throws Exception { Admin admin = TEST_UTIL.getAdmin(); if (admin.tableExists(TABLE)) { if (admin.isTableEnabled(TABLE)) admin.disableTable(TABLE); admin.deleteTable(TABLE); } HTableDescriptor htd = new HTableDescriptor(TABLE); htd.addFamily(new HColumnDescriptor(COLUMN_1).setMaxVersions(3)); htd.addFamily(new HColumnDescriptor(COLUMN_2).setMaxVersions(3)); htd.addFamily(new HColumnDescriptor(COLUMN_3).setMaxVersions(3)); admin.createTable(htd); try (Table table = TEST_UTIL.getConnection().getTable(TABLE)) { Put put = new Put(ROW_1); put.addColumn(COLUMN_1, QUALIFIER_1, TS_2, VALUE_1); table.put(put); put = new Put(ROW_2); put.addColumn(COLUMN_1, QUALIFIER_1, TS_1, VALUE_1); put.addColumn(COLUMN_1, QUALIFIER_1, TS_2, VALUE_2); put.addColumn(COLUMN_2, QUALIFIER_2, TS_2, VALUE_2); table.put(put); } remoteTable = new RemoteHTable( new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())), TEST_UTIL.getConfiguration(), TABLE.toBytes()); }
setAuths(); REST_TEST_UTIL.startServletContainer(conf); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); context = JAXBContext.newInstance(CellModel.class, CellSetModel.class, RowModel.class, ScannerModel.class);
TEST_UTIL.startMiniCluster(3); REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration()); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); context = JAXBContext.newInstance(
marshaller = context.createMarshaller(); unmarshaller = context.createUnmarshaller(); client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort())); Admin admin = TEST_UTIL.getAdmin();
cluster.add("localhost", 8080); // co RestExample-1-Cluster Set up a cluster list adding all known REST server hosts. Client client = new Client(cluster); // co RestExample-2-Client Create the client handling the HTTP communication.
@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())); }