本文整理汇总了Java中org.apache.helix.model.LiveInstance.setHelixVersion方法的典型用法代码示例。如果您正苦于以下问题:Java LiveInstance.setHelixVersion方法的具体用法?Java LiveInstance.setHelixVersion怎么用?Java LiveInstance.setHelixVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.LiveInstance
的用法示例。
在下文中一共展示了LiveInstance.setHelixVersion方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryUpdateController
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
private boolean tryUpdateController(HelixManager manager) {
HelixDataAccessor accessor = manager.getHelixDataAccessor();
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = new LiveInstance(manager.getInstanceName());
try {
leader.setLiveInstance(ManagementFactory.getRuntimeMXBean().getName());
leader.setSessionId(manager.getSessionId());
leader.setHelixVersion(manager.getVersion());
boolean success = accessor.createControllerLeader(leader);
if (success) {
return true;
} else {
LOG.info("Unable to become leader probably because some other controller becames the leader");
}
} catch (Exception e) {
LOG.error(
"Exception when trying to updating leader record in cluster:" + manager.getClusterName()
+ ". Need to check again whether leader node has been created or not", e);
}
leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader != null) {
String leaderSessionId = leader.getSessionId();
LOG.info("Leader exists for cluster: " + manager.getClusterName() + ", currentLeader: "
+ leader.getInstanceName() + ", leaderSessionId: " + leaderSessionId);
if (leaderSessionId != null && leaderSessionId.equals(manager.getSessionId())) {
return true;
}
}
return false;
}
示例2: setupLiveInstances
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
protected void setupLiveInstances(String clusterName, int[] liveInstances) {
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
for (int i = 0; i < liveInstances.length; i++) {
String instance = "localhost_" + liveInstances[i];
LiveInstance liveInstance = new LiveInstance(instance);
liveInstance.setSessionId("session_" + liveInstances[i]);
liveInstance.setHelixVersion("0.0.0");
accessor.setProperty(keyBuilder.liveInstance(instance), liveInstance);
}
}
示例3: testParticipantIncompatibleWithBatchMsg
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
@Test
public void testParticipantIncompatibleWithBatchMsg() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 2;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
"localhost", // participant name prefix
"TestDB", // resource name prefix
1, // resources
32, // partitions per resource
n, // number of nodes
2, // replicas
"MasterSlave", true); // do rebalance
// enable batch message
// --addResourceProperty <clusterName resourceName propertyName propertyValue>
ClusterSetup.processCommandLineArgs(new String[] {
"--zkSvr", ZK_ADDR, "--addResourceProperty", clusterName, "TestDB0",
HelixPropertyAttribute.BATCH_MESSAGE_MODE.toString(), "true"
});
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
// register a message listener so we know how many message generated
TestZkChildListener listener = new TestZkChildListener();
_gZkClient.subscribeChildChanges(keyBuilder.messages("localhost_12918").getPath(), listener);
ClusterControllerManager controller =
new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// pause controller
// --enableCluster <clusterName true/false>
ClusterSetup.processCommandLineArgs(new String[] {
"--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "false"
});
// start participants
MockParticipantManager[] participants = new MockParticipantManager[n];
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
// change localhost_12918 version to 0.5, so batch-message-mode will be ignored
LiveInstance liveInstance = accessor.getProperty(keyBuilder.liveInstance("localhost_12918"));
liveInstance.setHelixVersion("0.5");
accessor.setProperty(keyBuilder.liveInstance("localhost_12918"), liveInstance);
// resume controller
// --enableCluster <clusterName true/false>
ClusterSetup.processCommandLineArgs(new String[] {
"--zkSvr", ZK_ADDR, "--enableCluster", clusterName, "true"
});
boolean result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName));
Assert.assertTrue(result);
Assert.assertTrue(listener._maxNbOfChilds > 16,
"Should see more than 16 messages at the same time (32 O->S and 32 S->M)");
// clean up
// wait for all zk callbacks done
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
示例4: testCustomCodeRunner
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
@Test
public void testCustomCodeRunner() throws Exception {
System.out.println("START " + _clusterName + " at " + new Date(System.currentTimeMillis()));
TestHelper.setupCluster(_clusterName, ZK_ADDR, _startPort, "localhost", // participant name
// prefix
"TestDB", // resource name prefix
1, // resourceNb
5, // partitionNb
_nodeNb, // nodesNb
_nodeNb, // replica
"MasterSlave", true);
ClusterControllerManager controller =
new ClusterControllerManager(ZK_ADDR, _clusterName, "controller_0");
controller.syncStart();
MockParticipantManager[] participants = new MockParticipantManager[5];
for (int i = 0; i < _nodeNb; i++) {
String instanceName = "localhost_" + (_startPort + i);
participants[i] = new MockParticipantManager(ZK_ADDR, _clusterName, instanceName);
registerCustomCodeRunner(participants[i]);
participants[i].syncStart();
}
boolean result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, _clusterName));
Assert.assertTrue(result);
Thread.sleep(1000); // wait for the INIT type callback to finish
Assert.assertTrue(_callback._isCallbackInvoked);
_callback._isCallbackInvoked = false;
// add a new live instance
HelixDataAccessor accessor =
new ZKHelixDataAccessor(_clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = accessor.keyBuilder();
LiveInstance newLiveIns = new LiveInstance("newLiveInstance");
newLiveIns.setHelixVersion("0.6.0");
newLiveIns.setSessionId("randomSessionId");
accessor.setProperty(keyBuilder.liveInstance("newLiveInstance"), newLiveIns);
Thread.sleep(1000); // wait for the CALLBACK type callback to finish
Assert.assertTrue(_callback._isCallbackInvoked);
// clean up
controller.syncStop();
for (int i = 0; i < _nodeNb; i++) {
participants[i].syncStop();
}
System.out.println("END " + _clusterName + " at " + new Date(System.currentTimeMillis()));
}