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);
}
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));
}
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);
}
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);
}
}
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;
}
Aggregations