本文整理汇总了Java中org.apache.helix.model.LiveInstance.setSessionId方法的典型用法代码示例。如果您正苦于以下问题:Java LiveInstance.setSessionId方法的具体用法?Java LiveInstance.setSessionId怎么用?Java LiveInstance.setSessionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.model.LiveInstance
的用法示例。
在下文中一共展示了LiveInstance.setSessionId方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMapping
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
private Map<String, Map<String, String>> getMapping(final Map<String, List<String>> listResult) {
final Map<String, Map<String, String>> mapResult = new HashMap<String, Map<String, String>>();
ClusterDataCache cache = new ClusterDataCache();
MockAccessor accessor = new MockAccessor();
Builder keyBuilder = accessor.keyBuilder();
for (String node : _liveNodes) {
LiveInstance liveInstance = new LiveInstance(node);
liveInstance.setSessionId("testSession");
accessor.setProperty(keyBuilder.liveInstance(node), liveInstance);
}
cache.refresh(accessor);
IdealState is = new IdealState("resource");
for (String partition : _partitions) {
List<String> preferenceList = listResult.get(partition);
Map<String, String> currentStateMap = _currentMapping.get(partition);
Set<String> disabled = Collections.emptySet();
Map<String, String> assignment = new AutoRebalancer()
.computeBestPossibleStateForPartition(cache.getLiveInstances().keySet(), _stateModelDef, preferenceList,
currentStateMap, disabled, is);
mapResult.put(partition, assignment);
}
return mapResult;
}
示例2: 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;
}
示例3: setupLiveInstances
import org.apache.helix.model.LiveInstance; //导入方法依赖的package包/类
protected List<String> setupLiveInstances(int numLiveInstances) {
List<String> instances = new ArrayList<>();
for (int i = 0; i < numLiveInstances; i++) {
LiveInstance liveInstance = new LiveInstance(HOSTNAME_PREFIX + i);
liveInstance.setSessionId(SESSION_PREFIX + i);
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.liveInstance(HOSTNAME_PREFIX + i), liveInstance);
instances.add(liveInstance.getInstanceName());
}
return instances;
}
示例4: 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);
}
}
示例5: 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()));
}