Search in sources :

Example 86 with CalFacadeException

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);
    }
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) DateDatetimePropertyType(ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) TzidParamType(ietf.params.xml.ns.icalendar_2.TzidParamType) ParameterUpdater(org.bedework.caldav.bwserver.ParameterUpdater) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 87 with CalFacadeException

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);
    }
}
Also used : DuePropType(ietf.params.xml.ns.icalendar_2.DuePropType) BwDateTime(org.bedework.calfacade.BwDateTime) DateDatetimePropertyType(ietf.params.xml.ns.icalendar_2.DateDatetimePropertyType) Holder(javax.xml.ws.Holder) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 88 with CalFacadeException

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);
    }
}
Also used : CreateIndexRequestBuilder(org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) ElasticsearchException(org.elasticsearch.ElasticsearchException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) File(java.io.File) UpdateInfo(org.bedework.util.elasticsearch.DocBuilderBase.UpdateInfo) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 89 with CalFacadeException

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);
    }
}
Also used : GetAliasesResponse(org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse) GetAliasesRequestBuilder(org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequestBuilder) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) ElasticsearchException(org.elasticsearch.ElasticsearchException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) ArrayList(java.util.ArrayList) List(java.util.List) IndicesAliasesResponse(org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse) IndicesAliasesRequestBuilder(org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequestBuilder)

Example 90 with CalFacadeException

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;
    }
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequestBuilder(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder) Node(org.elasticsearch.node.Node) NodeBuilder(org.elasticsearch.node.NodeBuilder) ImmutableSettings(org.elasticsearch.common.settings.ImmutableSettings) InetSocketTransportAddress(org.elasticsearch.common.transport.InetSocketTransportAddress) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12