Search in sources :

Example 6 with ComponentSpecification

use of com.yahoo.component.ComponentSpecification in project vespa by vespa-engine.

the class QueryProfileRegistry method findPathParentQueryProfile.

private QueryProfile findPathParentQueryProfile(ComponentSpecification id) {
    // Try the name with "/" appended - should have the same semantics with path matching
    QueryProfile slashedProfile = getComponent(new ComponentSpecification(id.getName() + "/", id.getVersionSpecification()));
    if (slashedProfile != null && slashedProfile.getType() != null && slashedProfile.getType().getMatchAsPath())
        return slashedProfile;
    // Extract the parent (if any)
    int slashIndex = id.getName().lastIndexOf("/");
    if (slashIndex < 1)
        return null;
    String parentName = id.getName().substring(0, slashIndex);
    if (parentName.equals(""))
        return null;
    ComponentSpecification parentId = new ComponentSpecification(parentName, id.getVersionSpecification());
    QueryProfile pathParentProfile = getComponent(parentId);
    if (pathParentProfile != null && pathParentProfile.getType() != null && pathParentProfile.getType().getMatchAsPath())
        return pathParentProfile;
    return findPathParentQueryProfile(parentId);
}
Also used : ComponentSpecification(com.yahoo.component.ComponentSpecification)

Example 7 with ComponentSpecification

use of com.yahoo.component.ComponentSpecification in project vespa by vespa-engine.

the class QueryProfileRegistry method findQueryProfile.

/**
 * <p>Returns a query profile for the given request string, or null if a suitable one is not found.</p>
 *
 * The request string must be a valid {@link com.yahoo.component.ComponentId} or null.
 *
 * <p>
 * If the string is null, the profile named "default" is returned, or null if that does not exists.
 *
 * <p>
 * The version part (if any) is matched used the usual component version patching rules.
 * If the name part matches a query profile name perfectly, that profile is returned.
 * If not, and the name is a slash-separated path, the profile with the longest matching left sub-path
 * which has a type which allows path mahting is used. If there is no such profile, null is returned.
 */
public QueryProfile findQueryProfile(String idString) {
    if (idString == null)
        return getComponent("default");
    ComponentSpecification id = new ComponentSpecification(idString);
    QueryProfile profile = getComponent(id);
    if (profile != null)
        return profile;
    return findPathParentQueryProfile(new ComponentSpecification(idString));
}
Also used : ComponentSpecification(com.yahoo.component.ComponentSpecification)

Example 8 with ComponentSpecification

use of com.yahoo.component.ComponentSpecification in project vespa by vespa-engine.

the class CompiledQueryProfileRegistry method findPathParentQueryProfile.

private CompiledQueryProfile findPathParentQueryProfile(ComponentSpecification id) {
    // Try the name with "/" appended - should have the same semantics with path matching
    CompiledQueryProfile slashedProfile = getComponent(new ComponentSpecification(id.getName() + "/", id.getVersionSpecification()));
    if (slashedProfile != null && slashedProfile.getType() != null && slashedProfile.getType().getMatchAsPath())
        return slashedProfile;
    // Extract the parent (if any)
    int slashIndex = id.getName().lastIndexOf("/");
    if (slashIndex < 1)
        return null;
    String parentName = id.getName().substring(0, slashIndex);
    if (parentName.equals(""))
        return null;
    ComponentSpecification parentId = new ComponentSpecification(parentName, id.getVersionSpecification());
    CompiledQueryProfile pathParentProfile = getComponent(parentId);
    if (pathParentProfile != null && pathParentProfile.getType() != null && pathParentProfile.getType().getMatchAsPath())
        return pathParentProfile;
    return findPathParentQueryProfile(parentId);
}
Also used : ComponentSpecification(com.yahoo.component.ComponentSpecification)

Example 9 with ComponentSpecification

use of com.yahoo.component.ComponentSpecification in project vespa by vespa-engine.

the class QueryProfileConfigurer method fillProfile.

private static void fillProfile(QueryProfilesConfig.Queryprofile config, QueryProfilesConfig queryProfilesConfig, QueryProfileRegistry registry, Set<ComponentId> filled) {
    QueryProfile profile = registry.getComponent(new ComponentSpecification(config.id()).toId());
    if (filled.contains(profile.getId()))
        return;
    filled.add(profile.getId());
    try {
        for (String inheritedId : config.inherit()) {
            QueryProfile inherited = registry.getComponent(inheritedId);
            if (inherited == null)
                throw new IllegalArgumentException("Inherited query profile '" + inheritedId + "' in " + profile + " was not found");
            fillProfile(inherited, queryProfilesConfig, registry, filled);
            profile.addInherited(inherited);
        }
        for (QueryProfilesConfig.Queryprofile.Reference referenceConfig : config.reference()) {
            QueryProfile referenced = registry.getComponent(referenceConfig.value());
            if (referenced == null)
                throw new IllegalArgumentException("Query profile '" + referenceConfig.value() + "' referenced as '" + referenceConfig.name() + "' in " + profile + " was not found");
            profile.set(referenceConfig.name(), referenced, registry);
            if (referenceConfig.overridable() != null && !referenceConfig.overridable().isEmpty())
                profile.setOverridable(referenceConfig.name(), BooleanParser.parseBoolean(referenceConfig.overridable()), null);
        }
        for (QueryProfilesConfig.Queryprofile.Property propertyConfig : config.property()) {
            profile.set(propertyConfig.name(), propertyConfig.value(), registry);
            if (propertyConfig.overridable() != null && !propertyConfig.overridable().isEmpty())
                profile.setOverridable(propertyConfig.name(), BooleanParser.parseBoolean(propertyConfig.overridable()), null);
        }
        for (QueryProfilesConfig.Queryprofile.Queryprofilevariant variantConfig : config.queryprofilevariant()) {
            String[] forDimensionValueArray = new String[variantConfig.fordimensionvalues().size()];
            for (int i = 0; i < variantConfig.fordimensionvalues().size(); i++) {
                forDimensionValueArray[i] = variantConfig.fordimensionvalues().get(i).trim();
                if ("*".equals(forDimensionValueArray[i]))
                    forDimensionValueArray[i] = null;
            }
            DimensionValues forDimensionValues = DimensionValues.createFrom(forDimensionValueArray);
            for (String inheritedId : variantConfig.inherit()) {
                QueryProfile inherited = registry.getComponent(inheritedId);
                if (inherited == null)
                    throw new IllegalArgumentException("Inherited query profile '" + inheritedId + "' in " + profile + " for '" + forDimensionValues + "' was not found");
                fillProfile(inherited, queryProfilesConfig, registry, filled);
                profile.addInherited(inherited, forDimensionValues);
            }
            for (QueryProfilesConfig.Queryprofile.Queryprofilevariant.Reference referenceConfig : variantConfig.reference()) {
                QueryProfile referenced = registry.getComponent(referenceConfig.value());
                if (referenced == null)
                    throw new IllegalArgumentException("Query profile '" + referenceConfig.value() + "' referenced as '" + referenceConfig.name() + "' in " + profile + " for '" + forDimensionValues + "' was not found");
                profile.set(referenceConfig.name(), referenced, forDimensionValues, registry);
            }
            for (QueryProfilesConfig.Queryprofile.Queryprofilevariant.Property propertyConfig : variantConfig.property()) {
                profile.set(propertyConfig.name(), propertyConfig.value(), forDimensionValues, registry);
            }
        }
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Invalid " + profile, e);
    }
}
Also used : QueryProfile(com.yahoo.search.query.profile.QueryProfile) ComponentSpecification(com.yahoo.component.ComponentSpecification) DimensionValues(com.yahoo.search.query.profile.DimensionValues)

Example 10 with ComponentSpecification

use of com.yahoo.component.ComponentSpecification in project vespa by vespa-engine.

the class ChainsConfigurer method resolveComponents.

private static <T extends ChainedComponent> List<T> resolveComponents(Set<ComponentSpecification> componentSpecifications, ComponentRegistry<T> allComponents) {
    List<T> components = new ArrayList<>(componentSpecifications.size());
    for (ComponentSpecification componentSpec : componentSpecifications) {
        T component = getComponentOrThrow(allComponents, componentSpec);
        components.add(component);
    }
    return components;
}
Also used : ComponentSpecification(com.yahoo.component.ComponentSpecification) ArrayList(java.util.ArrayList)

Aggregations

ComponentSpecification (com.yahoo.component.ComponentSpecification)17 ArrayList (java.util.ArrayList)4 Element (org.w3c.dom.Element)4 ComponentId (com.yahoo.component.ComponentId)2 BundleInstantiationSpecification (com.yahoo.container.bundle.BundleInstantiationSpecification)2 QueryProfile (com.yahoo.search.query.profile.QueryProfile)2 Phase (com.yahoo.component.chain.Phase)1 ChainSpecification (com.yahoo.component.chain.model.ChainSpecification)1 FileReference (com.yahoo.config.FileReference)1 CloudSubscriberFactory (com.yahoo.container.di.CloudSubscriberFactory)1 Container (com.yahoo.container.di.Container)1 ContainerTest (com.yahoo.container.di.ContainerTest)1 Osgi (com.yahoo.container.di.Osgi)1 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1 DimensionValues (com.yahoo.search.query.profile.DimensionValues)1 QueryProfileType (com.yahoo.search.query.profile.types.QueryProfileType)1 FederationOptions (com.yahoo.search.searchchain.model.federation.FederationOptions)1 TargetSpec (com.yahoo.search.searchchain.model.federation.FederationSearcherModel.TargetSpec)1 Container (com.yahoo.vespa.model.container.Container)1