use of org.apache.helix.PropertyKey in project helix by apache.
the class HelixTaskExecutor method updateMessageState.
private void updateMessageState(List<Message> readMsgs, HelixDataAccessor accessor, String instanceName) {
Builder keyBuilder = accessor.keyBuilder();
List<PropertyKey> readMsgKeys = new ArrayList<>();
for (Message msg : readMsgs) {
readMsgKeys.add(msg.getKey(keyBuilder, instanceName));
_knownMessageIds.add(msg.getId());
}
accessor.setChildren(readMsgKeys, readMsgs);
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class BatchMessageHandler method postHandleMessage.
public void postHandleMessage() {
if (_message.getBatchMessageMode() == true && _batchMsgWrapper != null) {
_batchMsgWrapper.end(_message, _notificationContext);
}
// update currentState
HelixManager manager = _notificationContext.getManager();
HelixDataAccessor accessor = manager.getHelixDataAccessor();
ConcurrentHashMap<String, CurrentStateUpdate> csUpdateMap = (ConcurrentHashMap<String, CurrentStateUpdate>) _notificationContext.get(MapKey.CURRENT_STATE_UPDATE.toString());
if (csUpdateMap != null) {
Map<PropertyKey, CurrentState> csUpdate = mergeCurStateUpdate(csUpdateMap);
// TODO: change to use asyncSet
for (PropertyKey key : csUpdate.keySet()) {
// curStateMap.get(key));
if (!accessor.updateProperty(key, csUpdate.get(key))) {
LOG.error("Fails to persist current state to ZK for key " + key);
}
}
}
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class TestSchemataSM method testSchemataSM.
@Test
public void testSchemataSM() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
int n = 5;
MockParticipantManager[] participants = new MockParticipantManager[n];
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant start port
TestHelper.setupCluster(// participant start port
clusterName, // participant start port
ZK_ADDR, // participant start port
12918, // participant name prefix
"localhost", // resource name prefix
"TestSchemata", // resources
1, // partitions per resource
1, // number of nodes
n, // replicas
0, "STORAGE_DEFAULT_SM_SCHEMATA", // don't rebalance
false);
// rebalance ideal-state to use ANY_LIVEINSTANCE for preference list
ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
PropertyKey key = keyBuilder.idealStates("TestSchemata0");
IdealState idealState = accessor.getProperty(key);
idealState.setReplicas(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString());
idealState.getRecord().setListField("TestSchemata0_0", Arrays.asList(IdealState.IdealStateConstants.ANY_LIVEINSTANCE.toString()));
accessor.setProperty(key, idealState);
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller");
controller.syncStart();
// start n-1 participants
for (int i = 1; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participants[i].syncStart();
}
boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// start the remaining 1 participant
participants[0] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
participants[0].syncStart();
// make sure we have all participants in MASTER state
result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
key = keyBuilder.externalView("TestSchemata0");
ExternalView externalView = accessor.getProperty(key);
Map<String, String> stateMap = externalView.getStateMap("TestSchemata0_0");
Assert.assertNotNull(stateMap);
Assert.assertEquals(stateMap.size(), n, "all " + n + " participants should be in Master state");
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
Assert.assertNotNull(stateMap.get(instanceName));
Assert.assertEquals(stateMap.get(instanceName), "MASTER");
}
// clean up
controller.syncStop();
for (int i = 0; i < n; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class TestResourceValidationStage method createISSpec.
private void createISSpec(HelixDataAccessor accessor, String specId, String stateModelDefRef, RebalanceMode rebalanceMode) {
PropertyKey propertyKey = accessor.keyBuilder().clusterConfig();
HelixProperty property = accessor.getProperty(propertyKey);
if (property == null) {
property = new HelixProperty("sampleClusterConfig");
}
String key = "IdealStateRule!" + specId;
String value = IdealStateProperty.REBALANCE_MODE.toString() + "=" + rebalanceMode.toString() + "," + IdealStateProperty.STATE_MODEL_DEF_REF.toString() + "=" + stateModelDefRef;
property.getRecord().setSimpleField(key, value);
accessor.setProperty(propertyKey, property);
}
use of org.apache.helix.PropertyKey in project helix by apache.
the class TaskTestUtil method pollForAllTasksBlock.
public static boolean pollForAllTasksBlock(HelixDataAccessor accessor, String instance, int numTask, long timeout) throws InterruptedException {
PropertyKey propertyKey = accessor.keyBuilder().messages(instance);
long startTime = System.currentTimeMillis();
while (true) {
List<Message> messages = accessor.getChildValues(propertyKey);
if (allTasksBlock(messages, numTask)) {
return true;
} else if (startTime + timeout < System.currentTimeMillis()) {
return false;
} else {
Thread.sleep(100);
}
}
}
Aggregations