Search in sources :

Example 1 with ServerSet

use of com.twitter.common.zookeeper.ServerSet in project commons by twitter.

the class ServerSetModuleTest method mySetUp.

@Before
public void mySetUp() {
    control = EasyMock.createControl();
    serverSet = control.createMock(ServerSet.class);
    shutdownRegistry = new ShutdownRegistryImpl();
    zooKeeperClient = createZkClient();
    Set<ServiceRunner> localServices = ImmutableSet.of();
    localServiceRegistry = new LocalServiceRegistry(Providers.of(localServices), shutdownRegistry);
}
Also used : LocalServiceRegistry(com.twitter.common.application.modules.LocalServiceRegistry) ServerSet(com.twitter.common.zookeeper.ServerSet) ShutdownRegistryImpl(com.twitter.common.application.ShutdownRegistry.ShutdownRegistryImpl) ServiceRunner(com.twitter.common.application.modules.LifecycleModule.ServiceRunner) Before(org.junit.Before)

Example 2 with ServerSet

use of com.twitter.common.zookeeper.ServerSet in project distributedlog by twitter.

the class WriterWorker method buildDlogClient.

private DistributedLogClient buildDlogClient() {
    ClientBuilder clientBuilder = ClientBuilder.get().hostConnectionLimit(hostConnectionLimit).hostConnectionCoresize(hostConnectionCoreSize).tcpConnectTimeout(Duration$.MODULE$.fromMilliseconds(200)).connectTimeout(Duration$.MODULE$.fromMilliseconds(200)).requestTimeout(Duration$.MODULE$.fromSeconds(10)).sendBufferSize(sendBufferSize).recvBufferSize(recvBufferSize);
    ClientId clientId = ClientId$.MODULE$.apply("dlog_loadtest_writer");
    DistributedLogClientBuilder builder = DistributedLogClientBuilder.newBuilder().clientId(clientId).clientBuilder(clientBuilder).thriftmux(thriftmux).redirectBackoffStartMs(100).redirectBackoffMaxMs(500).requestTimeoutMs(10000).statsReceiver(statsReceiver).streamNameRegex("^" + streamPrefix + "_[0-9]+$").handshakeWithClientInfo(handshakeWithClientInfo).periodicHandshakeIntervalMs(TimeUnit.SECONDS.toMillis(30)).periodicOwnershipSyncIntervalMs(TimeUnit.MINUTES.toMillis(5)).periodicDumpOwnershipCache(true).handshakeTracing(true).name("writer");
    if (!finagleNames.isEmpty()) {
        String local = finagleNames.get(0);
        String[] remotes = new String[finagleNames.size() - 1];
        finagleNames.subList(1, finagleNames.size()).toArray(remotes);
        builder = builder.finagleNameStrs(local, remotes);
    } else if (serverSets.length != 0) {
        ServerSet local = serverSets[0].getServerSet();
        ServerSet[] remotes = new ServerSet[serverSets.length - 1];
        for (int i = 1; i < serverSets.length; i++) {
            remotes[i - 1] = serverSets[i].getServerSet();
        }
        builder = builder.serverSets(local, remotes);
    } else {
        builder = builder.uri(dlUri);
    }
    return builder.build();
}
Also used : ServerSet(com.twitter.common.zookeeper.ServerSet) DLZkServerSet(com.twitter.distributedlog.client.serverset.DLZkServerSet) ClientId(com.twitter.finagle.thrift.ClientId) DistributedLogClientBuilder(com.twitter.distributedlog.service.DistributedLogClientBuilder) ClientBuilder(com.twitter.finagle.builder.ClientBuilder) DistributedLogClientBuilder(com.twitter.distributedlog.service.DistributedLogClientBuilder)

Example 3 with ServerSet

use of com.twitter.common.zookeeper.ServerSet in project distributedlog by twitter.

the class DLZkServerSet method of.

public static DLZkServerSet of(URI uri, int zkSessionTimeoutMs) {
    // Create zookeeper and server set
    String zkPath = uri.getPath() + "/" + ZNODE_WRITE_PROXY;
    Iterable<InetSocketAddress> zkAddresses = getZkAddresses(uri);
    ZooKeeperClient zkClient = new ZooKeeperClient(Amount.of(zkSessionTimeoutMs, Time.MILLISECONDS), zkAddresses);
    ServerSet serverSet = ServerSets.create(zkClient, ZooDefs.Ids.OPEN_ACL_UNSAFE, zkPath);
    return new DLZkServerSet(zkClient, serverSet);
}
Also used : ServerSet(com.twitter.common.zookeeper.ServerSet) ZooKeeperClient(com.twitter.common.zookeeper.ZooKeeperClient) InetSocketAddress(java.net.InetSocketAddress)

Example 4 with ServerSet

use of com.twitter.common.zookeeper.ServerSet in project distributedlog by twitter.

the class MonitorService method runServer.

public void runServer() throws IllegalArgumentException, IOException {
    Preconditions.checkArgument(uriArg.isPresent(), "No distributedlog uri provided.");
    Preconditions.checkArgument(serverSetArg.isPresent(), "No proxy server set provided.");
    if (intervalArg.isPresent()) {
        interval = intervalArg.get();
    }
    if (regionIdArg.isPresent()) {
        regionId = regionIdArg.get();
    }
    if (streamRegexArg.isPresent()) {
        streamRegex = streamRegexArg.get();
    }
    if (instanceIdArg.isPresent()) {
        instanceId = instanceIdArg.get();
    }
    if (totalInstancesArg.isPresent()) {
        totalInstances = totalInstancesArg.get();
    }
    if (heartbeatEveryChecksArg.isPresent()) {
        heartbeatEveryChecks = heartbeatEveryChecksArg.get();
    }
    if (instanceId < 0 || totalInstances <= 0 || instanceId >= totalInstances) {
        throw new IllegalArgumentException("Invalid instance id or total instances number.");
    }
    handshakeWithClientInfo = handshakeWithClientInfoArg.isPresent();
    watchNamespaceChanges = watchNamespaceChangesArg.isPresent();
    URI uri = URI.create(uriArg.get());
    DistributedLogConfiguration dlConf = new DistributedLogConfiguration();
    if (confFileArg.isPresent()) {
        String configFile = confFileArg.get();
        try {
            dlConf.loadConf(new File(configFile).toURI().toURL());
        } catch (ConfigurationException e) {
            throw new IOException("Failed to load distributedlog configuration from " + configFile + ".");
        } catch (MalformedURLException e) {
            throw new IOException("Failed to load distributedlog configuration from malformed " + configFile + ".");
        }
    }
    logger.info("Starting stats provider : {}.", statsProvider.getClass());
    statsProvider.start(dlConf);
    String[] serverSetPaths = StringUtils.split(serverSetArg.get(), ",");
    if (serverSetPaths.length == 0) {
        throw new IllegalArgumentException("Invalid serverset paths provided : " + serverSetArg.get());
    }
    ServerSet[] serverSets = createServerSets(serverSetPaths);
    ServerSet local = serverSets[0];
    ServerSet[] remotes = new ServerSet[serverSets.length - 1];
    System.arraycopy(serverSets, 1, remotes, 0, remotes.length);
    dlClient = DistributedLogClientBuilder.newBuilder().name("monitor").clientId(ClientId$.MODULE$.apply("monitor")).redirectBackoffMaxMs(50).redirectBackoffStartMs(100).requestTimeoutMs(2000).maxRedirects(2).serverSets(local, remotes).streamNameRegex(streamRegex).handshakeWithClientInfo(handshakeWithClientInfo).clientBuilder(ClientBuilder.get().connectTimeout(Duration.fromSeconds(1)).tcpConnectTimeout(Duration.fromSeconds(1)).requestTimeout(Duration.fromSeconds(2)).hostConnectionLimit(2).hostConnectionCoresize(2).keepAlive(true).failFast(false)).statsReceiver(monitorReceiver.scope("client")).buildMonitorClient();
    runMonitor(dlConf, uri);
}
Also used : DistributedLogConfiguration(com.twitter.distributedlog.DistributedLogConfiguration) MalformedURLException(java.net.MalformedURLException) ServerSet(com.twitter.common.zookeeper.ServerSet) DLZkServerSet(com.twitter.distributedlog.client.serverset.DLZkServerSet) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File)

Aggregations

ServerSet (com.twitter.common.zookeeper.ServerSet)4 DLZkServerSet (com.twitter.distributedlog.client.serverset.DLZkServerSet)2 ShutdownRegistryImpl (com.twitter.common.application.ShutdownRegistry.ShutdownRegistryImpl)1 ServiceRunner (com.twitter.common.application.modules.LifecycleModule.ServiceRunner)1 LocalServiceRegistry (com.twitter.common.application.modules.LocalServiceRegistry)1 ZooKeeperClient (com.twitter.common.zookeeper.ZooKeeperClient)1 DistributedLogConfiguration (com.twitter.distributedlog.DistributedLogConfiguration)1 DistributedLogClientBuilder (com.twitter.distributedlog.service.DistributedLogClientBuilder)1 ClientBuilder (com.twitter.finagle.builder.ClientBuilder)1 ClientId (com.twitter.finagle.thrift.ClientId)1 File (java.io.File)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 Before (org.junit.Before)1