本文整理汇总了Java中org.apache.helix.HelixManager.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Java HelixManager.disconnect方法的具体用法?Java HelixManager.disconnect怎么用?Java HelixManager.disconnect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.HelixManager
的用法示例。
在下文中一共展示了HelixManager.disconnect方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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();
}
}
}
示例4: 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();
}
}
}
示例5: main
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// read the config;
// check if the this process is the master wait indefinitely
// other approach is always process the events but when updating the zk
// check if this is master.
// This is difficult to get right
// get the clusters to manage
// for each cluster create a manager
// add the respective listeners for each manager
CommandLine cmd = processCommandLineArgs(args);
String zkConnectString = cmd.getOptionValue(zkServerAddress);
String clusterName = cmd.getOptionValue(cluster);
String controllerMode = STANDALONE;
String controllerName = null;
if (cmd.hasOption(mode)) {
controllerMode = cmd.getOptionValue(mode);
}
if (controllerMode.equalsIgnoreCase(DISTRIBUTED) && !cmd.hasOption(name)) {
throw new IllegalArgumentException(
"A unique cluster controller name is required in DISTRIBUTED mode");
}
controllerName = cmd.getOptionValue(name);
// Espresso_driver.py will consume this
logger.info("Cluster manager started, zkServer: " + zkConnectString + ", clusterName:"
+ clusterName + ", controllerName:" + controllerName + ", mode:" + controllerMode);
HelixManager manager =
startHelixController(zkConnectString, clusterName, controllerName, controllerMode);
Runtime.getRuntime().addShutdownHook(new HelixManagerShutdownHook(manager));
try {
Thread.currentThread().join();
} catch (InterruptedException e) {
logger.info("controller:" + controllerName + ", " + Thread.currentThread().getName()
+ " interrupted");
} finally {
manager.disconnect();
}
}
示例6: main
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
/**
* Parses the first argument as a driver command and the rest of the
* arguments are parsed based on that command. Constructs a Helix
* message and posts it to the controller
*/
public static void main(String[] args) throws Exception {
String[] cmdArgs = Arrays.copyOfRange(args, 1, args.length);
CommandLine cl = parseOptions(cmdArgs, constructOptions(), args[0]);
String zkAddr = cl.getOptionValue(ZK_ADDRESS);
String clusterName = cl.getOptionValue(CLUSTER_NAME_OPTION);
String workflow = cl.getOptionValue(RESOURCE_OPTION);
if (zkAddr == null || clusterName == null || workflow == null) {
printUsage(constructOptions(), "[cmd]");
throw new IllegalArgumentException(
"zk, cluster, and resource must all be non-null for all commands");
}
HelixManager helixMgr =
HelixManagerFactory.getZKHelixManager(clusterName, "Admin", InstanceType.ADMINISTRATOR,
zkAddr);
helixMgr.connect();
TaskDriver driver = new TaskDriver(helixMgr);
try {
TaskDriver.DriverCommand cmd = TaskDriver.DriverCommand.valueOf(args[0]);
switch (cmd) {
case start:
if (cl.hasOption(WORKFLOW_FILE_OPTION)) {
driver.start(Workflow.parse(new File(cl.getOptionValue(WORKFLOW_FILE_OPTION))));
} else {
throw new IllegalArgumentException("Workflow file is required to start flow.");
}
break;
case stop:
driver.stop(workflow);
break;
case resume:
driver.resume(workflow);
break;
case delete:
driver.delete(workflow);
break;
case list:
list(driver, workflow);
break;
case flush:
driver.flushQueue(workflow);
break;
case clean:
driver.cleanupQueue(workflow);
break;
default:
throw new IllegalArgumentException("Unknown command " + args[0]);
}
} catch (IllegalArgumentException e) {
LOG.error("Unknown driver command " + args[0]);
throw e;
}
helixMgr.disconnect();
}
示例7: simpleIntegrationTest
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void simpleIntegrationTest() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 1;
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
4, // partitions per resource
n, // number of nodes
1, // replicas
"MasterSlave", true); // do rebalance
HelixManager participant =
new ZKHelixManager(clusterName, "localhost_12918", InstanceType.PARTICIPANT, ZK_ADDR);
participant.getStateMachineEngine().registerStateModelFactory("MasterSlave",
new MockMSModelFactory());
participant.connect();
HelixManager controller =
new ZKHelixManager(clusterName, "controller_0", InstanceType.CONTROLLER, ZK_ADDR);
controller.connect();
boolean result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
clusterName));
Assert.assertTrue(result);
// cleanup
controller.disconnect();
participant.disconnect();
// verify all live-instances and leader nodes are gone
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12918")));
Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader()));
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
示例8: testDataChange
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void testDataChange() throws Exception {
// Create an admin and add LiveInstanceChange listener to it
HelixManager adminManager =
HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR,
ZK_ADDR);
adminManager.connect();
final BlockingQueue<List<LiveInstance>> changeList =
new LinkedBlockingQueue<List<LiveInstance>>();
adminManager.addLiveInstanceChangeListener(new LiveInstanceChangeListener() {
@Override
public void onLiveInstanceChange(List<LiveInstance> liveInstances,
NotificationContext changeContext) {
// The queue is basically unbounded, so shouldn't throw exception when calling
// "add".
changeList.add(deepCopy(liveInstances));
}
});
// Check the initial condition
List<LiveInstance> instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertTrue(instances.isEmpty(), "Expecting an empty list of live instance");
// Join as participant, should trigger a live instance change event
HelixManager manager =
HelixManagerFactory.getZKHelixManager(clusterName, "localhost_54321",
InstanceType.PARTICIPANT, ZK_ADDR);
manager.connect();
instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertEquals(instances.size(), 1, "Expecting one live instance");
Assert.assertEquals(instances.get(0).getInstanceName(), manager.getInstanceName());
// Update data in the live instance node, should trigger another live instance change
// event
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
PropertyKey propertyKey =
helixDataAccessor.keyBuilder().liveInstance(manager.getInstanceName());
LiveInstance instance = helixDataAccessor.getProperty(propertyKey);
Map<String, String> map = new TreeMap<String, String>();
map.put("k1", "v1");
instance.getRecord().setMapField("test", map);
Assert.assertTrue(helixDataAccessor.updateProperty(propertyKey, instance),
"Failed to update live instance node");
instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertEquals(instances.get(0).getRecord().getMapField("test"), map, "Wrong map data.");
manager.disconnect();
Thread.sleep(1000); // wait for callback finish
instances = changeList.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull(instances, "Expecting a list of live instance");
Assert.assertTrue(instances.isEmpty(), "Expecting an empty list of live instance");
adminManager.disconnect();
}
示例9: deregister
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public void deregister(final String serviceId) {
HelixManager helixManager = serviceMap.get(serviceId);
if (helixManager != null && helixManager.isConnected()) {
helixManager.disconnect();
}
}
示例10: main
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
/**
* LockManagerDemo clusterName, numInstances, lockGroupName, numLocks
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
final String zkAddress = "localhost:2199";
final String clusterName = "lock-manager-demo";
final String lockGroupName = "lock-group";
final int numInstances = 3;
final int numPartitions = 12;
final boolean startController = false;
HelixManager controllerManager = null;
Thread[] processArray;
processArray = new Thread[numInstances];
try {
startLocalZookeeper(2199);
HelixAdmin admin = new ZKHelixAdmin(zkAddress);
admin.addCluster(clusterName, true);
StateModelConfigGenerator generator = new StateModelConfigGenerator();
admin.addStateModelDef(clusterName, "OnlineOffline",
new StateModelDefinition(generator.generateConfigForOnlineOffline()));
admin.addResource(clusterName, lockGroupName, numPartitions, "OnlineOffline",
RebalanceMode.FULL_AUTO.toString());
admin.rebalance(clusterName, lockGroupName, 1);
for (int i = 0; i < numInstances; i++) {
final String instanceName = "localhost_" + (12000 + i);
processArray[i] = new Thread(new Runnable() {
@Override
public void run() {
LockProcess lockProcess = null;
try {
lockProcess = new LockProcess(clusterName, zkAddress, instanceName, startController);
lockProcess.start();
Thread.currentThread().join();
} catch (InterruptedException e) {
System.out.println(instanceName + "Interrupted");
if (lockProcess != null) {
lockProcess.stop();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
processArray[i].start();
}
Thread.sleep(3000);
controllerManager =
HelixControllerMain.startHelixController(zkAddress, clusterName, "controller",
HelixControllerMain.STANDALONE);
Thread.sleep(5000);
printStatus(admin, clusterName, lockGroupName);
System.out.println("Stopping localhost_12000");
processArray[0].interrupt();
Thread.sleep(3000);
printStatus(admin, clusterName, lockGroupName);
Thread.currentThread().join();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (controllerManager != null) {
controllerManager.disconnect();
}
for (Thread process : processArray) {
if (process != null) {
process.interrupt();
}
}
}
}
示例11: post
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Override
public Representation post(Representation entity) {
try {
String clusterName = (String) getRequest().getAttributes().get("clusterName");
Form form = new Form(entity);
// Get the workflow and submit it
if (form.size() < 1) {
throw new HelixException("yaml workflow is required!");
}
Parameter payload = form.get(0);
String yamlPayload = payload.getName();
if (yamlPayload == null) {
throw new HelixException("yaml workflow is required!");
}
String zkAddr =
(String) getContext().getAttributes().get(RestAdminApplication.ZKSERVERADDRESS);
HelixManager manager =
HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.ADMINISTRATOR,
zkAddr);
manager.connect();
try {
Workflow workflow = Workflow.parse(yamlPayload);
TaskDriver driver = new TaskDriver(manager);
driver.start(workflow);
} finally {
manager.disconnect();
}
getResponse().setEntity(getHostedEntitiesRepresentation(clusterName));
getResponse().setStatus(Status.SUCCESS_OK);
}
catch (Exception e) {
getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e),
MediaType.APPLICATION_JSON);
getResponse().setStatus(Status.SUCCESS_OK);
LOG.error("Error in posting " + entity, e);
}
return null;
}