Search in sources :

Example 1 with DocumentSelector

use of com.yahoo.document.select.DocumentSelector in project vespa by vespa-engine.

the class DocumentSelectionBuilder method validateSelectionExpression.

private void validateSelectionExpression(String sel, String allowedType) {
    DocumentSelector s;
    try {
        s = new DocumentSelector(sel);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Could not parse document routing selection: " + sel, e);
    }
    AllowedDocumentTypesChecker checker = new AllowedDocumentTypesChecker(allowedType);
    s.visit(checker);
}
Also used : DocumentSelector(com.yahoo.document.select.DocumentSelector) ParseException(com.yahoo.document.select.parser.ParseException)

Example 2 with DocumentSelector

use of com.yahoo.document.select.DocumentSelector in project vespa by vespa-engine.

the class FieldPathUpdate method setWhereClause.

public void setWhereClause(String whereClause) throws ParseException {
    this.whereClause = whereClause;
    selector = null;
    if (whereClause != null && !whereClause.equals("")) {
        selector = new DocumentSelector(whereClause);
    }
}
Also used : DocumentSelector(com.yahoo.document.select.DocumentSelector)

Example 3 with DocumentSelector

use of com.yahoo.document.select.DocumentSelector in project vespa by vespa-engine.

the class DocumentRouteSelectorPolicy method select.

/**
 * This method runs the selector associated with the given location on the content of the message. If the selector
 * validates the location, this method returns true.
 *
 * @param context   The routing context that contains the necessary data.
 * @param routeName The candidate route whose selector to run.
 * @return Whether or not to send to the given recipient.
 */
private boolean select(RoutingContext context, String routeName) {
    if (config == null) {
        return true;
    }
    DocumentSelector selector = config.get(routeName);
    if (selector == null) {
        return true;
    }
    // Select based on message content.
    Message msg = context.getMessage();
    switch(msg.getType()) {
        case DocumentProtocol.MESSAGE_PUTDOCUMENT:
            return selector.accepts(((PutDocumentMessage) msg).getDocumentPut()) == Result.TRUE;
        case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
            return selector.accepts(((UpdateDocumentMessage) msg).getDocumentUpdate()) != Result.FALSE;
        case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
            {
                RemoveDocumentMessage removeMsg = (RemoveDocumentMessage) msg;
                if (removeMsg.getDocumentId().hasDocType()) {
                    return selector.accepts(removeMsg.getDocumentRemove()) != Result.FALSE;
                } else {
                    return true;
                }
            }
        case DocumentProtocol.MESSAGE_BATCHDOCUMENTUPDATE:
            BatchDocumentUpdateMessage bdu = (BatchDocumentUpdateMessage) msg;
            for (int i = 0; i < bdu.getUpdates().size(); i++) {
                if (selector.accepts(bdu.getUpdates().get(i)) == Result.FALSE) {
                    return false;
                }
            }
            return true;
        default:
            return true;
    }
}
Also used : DocumentSelector(com.yahoo.document.select.DocumentSelector) Message(com.yahoo.messagebus.Message)

Example 4 with DocumentSelector

use of com.yahoo.document.select.DocumentSelector in project vespa by vespa-engine.

the class DocumentRouteSelectorPolicy method configure.

/**
 * This method is called when configuration arrives from the config server. The received config object is traversed
 * and a local map is constructed and swapped with the current {@link #config} map.
 *
 * @param cfg The configuration object given by subscription.
 */
@Override
public void configure(DocumentrouteselectorpolicyConfig cfg) {
    String error = null;
    Map<String, DocumentSelector> config = new HashMap<>();
    for (int i = 0; i < cfg.route().size(); i++) {
        DocumentrouteselectorpolicyConfig.Route route = cfg.route(i);
        if (route.selector().isEmpty()) {
            continue;
        }
        DocumentSelector selector;
        try {
            selector = new DocumentSelector(route.selector());
            log.log(LogLevel.CONFIG, "Selector for route '" + route.name() + "' is '" + selector + "'.");
        } catch (com.yahoo.document.select.parser.ParseException e) {
            error = "Error parsing selector '" + route.selector() + "' for route '" + route.name() + "; " + e.getMessage();
            break;
        }
        config.put(route.name(), selector);
    }
    synchronized (this) {
        this.config = config;
        this.error = error;
    }
}
Also used : DocumentSelector(com.yahoo.document.select.DocumentSelector) HashMap(java.util.HashMap)

Example 5 with DocumentSelector

use of com.yahoo.document.select.DocumentSelector in project vespa by vespa-engine.

the class RoutingSelectorValidator method validate.

@Override
public void validate(VespaModel model, DeployState deployState) {
    for (AbstractSearchCluster cluster : model.getSearchClusters()) {
        if (cluster instanceof IndexedSearchCluster) {
            IndexedSearchCluster sc = (IndexedSearchCluster) cluster;
            String routingSelector = sc.getRoutingSelector();
            if (routingSelector == null)
                continue;
            try {
                new DocumentSelector(routingSelector);
            } catch (com.yahoo.document.select.parser.ParseException e) {
                throw new IllegalArgumentException("Failed to parse routing selector for search cluster '" + sc.getClusterName() + "'", e);
            }
        }
    }
}
Also used : IndexedSearchCluster(com.yahoo.vespa.model.search.IndexedSearchCluster) DocumentSelector(com.yahoo.document.select.DocumentSelector) AbstractSearchCluster(com.yahoo.vespa.model.search.AbstractSearchCluster)

Aggregations

DocumentSelector (com.yahoo.document.select.DocumentSelector)5 ParseException (com.yahoo.document.select.parser.ParseException)1 Message (com.yahoo.messagebus.Message)1 AbstractSearchCluster (com.yahoo.vespa.model.search.AbstractSearchCluster)1 IndexedSearchCluster (com.yahoo.vespa.model.search.IndexedSearchCluster)1 HashMap (java.util.HashMap)1