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;
}
}
Aggregations