use of org.bedework.util.elasticsearch.DocBuilderBase.UpdateInfo in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method newIndex.
@Override
public String newIndex(final String name) throws CalFacadeException {
try {
final String newName = name + newIndexSuffix();
targetIndex = newName;
final IndicesAdminClient idx = getAdminIdx();
final CreateIndexRequestBuilder cirb = idx.prepareCreate(newName);
final File f = new File(idxpars.getIndexerConfig());
final byte[] sbBytes = Streams.copyToByteArray(f);
cirb.setSource(sbBytes);
final CreateIndexRequest cir = cirb.request();
final ActionFuture<CreateIndexResponse> af = idx.create(cir);
/*resp = */
af.actionGet();
index(new UpdateInfo());
info("Index created: change token set to " + currentChangeToken());
return newName;
} catch (final ElasticsearchException ese) {
// Failed somehow
error(ese);
return null;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
error(t);
throw new CalFacadeException(t);
}
}
use of org.bedework.util.elasticsearch.DocBuilderBase.UpdateInfo in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method markUpdated.
private void markUpdated(final String docType) throws CalFacadeException {
UpdateInfo ui = updateInfo.get(targetIndex);
if (ui == null) {
currentChangeToken();
}
ui = updateInfo.get(targetIndex);
if (ui == null) {
throw new CalFacadeException("Unable to set updateInfo");
}
if ((docType == null) || docType.equals(docTypeUnknown)) {
categories.clear();
contacts.clear();
locations.clear();
} else if (docType.equals(docTypeCategory)) {
categories.clear();
} else if (docType.equals(docTypeContact)) {
contacts.clear();
} else if (docType.equals(docTypeLocation)) {
locations.clear();
}
ui.setUpdate(true);
}
use of org.bedework.util.elasticsearch.DocBuilderBase.UpdateInfo in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method currentChangeToken.
@Override
public String currentChangeToken() throws CalFacadeException {
UpdateInfo ui;
try {
final GetRequestBuilder grb = getClient().prepareGet(targetIndex, docTypeUpdateTracker, updateTrackerId).setFields("count", "_timestamp");
final GetResponse gr = grb.execute().actionGet();
if (!gr.isExists()) {
return null;
}
final EntityBuilder er = getEntityBuilder(gr.getFields());
ui = er.makeUpdateInfo();
} catch (final ElasticsearchException ese) {
warn("Exception getting UpdateInfo: " + ese.getLocalizedMessage());
ui = new UpdateInfo();
}
synchronized (updateInfo) {
UpdateInfo tui = updateInfo.get(targetIndex);
if ((tui != null) && (tui.getCount() >= (0111111111 - 1000))) {
// Reset before we overflow
tui = null;
}
if ((tui == null) || (!tui.getCount().equals(ui.getCount()))) {
updateInfo.put(targetIndex, ui);
} else {
ui = tui;
}
}
return ui.getChangeToken();
}
use of org.bedework.util.elasticsearch.DocBuilderBase.UpdateInfo in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method markTransaction.
@Override
public void markTransaction() throws CalFacadeException {
final UpdateInfo ui = updateInfo.get(targetIndex);
if ((ui != null) && !ui.isUpdate()) {
return;
}
try {
final UpdateRequestBuilder urb = getClient().prepareUpdate(targetIndex, docTypeUpdateTracker, updateTrackerId).setRetryOnConflict(20).setRefresh(true);
urb.setScript("ctx._source.count += 1", ScriptService.ScriptType.INLINE);
final UpdateResponse ur = urb.execute().actionGet();
} catch (final ElasticsearchException ese) {
warn("Exception updating UpdateInfo: " + ese.getLocalizedMessage());
index(new UpdateInfo());
}
}
Aggregations