use of org.platformlayer.service.zookeeper.ops.ZookeeperUtils.ZookeeperResponse in project platformlayer by platformlayer.
the class ZookeeperStatusChecker method handler.
@Handler
public void handler(OpsTarget target, ZookeeperServer zookeeperServer) throws OpsException {
if (OpsContext.isConfigure() || OpsContext.isValidate()) {
int port = ZookeeperConstants.ZK_PUBLIC_PORT;
List<EndpointInfo> endpoints = EndpointInfo.findEndpoints(zookeeperServer.getTags(), port);
EndpointInfo endpoint = EndpointChooser.any().choose(endpoints);
if (endpoint == null) {
throw new OpsException("Cannot find endpoint for zookeeper");
}
InetSocketAddress socketAddress = endpoint.asSocketAddress();
{
ZookeeperResponse response;
try {
// IPV6 requires ipsec; use the IPV4 loopback instead
socketAddress = new InetSocketAddress(InetAddresses.forString("127.0.0.1"), socketAddress.getPort());
response = ZookeeperUtils.sendCommand(target, socketAddress, "ruok");
Deviations.assertEquals("imok", response.getRaw(), "Zookeeper ruok status");
} catch (OpsException e) {
Deviations.fail("Unable to connect to zookeeper", e);
}
}
{
ZookeeperResponse response;
try {
response = ZookeeperUtils.sendCommand(target, socketAddress, "srvr");
Map<String, String> responseMap = response.asMap();
String mode = responseMap.get("Mode");
Deviations.assertIn(Arrays.asList("follower", "leader"), mode, "Zookeeper mode");
} catch (OpsException e) {
Deviations.fail("Unable to connect to zookeeper", e);
}
}
}
}
Aggregations