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);
}
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();
}
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);
}
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);
}
Aggregations