Search in sources :

Example 6 with ParticipantHistory

use of org.apache.helix.model.ParticipantHistory in project helix by apache.

the class ClusterDataCache method updateOfflineInstanceHistory.

private void updateOfflineInstanceHistory(HelixDataAccessor accessor) {
    List<String> offlineNodes = new ArrayList<>(_instanceConfigMap.keySet());
    offlineNodes.removeAll(_liveInstanceMap.keySet());
    _instanceOfflineTimeMap = new HashMap<>();
    for (String instance : offlineNodes) {
        Builder keyBuilder = accessor.keyBuilder();
        PropertyKey propertyKey = keyBuilder.participantHistory(instance);
        ParticipantHistory history = accessor.getProperty(propertyKey);
        if (history == null) {
            history = new ParticipantHistory(instance);
        }
        if (history.getLastOfflineTime() == ParticipantHistory.ONLINE) {
            history.reportOffline();
            // persist history back to ZK.
            if (!accessor.setProperty(propertyKey, history)) {
                LOG.error("Fails to persist participant online history back to ZK!");
            }
        }
        _instanceOfflineTimeMap.put(instance, history.getLastOfflineTime());
    }
    _updateInstanceOfflineTime = false;
}
Also used : Builder(org.apache.helix.PropertyKey.Builder) ArrayList(java.util.ArrayList) PropertyKey(org.apache.helix.PropertyKey) ParticipantHistory(org.apache.helix.model.ParticipantHistory)

Example 7 with ParticipantHistory

use of org.apache.helix.model.ParticipantHistory in project helix by apache.

the class ParticipantManager method getHistory.

private ParticipantHistory getHistory() {
    PropertyKey propertyKey = _keyBuilder.participantHistory(_instanceName);
    ParticipantHistory history = _dataAccessor.getProperty(propertyKey);
    if (history == null) {
        history = new ParticipantHistory(_instanceName);
    }
    return history;
}
Also used : PropertyKey(org.apache.helix.PropertyKey) ParticipantHistory(org.apache.helix.model.ParticipantHistory)

Aggregations

ParticipantHistory (org.apache.helix.model.ParticipantHistory)7 PropertyKey (org.apache.helix.PropertyKey)3 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 ZkNodeExistsException (org.I0Itec.zkclient.exception.ZkNodeExistsException)1 HelixDataAccessor (org.apache.helix.HelixDataAccessor)1 HelixException (org.apache.helix.HelixException)1 HelixManager (org.apache.helix.HelixManager)1 Builder (org.apache.helix.PropertyKey.Builder)1 ZNRecord (org.apache.helix.ZNRecord)1 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)1 LiveInstance (org.apache.helix.model.LiveInstance)1 Stat (org.apache.zookeeper.data.Stat)1