use of org.apache.helix.model.InstanceConfig in project pinot by linkedin.
the class ValidationManagerTest method testRebuildBrokerResourceWhenBrokerAdded.
@Test
public void testRebuildBrokerResourceWhenBrokerAdded() throws Exception {
// Check that the first table we added doesn't need to be rebuilt(case where ideal state brokers and brokers in broker resource are the same.
String partitionName = _offlineTableConfig.getTableName();
HelixAdmin helixAdmin = _helixManager.getClusterManagmentTool();
IdealState idealState = HelixHelper.getBrokerIdealStates(helixAdmin, HELIX_CLUSTER_NAME);
// Ensure that the broker resource is not rebuilt.
Assert.assertTrue(idealState.getInstanceSet(partitionName).equals(_pinotHelixResourceManager.getAllInstancesForBrokerTenant(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME)));
_pinotHelixResourceManager.rebuildBrokerResourceFromHelixTags(partitionName);
// Add another table that needs to be rebuilt
String offlineTableTwoConfigJson = ControllerRequestBuilderUtil.buildCreateOfflineTableJSON(TEST_TABLE_TWO, null, null, 1).toString();
AbstractTableConfig offlineTableConfigTwo = AbstractTableConfig.init(offlineTableTwoConfigJson);
_pinotHelixResourceManager.addTable(offlineTableConfigTwo);
String partitionNameTwo = offlineTableConfigTwo.getTableName();
// Add a new broker manually such that the ideal state is not updated and ensure that rebuild broker resource is called
final String brokerId = "Broker_localhost_2";
InstanceConfig instanceConfig = new InstanceConfig(brokerId);
instanceConfig.setInstanceEnabled(true);
instanceConfig.setHostName("Broker_localhost");
instanceConfig.setPort("2");
helixAdmin.addInstance(HELIX_CLUSTER_NAME, instanceConfig);
helixAdmin.addInstanceTag(HELIX_CLUSTER_NAME, instanceConfig.getInstanceName(), ControllerTenantNameBuilder.getBrokerTenantNameForTenant(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
idealState = HelixHelper.getBrokerIdealStates(helixAdmin, HELIX_CLUSTER_NAME);
// Assert that the two don't equal before the call to rebuild the broker resource.
Assert.assertTrue(!idealState.getInstanceSet(partitionNameTwo).equals(_pinotHelixResourceManager.getAllInstancesForBrokerTenant(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME)));
_pinotHelixResourceManager.rebuildBrokerResourceFromHelixTags(partitionNameTwo);
idealState = HelixHelper.getBrokerIdealStates(helixAdmin, HELIX_CLUSTER_NAME);
// Assert that the two do equal after being rebuilt.
Assert.assertTrue(idealState.getInstanceSet(partitionNameTwo).equals(_pinotHelixResourceManager.getAllInstancesForBrokerTenant(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME)));
}
use of org.apache.helix.model.InstanceConfig in project pinot by linkedin.
the class PinotHelixResourceManager method getAllServerTenantNames.
public Set<String> getAllServerTenantNames() {
Set<String> tenantSet = new HashSet<String>();
List<String> instancesInCluster = _helixAdmin.getInstancesInCluster(_helixClusterName);
for (String instanceName : instancesInCluster) {
InstanceConfig config = _helixDataAccessor.getProperty(_keyBuilder.instanceConfig(instanceName));
for (String tag : config.getTags()) {
if (tag.equals(CommonConstants.Helix.UNTAGGED_BROKER_INSTANCE) || tag.equals(CommonConstants.Helix.UNTAGGED_SERVER_INSTANCE)) {
continue;
}
if (ControllerTenantNameBuilder.getTenantRoleFromTenantName(tag) == TenantRole.SERVER) {
tenantSet.add(ControllerTenantNameBuilder.getExternalTenantName(tag));
}
}
}
return tenantSet;
}
use of org.apache.helix.model.InstanceConfig in project pinot by linkedin.
the class PinotHelixResourceManager method getDataInstanceAdminEndpoints.
/**
* Provides admin endpoints for the provided data instances
* @param instances instances for which to read endpoints
* @return returns map of instances to their admin endpoints.
* The return value is a bimap because admin instances are typically used for
* http requests. So, on response, we need mapping from the endpoint to the
* server instances. With BiMap, both mappings are easily available
*/
@Nonnull
public BiMap<String, String> getDataInstanceAdminEndpoints(@Nonnull Set<String> instances) {
Preconditions.checkNotNull(instances);
BiMap<String, String> endpointToInstance = HashBiMap.create(instances.size());
for (String instance : instances) {
InstanceConfig helixInstanceConfig = getHelixInstanceConfig(instance);
ZNRecord record = helixInstanceConfig.getRecord();
String[] hostnameSplit = helixInstanceConfig.getHostName().split("_");
Preconditions.checkState(hostnameSplit.length >= 2);
String port = record.getSimpleField(CommonConstants.Helix.Instance.ADMIN_PORT_KEY);
endpointToInstance.put(instance, hostnameSplit[1] + ":" + port);
}
return endpointToInstance;
}
use of org.apache.helix.model.InstanceConfig in project pinot by linkedin.
the class HelixServerStarter method addInstanceTagIfNeeded.
private void addInstanceTagIfNeeded(String clusterName, String instanceName) {
InstanceConfig instanceConfig = _helixAdmin.getInstanceConfig(clusterName, instanceName);
List<String> instanceTags = instanceConfig.getTags();
if (instanceTags == null || instanceTags.size() == 0) {
if (ZKMetadataProvider.getClusterTenantIsolationEnabled(_helixManager.getHelixPropertyStore())) {
_helixAdmin.addInstanceTag(clusterName, instanceName, TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
_helixAdmin.addInstanceTag(clusterName, instanceName, TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
} else {
_helixAdmin.addInstanceTag(clusterName, instanceName, CommonConstants.Helix.UNTAGGED_SERVER_INSTANCE);
}
}
}
use of org.apache.helix.model.InstanceConfig in project pinot by linkedin.
the class HelixHelper method getEnabledInstancesWithTag.
public static List<String> getEnabledInstancesWithTag(HelixAdmin helixAdmin, String helixClusterName, String instanceTag) {
List<String> instances = helixAdmin.getInstancesInCluster(helixClusterName);
List<String> enabledInstances = new ArrayList<>();
for (String instance : instances) {
InstanceConfig instanceConfig = helixAdmin.getInstanceConfig(helixClusterName, instance);
if (instanceConfig == null) {
LOGGER.warn("InstanceConfig not found for instance: {}", instance);
continue;
}
if (instanceConfig.containsTag(instanceTag) && instanceConfig.getInstanceEnabled()) {
enabledInstances.add(instance);
}
}
return enabledInstances;
}
Aggregations