本文整理汇总了Java中org.apache.helix.HelixManager.connect方法的典型用法代码示例。如果您正苦于以下问题:Java HelixManager.connect方法的具体用法?Java HelixManager.connect怎么用?Java HelixManager.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.HelixManager
的用法示例。
在下文中一共展示了HelixManager.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addFakeBrokerInstancesToAutoJoinHelixCluster
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static void addFakeBrokerInstancesToAutoJoinHelixCluster(String helixClusterName, String zkServer, int numInstances, boolean isSingleTenant) throws Exception {
for (int i = 0; i < numInstances; ++i) {
final String brokerId = "Broker_localhost_" + i;
final HelixManager helixZkManager =
HelixManagerFactory.getZKHelixManager(helixClusterName, brokerId, InstanceType.PARTICIPANT, zkServer);
final StateMachineEngine stateMachineEngine = helixZkManager.getStateMachineEngine();
final StateModelFactory<?> stateModelFactory = new EmptyBrokerOnlineOfflineStateModelFactory();
stateMachineEngine.registerStateModelFactory(EmptyBrokerOnlineOfflineStateModelFactory.getStateModelDef(),
stateModelFactory);
helixZkManager.connect();
if (isSingleTenant) {
helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, brokerId, ControllerTenantNameBuilder.getBrokerTenantNameForTenant(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
} else {
helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, brokerId, UNTAGGED_BROKER_INSTANCE);
}
Thread.sleep(1000);
}
}
示例2: addFakeDataInstancesToAutoJoinHelixCluster
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static void addFakeDataInstancesToAutoJoinHelixCluster(String helixClusterName, String zkServer, int numInstances, boolean isSingleTenant) 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);
}
}
}
示例3: start
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public HelixManager start() throws Exception {
HelixManager manager = null;
// zk cluster manager
if (_clusterMangerType.equalsIgnoreCase("zk")) {
manager =
HelixManagerFactory.getZKHelixManager(_clusterName, _instanceName,
InstanceType.PARTICIPANT, _zkConnectString);
} else {
throw new IllegalArgumentException("Unsupported cluster manager type:" + _clusterMangerType);
}
MockOnlineOfflineStateModelFactory stateModelFactory2 =
new MockOnlineOfflineStateModelFactory(_transDelayInMs, _resourceName, _resourceTag,
_instanceName);
// genericStateMachineHandler = new StateMachineEngine();
StateMachineEngine stateMach = manager.getStateMachineEngine();
stateMach.registerStateModelFactory("OnlineOffline", stateModelFactory2);
manager.connect();
//manager.getMessagingService().registerMessageHandlerFactory(MessageType.STATE_TRANSITION.name(), genericStateMachineHandler);
return manager;
}
示例4: testControllerLeaderHistory
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test()
public void testControllerLeaderHistory() throws Exception {
HelixManager manager = HelixManagerFactory
.getZKHelixManager(CLUSTER_NAME, "admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
manager.connect();
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(CLUSTER_NAME);
PropertyKey propertyKey = keyBuilder.controllerLeaderHistory();
LeaderHistory leaderHistory = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(leaderHistory);
List<String> list = leaderHistory.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 1);
for (int i = 0; i <= 12; i++) {
_controller.syncStop();
_controller = new ClusterControllerManager(ZK_ADDR, CLUSTER_NAME, "Controller-" + i);
_controller.syncStart();
}
leaderHistory = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(leaderHistory);
list = leaderHistory.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 10);
manager.disconnect();
}
示例5: TestSpectator
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void TestSpectator() throws Exception {
HelixManager relayHelixManager =
HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, null, InstanceType.SPECTATOR, ZK_ADDR);
relayHelixManager.connect();
relayHelixManager.addExternalViewChangeListener(this);
_setupTool.addResourceToCluster(CLUSTER_NAME, "NextDB", 64, STATE_MODEL);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, "NextDB", 3);
boolean result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
Assert.assertTrue(_externalViewChanges.containsKey("NextDB"));
Assert.assertTrue(_externalViewChanges.containsKey(TEST_DB));
}
示例6: testInstanceHistory
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test() public void testInstanceHistory() throws Exception {
HelixManager manager = HelixManagerFactory
.getZKHelixManager(CLUSTER_NAME, "admin", InstanceType.ADMINISTRATOR, ZK_ADDR);
manager.connect();
PropertyKey.Builder keyBuilder = new PropertyKey.Builder(CLUSTER_NAME);
PropertyKey propertyKey = keyBuilder.participantHistory(_participants[0].getInstanceName());
ParticipantHistory history = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(history);
List<String> list = history.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 1);
for (int i = 0; i <= 22; i++) {
_participants[0].disconnect();
_participants[0].connect();
}
history = manager.getHelixDataAccessor().getProperty(propertyKey);
Assert.assertNotNull(history);
list = history.getRecord().getListField("HISTORY");
Assert.assertEquals(list.size(), 20);
list = history.getRecord().getListField("OFFLINE");
Assert.assertEquals(list.size(), 20);
manager.disconnect();
}
示例7: main
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
CommandLine cmd = processCommandLineArgs(args);
String zkAddress = cmd.getOptionValue(zkAddr);
String clusterName = cmd.getOptionValue(cluster);
String instance = cmd.getOptionValue(instanceName);
String stateModelName = cmd.getOptionValue(stateModel);
HelixManager manager =
new ZKHelixManager(clusterName, instance, InstanceType.PARTICIPANT, zkAddress);
StateMachineEngine stateMach = manager.getStateMachineEngine();
stateMach.registerStateModelFactory(stateModelName, new AgentStateModelFactory());
Runtime.getRuntime().addShutdownHook(new HelixAgentShutdownHook(manager));
try {
manager.connect();
Thread.currentThread().join();
} catch (Exception e) {
LOG.error(e.toString());
} finally {
if (manager != null && manager.isConnected()) {
manager.disconnect();
}
}
}
示例8: register
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public boolean register(final String serviceId, final ServiceMetadata serviceMetadata)
throws Exception {
HelixManager helixManager =
HelixManagerFactory.getZKHelixManager(cluster, serviceId, InstanceType.PARTICIPANT,
zkAddress);
LiveInstanceInfoProvider liveInstanceInfoProvider = new LiveInstanceInfoProvider() {
@Override
public ZNRecord getAdditionalLiveInstanceInfo() {
// serialize serviceMetadata to ZNRecord
ZNRecord rec = new ZNRecord(serviceId);
rec.setSimpleField("HOST", serviceMetadata.getHost());
rec.setSimpleField("PORT", String.valueOf(serviceMetadata.getPort()));
rec.setSimpleField("SERVICE_NAME", serviceMetadata.getServiceName());
return rec;
}
};
helixManager.setLiveInstanceInfoProvider(liveInstanceInfoProvider);
helixManager.connect();
serviceMap.put(serviceId, helixManager);
refreshCache();
return true;
}
示例9: addFakeBrokerInstancesToAutoJoinHelixCluster
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static void addFakeBrokerInstancesToAutoJoinHelixCluster(String helixClusterName, String zkServer,
int numInstances, boolean isSingleTenant)
throws Exception {
for (int i = 0; i < numInstances; ++i) {
final String brokerId = "Broker_localhost_" + i;
final HelixManager helixZkManager =
HelixManagerFactory.getZKHelixManager(helixClusterName, brokerId, InstanceType.PARTICIPANT, zkServer);
final StateMachineEngine stateMachineEngine = helixZkManager.getStateMachineEngine();
final StateModelFactory<?> stateModelFactory = new EmptyBrokerOnlineOfflineStateModelFactory();
stateMachineEngine
.registerStateModelFactory(EmptyBrokerOnlineOfflineStateModelFactory.getStateModelDef(), stateModelFactory);
helixZkManager.connect();
if (isSingleTenant) {
helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, brokerId,
ControllerTenantNameBuilder.getBrokerTenantNameForTenant(ControllerTenantNameBuilder.DEFAULT_TENANT_NAME));
} else {
helixZkManager.getClusterManagmentTool().addInstanceTag(helixClusterName, brokerId, UNTAGGED_BROKER_INSTANCE);
}
}
}
示例10: start
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public void start() throws Exception {
MySQLAdmin mysqlAdmin = new MySQLAdmin(_instanceConfig);
Replicator replicator = new Replicator(_instanceConfig);
HelixManager helixManager =
HelixManagerFactory.getZKHelixManager(_clusterName, _instanceName,
InstanceType.PARTICIPANT, _zkAddress);
_context.setHelixManager(helixManager);
_context.setMysqlAdmin(mysqlAdmin);
_context.setReplicator(replicator);
MasterSlaveTransitionHandlerFactory factory = new MasterSlaveTransitionHandlerFactory(_context);
helixManager.getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
DatabaseTransitionHandlerFactory databaseTransitionHandlerFactory =
new DatabaseTransitionHandlerFactory(_context);
helixManager.getStateMachineEngine().registerStateModelFactory("OnlineOffline",
databaseTransitionHandlerFactory, "DatabaseTransitionHandlerFactory");
TableTransitionHandlerFactory tableTransitionHandlerFactory =
new TableTransitionHandlerFactory(_context);
helixManager.getStateMachineEngine().registerStateModelFactory("OnlineOffline",
tableTransitionHandlerFactory, "TableTransitionHandlerFactory");
helixManager.connect();
ReplicationManager observer = new ReplicationManager(_context);
helixManager.addExternalViewChangeListener(observer);
MasterSlaveRebalancer rebalancer = new MasterSlaveRebalancer(_context);
HelixCustomCodeRunner helixCustomCodeRunner =
new HelixCustomCodeRunner(helixManager, _zkAddress).invoke(rebalancer)
.on(ChangeType.CONFIG, ChangeType.LIVE_INSTANCE)
.usingLeaderStandbyModel("MasterSlave_rebalancer");
helixCustomCodeRunner.start();
monitor();
}
示例11: main
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static void main(String[] args) {
if (args.length < 3) {
System.err.println("USAGE: DummyParticipant zkAddress clusterName instanceName");
System.exit(1);
}
String zkAddr = args[0];
String clusterName = args[1];
String instanceName = args[2];
HelixManager manager = null;
try {
manager =
HelixManagerFactory.getZKHelixManager(clusterName, instanceName,
InstanceType.PARTICIPANT, zkAddr);
StateMachineEngine stateMach = manager.getStateMachineEngine();
DummyMSModelFactory msModelFactory = new DummyMSModelFactory();
stateMach.registerStateModelFactory("MasterSlave", msModelFactory);
manager.connect();
Thread.currentThread().join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (manager != null) {
manager.disconnect();
}
}
}
示例12: startHelixController
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static HelixManager startHelixController(final String zkConnectString,
final String clusterName, final String controllerName, final String controllerMode) {
HelixManager manager = null;
try {
if (controllerMode.equalsIgnoreCase(STANDALONE)) {
manager =
HelixManagerFactory.getZKHelixManager(clusterName, controllerName,
InstanceType.CONTROLLER, zkConnectString);
manager.connect();
} else if (controllerMode.equalsIgnoreCase(DISTRIBUTED)) {
manager =
HelixManagerFactory.getZKHelixManager(clusterName, controllerName,
InstanceType.CONTROLLER_PARTICIPANT, zkConnectString);
DistClusterControllerStateModelFactory stateModelFactory =
new DistClusterControllerStateModelFactory(zkConnectString);
StateMachineEngine stateMach = manager.getStateMachineEngine();
stateMach.registerStateModelFactory("LeaderStandby", stateModelFactory);
manager.connect();
} else {
logger.error("cluster controller mode:" + controllerMode + " NOT supported");
}
} catch (Exception e) {
logger.error("Exception while starting controller", e);
}
return manager;
}
示例13: testParticipant
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void testParticipant() throws Exception {
Map<String, Integer> stateReachedCounts = Maps.newHashMap();
HelixManager participant =
HelixManagerFactory.getZKHelixManager(_clusterName, "localhost_12918",
InstanceType.PARTICIPANT, ZK_ADDR);
participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline",
new MyStateModelFactory(stateReachedCounts));
participant.connect();
Thread.sleep(1000);
// Ensure that the external view coalesces
boolean result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
_clusterName));
Assert.assertTrue(result);
// Ensure that there was only one state transition
Assert.assertEquals(stateReachedCounts.size(), 1);
Assert.assertTrue(stateReachedCounts.containsKey("ONLINE"));
Assert.assertEquals(stateReachedCounts.get("ONLINE").intValue(), 1);
// Now let's stop the ZK server; this should do nothing
TestHelper.stopZkServer(_zkServer);
Thread.sleep(1000);
// Verify no change
Assert.assertEquals(stateReachedCounts.size(), 1);
Assert.assertTrue(stateReachedCounts.containsKey("ONLINE"));
Assert.assertEquals(stateReachedCounts.get("ONLINE").intValue(), 1);
}
示例14: testSpectator
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void testSpectator() throws Exception {
Map<String, Integer> stateReachedCounts = Maps.newHashMap();
HelixManager participant =
HelixManagerFactory.getZKHelixManager(_clusterName, "localhost_12918",
InstanceType.PARTICIPANT, ZK_ADDR);
participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline",
new MyStateModelFactory(stateReachedCounts));
participant.connect();
RoutingTableProvider routingTableProvider = new RoutingTableProvider();
HelixManager spectator =
HelixManagerFactory.getZKHelixManager(_clusterName, "spectator", InstanceType.SPECTATOR,
ZK_ADDR);
spectator.connect();
spectator.addConfigChangeListener(routingTableProvider);
spectator.addExternalViewChangeListener(routingTableProvider);
Thread.sleep(1000);
// Now let's stop the ZK server; this should do nothing
TestHelper.stopZkServer(_zkServer);
Thread.sleep(1000);
// Verify routing table still works
Assert.assertEquals(routingTableProvider.getInstances("resource0", "ONLINE").size(), 1);
Assert.assertEquals(routingTableProvider.getInstances("resource0", "OFFLINE").size(), 0);
}
示例15: test
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
HelixManager manager =
HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, null, InstanceType.SPECTATOR, ZK_ADDR);
manager.connect();
manager.addExternalViewChangeListener(this);
manager.addIdealStateChangeListener(this);
enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
// Start half number of nodes.
int i = 0;
for (; i < NUM_NODE / 2; i++) {
_participants.get(i).syncStart();
}
int replica = 3;
int partition = 30;
for (String stateModel : TestStateModels) {
String db = "Test-DB-" + stateModel;
createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, partition, replica, replica,
0);
}
Assert.assertTrue(_clusterVerifier.verify(50000));
_startListen = true;
DelayedTransition.setDelay(50);
// add the other half of nodes.
for (; i < NUM_NODE; i++) {
_participants.get(i).syncStart();
}
Assert.assertTrue(_clusterVerifier.verify(50000));
Assert.assertTrue(_testSuccess);
}