- 使用 Spring Initializr 创建 Spring Boot 应用程序
- 在Spring Boot中配置Cassandra
- 在 Spring Boot 上配置 Tomcat 连接池
- 将Camel消息路由到嵌入WildFly的Artemis上
本文整理了Java中com.spotify.helios.servicescommon.coordination.ZooKeeperClient
类的一些代码示例,展示了ZooKeeperClient
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperClient
类的具体详情如下:
包路径:com.spotify.helios.servicescommon.coordination.ZooKeeperClient
类名称:ZooKeeperClient
[英]Exists because the Curator library makes things ununit-testable without this. Also it avoids having to catch Exception at call-sites.
[中]之所以存在,是因为策展人图书馆让没有这个东西就无法进行测试。此外,它还避免了在调用站点捕获异常。
代码示例来源:origin: spotify/helios
@Test
public void testZooKeeperClient() throws Exception {
// Create the cluster ID node
zk().curatorWithSuperAuth().newNamespaceAwareEnsurePath(Paths.configId(zkClusterId))
.ensure(zk().curatorWithSuperAuth().getZookeeperClient());
// We need to create a new curator because ZooKeeperClient will try to start it,
// and zk().curator() has already been started.
final ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
final CuratorFramework curator = CuratorFrameworkFactory.builder()
.retryPolicy(retryPolicy)
.connectString(zk().connectString())
.build();
final ZooKeeperClient client = new DefaultZooKeeperClient(curator, zkClusterId);
client.start();
// This should work since the cluster ID exists
client.create("/test");
// Now let's remove the cluster ID
client.delete(Paths.configId(zkClusterId));
// Sleep so the watcher thread in ZooKeeperClient has a chance to update state
Thread.sleep(500);
// Try the same operation again, and it should fail this time
try {
client.ensurePath(Paths.configJobs());
fail("ZooKeeper operation should have failed because cluster ID was removed");
} catch (IllegalStateException ignore) {
// ignored
}
}
代码示例来源:origin: spotify/helios
private void write(final String node, final byte[] data) throws KeeperException {
final ZooKeeperClient client = client("write");
final String nodePath = ZKPaths.makePath(path, node);
if (client.stat(nodePath) != null) {
log.debug("setting node: {}", nodePath);
client.setData(nodePath, data);
} else {
log.debug("creating node: {}", nodePath);
client.createAndSetData(nodePath, data);
}
}
代码示例来源:origin: spotify/helios
static void initializeAcl(final String zooKeeperConnectionString,
final String zooKeeperClusterId,
final String masterUser,
final String masterPassword,
final String agentUser,
final String agentPassword)
throws KeeperException {
final ACLProvider aclProvider = heliosAclProvider(
masterUser, digest(masterUser, masterPassword),
agentUser, digest(agentUser, agentPassword));
final List<AuthInfo> authorization = Lists.newArrayList(new AuthInfo(
"digest", String.format("%s:%s", masterUser, masterPassword).getBytes()));
final RetryPolicy zooKeeperRetryPolicy = new ExponentialBackoffRetry(1000, 3);
final CuratorFramework curator = new CuratorClientFactoryImpl().newClient(
zooKeeperConnectionString,
(int) TimeUnit.SECONDS.toMillis(60),
(int) TimeUnit.SECONDS.toMillis(15),
zooKeeperRetryPolicy,
aclProvider,
authorization);
final ZooKeeperClient client = new DefaultZooKeeperClient(curator, zooKeeperClusterId);
try {
client.start();
initializeAclRecursive(client, "/", aclProvider);
} finally {
client.close();
}
}
代码示例来源:origin: spotify/helios
private void delete(final String node) throws KeeperException {
final ZooKeeperClient client = client("delete");
final String nodePath = ZKPaths.makePath(path, node);
if (client.stat(nodePath) != null) {
log.debug("deleting node: {}", nodePath);
client.delete(nodePath);
}
}
代码示例来源:origin: spotify/helios
@Override
public void start() {
client.start();
client.getConnectionStateListenable().addListener(
(client, newState) -> reporter.connectionStateChanged(newState));
}
代码示例来源:origin: spotify/helios
private void syncChecked() throws KeeperException {
final ZooKeeperClient client = client("sync");
final List<String> nodes = client.getChildren(path);
final Map<String, byte[]> snapshot = entries.get();
for (final String node : nodes) {
final String nodePath = ZKPaths.makePath(path, node);
final byte[] data = client.getData(nodePath);
remote.put(node, data);
if (remoteData == null) {
log.debug("sync: creating node {}", nodePath);
client.createAndSetData(nodePath, localData);
remote.put(node, localData);
} else if (!Arrays.equals(remoteData, localData)) {
log.debug("sync: updating node {}", nodePath);
client.setData(nodePath, localData);
remote.put(node, localData);
final String nodePath = ZKPaths.makePath(path, node);
log.debug("sync: deleting node {}", nodePath);
client.delete(nodePath);
remote.remove(node);
代码示例来源:origin: spotify/helios
client.getNode(taskPath);
client.transaction(operations);
log.info("deployed {}: {} (retry={})", deployment, host, count);
} catch (NoNodeException e) {
if (client.exists(taskCreationPath) != null) {
if (client.stat(taskPath) != null) {
throw new JobAlreadyDeployedException(host, id);
代码示例来源:origin: spotify/helios
final String hostInfoPath = Paths.statusHostInfo(name);
final Stat stat = client.exists(idPath);
if (stat == null) {
log.debug("Agent id node not present, registering agent {}: {}", id, name);
ZooKeeperRegistrarUtil.registerHost(client, idPath, name, id);
} else {
final byte[] bytes = client.getData(idPath);
final String existingId = bytes == null ? "" : new String(bytes, UTF_8);
if (!id.equals(existingId)) {
final Stat hostInfoStat = client.stat(hostInfoPath);
if (hostInfoStat != null) {
final long mtime = hostInfoStat.getMtime();
final String upPath = Paths.statusHostUp(name);
log.debug("Creating up node: {}", upPath);
client.ensurePath(upPath, true);
upNode = client.persistentEphemeralNode(upPath, EPHEMERAL, EMPTY_BYTES);
upNode.start();
代码示例来源:origin: spotify/helios
final ZooKeeperClient client = provider.get("removeDeploymentGroup");
try {
client.ensurePath(Paths.configDeploymentGroups());
client.ensurePath(Paths.statusDeploymentGroups());
client.ensurePath(Paths.statusDeploymentGroupTasks());
if (client.exists(path) == null) {
operations.add(create(path));
client.transaction(operations);
} catch (final NoNodeException e) {
throw new DeploymentGroupDoesNotExistException(name);
代码示例来源:origin: at.molindo/helios-services
final String idPath = Paths.configHostId(name);
final Stat stat = client.exists(idPath);
if (stat == null) {
log.debug("Agent id node not present, registering agent {}: {}", id, name);
client.ensurePath(Paths.configHost(name));
client.ensurePath(Paths.configHost(name));
client.ensurePath(Paths.configHostJobs(name));
client.ensurePath(Paths.configHostPorts(name));
client.ensurePath(Paths.statusHost(name));
client.ensurePath(Paths.statusHostJobs(name));
client.createAndSetData(idPath, id.getBytes(UTF_8));
} else {
final byte[] bytes = client.getData(idPath);
final String existingId = bytes == null ? "" : new String(bytes, UTF_8);
if (!id.equals(existingId)) {
final String upPath = Paths.statusHostUp(name);
log.debug("Creating up node: {}", upPath);
upNode = client.persistentEphemeralNode(upPath, EPHEMERAL, EMPTY_BYTES);
upNode.start();
代码示例来源:origin: spotify/helios
client.ensurePath(Paths.configDeploymentGroups());
client.ensurePath(Paths.statusDeploymentGroups());
client.transaction(
create(Paths.configDeploymentGroup(deploymentGroup.getName()), deploymentGroup),
create(Paths.statusDeploymentGroup(deploymentGroup.getName())),
代码示例来源:origin: spotify/helios
item.getTimestamp());
client.ensurePath(historyPath, true);
client.createAndSetData(historyPath, item.getStatus().toJsonBytes());
final List<String> events = client.getChildren(Paths.historyJobHostEvents(jobId, hostname));
if (events.size() > MAX_NUMBER_STATUS_EVENTS_TO_RETAIN) {
trimStatusEvents(events, jobId);
代码示例来源:origin: at.molindo/helios-services
@Override
public void removeDeploymentGroup(final String name) throws DeploymentGroupDoesNotExistException {
log.info("removing deployment-group: name={}", name);
final ZooKeeperClient client = provider.get("removeDeploymentGroup");
try {
client.ensurePath(Paths.configDeploymentGroups());
client.delete(Paths.configDeploymentGroup(name));
if (client.exists(Paths.statusDeploymentGroupHosts(name)) != null) {
client.delete(Paths.statusDeploymentGroupHosts(name));
}
if (client.exists(Paths.statusDeploymentGroup(name)) != null) {
client.delete(Paths.statusDeploymentGroup(name));
}
} catch (final NoNodeException e) {
throw new DeploymentGroupDoesNotExistException(name);
} catch (final KeeperException e) {
throw new HeliosRuntimeException("removing deployment-group " + name + " failed", e);
}
}
代码示例来源:origin: spotify/helios
@Override
public void delete(String path) throws KeeperException {
reporter.time(tag, "delete", () -> {
client.delete(path);
return null;
});
}
代码示例来源:origin: spotify/helios
public static void registerHost(final ZooKeeperClient client, final String idPath,
final String hostname, final String hostId)
throws KeeperException {
log.info("registering host: {}", hostname);
// This would've been nice to do in a transaction but PathChildrenCache ensures paths
// so we can't know what paths already exist so assembling a suitable transaction is too
// painful.
client.ensurePath(Paths.configHost(hostname));
client.ensurePath(Paths.configHostJobs(hostname));
client.ensurePath(Paths.configHostPorts(hostname));
client.ensurePath(Paths.statusHost(hostname));
client.ensurePath(Paths.statusHostJobs(hostname));
// Finish registration by creating the id node last
client.createAndSetData(idPath, hostId.getBytes(UTF_8));
}
代码示例来源:origin: spotify/helios
@Override
public boolean tryToRegister(final ZooKeeperClient client) throws KeeperException {
client.ensurePath(Paths.configHosts());
client.ensurePath(Paths.configJobs());
client.ensurePath(Paths.configJobRefs());
client.ensurePath(Paths.statusHosts());
client.ensurePath(Paths.statusMasters());
client.ensurePath(Paths.historyJobs());
client.ensurePath(Paths.configDeploymentGroups());
client.ensurePath(Paths.statusDeploymentGroups());
if (upNode == null) {
final String upPath = Paths.statusMasterUp(name);
client.ensurePath(upPath, true);
upNode = client.persistentEphemeralNode(upPath, Mode.EPHEMERAL, new byte[]{});
upNode.start();
}
log.info("ZooKeeper registration complete");
return true;
}
}
代码示例来源:origin: spotify/helios
@Override
public Stat stat(String path) throws KeeperException {
return reporter.time(tag, "stat", () -> client.stat(path));
}
代码示例来源:origin: spotify/helios
final ZooKeeperClient client =
new DefaultZooKeeperClient(curator, config.getZooKeeperClusterId());
client.start();
zkRegistrar = ZooKeeperRegistrarService.newBuilder()
.setZooKeeperClient(client)
final List<ACL> curAcls = client.getAcl("/");
final List<ACL> wantedAcls = aclProvider.getAclForPath("/");
if (!Sets.newHashSet(curAcls).equals(Sets.newHashSet(wantedAcls))) {
"Current ACL's on the zookeeper root node differ from desired, updating: {} -> {}",
curAcls, wantedAcls);
client.getCuratorFramework().setACL().withACL(wantedAcls).forPath("/");
代码示例来源:origin: spotify/helios
private static void checkForPortConflicts(final ZooKeeperClient client,
final String host,
final int port,
final JobId jobId)
throws JobPortAllocationConflictException {
try {
final String path = Paths.configHostPort(host, port);
if (client.stat(path) == null) {
return;
}
final byte[] b = client.getData(path);
final JobId existingJobId = parse(b, JobId.class);
throw new JobPortAllocationConflictException(jobId, existingJobId, host, port);
} catch (KeeperException | IOException ex) {
throw new HeliosRuntimeException("checking port allocations failed", ex);
}
}
代码示例来源:origin: spotify/helios
@Override
public void ensurePath(String path) throws KeeperException {
reporter.time(tag, "ensurePath", () -> {
client.ensurePath(path);
return null;
});
}
在我的项目中,我使用 LocationSearchTable/MKLocalSearch。当用户点击一个项目时,我的添加注释方法在 MapViewController 中被调用: func dropP
我很想知道如何检查字符串是否具有两个坐标的格式,例如: (signed int x,signed int y) 我已经通过搜索找到了一些答案,但我还没有完全理解它们(刚开始使用 C++),我要求一个简
在我正在编写的程序中,我为两个类(坐标和图形)编写了代码,其中一个将另一个作为构造函数参数。当我尝试编译它时,出现以下 Graph.cpp 错误: undefined symbol : “Graph:
我在 OpenGL ES 中绘制变化的条,它有坐标 (x,y,z)。 我想在 Action_Down 上添加一些更改(例如:栏中的颜色)。有 getX(),但此方法返回以像素为单位的 x 坐标,而不是
因为我之前的问题很不清楚,所以我编辑了一下: 我有以下问题: 我想为半径为 r+fcr_size 的空心球体构建一个图案。空心球体的空腔半径应为 r。有了这个图案,我可以在许多不同的球体中心使用它,并
我想使用 Vuforia 检测标记并在其上放置一个 3d 对象。从那时起,我想在我的应用程序中使用 ARKit。我如何知道检测到的标记或 3d 对象的 ARKit 世界变换? 我正在使用相同的 Vie
我有一组纬度/经度坐标,我可以使用它们进行投影,例如 Mollweide 投影。 library(mapproj) set.seed(0) n 180] = my.points$x[my.point
我正在使用 JavaScript 进行视频处理,我做得很好,但我使用的是一种名为 canvasCtx.rect () 的方法,它接收这些参数。 然后我可以从使用 getImageData () 方法绘
我创建了一个新项目作为单 View 应用程序。在 View Controller 中添加了用于将 View 坐标转换为窗口坐标的代码: - (void) dumpFrame { CGRect
简短版本:如何将 SVG 路径添加到 Leaflet map ,以便在 map 坐标更改时(例如缩放更改或滑动时)路径会更新? 长版:你好,我有一个地形image包含建筑轮廓。对图像进行地理校正后,我
我编写了一个代码,使用 astropy 将坐标从地球固定系统转换为惯性坐标系: from astropy import coordinates as coord from astropy import
我的多显示器设置中遇到以下情况: 在此示例中,我希望将窗口精确定位在黄色箭头所示的坐标处。然而,我所拥有的只是 NSView 的坐标,它是跨越整个(更大、更上面)辅助监视器的 NSWindow 的 c
我不知道如何将 Pane 上圆形对象的所有 x 和 y 与鼠标的 x 和 y 进行比较。我正在处理的问题要求我设置它,以便鼠标的二次单击会在放置在其上时删除一个点,我想我可以通过比较圆坐标和鼠标坐标的
我正在尝试将图像中的几个点转换为 OpenCV 中的极坐标。我遇到了名为 cartToPolar 的函数,它会为我的点提供相对于 0,0 作为我的原点的极坐标。但是,我想通过将图像中的另一个点作为原点
是的,我想知道如何检查某个坐标是否在另一个坐标半径内。但这可能是一个很小的差异,因为纬度、经度、半径存储在数据库中,而我们要检查的只是给定的坐标。 示例 数据库表 name | lat
我正在使用带有图层的 map (来自示例): var lonLat = new OpenLayers.LonLat(40.4088576, -86.8576718) .
我在坐标转换方面遇到了一些麻烦。 我在屏幕上有一个已知坐标(x,y)的对象,我想将其转换为世界坐标(x,y,z),因为它会投影在相机的近平面上。 到目前为止,我可以像这样在Z平面上进行投影: var
我有4个足球场点(角点): P1(lat, lon, alt) , P2(lat, lon, alt) , P3(lat, lon, alt) , P4(lat, lon, alt) . 以及球场上的
我有一个交换了纬度和经度位置的 NetCDF 文件。 我通常使用的 Netcdf 的标准方式定义如下: Coordinates: * time (time) datetime64[n
如果 line1 和 lin2 都由 x,y,alpha 定义,其中 x,y 是直线上一点的坐标,alpha 是直线与 x=const 之间的角度,如何找到 line1 和 lin2 相交的点? 我尝
我是一名优秀的程序员,十分优秀!