Search in sources :

Example 1 with HostConfigStorable

use of com.hortonworks.registries.schemaregistry.HostConfigStorable in project registry by hortonworks.

the class RefreshHAServerListTask method run.

@Override
public void run() {
    try {
        transactionManager.beginTransaction(TransactionIsolation.SERIALIZABLE);
        Collection<HostConfigStorable> hostConfigStorables = storageManager.<HostConfigStorable>list(HostConfigStorable.NAME_SPACE);
        List<HostConfigStorable> hostConfigWithoutStaleEntries = hostConfigStorables.stream().filter(hostConfigStorable -> {
            if ((System.currentTimeMillis() - hostConfigStorable.getTimestamp()) > 600000) {
                LOG.debug("Removing : {} from list of available servers", hostConfigStorable.getHostUrl());
                storageManager.remove(hostConfigStorable.getStorableKey());
                return false;
            } else {
                return true;
            }
        }).collect(Collectors.toList());
        LOG.debug("Fetched : {} as the latest available servers", Arrays.toString(hostConfigWithoutStaleEntries.toArray()));
        haServerNotificationManager.refreshServerInfo(hostConfigWithoutStaleEntries);
        HostConfigStorable hostConfWithUpdatedTimeStamp = storageManager.get(new HostConfigStorable(haServerNotificationManager.getHomeNodeURL()).getStorableKey());
        if (hostConfWithUpdatedTimeStamp == null) {
            hostConfWithUpdatedTimeStamp = new HostConfigStorable(storageManager.nextId(HostConfigStorable.NAME_SPACE), haServerNotificationManager.getHomeNodeURL(), System.currentTimeMillis());
        } else {
            hostConfWithUpdatedTimeStamp.setTimestamp(System.currentTimeMillis());
        }
        storageManager.addOrUpdate(hostConfWithUpdatedTimeStamp);
        transactionManager.commitTransaction();
    } catch (Exception e) {
        transactionManager.rollbackTransaction();
        throw e;
    }
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Logger(org.slf4j.Logger) TransactionManager(com.hortonworks.registries.storage.TransactionManager) Collection(java.util.Collection) HAServerNotificationManager(com.hortonworks.registries.schemaregistry.HAServerNotificationManager) HostConfigStorable(com.hortonworks.registries.schemaregistry.HostConfigStorable) LoggerFactory(org.slf4j.LoggerFactory) TransactionIsolation(com.hortonworks.registries.common.transaction.TransactionIsolation) TimerTask(java.util.TimerTask) StorageManager(com.hortonworks.registries.storage.StorageManager) Collectors(java.util.stream.Collectors) HostConfigStorable(com.hortonworks.registries.schemaregistry.HostConfigStorable)

Aggregations

TransactionIsolation (com.hortonworks.registries.common.transaction.TransactionIsolation)1 HAServerNotificationManager (com.hortonworks.registries.schemaregistry.HAServerNotificationManager)1 HostConfigStorable (com.hortonworks.registries.schemaregistry.HostConfigStorable)1 StorageManager (com.hortonworks.registries.storage.StorageManager)1 TransactionManager (com.hortonworks.registries.storage.TransactionManager)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 TimerTask (java.util.TimerTask)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1