use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class IndexUpdater method run.
@Override
public void run() {
if (dataService == null) {
throw new FessSystemException("DataService is null.");
}
if (logger.isDebugEnabled()) {
logger.debug("Starting indexUpdater.");
}
executeTime = 0;
documentSize = 0;
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final long updateInterval = fessConfig.getIndexerWebfsUpdateIntervalAsInteger().longValue();
final int maxEmptyListCount = fessConfig.getIndexerWebfsMaxEmptyListCountAsInteger();
final IntervalControlHelper intervalControlHelper = ComponentUtil.getIntervalControlHelper();
try {
final Consumer<SearchRequestBuilder> cb = builder -> {
final QueryBuilder queryBuilder = QueryBuilders.boolQuery().filter(QueryBuilders.termsQuery(EsAccessResult.SESSION_ID, sessionIdList)).filter(QueryBuilders.termQuery(EsAccessResult.STATUS, org.codelibs.fess.crawler.Constants.OK_STATUS));
builder.setQuery(queryBuilder);
builder.setFrom(0);
final int maxDocumentCacheSize = fessConfig.getIndexerWebfsMaxDocumentCacheSizeAsInteger();
builder.setSize(maxDocumentCacheSize <= 0 ? 1 : maxDocumentCacheSize);
builder.addSort(EsAccessResult.CREATE_TIME, SortOrder.ASC);
};
final DocList docList = new DocList();
final List<EsAccessResult> accessResultList = new ArrayList<>();
long updateTime = System.currentTimeMillis();
int errorCount = 0;
int emptyListCount = 0;
long cleanupTime = -1;
while (!finishCrawling || !accessResultList.isEmpty()) {
try {
final int sessionIdListSize = finishedSessionIdList.size();
intervalControlHelper.setCrawlerRunning(true);
updateTime = System.currentTimeMillis() - updateTime;
final long interval = updateInterval - updateTime;
if (interval > 0) {
// sleep
// 10 sec (default)
ThreadUtil.sleep(interval);
}
systemHelper.calibrateCpuLoad();
docList.clear();
accessResultList.clear();
intervalControlHelper.delayByRules();
if (logger.isDebugEnabled()) {
logger.debug("Processing documents in IndexUpdater queue.");
}
updateTime = System.currentTimeMillis();
List<EsAccessResult> arList = getAccessResultList(cb, cleanupTime);
if (arList.isEmpty()) {
emptyListCount++;
} else {
// reset
emptyListCount = 0;
}
long hitCount = ((EsResultList<EsAccessResult>) arList).getTotalHits();
while (hitCount > 0) {
if (arList.isEmpty()) {
ThreadUtil.sleep(fessConfig.getIndexerWebfsCommitMarginTimeAsInteger().longValue());
cleanupTime = -1;
} else {
processAccessResults(docList, accessResultList, arList);
cleanupTime = cleanupAccessResults(accessResultList);
}
arList = getAccessResultList(cb, cleanupTime);
hitCount = ((EsResultList<EsAccessResult>) arList).getTotalHits();
}
if (!docList.isEmpty()) {
indexingHelper.sendDocuments(searchEngineClient, docList);
}
synchronized (finishedSessionIdList) {
if (sessionIdListSize != 0 && sessionIdListSize == finishedSessionIdList.size()) {
cleanupFinishedSessionData();
}
}
executeTime += System.currentTimeMillis() - updateTime;
if (logger.isDebugEnabled()) {
logger.debug("Processed documents in IndexUpdater queue.");
}
// reset count
errorCount = 0;
} catch (final Exception e) {
if (errorCount > maxErrorCount) {
throw e;
}
errorCount++;
logger.warn("Failed to access data. Retry to access it {} times.", errorCount, e);
} finally {
if (systemHelper.isForceStop()) {
finishCrawling = true;
if (logger.isDebugEnabled()) {
logger.debug("Stopped indexUpdater.");
}
}
}
if (emptyListCount >= maxEmptyListCount) {
if (logger.isInfoEnabled()) {
logger.info("Terminating indexUpdater. emptyListCount is over {}.", maxEmptyListCount);
}
// terminate crawling
finishCrawling = true;
forceStop();
if (fessConfig.getIndexerThreadDumpEnabledAsBoolean()) {
ThreadDumpUtil.printThreadDump();
}
org.codelibs.fess.exec.Crawler.addError("QueueTimeout");
}
if (!ComponentUtil.available()) {
logger.info("IndexUpdater is terminated.");
forceStop();
break;
}
}
if (logger.isDebugEnabled()) {
logger.debug("Finished indexUpdater.");
}
} catch (final ContainerNotAvailableException e) {
if (logger.isDebugEnabled()) {
logger.error("IndexUpdater is terminated.", e);
} else if (logger.isInfoEnabled()) {
logger.info("IndexUpdater is terminated.");
}
forceStop();
} catch (final Throwable t) {
if (ComponentUtil.available()) {
logger.error("IndexUpdater is terminated.", t);
} else if (logger.isDebugEnabled()) {
logger.error("IndexUpdater is terminated.", t);
org.codelibs.fess.exec.Crawler.addError(t.getClass().getSimpleName());
} else if (logger.isInfoEnabled()) {
logger.info("IndexUpdater is terminated.");
org.codelibs.fess.exec.Crawler.addError(t.getClass().getSimpleName());
}
forceStop();
} finally {
intervalControlHelper.setCrawlerRunning(true);
}
if (logger.isInfoEnabled()) {
logger.info("[EXEC TIME] index update time: {}ms", executeTime);
}
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class CrawlingInfoHelper method updateParams.
public void updateParams(final String sessionId, final String name, final int dayForCleanup) {
final CrawlingInfo crawlingInfo = getCrawlingInfoService().getLast(sessionId);
if (crawlingInfo == null) {
logger.warn("No crawling session: {}", sessionId);
return;
}
if (StringUtil.isNotBlank(name)) {
crawlingInfo.setName(name);
} else {
crawlingInfo.setName(Constants.CRAWLING_INFO_SYSTEM_NAME);
}
if (dayForCleanup >= 0) {
final long expires = getExpiredTime(dayForCleanup);
crawlingInfo.setExpiredTime(expires);
documentExpires = expires;
}
try {
getCrawlingInfoService().store(crawlingInfo);
} catch (final Exception e) {
throw new FessSystemException("No crawling session.", e);
}
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class AdminDesignAction method getJspFile.
private File getJspFile(final String fileName, final String jspType) {
try {
final String[] values = URLDecoder.decode(fileName, Constants.UTF_8).split(":");
if (values.length != 2) {
throwValidationError(messages -> messages.addErrorsInvalidDesignJspFileName(GLOBAL), this::asListHtml);
}
final String jspFileName = systemHelper.getDesignJspFileName(values[1]);
if (jspFileName == null) {
throwValidationError(messages -> messages.addErrorsInvalidDesignJspFileName(GLOBAL), this::asListHtml);
}
String path;
if ("view".equals(jspType)) {
path = "/WEB-INF/" + jspType + values[0] + "/" + jspFileName;
} else {
path = "/WEB-INF/" + jspType + "/" + jspFileName;
}
final File jspFile = new File(getServletContext().getRealPath(path));
if (!jspFile.exists()) {
throwValidationError(messages -> messages.addErrorsDesignJspFileDoesNotExist(GLOBAL), this::asListHtml);
}
return jspFile;
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Failed to decode " + fileName, e);
}
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class AdminDesignAction method editAsUseDefault.
@Execute
@Secured({ ROLE })
public HtmlResponse editAsUseDefault(final EditForm form) {
final String jspType = "orig/view";
final File jspFile = getJspFile(form.fileName, jspType);
try {
form.content = new String(FileUtil.readBytes(jspFile), Constants.UTF_8);
} catch (final UnsupportedEncodingException e) {
throw new FessSystemException("Invalid encoding", e);
}
saveToken();
return asEditHtml(form);
}
use of org.codelibs.fess.exception.FessSystemException in project fess by codelibs.
the class CrawlingInfoService method storeInfo.
public void storeInfo(final List<CrawlingInfoParam> crawlingInfoParamList) {
if (crawlingInfoParamList == null) {
throw new FessSystemException("Crawling Session Info is null.");
}
final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
for (final CrawlingInfoParam crawlingInfoParam : crawlingInfoParamList) {
if (crawlingInfoParam.getCreatedTime() == null) {
crawlingInfoParam.setCreatedTime(now);
}
}
crawlingInfoParamBhv.batchInsert(crawlingInfoParamList, op -> op.setRefreshPolicy(Constants.TRUE));
}
Aggregations