use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.
the class ZKHelixManager method resolveZkClient.
/*
* Resolves what type of ZkClient this HelixManager should use based on whether MULTI_ZK_ENABLED
* System config is set or not. Two types of ZkClients are available:
* 1) If MULTI_ZK_ENABLED is set to true or zkAddress is null, we create a dedicated
* RealmAwareZkClient that provides full ZkClient functionalities and connects to the correct ZK
* by querying MetadataStoreDirectoryService.
* 2) Otherwise, we create a dedicated HelixZkClient which plainly connects to
* the ZK address given.
*/
private RealmAwareZkClient resolveZkClient(HelixZkClientFactory zkClientFactory, RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig, RealmAwareZkClient.RealmAwareZkClientConfig clientConfig) {
if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED) || _zkAddress == null) {
try {
// Create realm-aware ZkClient.
return zkClientFactory.buildZkClient(connectionConfig, clientConfig);
} catch (IllegalArgumentException | IOException | InvalidRoutingDataException e) {
throw new HelixException("Not able to connect on realm-aware mode for sharding key: " + connectionConfig.getZkRealmShardingKey(), e);
}
}
// If multi-zk mode is not enabled, create HelixZkClient with the provided zk address.
HelixZkClient.ZkClientConfig helixZkClientConfig = clientConfig.createHelixZkClientConfig();
HelixZkClient.ZkConnectionConfig helixZkConnectionConfig = new HelixZkClient.ZkConnectionConfig(_zkAddress).setSessionTimeout(connectionConfig.getSessionTimeout());
return zkClientFactory.buildZkClient(helixZkConnectionConfig, helixZkClientConfig);
}
use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.
the class ZKUtil method getHelixZkClient.
/**
* Returns a dedicated ZkClient. A federatedZkClient will be used on multi-zk mode.
* WARNING: ephemeral operations will not be supported on multi-zk mode!
* @return
*/
private static RealmAwareZkClient getHelixZkClient(String zkAddr) {
if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED) || zkAddr == null) {
try {
// Create realm-aware ZkClient.
RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build();
RealmAwareZkClient.RealmAwareZkClientConfig clientConfig = new RealmAwareZkClient.RealmAwareZkClientConfig();
return new FederatedZkClient(connectionConfig, clientConfig);
} catch (IllegalArgumentException | InvalidRoutingDataException e) {
throw new HelixException("Not able to connect on realm-aware mode", e);
}
}
if (zkAddr.isEmpty()) {
throw new HelixException("ZK Address given is empty!");
}
HelixZkClient.ZkClientConfig clientConfig = new HelixZkClient.ZkClientConfig();
clientConfig.setZkSerializer(new ZNRecordSerializer());
return DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddr), clientConfig);
}
use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.
the class ZkBucketDataAccessor method createRealmAwareZkClient.
private static RealmAwareZkClient createRealmAwareZkClient(String zkAddr) {
RealmAwareZkClient zkClient;
if (Boolean.getBoolean(SystemPropertyKeys.MULTI_ZK_ENABLED) || zkAddr == null) {
LOG.warn("ZkBucketDataAccessor: either multi-zk enabled or zkAddr is null - " + "starting ZkBucketDataAccessor in multi-zk mode!");
try {
// Create realm-aware ZkClient.
RealmAwareZkClient.RealmAwareZkConnectionConfig connectionConfig = new RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build();
RealmAwareZkClient.RealmAwareZkClientConfig clientConfig = new RealmAwareZkClient.RealmAwareZkClientConfig();
zkClient = new FederatedZkClient(connectionConfig, clientConfig);
} catch (IllegalArgumentException | InvalidRoutingDataException e) {
throw new HelixException("Not able to connect on realm-aware mode", e);
}
} else {
zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkAddr));
}
return zkClient;
}
use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.
the class TestZkRoutingDataReader method testGetRoutingDataMSRDChildEmptyValue.
@Test(dependsOnMethods = "testGetRoutingData")
public void testGetRoutingDataMSRDChildEmptyValue() {
ZNRecord testZnRecord1 = new ZNRecord("testZnRecord1");
testZnRecord1.setListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY, Collections.emptyList());
_gZkClientTestNS.createPersistent(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/testRealmAddress1", testZnRecord1);
try {
Map<String, List<String>> routingData = _zkRoutingDataReader.getRoutingData();
Assert.assertEquals(routingData.size(), 1);
Assert.assertTrue(routingData.get("testRealmAddress1").isEmpty());
} catch (InvalidRoutingDataException e) {
Assert.fail("Not expecting InvalidRoutingDataException");
}
}
use of org.apache.helix.msdcommon.exception.InvalidRoutingDataException in project helix by apache.
the class ZkRoutingDataReader method getRoutingData.
/**
* Returns (realm, list of ZK path sharding keys) mappings.
* @return Map <realm, list of ZK path sharding keys>
* @throws InvalidRoutingDataException - when the node on
* MetadataStoreRoutingConstants.ROUTING_DATA_PATH is missing
*/
public Map<String, List<String>> getRoutingData() throws InvalidRoutingDataException {
Map<String, List<String>> routingData = new HashMap<>();
List<String> allRealmAddresses;
try {
allRealmAddresses = _zkClient.getChildren(MetadataStoreRoutingConstants.ROUTING_DATA_PATH);
} catch (ZkNoNodeException e) {
throw new InvalidRoutingDataException("Routing data directory ZNode " + MetadataStoreRoutingConstants.ROUTING_DATA_PATH + " does not exist. Routing ZooKeeper address: " + _zkAddress);
}
if (allRealmAddresses != null) {
for (String realmAddress : allRealmAddresses) {
ZNRecord record = _zkClient.readData(MetadataStoreRoutingConstants.ROUTING_DATA_PATH + "/" + realmAddress, true);
if (record != null) {
List<String> shardingKeys = record.getListField(MetadataStoreRoutingConstants.ZNRECORD_LIST_FIELD_KEY);
routingData.put(realmAddress, shardingKeys != null ? shardingKeys : Collections.emptyList());
}
}
}
return routingData;
}
Aggregations