Search in sources :

Example 86 with InstanceConfig

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)));
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) Matchers.anyString(org.mockito.Matchers.anyString) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 87 with InstanceConfig

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;
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) HashSet(java.util.HashSet)

Example 88 with InstanceConfig

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;
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) ZNRecord(org.apache.helix.ZNRecord) Nonnull(javax.annotation.Nonnull)

Example 89 with InstanceConfig

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);
        }
    }
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig)

Example 90 with InstanceConfig

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;
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) ArrayList(java.util.ArrayList)

Aggregations

InstanceConfig (org.apache.helix.model.InstanceConfig)149 ArrayList (java.util.ArrayList)40 Test (org.testng.annotations.Test)35 HashMap (java.util.HashMap)32 HashSet (java.util.HashSet)28 ZNRecord (org.apache.helix.ZNRecord)26 IdealState (org.apache.helix.model.IdealState)24 ExternalView (org.apache.helix.model.ExternalView)23 Map (java.util.Map)21 HelixException (org.apache.helix.HelixException)21 HelixAdmin (org.apache.helix.HelixAdmin)20 List (java.util.List)19 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)19 HelixDataAccessor (org.apache.helix.HelixDataAccessor)17 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)15 Test (org.junit.Test)15 Set (java.util.Set)13 VerifiableProperties (com.github.ambry.config.VerifiableProperties)12 IOException (java.io.IOException)12 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)12