use of com.yelp.nrtsearch.server.luceneserver.state.PersistentGlobalState in project nrtsearch by Yelp.
the class RemoteStateBackend method loadOrCreateGlobalState.
@Override
public PersistentGlobalState loadOrCreateGlobalState() throws IOException {
logger.info("Loading remote state");
Path downloadedPath = archiver.download(globalState.getConfiguration().getServiceName(), GLOBAL_STATE_RESOURCE);
if (downloadedPath == null) {
PersistentGlobalState state = new PersistentGlobalState();
logger.info("Remote state not present, initializing default");
commitGlobalState(state);
return state;
} else {
Path downloadedStateFilePath = downloadedPath.resolve(GLOBAL_STATE_FOLDER).resolve(GLOBAL_STATE_FILE);
if (!downloadedStateFilePath.toFile().exists()) {
throw new IllegalStateException("No state file present in downloaded directory");
}
// copy restored state to local state directory, not strictly required but ensures a
// current copy of the state is always in the local directory
Files.copy(downloadedStateFilePath, localFilePath.resolve(GLOBAL_STATE_FILE), StandardCopyOption.REPLACE_EXISTING);
PersistentGlobalState persistentGlobalState = StateUtils.readStateFromFile(downloadedStateFilePath);
logger.info("Loaded remote state: " + MAPPER.writeValueAsString(persistentGlobalState));
return persistentGlobalState;
}
}
Aggregations