/** * @param args */ public static void main(String[] args) throws Exception { /** TTransport transport = new TSocket("localhost", 8080); transport.open(); TProtocol protocol = new TBinaryProtocol(transport); ThriftTestService.Client client = new ThriftTestService.Client(protocol); System.out.println(client.test("name")); transport.close(); **/ InMemoryScribe client; ThriftCodecManager thriftCodecManager = new ThriftCodecManager(); HttpClientConnector connector = new HttpClientConnector(URI.create("http://localhost:" + 8080 +"/scribe")); ThriftClientManager clientManager = new ThriftClientManager(thriftCodecManager); client = clientManager.createClient(connector, InMemoryScribe.class).get(); List<LogEntry> msgs = new ArrayList<LogEntry>(); String name = client.log(msgs); System.out.println("name: "+ name); }
@Test public void testNonExistent() throws Exception { final int port = NetUtils.findUnusedPort(); final HiveMetastoreClientConfig metastoreConfig = new HiveMetastoreClientConfig() .setPort(port) .setMaxRetries(5) .setRetrySleep(new Duration(1, TimeUnit.SECONDS)) .setRetryTimeout(new Duration(30, TimeUnit.SECONDS)); try (final ThriftClientManager clientManager = new ThriftClientManager()) { final ThriftClientConfig clientConfig = new ThriftClientConfig(); final HiveMetastoreFactory factory = new SimpleHiveMetastoreFactory(clientManager, clientConfig, metastoreConfig); try (final HiveMetastore metastore = factory.getDefaultClient()) { assertFalse(metastore.isConnected()); metastore.getTable("hello", "world"); fail(); } catch (TTransportException te) { assertEquals(TTransportException.UNKNOWN, te.getType()); } } }
@Test public void testSimple() throws Exception { final int port = NetUtils.findUnusedPort(); startService(port); final HiveMetastoreClientConfig metastoreConfig = new HiveMetastoreClientConfig().setPort(port); try (final ThriftClientManager clientManager = new ThriftClientManager()) { final ThriftClientConfig clientConfig = new ThriftClientConfig(); final HiveMetastoreFactory factory = new SimpleHiveMetastoreFactory(clientManager, clientConfig, metastoreConfig); try (final HiveMetastore metastore = factory.getDefaultClient()) { final Table table = metastore.getTable("hello", "world"); assertNotNull(table); assertEquals("hello", table.getDbName()); assertEquals("world", table.getTableName()); } } }
@Test public void testLateConnectIsOk() throws Exception { final int port = NetUtils.findUnusedPort(); final HiveMetastoreClientConfig metastoreConfig = new HiveMetastoreClientConfig().setPort(port); final ThriftClientConfig clientConfig = new ThriftClientConfig(); try (final ThriftClientManager clientManager = new ThriftClientManager()) { final HiveMetastoreFactory factory = new SimpleHiveMetastoreFactory(clientManager, clientConfig, metastoreConfig); try (final HiveMetastore metastore = factory.getDefaultClient()) { assertFalse(metastore.isConnected()); } startService(port); try (final HiveMetastore metastore = factory.getDefaultClient()) { final Table table = metastore.getTable("hello", "world"); assertNotNull(table); assertEquals("hello", table.getDbName()); assertEquals("world", table.getTableName()); } } }
public static void main(String[] args) throws ExecutionException, InterruptedException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { ThriftClientManager clientManager = new ThriftClientManager(); FramedClientConnector connector = new FramedClientConnector(new InetSocketAddress("localhost",8899)); ThirdPartyCollectionService scribe = clientManager.createClient(connector, ThirdPartyCollectionService.class).get(); //scribe.getAll(); ThirdPartyCollection collection = new ThirdPartyCollection(1001, "2014-08-29"); ThirdPartyCollection co2 = scribe.save(collection); System.out.println("c:"+ co2.getId()); System.out.println("c:"+ co2.getDate()); }
@Before public void setUp() throws Exception { HttpClientConnector connector = new HttpClientConnector(URI.create("http://localhost:" + port + "/thrift/")); ThriftClientManager clientManager = new ThriftClientManager(thriftCodecManager); client = clientManager.createClient(connector, TCalculatorService.class).get(); }
/** Sets up clients before each benchmark */ private void setUp() throws Exception { try { fileSystem = (DistributedFileSystem) FileSystem.get( StorageServiceConfigKeys.translateToOldSchema(conf, nameserviceId), conf); InetSocketAddress nameNodeAddr = fileSystem.getClient().getNameNodeAddr(); metaInfo = new RequestMetaInfo(clusterId, nameserviceId, RequestMetaInfo.NO_NAMESPACE_ID, RequestMetaInfo.NO_APPLICATION_ID, (UnixUserGroupInformation) UserGroupInformation.getUGI( this.conf)); directClientProtocol = RPC.getProxy(ClientProtocol.class, ClientProtocol.versionID, nameNodeAddr, conf); directClientProxyProtocol = RPC.getProxy(ClientProxyProtocol.class, ClientProxyProtocol.versionID, nameNodeAddr, conf); clientManager = new ThriftClientManager(); FramedClientConnector connector = new FramedClientConnector(HostAndPort.fromParts( proxyHostname, proxyPortThrift)); proxyTClientProxyProtocol = clientManager.createClient(connector, TClientProxyProtocol.class) .get(); proxyClientProxyProtocol = RPC.getProxy(ClientProxyProtocol.class, ClientProxyProtocol.versionID, new InetSocketAddress(proxyHostname, proxyPortRPC), conf); fileSystem.mkdirs(new Path(ROOT)); } catch (Exception e) { tearDown(); throw e; } }
@Before public void setUp() throws Exception { try { Configuration conf = new Configuration(); // Bind ports automatically conf.setInt(StorageServiceConfigKeys.PROXY_THRIFT_PORT_KEY, 0); conf.setInt(StorageServiceConfigKeys.PROXY_RPC_PORT_KEY, 0); cluster = new MiniAvatarCluster(conf, 2, true, null, null, 1, true); fs = cluster.getFileSystem(0); metaInfo = new RequestMetaInfo(conf.getInt(FSConstants.DFS_CLUSTER_ID, RequestMetaInfo.NO_CLUSTER_ID), cluster.getNameNode(0).getNameserviceId(), RequestMetaInfo.NO_NAMESPACE_ID, RequestMetaInfo.NO_APPLICATION_ID, (UnixUserGroupInformation) UserGroupInformation.getUGI(conf)); proxy = new ClientProxyService(new ClientProxyCommons(conf, conf.get( FSConstants.DFS_CLUSTER_NAME))); conf.setInt(StorageServiceConfigKeys.PROXY_THRIFT_PORT_KEY, proxy.getThriftPort()); conf.setInt(StorageServiceConfigKeys.PROXY_RPC_PORT_KEY, proxy.getRPCPort()); clientManager = new ThriftClientManager(); FramedClientConnector connector = new FramedClientConnector( StorageServiceConfigKeys.getProxyThriftAddress(conf)); clientThrift = clientManager.createClient(connector, TClientProxyProtocol.class).get(); clientRPC = RPC.getProxy(ClientProxyProtocol.class, ClientProxyProtocol.versionID, StorageServiceConfigKeys.getProxyRPCAddress(conf), conf); } catch (IOException e) { tearDown(); throw e; } }
public HiveMetaStoreClient(HiveConf conf) throws MetaException { this.thriftClientManager = closer.register(new ThriftClientManager()); if (conf == null) { conf = new HiveConf(HiveMetaStoreClient.class); } this.conf = conf; String msUri = conf.getVar(HiveConf.ConfVars.METASTOREURIS); if (msUri == null || msUri.trim().length() == 0) { throw new MetaException("Local metastore is not supported!"); } if (conf.getBoolVar(ConfVars.METASTORE_USE_THRIFT_SASL)) { throw new MetaException("SASL is not supported"); } // get the number retries this.retries = HiveConf.getIntVar(conf, HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES); this.retryDelaySeconds = conf.getIntVar(ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY); // user wants file store based configuration List<String> metastoreUris = ImmutableList.copyOf(Splitter.on(',').omitEmptyStrings().trimResults().split(msUri)); metastoreHosts = new HostAndPort [metastoreUris.size()]; for (int i = 0; i < metastoreUris.size(); i++) { URI uri = URI.create(metastoreUris.get(i)); if (!uri.getScheme().equals("thrift")) { throw new MetaException("Only thrift:// URIs are supported!"); } metastoreHosts[i] = HostAndPort.fromParts(uri.getHost(), uri.getPort()); } // finally open the store open(); }
public SimpleHiveMetastoreFactory(final ThriftClientManager thriftClientManager, final ThriftClientConfig thriftClientConfig, final HiveMetastoreClientConfig hiveMetastoreClientConfig) { super(hiveMetastoreClientConfig, new ThriftClient<>(checkNotNull(thriftClientManager, "thiftClientManager is null"), HiveMetastore.class, checkNotNull(thriftClientConfig, "thriftClientConfig is null"), "hive-metastore")); }
@Test public void testExisting() throws Exception { final int port = NetUtils.findUnusedPort(); startService(port); final HiveMetastoreClientConfig metastoreConfig = new HiveMetastoreClientConfig() .setPort(port) .setMaxRetries(5) .setRetrySleep(new Duration(1, TimeUnit.SECONDS)) .setRetryTimeout(new Duration(30, TimeUnit.SECONDS)); try (final ThriftClientManager clientManager = new ThriftClientManager()) { final ThriftClientConfig clientConfig = new ThriftClientConfig(); final HiveMetastoreFactory factory = new SimpleHiveMetastoreFactory(clientManager, clientConfig, metastoreConfig); try (final HiveMetastore metastore = factory.getDefaultClient()) { assertFalse(metastore.isConnected()); final Table table = metastore.getTable("hello", "world"); assertNotNull(table); assertEquals("hello", table.getDbName()); assertEquals("world", table.getTableName()); assertTrue(metastore.isConnected()); } } }
@Test public void testLate() throws Exception { final int port = NetUtils.findUnusedPort(); runner.schedule(new Runnable() { @Override public void run() { try { startService(port); } catch (Exception e) { fail(e.getMessage()); } } }, 10, TimeUnit.SECONDS); final HiveMetastoreClientConfig metastoreConfig = new HiveMetastoreClientConfig() .setPort(port) .setMaxRetries(5) .setRetrySleep(new Duration(5, TimeUnit.SECONDS)) .setRetryTimeout(new Duration(30, TimeUnit.SECONDS)); try (final ThriftClientManager clientManager = new ThriftClientManager()) { final ThriftClientConfig clientConfig = new ThriftClientConfig(); final HiveMetastoreFactory factory = new SimpleHiveMetastoreFactory(clientManager, clientConfig, metastoreConfig); try (final HiveMetastore metastore = factory.getDefaultClient()) { assertFalse(metastore.isConnected()); final Table table = metastore.getTable("hello", "world"); assertNotNull(table); assertEquals("hello", table.getDbName()); assertEquals("world", table.getTableName()); assertTrue(metastore.isConnected()); } } }
@Test public void testLetsShuffleOne() throws Exception { final int port = NetUtils.findUnusedPort(); final ImmutableSet.Builder<HostAndPort> builder = ImmutableSet.builder(); builder.add(HostAndPort.fromParts("localhost", port)); for (int i = 0; i < 3; i++) { builder.add(HostAndPort.fromParts("localhost", NetUtils.findUnusedPort())); } runner.schedule(new Runnable() { @Override public void run() { try { startService(port); } catch (Exception e) { fail(e.getMessage()); } } }, 10, TimeUnit.SECONDS); final HiveMetastoreClientConfig metastoreConfig = new HiveMetastoreClientConfig() .setMaxRetries(10) .setRetrySleep(new Duration(3, TimeUnit.SECONDS)) .setRetryTimeout(new Duration(45, TimeUnit.SECONDS)); try (final ThriftClientManager clientManager = new ThriftClientManager()) { final ThriftClientConfig clientConfig = new ThriftClientConfig(); final HiveMetastoreFactory factory = new SimpleHiveMetastoreFactory(clientManager, clientConfig, metastoreConfig); try (final HiveMetastore metastore = factory.getClientForHost(builder.build())) { assertFalse(metastore.isConnected()); final Table table = metastore.getTable("hello", "world"); assertNotNull(table); assertEquals("hello", table.getDbName()); assertEquals("world", table.getTableName()); assertTrue(metastore.isConnected()); } } }