Search in sources :

Example 16 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project ambry by linkedin.

the class VcrTestUtil method populateZkInfoAndStartController.

/**
 * Populate info on ZooKeeper server and start {@link HelixControllerManager}.
 * @param zkConnectString zk connect string to zk server.
 * @param vcrClusterName the vcr cluster name.
 * @param clusterMap the {@link ClusterMap} to use.
 * @param vcrHelixStateModel the state model to use for helix cluster events.
 * @return the created {@link HelixControllerManager}.
 */
public static HelixControllerManager populateZkInfoAndStartController(String zkConnectString, String vcrClusterName, ClusterMap clusterMap, String vcrHelixStateModel) {
    HelixZkClient zkClient = DedicatedZkClientFactory.getInstance().buildZkClient(new HelixZkClient.ZkConnectionConfig(zkConnectString), new HelixZkClient.ZkClientConfig());
    try {
        zkClient.setZkSerializer(new ZNRecordSerializer());
        ClusterSetup clusterSetup = new ClusterSetup(zkClient);
        clusterSetup.addCluster(vcrClusterName, true);
        HelixAdmin admin = new ZKHelixAdmin(zkClient);
        // set ALLOW_PARTICIPANT_AUTO_JOIN
        HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(vcrClusterName).build();
        Map<String, String> helixClusterProperties = new HashMap<>();
        helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(true));
        admin.setConfig(configScope, helixClusterProperties);
        // set PersistBestPossibleAssignment
        ConfigAccessor configAccessor = new ConfigAccessor(zkClient);
        ClusterConfig clusterConfig = configAccessor.getClusterConfig(vcrClusterName);
        clusterConfig.setPersistBestPossibleAssignment(true);
        configAccessor.setClusterConfig(vcrClusterName, clusterConfig);
        FullAutoModeISBuilder builder = new FullAutoModeISBuilder(helixResource);
        builder.setStateModel(vcrHelixStateModel);
        for (PartitionId partitionId : clusterMap.getAllPartitionIds(null)) {
            builder.add(partitionId.toPathString());
        }
        builder.setMinActiveReplica(MIN_ACTIVE_REPLICAS);
        builder.setRebalanceDelay((int) REBALANCE_DELAY_MS);
        builder.setRebalancerClass(DelayedAutoRebalancer.class.getName());
        builder.setRebalanceStrategy(CrushEdRebalanceStrategy.class.getName());
        IdealState idealState = builder.build();
        admin.addResource(vcrClusterName, helixResource, idealState);
        admin.rebalance(vcrClusterName, helixResource, NUM_REPLICAS, "", "");
        HelixControllerManager helixControllerManager = new HelixControllerManager(zkConnectString, vcrClusterName);
        helixControllerManager.syncStart();
        return helixControllerManager;
    } finally {
        zkClient.close();
    }
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) HashMap(java.util.HashMap) CrushEdRebalanceStrategy(org.apache.helix.controller.rebalancer.strategy.CrushEdRebalanceStrategy) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) HelixControllerManager(com.github.ambry.utils.HelixControllerManager) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) PartitionId(com.github.ambry.clustermap.PartitionId) DelayedAutoRebalancer(org.apache.helix.controller.rebalancer.DelayedAutoRebalancer) IdealState(org.apache.helix.model.IdealState) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) HelixConfigScope(org.apache.helix.model.HelixConfigScope) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) ClusterConfig(org.apache.helix.model.ClusterConfig)

Example 17 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project pinot by linkedin.

the class ControllerRequestBuilderUtil method addFakeDataInstancesToAutoJoinHelixCluster.

public static void addFakeDataInstancesToAutoJoinHelixCluster(String helixClusterName, String zkServer, int numInstances, boolean isSingleTenant, int adminPort) throws Exception {
    for (int i = 0; i < numInstances; ++i) {
        final String instanceId = "Server_localhost_" + i;
        final HelixManager helixZkManager = HelixManagerFactory.getZKHelixManager(helixClusterName, instanceId, InstanceType.PARTICIPANT, zkServer);
        final StateMachineEngine stateMachineEngine = helixZkManager.getStateMachineEngine();
        final StateModelFactory<?> stateModelFactory = new EmptySegmentOnlineOfflineStateModelFactory();
        stateMachineEngine.registerStateModelFactory(EmptySegmentOnlineOfflineStateModelFactory.getStateModelDef(), stateModelFactory);
        helixZkManager.connect();
        if (isSingleTenant) {
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, instanceId, TableNameBuilder.OFFLINE_TABLE_NAME_BUILDER.forTable(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, instanceId, TableNameBuilder.REALTIME_TABLE_NAME_BUILDER.forTable(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
        } else {
            helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, instanceId, UNTAGGED_SERVER_INSTANCE);
        }
        HelixConfigScope scope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.PARTICIPANT, helixClusterName).forParticipant(instanceId).build();
        Map<String, String> props = new HashMap<>();
        props.put(CommonConstants.Helix.Instance.ADMIN_PORT_KEY, String.valueOf(adminPort + i));
        helixZkManager.getClusterManagmentTool().setConfig(scope, props);
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) StateMachineEngine(org.apache.helix.participant.StateMachineEngine) HashMap(java.util.HashMap) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope)

Example 18 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project pinot by linkedin.

the class HelixServerStarter method updateInstanceConfigInHelix.

private void updateInstanceConfigInHelix(Map<String, String> props) {
    HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.PARTICIPANT, _helixClusterName).forParticipant(_instanceId).build();
    _helixAdmin.setConfig(scope, props);
}
Also used : HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope)

Example 19 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project ambry by linkedin.

the class HelixVcrUtil method createCluster.

/**
 * Create a helix cluster with given information.
 * @param destZkString the cluster's zk string
 * @param destClusterName the cluster's name
 */
public static void createCluster(String destZkString, String destClusterName, VcrHelixConfig config) {
    HelixZkClient destZkClient = getHelixZkClient(destZkString);
    HelixAdmin destAdmin = new ZKHelixAdmin(destZkClient);
    if (ZKUtil.isClusterSetup(destClusterName, destZkClient)) {
        errorAndExit("Failed to create cluster because " + destClusterName + " already exist.");
    }
    ClusterSetup clusterSetup = new ClusterSetup.Builder().setZkAddress(destZkString).build();
    clusterSetup.addCluster(destClusterName, true);
    // set ALLOW_PARTICIPANT_AUTO_JOIN
    HelixConfigScope configScope = new HelixConfigScopeBuilder(HelixConfigScope.ConfigScopeProperty.CLUSTER).forCluster(destClusterName).build();
    Map<String, String> helixClusterProperties = new HashMap<>();
    helixClusterProperties.put(ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN, String.valueOf(config.getClusterConfigFields().isAllowAutoJoin()));
    destAdmin.setConfig(configScope, helixClusterProperties);
    setClusterConfig(destZkClient, destClusterName, config, false);
    logger.info("Cluster {} is created successfully!", destClusterName);
}
Also used : HelixZkClient(org.apache.helix.zookeeper.api.client.HelixZkClient) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) HashMap(java.util.HashMap) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) FullAutoModeISBuilder(org.apache.helix.model.builder.FullAutoModeISBuilder) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope) HelixAdmin(org.apache.helix.HelixAdmin) ZKHelixAdmin(org.apache.helix.manager.zk.ZKHelixAdmin) ClusterSetup(org.apache.helix.tools.ClusterSetup)

Example 20 with HelixConfigScopeBuilder

use of org.apache.helix.model.builder.HelixConfigScopeBuilder in project helix by apache.

the class HelixTaskExecutor method updateStateTransitionMessageThreadPool.

/**
 * Dedicated Thread pool can be provided in configuration or by client.
 *  This method is to check it and update the thread pool if necessary.
 */
private void updateStateTransitionMessageThreadPool(Message message, HelixManager manager) {
    if (!message.getMsgType().equals(MessageType.STATE_TRANSITION.name())) {
        return;
    }
    String resourceName = message.getResourceName();
    String factoryName = message.getStateModelFactoryName();
    String stateModelName = message.getStateModelDef();
    if (factoryName == null) {
        factoryName = HelixConstants.DEFAULT_STATE_MODEL_FACTORY;
    }
    StateModelFactory<? extends StateModel> stateModelFactory = manager.getStateMachineEngine().getStateModelFactory(stateModelName, factoryName);
    String perStateTransitionTypeKey = getStateTransitionType(getPerResourceStateTransitionPoolName(resourceName), message.getFromState(), message.getToState());
    if (perStateTransitionTypeKey != null && stateModelFactory != null && !_transitionTypeThreadpoolChecked.contains(perStateTransitionTypeKey)) {
        ExecutorService perStateTransitionTypeExecutor = stateModelFactory.getExecutorService(resourceName, message.getFromState(), message.getToState());
        _transitionTypeThreadpoolChecked.add(perStateTransitionTypeKey);
        if (perStateTransitionTypeExecutor != null) {
            _executorMap.put(perStateTransitionTypeKey, perStateTransitionTypeExecutor);
            LOG.info(String.format("Added client specified dedicate threadpool for resource %s from %s to %s", getPerResourceStateTransitionPoolName(resourceName), message.getFromState(), message.getToState()));
            return;
        }
    }
    if (!_resourcesThreadpoolChecked.contains(resourceName)) {
        int threadpoolSize = -1;
        ConfigAccessor configAccessor = manager.getConfigAccessor();
        // Changes to this configuration on thread pool size will only take effect after the participant get restarted.
        if (configAccessor != null) {
            HelixConfigScope scope = new HelixConfigScopeBuilder(ConfigScopeProperty.RESOURCE).forCluster(manager.getClusterName()).forResource(resourceName).build();
            String threadpoolSizeStr = configAccessor.get(scope, MAX_THREADS);
            try {
                if (threadpoolSizeStr != null) {
                    threadpoolSize = Integer.parseInt(threadpoolSizeStr);
                }
            } catch (Exception e) {
                LOG.error("Failed to parse ThreadPoolSize from resourceConfig for resource" + resourceName, e);
            }
        }
        final String key = getPerResourceStateTransitionPoolName(resourceName);
        if (threadpoolSize > 0) {
            _executorMap.put(key, Executors.newFixedThreadPool(threadpoolSize, new ThreadFactory() {

                @Override
                public Thread newThread(Runnable r) {
                    return new Thread(r, "GerenricHelixController-message_handle_" + key);
                }
            }));
            LOG.info("Added dedicate threadpool for resource: " + resourceName + " with size: " + threadpoolSize);
        } else {
            // check whether client specifies customized threadpool.
            if (stateModelFactory != null) {
                ExecutorService executor = stateModelFactory.getExecutorService(resourceName);
                if (executor != null) {
                    _executorMap.put(key, executor);
                    LOG.info("Added client specified dedicate threadpool for resource: " + key);
                }
            } else {
                LOG.error(String.format("Fail to get dedicate threadpool defined in stateModelFactory %s: using factoryName: %s for resource %s. No stateModelFactory was found!", stateModelName, factoryName, resourceName));
            }
        }
        _resourcesThreadpoolChecked.add(resourceName);
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) ExecutorService(java.util.concurrent.ExecutorService) ConfigAccessor(org.apache.helix.ConfigAccessor) HelixConfigScope(org.apache.helix.model.HelixConfigScope) HelixException(org.apache.helix.HelixException)

Aggregations

HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)35 HelixConfigScope (org.apache.helix.model.HelixConfigScope)33 HashMap (java.util.HashMap)12 HelixAdmin (org.apache.helix.HelixAdmin)10 Test (org.testng.annotations.Test)9 Date (java.util.Date)8 ConfigAccessor (org.apache.helix.ConfigAccessor)8 ZNRecord (org.apache.helix.ZNRecord)6 HelixException (org.apache.helix.HelixException)5 HelixManager (org.apache.helix.HelixManager)5 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)5 InstanceConfig (org.apache.helix.model.InstanceConfig)4 StateModelDefinition (org.apache.helix.model.StateModelDefinition)4 ClusterSetup (org.apache.helix.tools.ClusterSetup)4 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)3 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)3 ZkClient (org.apache.helix.manager.zk.ZkClient)3 ClusterConfig (org.apache.helix.model.ClusterConfig)3 IdealState (org.apache.helix.model.IdealState)3 File (java.io.File)2