/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package gobblin.cluster;
import org.apache.helix.manager.zk.ZKHelixManager;
import org.apache.helix.model.HelixConfigScope;
import org.apache.helix.tools.ClusterSetup;
import gobblin.annotation.Alpha;
/**
* A utility class for working with Gobblin on Helix.
*
* @author Yinan Li
*/
@Alpha
public class HelixUtils {
/**
* Create a Helix cluster for the Gobblin Cluster application.
*
* @param zkConnectionString the ZooKeeper connection string
* @param clusterName the Helix cluster name
*/
public static void createGobblinHelixCluster(String zkConnectionString, String clusterName) {
createGobblinHelixCluster(zkConnectionString, clusterName, true);
}
/**
* Create a Helix cluster for the Gobblin Cluster application.
*
* @param zkConnectionString the ZooKeeper connection string
* @param clusterName the Helix cluster name
* @param overwrite true to overwrite exiting cluster, false to reuse existing cluster
*/
public static void createGobblinHelixCluster(String zkConnectionString, String clusterName, boolean overwrite) {
ClusterSetup clusterSetup = new ClusterSetup(zkConnectionString);
// Create the cluster and overwrite if it already exists
clusterSetup.addCluster(clusterName, overwrite);
// Helix 0.6.x requires a configuration property to have the form key=value.
String autoJoinConfig = ZKHelixManager.ALLOW_PARTICIPANT_AUTO_JOIN + "=true";
clusterSetup.setConfig(HelixConfigScope.ConfigScopeProperty.CLUSTER, clusterName, autoJoinConfig);
}
/**
* Get a Helix instance name.
*
* @param namePrefix a prefix of Helix instance names
* @param instanceId an integer instance ID
* @return a Helix instance name that is a concatenation of the given prefix and instance ID
*/
public static String getHelixInstanceName(String namePrefix, int instanceId) {
return namePrefix + "_" + instanceId;
}
}