use of org.apache.helix.model.StatusUpdate in project helix by apache.
the class TestZKPathDataDumpTask method testCapacityReached.
@Test
public void testCapacityReached() throws Exception {
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()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
2, // number of nodes
n, // replicas
1, "MasterSlave", // do rebalance
true);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor();
HelixManager manager = mock(HelixManager.class);
when(manager.getHelixDataAccessor()).thenReturn(accessor);
when(manager.getClusterName()).thenReturn(clusterName);
// run dump task without statusUpdates and errors, should not remove any existing
// statusUpdate/error paths
ZKPathDataDumpTask task = new ZKPathDataDumpTask(manager, Long.MAX_VALUE, Long.MAX_VALUE, 1);
task.run();
PropertyKey controllerStatusUpdateKey = keyBuilder.controllerTaskStatuses();
Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
PropertyKey controllerErrorKey = keyBuilder.controllerTaskErrors();
Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
PropertyKey statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918");
Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
PropertyKey errorKey = keyBuilder.stateTransitionErrors("localhost_12918");
Assert.assertTrue(baseAccessor.exists(errorKey.getPath(), 0));
// add participant status updates and errors
statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
accessor.setProperty(statusUpdateKey, new StatusUpdate(new ZNRecord("statusUpdate")));
errorKey = keyBuilder.stateTransitionError("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
accessor.setProperty(errorKey, new Error(new ZNRecord("error")));
// add controller status updates and errors (one of each, should not trigger anything)
controllerStatusUpdateKey = keyBuilder.controllerTaskStatus("session_0", "TestDB");
accessor.setProperty(controllerStatusUpdateKey, new StatusUpdate(new ZNRecord("controllerStatusUpdate")));
controllerErrorKey = keyBuilder.controllerTaskError("TestDB_error");
accessor.setProperty(controllerErrorKey, new Error(new ZNRecord("controllerError")));
// run dump task, should not remove anything because the threshold is not exceeded
task.run();
Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
Assert.assertTrue(baseAccessor.exists(errorKey.getPath(), 0));
// add a second set of all status updates and errors
statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918", "session_0", "TestDB0", "TestDB0_1");
accessor.setProperty(statusUpdateKey, new StatusUpdate(new ZNRecord("statusUpdate")));
errorKey = keyBuilder.stateTransitionError("localhost_12918", "session_0", "TestDB0", "TestDB0_1");
accessor.setProperty(errorKey, new Error(new ZNRecord("error")));
controllerStatusUpdateKey = keyBuilder.controllerTaskStatus("session_0", "TestDB1");
accessor.setProperty(controllerStatusUpdateKey, new StatusUpdate(new ZNRecord("controllerStatusUpdate")));
controllerErrorKey = keyBuilder.controllerTaskError("TestDB1_error");
accessor.setProperty(controllerErrorKey, new Error(new ZNRecord("controllerError")));
// run dump task, should remove everything since capacities are exceeded
task.run();
Assert.assertFalse(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
Assert.assertFalse(baseAccessor.exists(controllerErrorKey.getPath(), 0));
Assert.assertFalse(baseAccessor.exists(statusUpdateKey.getPath(), 0));
Assert.assertFalse(baseAccessor.exists(errorKey.getPath(), 0));
}
use of org.apache.helix.model.StatusUpdate in project helix by apache.
the class StatusUpdateUtil method publishStatusUpdateRecord.
/**
* Write a status update record to zookeeper to the zookeeper store.
* @param record
* the status update record
* @param message
* the message to be logged
* @param level
* the error level of the message update
* @param accessor
* the zookeeper data accessor that writes the status update to zookeeper
* @param isController
* if the update is for a controller instance or not
*/
void publishStatusUpdateRecord(ZNRecord record, Message message, Level level, HelixDataAccessor accessor, boolean isController) {
String instanceName = message.getTgtName();
String statusUpdateSubPath = getStatusUpdateSubPath(message);
String statusUpdateKey = getStatusUpdateKey(message);
String sessionId = message.getExecutionSessionId();
if (sessionId == null) {
sessionId = message.getTgtSessionId();
}
if (sessionId == null) {
sessionId = "*";
}
Builder keyBuilder = accessor.keyBuilder();
if (!_recordedMessages.containsKey(message.getMsgId())) {
if (isController) {
accessor.updateProperty(keyBuilder.controllerTaskStatus(statusUpdateSubPath, statusUpdateKey), new StatusUpdate(createMessageLogRecord(message)));
} else {
PropertyKey propertyKey = keyBuilder.stateTransitionStatus(instanceName, sessionId, statusUpdateSubPath, statusUpdateKey);
ZNRecord statusUpdateRecord = createMessageLogRecord(message);
// we are using restlet as another data channel to report to controller.
if (_logger.isTraceEnabled()) {
_logger.trace("StatusUpdate path:" + propertyKey.getPath() + ", updates:" + statusUpdateRecord);
}
accessor.updateProperty(propertyKey, new StatusUpdate(statusUpdateRecord));
}
_recordedMessages.put(message.getMsgId(), message.getMsgId());
}
if (isController) {
accessor.updateProperty(keyBuilder.controllerTaskStatus(statusUpdateSubPath, statusUpdateKey), new StatusUpdate(record));
} else {
PropertyKey propertyKey = keyBuilder.stateTransitionStatus(instanceName, sessionId, statusUpdateSubPath, statusUpdateKey);
// we are using restlet as another data channel to report to controller.
if (_logger.isTraceEnabled()) {
_logger.trace("StatusUpdate path:" + propertyKey.getPath() + ", updates:" + record);
}
accessor.updateProperty(propertyKey, new StatusUpdate(record));
}
// If the error level is ERROR, also write the record to "ERROR" ZNode
if (Level.HELIX_ERROR == level) {
publishErrorRecord(record, instanceName, statusUpdateSubPath, statusUpdateKey, sessionId, accessor, isController);
}
}
use of org.apache.helix.model.StatusUpdate in project helix by apache.
the class TestSchedulerMessage method testSchedulerZeroMsg.
@Test
public void testSchedulerZeroMsg() throws Exception {
_factory._results.clear();
HelixManager manager = null;
for (int i = 0; i < NODE_NR; i++) {
_participants[i].getMessagingService().registerMessageHandlerFactory(_factory.getMessageTypes(), _factory);
// _startCMResultMap.get(hostDest)._manager;
manager = _participants[i];
}
Message schedulerMessage = new Message(MessageType.SCHEDULER_MSG + "", UUID.randomUUID().toString());
schedulerMessage.setTgtSessionId("*");
schedulerMessage.setTgtName("CONTROLLER");
// TODO: change it to "ADMIN" ?
schedulerMessage.setSrcName("CONTROLLER");
// Template for the individual message sent to each participant
Message msg = new Message(_factory.getMessageTypes().get(0), "Template");
msg.setTgtSessionId("*");
msg.setMsgState(MessageState.NEW);
// Criteria to send individual messages
Criteria cr = new Criteria();
cr.setInstanceName("localhost_DOESNOTEXIST");
cr.setRecipientInstanceType(InstanceType.PARTICIPANT);
cr.setSessionSpecific(false);
cr.setResource("%");
cr.setPartition("%");
ObjectMapper mapper = new ObjectMapper();
SerializationConfig serializationConfig = mapper.getSerializationConfig();
serializationConfig.set(SerializationConfig.Feature.INDENT_OUTPUT, true);
StringWriter sw = new StringWriter();
mapper.writeValue(sw, cr);
String crString = sw.toString();
schedulerMessage.getRecord().setSimpleField("Criteria", crString);
schedulerMessage.getRecord().setMapField("MessageTemplate", msg.getRecord().getSimpleFields());
schedulerMessage.getRecord().setSimpleField("TIMEOUT", "-1");
HelixDataAccessor helixDataAccessor = manager.getHelixDataAccessor();
Builder keyBuilder = helixDataAccessor.keyBuilder();
PropertyKey controllerMessageKey = keyBuilder.controllerMessage(schedulerMessage.getMsgId());
helixDataAccessor.setProperty(controllerMessageKey, schedulerMessage);
Thread.sleep(3000);
Assert.assertEquals(0, _factory._results.size());
PropertyKey controllerTaskStatus = keyBuilder.controllerTaskStatus(MessageType.SCHEDULER_MSG.name(), schedulerMessage.getMsgId());
for (int i = 0; i < 10; i++) {
StatusUpdate update = helixDataAccessor.getProperty(controllerTaskStatus);
if (update == null || update.getRecord().getMapField("SentMessageCount") == null) {
Thread.sleep(1000);
}
}
ZNRecord statusUpdate = helixDataAccessor.getProperty(controllerTaskStatus).getRecord();
Assert.assertTrue(statusUpdate.getMapField("SentMessageCount").get("MessageCount").equals("0"));
int count = 0;
for (Set<String> val : _factory._results.values()) {
count += val.size();
}
Assert.assertEquals(count, 0);
}
use of org.apache.helix.model.StatusUpdate in project helix by apache.
the class TestZKPathDataDumpTask method test.
@Test
public void test() throws Exception {
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()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
2, // number of nodes
n, // replicas
1, "MasterSlave", // do rebalance
true);
HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
PropertyKey.Builder keyBuilder = accessor.keyBuilder();
BaseDataAccessor<ZNRecord> baseAccessor = accessor.getBaseDataAccessor();
HelixManager manager = mock(HelixManager.class);
when(manager.getHelixDataAccessor()).thenReturn(accessor);
when(manager.getClusterName()).thenReturn(clusterName);
// run dump task without statusUpdates and errors, should not remove any existing
// statusUpdate/error paths
ZKPathDataDumpTask task = new ZKPathDataDumpTask(manager, 0L, 0L, Integer.MAX_VALUE);
task.run();
PropertyKey controllerStatusUpdateKey = keyBuilder.controllerTaskStatuses();
Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
PropertyKey controllerErrorKey = keyBuilder.controllerTaskErrors();
Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
PropertyKey statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918");
Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
PropertyKey errorKey = keyBuilder.stateTransitionErrors("localhost_12918");
// add participant status updates and errors
statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
accessor.setProperty(statusUpdateKey, new StatusUpdate(new ZNRecord("statusUpdate")));
errorKey = keyBuilder.stateTransitionError("localhost_12918", "session_0", "TestDB0", "TestDB0_0");
accessor.setProperty(errorKey, new Error(new ZNRecord("error")));
// add controller status updates and errors
controllerStatusUpdateKey = keyBuilder.controllerTaskStatus("session_0", "TestDB");
accessor.setProperty(controllerStatusUpdateKey, new StatusUpdate(new ZNRecord("controllerStatusUpdate")));
controllerErrorKey = keyBuilder.controllerTaskError("TestDB_error");
accessor.setProperty(controllerErrorKey, new Error(new ZNRecord("controllerError")));
// run dump task, should remove existing statusUpdate/error paths
task.run();
Assert.assertFalse(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
Assert.assertFalse(baseAccessor.exists(controllerErrorKey.getPath(), 0));
Assert.assertFalse(baseAccessor.exists(statusUpdateKey.getPath(), 0));
Assert.assertFalse(baseAccessor.exists(errorKey.getPath(), 0));
controllerStatusUpdateKey = keyBuilder.controllerTaskStatuses();
Assert.assertTrue(baseAccessor.exists(controllerStatusUpdateKey.getPath(), 0));
controllerErrorKey = keyBuilder.controllerTaskErrors();
Assert.assertTrue(baseAccessor.exists(controllerErrorKey.getPath(), 0));
statusUpdateKey = keyBuilder.stateTransitionStatus("localhost_12918");
Assert.assertTrue(baseAccessor.exists(statusUpdateKey.getPath(), 0));
errorKey = keyBuilder.stateTransitionErrors("localhost_12918");
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations