@Override public Void call() throws Exception { DRPCInvocationsClient c = new DRPCInvocationsClient(conf, server, port); synchronized (_clients) { _clients.add(c); } return null; } }
@Override public void close() { for (DRPCInvocationsClient client : _clients) { client.close(); } }
public void reconnectClient() throws TException { if (client.get() == null) { reconnect(); client.set(new DistributedRPCInvocations.Client(_protocol)); } }
client = _clients.get(i); if (!client.isConnected()) { LOG.warn("DRPCInvocationsClient [{}:{}] is not connected.", client.getHost(), client.getPort()); reconnectAsync(client); continue; DRPCRequest req = client.fetchRequest(_function); if (req.get_request_id().length() > 0) { Map<String, Object> returnInfo = new HashMap<>(); returnInfo.put("id", req.get_request_id()); returnInfo.put("host", client.getHost()); returnInfo.put("port", client.getPort()); _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), i));
@Test public void testGoodHttpGet() throws Exception { LOG.info("STARTING HTTP GET TEST..."); Map<String, Object> conf = getConf(0, 0, 0); try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) { server.start(); //TODO need a better way to do this Thread.sleep(2000); try (DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) { final Future<String> found = exec.submit(() -> doGet(server.getHttpServerPort(), "testing", "test")); DRPCRequest request = getNextAvailableRequest(invoke, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); invoke.result(request.get_request_id(), "tested"); String result = found.get(1000, TimeUnit.MILLISECONDS); assertEquals("tested", result); } } }
@Test public void testFailedHttpGet() throws Exception { LOG.info("STARTING HTTP GET (FAIL) TEST..."); Map<String, Object> conf = getConf(0, 0, 0); try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) { server.start(); //TODO need a better way to do this Thread.sleep(2000); try (DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) { Future<String> found = exec.submit(() -> doGet(server.getHttpServerPort(), "testing", "test")); DRPCRequest request = getNextAvailableRequest(invoke, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); invoke.getClient().failRequest(request.get_request_id()); try { found.get(1000, TimeUnit.MILLISECONDS); fail("exec did not throw an exception"); } catch (ExecutionException e) { LOG.warn("Got Expected Exception", e); //Getting the exact response code is a bit more complex. //TODO should use a better client } } } } }
@Test public void testFailedThrift() throws Exception { Map<String, Object> conf = getConf(0, 0, null); try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) { server.start(); try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort()); DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) { Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test")); DRPCRequest request = getNextAvailableRequest(invoke, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); invoke.failRequest(request.get_request_id()); try { found.get(1000, TimeUnit.MILLISECONDS); fail("exec did not throw an exception"); } catch (ExecutionException e) { Throwable t = e.getCause(); assertEquals(t.getClass(), DRPCExecutionException.class); //Don't know a better way to validate that it failed. assertEquals("Request failed", ((DRPCExecutionException)t).get_msg()); } } } }
@Override public Void call() throws Exception { client.reconnectClient(); return null; } }));
client = _clients.get(i); if (!client.isConnected()) { LOG.warn("DRPCInvocationsClient [{}:{}] is not connected.", client.getHost(), client.getPort()); reconnect(client); continue; DRPCRequest req = client.fetchRequest(_function); if(req.get_request_id().length() > 0) { Map returnInfo = new HashMap(); returnInfo.put("id", req.get_request_id()); returnInfo.put("host", client.getHost()); returnInfo.put("port", client.getPort()); _collector.emit(new Values(req.get_func_args(), JSONValue.toJSONString(returnInfo)), new DRPCMessageId(req.get_request_id(), i)); break;
@Test public void testGoodThrift() throws Exception { Map<String, Object> conf = getConf(0, 0, null); try (DRPCServer server = new DRPCServer(conf, new StormMetricsRegistry())) { server.start(); try (DRPCClient client = new DRPCClient(conf, "localhost", server.getDrpcPort()); DRPCInvocationsClient invoke = new DRPCInvocationsClient(conf, "localhost", server.getDrpcInvokePort())) { final Future<String> found = exec.submit(() -> client.getClient().execute("testing", "test")); DRPCRequest request = getNextAvailableRequest(invoke, "testing"); assertNotNull(request); assertEquals("test", request.get_func_args()); assertNotNull(request.get_request_id()); invoke.result(request.get_request_id(), "tested"); String result = found.get(1000, TimeUnit.MILLISECONDS); assertEquals("tested", result); } } }
private void reconnectClient(DRPCInvocationsClient client) { if (client instanceof DRPCInvocationsClient) { try { LOG.info("reconnecting... "); client.reconnectClient(); //Blocking call } catch (TException e2) { LOG.error("Failed to connect to DRPC server", e2); } } }
_clients.put(server, new DRPCInvocationsClient(conf, host, port)); } catch (TTransportException ex) { throw new RuntimeException(ex);
@Override public void cleanup() { for (DRPCInvocationsClient c : _clients.values()) { c.close(); } }
private void reconnectSync(DRPCInvocationsClient client) { try { LOG.info("reconnecting... "); client.reconnectClient(); //Blocking call } catch (TException e2) { LOG.error("Failed to connect to DRPC server", e2); } }
public void reconnectClient() throws TException { if (client.get() == null) { reconnect(); client.set(new DistributedRPCInvocations.Client(_protocol)); } }
_clients.put(server, new DRPCInvocationsClient(_conf, host, port)); } catch (TTransportException ex) { throw new RuntimeException(ex);
@Override public void cleanup() { for (DRPCInvocationsClient c : _clients.values()) { c.close(); } }
@Override public Void call() throws Exception { c.reconnectClient(); return null; } }));
@Override public Void call() throws Exception { DRPCInvocationsClient c = new DRPCInvocationsClient(conf, server, port); synchronized (_clients) { _clients.add(c); } return null; } }
@Override public void close() { for(DRPCInvocationsClient client: _clients) { client.close(); } }