Search in sources :

Example 21 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class LoadBalancerEchoServer method markDown.

public void markDown() throws PropertyStoreException {
    FutureCallback<None> callback = new FutureCallback<None>();
    _announcer.markDown(_cluster, _uri, callback);
    try {
        callback.get(10, TimeUnit.SECONDS);
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) RestException(com.linkedin.r2.message.rest.RestException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 22 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class LoadBalancerEchoServer method markUp.

public void markUp(Map<Integer, Double> partitionWeight) throws PropertyStoreException {
    FutureCallback<None> callback = new FutureCallback<None>();
    Map<Integer, PartitionData> partitionDataMap = new HashMap<Integer, PartitionData>();
    if (partitionWeight != null) {
        for (int partitionId : partitionWeight.keySet()) {
            partitionDataMap.put(partitionId, new PartitionData(partitionWeight.get(partitionId)));
        }
    } else {
        partitionDataMap.put(DefaultPartitionAccessor.DEFAULT_PARTITION_ID, new PartitionData(1d));
    }
    _announcer.markUp(_cluster, _uri, partitionDataMap, callback);
    try {
        callback.get(10, TimeUnit.SECONDS);
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) HashMap(java.util.HashMap) PartitionData(com.linkedin.d2.balancer.properties.PartitionData) None(com.linkedin.common.util.None) FutureCallback(com.linkedin.common.callback.FutureCallback) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) RestException(com.linkedin.r2.message.rest.RestException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 23 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class ZooKeeperEphemeralStoreTest method testPutGetRemovePartial.

@Test(groups = { "small", "back-end" })
public void testPutGetRemovePartial() throws InterruptedException, IOException, PropertyStoreException, ExecutionException {
    ZooKeeperEphemeralStore<String> store = getStore();
    store.put("service-1", "1");
    store.put("service-1", "2");
    store.put("service-2", "3");
    assertTrue(store.get("service-1").equals("1,2") || store.get("service-1").equals("2,1"));
    assertEquals(store.get("service-2"), "3");
    assertNull(store.get("service-3"));
    store.removePartial("service-1", "2");
    assertEquals(store.get("service-1"), "1");
    store.remove("service-2");
    assertNull(store.get("service-2"));
    final CountDownLatch latch = new CountDownLatch(1);
    store.shutdown(new PropertyEventShutdownCallback() {

        @Override
        public void done() {
            latch.countDown();
        }
    });
    if (!latch.await(5, TimeUnit.SECONDS)) {
        fail("unable to shut down");
    }
}
Also used : PropertyEventShutdownCallback(com.linkedin.d2.discovery.event.PropertyEventThread.PropertyEventShutdownCallback) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 24 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class ZooKeeperPermanentStoreTest method getStore.

@Override
public PropertyStore<String> getStore() throws PropertyStoreException {
    try {
        ZKConnection client = new ZKConnection("localhost:" + PORT, 30000);
        client.start();
        ZooKeeperPermanentStore<String> store = new ZooKeeperPermanentStore<String>(client, new PropertyStringSerializer(), "/test-path");
        FutureCallback<None> callback = new FutureCallback<None>();
        store.start(callback);
        callback.get();
        return store;
    } catch (Exception e) {
        throw new PropertyStoreException(e);
    }
}
Also used : PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException) None(com.linkedin.common.util.None) PropertyStringSerializer(com.linkedin.d2.discovery.stores.PropertyStringSerializer) FutureCallback(com.linkedin.common.callback.FutureCallback) IOException(java.io.IOException) PropertyStoreException(com.linkedin.d2.discovery.stores.PropertyStoreException)

Example 25 with PropertyStoreException

use of com.linkedin.d2.discovery.stores.PropertyStoreException in project rest.li by linkedin.

the class TestPartitionsWithZKQuorum method testRegisterUnregisterAllEchoServers.

@Test
public void testRegisterUnregisterAllEchoServers() throws IOException, URISyntaxException, PropertyStoreException, ExecutionException, TimeoutException, InterruptedException, Exception {
    _echoServers = new ArrayList<LoadBalancerEchoServer>();
    setup();
    assertEquals(LoadBalancerClientCli.runDiscovery(_quorum.getHosts(), "/d2", D2_CONFIG_DATA), 0);
    _cli = new LoadBalancerClientCli(_quorum.getHosts(), "/d2");
    _client = _cli.createZKFSTogglingLBClient(_quorum.getHosts(), "/d2", null);
    // Echo servers startup
    Map<Integer, Double> partitionWeight = new HashMap<Integer, Double>();
    partitionWeight.put(new Integer(1), new Double(1.0d));
    startAllEchoServers(partitionWeight);
    assertAllEchoServersRegistered(_cli.getZKClient(), _zkUriString, _echoServers);
    assertQuorumProcessAllRequests(D2_CONFIG_DATA);
    // Markdown echo servers
    stopAllEchoServers(_echoServers);
    assertAllEchoServersUnregistered(_cli.getZKClient(), _zkUriString, _echoServers);
}
Also used : LoadBalancerClientCli(com.linkedin.d2.balancer.util.LoadBalancerClientCli) HashMap(java.util.HashMap) LoadBalancerEchoServer(com.linkedin.d2.balancer.util.LoadBalancerEchoServer) D2BaseTest(com.linkedin.d2.D2BaseTest) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest)

Aggregations

None (com.linkedin.common.util.None)19 FutureCallback (com.linkedin.common.callback.FutureCallback)18 HashMap (java.util.HashMap)18 UriProperties (com.linkedin.d2.balancer.properties.UriProperties)15 Test (org.testng.annotations.Test)14 PartitionData (com.linkedin.d2.balancer.properties.PartitionData)9 PropertyStoreException (com.linkedin.d2.discovery.stores.PropertyStoreException)9 ServiceProperties (com.linkedin.d2.balancer.properties.ServiceProperties)8 URI (java.net.URI)8 ClusterProperties (com.linkedin.d2.balancer.properties.ClusterProperties)7 ServicePropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ServicePropertiesJsonSerializer)7 UriPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.UriPropertiesJsonSerializer)7 UriPropertiesMerger (com.linkedin.d2.balancer.properties.UriPropertiesMerger)7 IOException (java.io.IOException)7 HashSet (java.util.HashSet)6 PropertyEventBusImpl (com.linkedin.d2.discovery.event.PropertyEventBusImpl)5 ZooKeeperEphemeralStore (com.linkedin.d2.discovery.stores.zk.ZooKeeperEphemeralStore)5 ExecutionException (java.util.concurrent.ExecutionException)5 ClusterPropertiesJsonSerializer (com.linkedin.d2.balancer.properties.ClusterPropertiesJsonSerializer)4 PropertyStringSerializer (com.linkedin.d2.discovery.stores.PropertyStringSerializer)4