use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class AbstractTestClass method beforeSuite.
@BeforeSuite
public void beforeSuite() throws Exception {
if (!_init) {
// TODO: use logging.properties file to config java.util.logging.Logger levels
java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
topJavaLogger.setLevel(Level.WARNING);
_gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
_gZkClientTestNS = new ZkClient(_zkAddrTestNS, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
_gSetupTool = new ClusterSetup(_gZkClient);
_configAccessor = new ConfigAccessor(_gZkClient);
_baseAccessor = new ZkBaseDataAccessor<>(_gZkClient);
_baseAccessorTestNS = new ZkBaseDataAccessor<>(_gZkClientTestNS);
// wait for the web service to start
Thread.sleep(100);
setup();
_init = true;
}
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestClusterSetup method beforeClass.
@BeforeClass()
public void beforeClass() throws IOException, Exception {
System.out.println("START TestClusterSetup.beforeClass() " + new Date(System.currentTimeMillis()));
_zkClient = new ZkClient(ZK_ADDR);
_zkClient.setZkSerializer(new ZNRecordSerializer());
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class TestZKClientPool method test.
@Test
public void test() throws Exception {
String testName = "TestZKClientPool";
System.out.println("START " + testName + " at " + new Date(System.currentTimeMillis()));
String zkAddr = "localhost:2189";
ZkServer zkServer = TestHelper.startZkServer(zkAddr);
ZkClient zkClient = ZKClientPool.getZkClient(zkAddr);
zkClient.createPersistent("/" + testName, new ZNRecord(testName));
ZNRecord record = zkClient.readData("/" + testName);
Assert.assertEquals(record.getId(), testName);
TestHelper.stopZkServer(zkServer);
// restart zk
zkServer = TestHelper.startZkServer(zkAddr);
try {
zkClient = ZKClientPool.getZkClient(zkAddr);
record = zkClient.readData("/" + testName);
Assert.fail("should fail on zk no node exception");
} catch (ZkNoNodeException e) {
// OK
} catch (Exception e) {
Assert.fail("should not fail on exception other than ZkNoNodeException");
}
zkClient.createPersistent("/" + testName, new ZNRecord(testName));
record = zkClient.readData("/" + testName);
Assert.assertEquals(record.getId(), testName);
zkClient.close();
TestHelper.stopZkServer(zkServer);
System.out.println("END " + testName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class ResourceAccessor method getResources.
@GET
public Response getResources(@PathParam("clusterId") String clusterId) {
ObjectNode root = JsonNodeFactory.instance.objectNode();
root.put(Properties.id.name(), JsonNodeFactory.instance.textNode(clusterId));
ZkClient zkClient = getZkClient();
ArrayNode idealStatesNode = root.putArray(ResourceProperties.idealStates.name());
ArrayNode externalViewsNode = root.putArray(ResourceProperties.externalViews.name());
List<String> idealStates = zkClient.getChildren(PropertyPathBuilder.idealState(clusterId));
List<String> externalViews = zkClient.getChildren(PropertyPathBuilder.externalView(clusterId));
if (idealStates != null) {
idealStatesNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(idealStates));
} else {
return notFound();
}
if (externalViews != null) {
externalViewsNode.addAll((ArrayNode) OBJECT_MAPPER.valueToTree(externalViews));
}
return JSONRepresentation(root);
}
use of org.apache.helix.manager.zk.ZkClient in project helix by apache.
the class HelixCustomCodeRunner method start.
/**
* This method will be invoked when there is a change in any subscribed
* notificationTypes
* @throws Exception
*/
public void start() throws Exception {
if (_callback == null || _notificationTypes == null || _notificationTypes.size() == 0 || _resourceName == null) {
throw new IllegalArgumentException("Require callback | notificationTypes | resourceName");
}
LOG.info("Register participantLeader on " + _notificationTypes + " using " + _resourceName);
_stateModelFty = new GenericLeaderStandbyStateModelFactory(_callback, _notificationTypes);
StateMachineEngine stateMach = _manager.getStateMachineEngine();
stateMach.registerStateModelFactory(LEADER_STANDBY, _stateModelFty, _resourceName);
ZkClient zkClient = null;
try {
// manually add ideal state for participant leader using LeaderStandby
// model
zkClient = new ZkClient(_zkAddr, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
HelixDataAccessor accessor = new ZKHelixDataAccessor(_manager.getClusterName(), new ZkBaseDataAccessor<ZNRecord>(zkClient));
Builder keyBuilder = accessor.keyBuilder();
IdealState idealState = new IdealState(_resourceName);
idealState.setRebalanceMode(RebalanceMode.SEMI_AUTO);
idealState.setReplicas(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString());
idealState.setNumPartitions(1);
idealState.setStateModelDefRef(LEADER_STANDBY);
idealState.setStateModelFactoryName(_resourceName);
List<String> prefList = new ArrayList<String>(Arrays.asList(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString()));
idealState.getRecord().setListField(_resourceName + "_0", prefList);
List<String> idealStates = accessor.getChildNames(keyBuilder.idealStates());
while (idealStates == null || !idealStates.contains(_resourceName)) {
accessor.setProperty(keyBuilder.idealStates(_resourceName), idealState);
idealStates = accessor.getChildNames(keyBuilder.idealStates());
}
LOG.info("Set idealState for participantLeader:" + _resourceName + ", idealState:" + idealState);
} finally {
if (zkClient != null && zkClient.getConnection() != null) {
zkClient.close();
}
}
}
Aggregations