public ConnectionInfoKey(ConnectionInfo connectionInfo) { this.host = connectionInfo.getThriftHost().toString(); this.port = connectionInfo.getThriftPort().intValue(); }
private byte[] hash(OperationsNodeInfo node, int replica) { byte[] key = node.getConnectionInfo().getPublicKey().array(); ByteBuffer data = ByteBuffer.wrap(new byte[key.length + SIZE_OF_INT]); data.put(key); data.putInt(replica); return md5.get().digest(data.array()); }
@Override public ConnectionInfo build() { try { ConnectionInfo record = new ConnectionInfo(); record.thriftHost = fieldSetFlags()[0] ? this.thriftHost : (java.lang.CharSequence) defaultValue(fields()[0]); record.thriftPort = fieldSetFlags()[1] ? this.thriftPort : (java.lang.Integer) defaultValue(fields()[1]); record.publicKey = fieldSetFlags()[2] ? this.publicKey : (java.nio.ByteBuffer) defaultValue(fields()[2]); return record; } catch (Exception e) { throw new org.apache.avro.AvroRuntimeException(e); } } }
/** * Use when one need to write an OperationsNodeInfo instance to logs. The OperationsNodeInfo * instance has ByteBuffer fields which should be represented in log files as null because their * values are unrepresentative and redundant. * * @param format the format string * @param node the instance of OperationsNodeInfo * @param resolver the instance of OperationsServerResolver */ private void writeLogWithoutByteBuffer(String format, OperationsNodeInfo node, OperationsServerResolver resolver) { // Temporary remove connection info for transports Map<TransportMetaData, Map<VersionConnectionInfoPair, ByteBuffer>> transportMetaData = new HashMap<>(); node.getTransports().forEach(transport -> transportMetaData.put(transport, removeTransportConnectionInfo(transport))); // Temporary remove public key final ByteBuffer publicKey = node.getConnectionInfo().getPublicKey(); node.getConnectionInfo().setPublicKey(null); LOG.info(format, node, resolver); // Restore connection info for transports node.getTransports().forEach(transport -> restoreTransportConnectionInfo(transport, transportMetaData.get(transport))); // Restore public key node.getConnectionInfo().setPublicKey(publicKey); }
/** * Start zk. * * @throws Exception in case of error */ private void startZk() throws Exception { // NOSONAR if (getNodeConfig().isZkEnabled()) { LOG.info("Bootstrap service starting ZooKepper connection to {}", getNodeConfig().getZkHostPortList()); BootstrapNodeInfo nodeInfo = new BootstrapNodeInfo(); ByteBuffer keyData = ByteBuffer.wrap(bootstrapKeyStoreService.getPublicKey().getEncoded()); LOG.trace("Bootstrap service: registering in ZK: thriftHost {}; " + "thriftPort {}; nettyHost {}; nettyPort {}", getNodeConfig().getThriftHost(), getNodeConfig().getThriftPort()); nodeInfo.setConnectionInfo(new ConnectionInfo( getNodeConfig().getThriftHost(), getNodeConfig().getThriftPort(), keyData)); nodeInfo.setTransports(new ArrayList<>()); nodeInfo.setTimeStarted(System.currentTimeMillis()); bootstrapNode = new BootstrapNode(nodeInfo, zkClient); if (bootstrapNode != null) { bootstrapNode.start(); } } }
/** * Builds the server name based on the connection info properties. * * @param connectionInfo the connection info * @return name of the server */ public static String getNameFromConnectionInfo(ConnectionInfo connectionInfo) { StringBuilder name = new StringBuilder(); name.append(connectionInfo.getThriftHost()); name.append(HOST_PORT_DELIMITER); name.append(connectionInfo.getThriftPort()); return name.toString(); }
/** * Start Zookeeper service. */ public void start() { if (getNodeConfig().isZkEnabled()) { LOG.info("Control service starting ZooKepper connection to {}", getNodeConfig().getZkHostPortList()); ControlNodeInfo nodeInfo = new ControlNodeInfo(); ConnectionInfo connectionInfo = new ConnectionInfo( getNodeConfig().getThriftHost(), getNodeConfig().getThriftPort(), null); nodeInfo.setConnectionInfo(connectionInfo); controlZkNode = new ControlNode(nodeInfo, zkClient); try { controlZkNode.start(); } catch (Exception ex) { if (getNodeConfig().isZkIgnoreErrors()) { LOG.info("Failed to register control in ZooKeeper", ex); } else { LOG.error("Failed to register control in ZooKeeper", ex); throw new RuntimeException(ex); // NOSONAR } } } }
/** * Build server ID from ConnectionInfo object. * * @param service KaaThriftService * @param info ConnectionInfo * @return server ID in format thriftHost:thriftPort */ public static String getServerId(KaaThriftService service, ConnectionInfo info) { StringBuffer sb = new StringBuffer(); sb.append(info.getThriftHost()); sb.append(":"); sb.append(info.getThriftPort()); sb.append(":"); sb.append(service.name()); return sb.toString(); }
OperationsNodeInfo nodeInfo = new OperationsNodeInfo(); ByteBuffer keyData = ByteBuffer.wrap(operationsKeyStoreService.getPublicKey().getEncoded()); nodeInfo.setConnectionInfo(new ConnectionInfo(getNodeConfig().getThriftHost(), getNodeConfig().getThriftPort(), keyData)); nodeInfo.setLoadInfo(new LoadInfo(DEFAULT_LOAD_INDEX, 1.0));
private String constructEndpointAddress(OperationsNodeInfo nodeInfo) { return nodeInfo.getConnectionInfo().getThriftHost() + ":" + String.valueOf(nodeInfo.getConnectionInfo().getThriftPort()); }
private String constructBootstrapAddress(BootstrapNodeInfo nodeInfo) { return nodeInfo.getConnectionInfo().getThriftHost() + ":" + String.valueOf(nodeInfo.getConnectionInfo().getThriftPort()); }
@Override public String toString() { return "BootstrapNode {" + "host =" + nodeInfo.getConnectionInfo().getThriftHost() + "port =" + nodeInfo.getConnectionInfo().getThriftPort() + "timeStarted =" + nodeInfo.getTimeStarted() + '}'; } }
@Override public String toString() { return "OperationsNode {" + "host =" + nodeInfo.getConnectionInfo().getThriftHost() + "port =" + nodeInfo.getConnectionInfo().getThriftPort() + "timeStarted =" + nodeInfo.getTimeStarted() + '}'; } }
/** * Checks if is master. * * @return true, if is master */ public boolean isMaster() { ControlNodeInfo serverInfo = getControlServerInfo(); if (currentNodeInfo != null && serverInfo != null) { String curHost = currentNodeInfo.getConnectionInfo().getThriftHost().toString(); int curPort = currentNodeInfo.getConnectionInfo().getThriftPort(); String masterHost = serverInfo.getConnectionInfo().getThriftHost().toString(); int masterPort = serverInfo.getConnectionInfo().getThriftPort(); return curHost.equals(masterHost) && curPort == masterPort; } else { return false; } }
private static String toString(OperationsNodeInfo node) { return "[" + node.getConnectionInfo().getThriftHost() + ":" + node.getConnectionInfo().getThriftPort() + ":" + node.getTimeStarted() + "]-[" + node.getLoadInfo() + "]"; }
final List<RedirectionRule> rules) { LOG.trace("Set redirection rule for Operations server: {}; Thrift: {}:{}", accessPointId, nodeInfo.getConnectionInfo().getThriftHost().toString(), nodeInfo.getConnectionInfo().getThriftPort()); try { nodeInfo.getConnectionInfo().getThriftHost().toString(), nodeInfo.getConnectionInfo().getThriftPort(), KaaThriftService.OPERATIONS_SERVICE, OperationsThriftService.Client.class
clientFactory = ThriftFactory.create(OperationsThriftService.Iface.class); InetSocketAddress address = new InetSocketAddress( connectionInfo.getThriftHost().toString(), connectionInfo.getThriftPort() ); Set<InetSocketAddress> backends = new HashSet<>();
try { ThriftClient<BootstrapThriftService.Client> thriftClient = new ThriftClient<>( nodeInfo.getConnectionInfo().getThriftHost().toString(), nodeInfo.getConnectionInfo().getThriftPort(), KaaThriftService.BOOTSTRAP_SERVICE, BootstrapThriftService.Client.class
List<OperationsNodeInfo> endpoints = controlZkNode.getCurrentOperationServerNodes(); for (OperationsNodeInfo endpoint : endpoints) { String host = endpoint.getConnectionInfo().getThriftHost().toString(); int port = endpoint.getConnectionInfo().getThriftPort(); try { ThriftClient<OperationsThriftService.Client> thriftClient = new ThriftClient<>(host, port,