private static void putOffsetInfoIntoZk(String groupId, Map<String, Map<Integer, Long>> topicOffsetsMap) { ZkUtils zkUtils = ZkUtils.apply(AuditConfig.INGESTER_ZK_CONNECT, Integer.valueOf(AuditConfig.INGESTER_ZK_SESSION_TIMEOUT_MS), Integer.valueOf(AuditConfig.INGESTER_ZK_SESSION_TIMEOUT_MS), false); try { for (Map.Entry<String, Map<Integer, Long>> topicEntry : topicOffsetsMap.entrySet()) { String zkPath = String.format("%s/%s/offsets/%s/", ZkUtils.ConsumersPath(), groupId, topicEntry.getKey()); for (Map.Entry<Integer, Long> offsetEntry : topicEntry.getValue().entrySet()) { logger.info("Put offset={} to partition={} with znode path={}", offsetEntry.getValue(), offsetEntry.getKey(), zkPath + offsetEntry.getKey()); zkUtils.updatePersistentPath(zkPath + offsetEntry.getKey(), offsetEntry.getValue().toString(), zkUtils.DefaultAcls()); } } } catch (Exception e) { logger.error("Got exception to put offset, with zkPathPrefix={}", String.format("%s/%s/offsets", ZkUtils.ConsumersPath(), groupId)); throw e; } finally { zkUtils.close(); } }
public void electMaster() throws RegistryStoreException, RegistryTimeoutException { RegistryIdentity masterIdentity = null; try { zkUtils.createEphemeralPathExpectConflict(MASTER_PATH, myIdentityString, zkUtils.DefaultAcls()); log.info("Successfully elected the new master: " + myIdentityString); masterIdentity = myIdentity; schemaRegistry.setMaster(masterIdentity); } catch (ZkNodeExistsException znee) { readCurrentMaster(); } }
private void createZkNamespace() { int kafkaNamespaceIndex = kafkaClusterZkUrl.indexOf("/"); String zkConnForNamespaceCreation = kafkaNamespaceIndex > 0 ? kafkaClusterZkUrl.substring(0, kafkaNamespaceIndex) : kafkaClusterZkUrl; String schemaRegistryNamespace = "/" + schemaRegistryZkNamespace; schemaRegistryZkUrl = zkConnForNamespaceCreation + schemaRegistryNamespace; ZkUtils zkUtilsForNamespaceCreation = ZkUtils.apply( zkConnForNamespaceCreation, zkSessionTimeoutMs, zkSessionTimeoutMs, JaasUtils.isZkSecurityEnabled()); // create the zookeeper namespace using cluster.name if it doesn't already exist zkUtilsForNamespaceCreation.makeSurePersistentPathExists( schemaRegistryNamespace, zkUtilsForNamespaceCreation.DefaultAcls()); log.info("Created schema registry namespace " + zkConnForNamespaceCreation + schemaRegistryNamespace); zkUtilsForNamespaceCreation.close(); this.zkUtils = ZkUtils.apply( schemaRegistryZkUrl, zkSessionTimeoutMs, zkSessionTimeoutMs, JaasUtils.isZkSecurityEnabled()); }
zkUtils.createPersistentPath(ZOOKEEPER_SCHEMA_ID_COUNTER, String.valueOf(nextIdBatchUpperBound), zkUtils.DefaultAcls()); return nextIdBatchLowerBound; } catch (ZkNodeExistsException ignore) {