Search in sources :

Example 1 with ZookeeperResponse

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);
            }
        }
    }
}
Also used : EndpointInfo(org.platformlayer.core.model.EndpointInfo) OpsException(org.platformlayer.ops.OpsException) ZookeeperResponse(org.platformlayer.service.zookeeper.ops.ZookeeperUtils.ZookeeperResponse) InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) Handler(org.platformlayer.ops.Handler)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 EndpointInfo (org.platformlayer.core.model.EndpointInfo)1 Handler (org.platformlayer.ops.Handler)1 OpsException (org.platformlayer.ops.OpsException)1 ZookeeperResponse (org.platformlayer.service.zookeeper.ops.ZookeeperUtils.ZookeeperResponse)1