use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class DateDatetimePropUpdater method makeDt.
protected UpdateResult makeDt(final BwDateTime evdt, final Holder<BwDateTime> resdt, final UpdateInfo ui) throws WebdavException {
try {
String tzid = evdt.getTzid();
String dtval = evdt.getDtval();
boolean dateOnly = evdt.getDateType();
BwDateTime newdt = null;
/* New or changed tzid? */
for (ParameterUpdater.UpdateInfo parui : ui.getParamUpdates()) {
if (parui.getParam() instanceof TzidParamType) {
if (parui.isRemove()) {
tzid = null;
break;
}
if (parui.isAdd()) {
if (tzid != null) {
return new UpdateResult(ui.getPropName().toString() + " already has tzid");
}
tzid = ((TzidParamType) parui.getParam()).getText();
break;
}
if (tzid == null) {
return new UpdateResult(ui.getPropName().toString() + " has no tzid to change");
}
tzid = ((TzidParamType) parui.getUpdparam()).getText();
break;
}
}
if (ui.getUpdprop() != null) {
// Has new value
DateDatetimePropertyType newdts = (DateDatetimePropertyType) ui.getUpdprop();
dateOnly = newdts.getDate() != null;
newdt = BwDateTime.makeBwDateTime(newdts, tzid);
}
if ((newdt == null) && (!Util.equalsString(tzid, evdt.getTzid()))) {
// Tzid changed
newdt = BwDateTime.makeBwDateTime(dateOnly, dtval, tzid);
}
if (newdt != null) {
// Validate
int res = newdt.validate();
if (res == BwDateTime.dtBadDtval) {
return new UpdateResult("Bad date value for " + ui.getPropName());
}
if (res == BwDateTime.dtBadTz) {
return new UpdateResult("Bad tzid for " + ui.getPropName());
}
}
resdt.value = newdt;
return UpdateResult.getOkResult();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class DtEndDuePropUpdater method applyUpdate.
@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
/* For start, end and duration we have to finish up at the end after all
* changes are made.
*/
try {
BwEvent ev = ui.getEvent();
DateDatetimePropertyType dt = (DateDatetimePropertyType) ui.getProp();
if (dt instanceof DuePropType) {
if (ev.getEntityType() != IcalDefs.entityTypeTodo) {
return new UpdateResult("DUE only valid for tasks");
}
} else {
if (ev.getEntityType() == IcalDefs.entityTypeTodo) {
return new UpdateResult("DUE required for tasks");
}
}
DatesState ds = (DatesState) ui.getState(DatesState.stateName);
if (ds == null) {
ds = new DatesState(ev);
ui.saveState(DatesState.stateName, ds);
}
ChangeTableEntry cte = ui.getCte();
if (ui.isRemove()) {
if (ev.getEndType() != StartEndComponent.endTypeDate) {
return new UpdateResult("Entity has no end date - cannot remove");
}
cte.setDeleted(ev.getDtend());
ds.end = null;
return UpdateResult.getOkResult();
}
if (ui.isAdd()) {
if (ev.getEndType() == StartEndComponent.endTypeDate) {
return new UpdateResult("Entity already has end date - cannot add");
}
ds.end = BwDateTime.makeBwDateTime(dt);
cte.setAdded(ds.end);
return UpdateResult.getOkResult();
}
/* Changing dtend - either value or parameters */
if (ev.getEndType() != StartEndComponent.endTypeDate) {
return new UpdateResult("Entity has no end date - cannot change");
}
Holder<BwDateTime> resdt = new Holder<BwDateTime>();
UpdateResult ur = makeDt(ev.getDtend(), resdt, ui);
if (!ur.getOk()) {
return ur;
}
if (resdt.value != null) {
cte.setChanged(ev.getDtend(), resdt.value);
ds.end = resdt.value;
}
return UpdateResult.getOkResult();
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.exc.CalFacadeException 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.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method setAlias.
@Override
public int setAlias(final String index, final String alias) throws CalFacadeException {
// IndicesAliasesResponse resp = null;
try {
/* Other is the alias name - index is the index we were just indexing into
*/
final IndicesAdminClient idx = getAdminIdx();
final GetAliasesRequestBuilder igarb = idx.prepareGetAliases(alias);
final ActionFuture<GetAliasesResponse> getAliasesAf = idx.getAliases(igarb.request());
final GetAliasesResponse garesp = getAliasesAf.actionGet();
final ImmutableOpenMap<String, List<AliasMetaData>> aliasesmeta = garesp.getAliases();
final IndicesAliasesRequestBuilder iarb = idx.prepareAliases();
final Iterator<String> it = aliasesmeta.keysIt();
while (it.hasNext()) {
final String indexName = it.next();
for (final AliasMetaData amd : aliasesmeta.get(indexName)) {
if (amd.getAlias().equals(alias)) {
iarb.removeAlias(indexName, alias);
}
}
}
iarb.addAlias(index, alias);
final ActionFuture<IndicesAliasesResponse> af = idx.aliases(iarb.request());
/*resp = */
af.actionGet();
return 0;
} catch (final ElasticsearchException ese) {
// Failed somehow
error(ese);
return -1;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.
the class BwIndexEsImpl method getClient.
private Client getClient() throws CalFacadeException {
if (theClient != null) {
return theClient;
}
synchronized (clientSyncher) {
if (theClient != null) {
return theClient;
}
if (idxpars.getEmbeddedIndexer()) {
/* Start up a node and get a client from it.
*/
final ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder();
if (idxpars.getNodeName() != null) {
settings.put("node.name", idxpars.getNodeName());
}
settings.put("path.data", idxpars.getDataDir());
if (idxpars.getHttpEnabled()) {
warn("*************************************************************");
warn("*************************************************************");
warn("*************************************************************");
warn("http is enabled for the indexer. This is a security risk. ");
warn("Turn it off in the indexer configuration. ");
warn("*************************************************************");
warn("*************************************************************");
warn("*************************************************************");
}
settings.put("http.enabled", idxpars.getHttpEnabled());
final NodeBuilder nbld = NodeBuilder.nodeBuilder().settings(settings);
if (idxpars.getClusterName() != null) {
nbld.clusterName(idxpars.getClusterName());
}
final Node theNode = nbld.data(true).local(true).node();
theClient = theNode.client();
} else {
/* Not embedded - use the URL */
TransportClient tClient = new TransportClient();
tClient = tClient.addTransportAddress(new InetSocketTransportAddress(host, port));
theClient = tClient;
}
/* Ensure status is at least yellow */
int tries = 0;
int yellowTries = 0;
for (; ; ) {
final ClusterHealthRequestBuilder chrb = theClient.admin().cluster().prepareHealth();
final ClusterHealthResponse chr = chrb.execute().actionGet();
if (chr.getStatus() == ClusterHealthStatus.GREEN) {
break;
}
if (chr.getStatus() == ClusterHealthStatus.YELLOW) {
yellowTries++;
if (yellowTries > 60) {
warn("Going ahead anyway on YELLOW status");
}
break;
}
tries++;
if (tries % 5 == 0) {
warn("Cluster status for " + chr.getClusterName() + " is still " + chr.getStatus() + " after " + tries + " tries");
}
try {
Thread.sleep(1000);
} catch (final InterruptedException ex) {
throw new CalFacadeException("Interrupted out of getClient");
}
}
return theClient;
}
}
Aggregations