Search in sources :

Example 6 with ZKServer

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.");
    }
}
Also used : LoadBalancerEchoServer(com.linkedin.d2.balancer.util.LoadBalancerEchoServer) URISyntaxException(java.net.URISyntaxException) PartitionAccessException(com.linkedin.d2.balancer.util.partitions.PartitionAccessException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) AfterMethod(org.testng.annotations.AfterMethod)

Example 7 with ZKServer

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();
    }
}
Also used : ZKServer(com.linkedin.d2.discovery.stores.zk.ZKServer) IOException(java.io.IOException) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 8 with ZKServer

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);
}
Also used : LoadBalancerClientCli(com.linkedin.d2.balancer.util.LoadBalancerClientCli) BeforeTest(org.testng.annotations.BeforeTest)

Example 9 with ZKServer

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);
}
Also used : ServiceProperties(com.linkedin.d2.balancer.properties.ServiceProperties) ServicePropertiesJsonSerializer(com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)

Example 10 with ZKServer

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;
}
Also used : RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) DynamicClient(com.linkedin.d2.balancer.clients.DynamicClient) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RequestContext(com.linkedin.r2.message.RequestContext) URI(java.net.URI)

Aggregations

ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)6 ServicePropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)6 ZKServer (com.linkedin.d2.discovery.stores.zk.ZKServer)6 IOException (java.io.IOException)6 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)5 UriPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer)5 UriPropertiesMerger (com.linkedin.d2.balancer.properties.UriPropertiesMerger)5 ZooKeeperEphemeralStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore)4 ZooKeeperPermanentStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperPermanentStore)4 BeforeMethod (org.testng.annotations.BeforeMethod)4 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)3 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)3 HashMap (java.util.HashMap)3 PartitionAccessException (com.linkedin.d2.balancer.util.partitions.PartitionAccessException)2 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)2 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 KeeperException (org.apache.zookeeper.KeeperException)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1