use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.
the class TestD2Config method teardown.
@AfterMethod
public void teardown() throws IOException, InterruptedException {
for (LoadBalancerEchoServer echoServer : _echoServerList) {
try {
echoServer.stopServer();
_log.info("Executed echoserver shutdown. ");
} catch (Exception e) {
_log.info("echoserver shutdown failed. EchoServer:" + echoServer);
e.printStackTrace();
}
}
try {
_zkclient.shutdown();
_log.info("Executed cli shutdown. ");
} catch (Exception e) {
_log.info("zkclient shutdown failed.");
}
try {
_zkServer.shutdown();
_log.info("Executed zkServer shutdown. ");
} catch (Exception e) {
_log.info("zk server shutdown failed.");
}
}
use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.
the class TestLoadBalancerClientCli method testSetup.
@BeforeMethod
public void testSetup() throws IOException, Exception {
// Startup zookeeper server
try {
_zkServer = new ZKServer();
_zkServer.startup();
_zkHosts = ZK_HOST + ":" + _zkServer.getPort();
} catch (IOException e) {
fail("unable to instantiate real zk server .");
e.printStackTrace();
}
}
use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.
the class TestD2ConfigWithSingleZKFailover method setup.
@BeforeTest
public void setup() throws IOException, Exception {
// zkServer
_zkServer = ZKTestUtil.startZKServer();
_zkPort = _zkServer.getPort();
_zkHosts = ZK_HOST + ":" + _zkPort;
_zkUriString = "zk://" + _zkHosts;
// Register clusters/services (two services per cluster)
LoadBalancerClientCli.runDiscovery(_zkHosts, "/d2", D2_CONFIG_DATA);
// Get LoadBalancer Client
_cli = new LoadBalancerClientCli(_zkHosts, "/d2");
// Echo servers startup
startAllEchoServers();
assertAllEchoServersRunning(_echoServers);
_client = _cli.createClient(_cli.getZKClient(), _zkUriString, "/d2", "service-1_1");
_log.info(LoadBalancerClientCli.printStores(_cli.getZKClient(), _zkUriString, "/d2"));
assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
}
use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.
the class LoadBalancerClientCli method hasService.
public static boolean hasService(ZKConnection zkclient, String zkserver, String d2path, String cluster, String service) throws URISyntaxException, IOException, PropertyStoreException {
ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = null;
String scstoreString = zkserver + ZKFSUtil.servicePath(d2path);
zkServiceRegistry = (ZooKeeperPermanentStore<ServiceProperties>) getStore(zkclient, scstoreString, new ServicePropertiesJsonSerializer());
return zkServiceRegistry.get(service).getClusterName().equals(cluster);
}
use of com.linkedin.d2.discovery.stores.zk.ZKServer in project rest.li by linkedin.
the class LoadBalancerClientCli method getSchema.
public String getSchema(ZKConnection zkclient, String zkserver, String d2path, String cluster, String service, String requestType) throws URISyntaxException, InterruptedException, ExecutionException, IOException, PropertyStoreException, TimeoutException {
String responseString = null;
if (hasService(zkclient, zkserver, d2path, cluster, service)) {
DynamicClient client = new DynamicClient(getLoadBalancer(zkclient, zkserver, d2path, service), null);
URI uri = URI.create("d2://" + service + "/");
try {
RestRequest restRequest = new RestRequestBuilder(uri).setEntity("".getBytes("UTF-8")).build();
Future<RestResponse> response = client.restRequest(restRequest, new RequestContext());
responseString = response.get().getEntity().asString("UTF-8");
} finally {
LoadBalancerUtil.syncShutdownClient(_client, _log);
zkclient.shutdown();
}
} else {
System.out.println("Service '" + service + "' is not defined for cluster '" + cluster + "'.");
}
return responseString;
}
Aggregations