Search in sources :

Example 6 with ComponentRegistry

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

the class HostProvisionerProvider method withProvisioner.

// for testing
public static HostProvisionerProvider withProvisioner(Provisioner provisioner) {
    ComponentRegistry<Provisioner> registry = new ComponentRegistry<>();
    registry.register(ComponentId.createAnonymousComponentId("foobar"), provisioner);
    return new HostProvisionerProvider(registry, new ConfigserverConfig(new ConfigserverConfig.Builder().hostedVespa(true)));
}
Also used : ConfigserverConfig(com.yahoo.cloud.config.ConfigserverConfig) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) Provisioner(com.yahoo.config.provision.Provisioner)

Example 7 with ComponentRegistry

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

the class FilterBindingsProviderTest method requireThatCorrectlyConfiguredFiltersAreIncluded.

@Test
public void requireThatCorrectlyConfiguredFiltersAreIncluded() {
    final String requestFilter1Id = "requestFilter1";
    final String requestFilter2Id = "requestFilter2";
    final String requestFilter3Id = "requestFilter3";
    final String responseFilter1Id = "responseFilter1";
    final String responseFilter2Id = "responseFilter2";
    final String responseFilter3Id = "responseFilter3";
    // Set up config.
    configBuilder.filter(new ServerConfig.Filter.Builder().id(requestFilter1Id).binding("http://*/a"));
    configBuilder.filter(new ServerConfig.Filter.Builder().id(requestFilter2Id).binding("http://*/b"));
    configBuilder.filter(new ServerConfig.Filter.Builder().id(responseFilter1Id).binding("http://*/c"));
    configBuilder.filter(new ServerConfig.Filter.Builder().id(responseFilter3Id).binding("http://*/d"));
    // Set up registry.
    final ComponentRegistry<RequestFilter> availableRequestFilters = new ComponentRegistry<>();
    final RequestFilter requestFilter1Instance = mock(RequestFilter.class);
    final RequestFilter requestFilter2Instance = mock(RequestFilter.class);
    final RequestFilter requestFilter3Instance = mock(RequestFilter.class);
    availableRequestFilters.register(ComponentId.fromString(requestFilter1Id), requestFilter1Instance);
    availableRequestFilters.register(ComponentId.fromString(requestFilter2Id), requestFilter2Instance);
    availableRequestFilters.register(ComponentId.fromString(requestFilter3Id), requestFilter3Instance);
    final ComponentRegistry<ResponseFilter> availableResponseFilters = new ComponentRegistry<>();
    final ResponseFilter responseFilter1Instance = mock(ResponseFilter.class);
    final ResponseFilter responseFilter2Instance = mock(ResponseFilter.class);
    final ResponseFilter responseFilter3Instance = mock(ResponseFilter.class);
    availableResponseFilters.register(ComponentId.fromString(responseFilter1Id), responseFilter1Instance);
    availableResponseFilters.register(ComponentId.fromString(responseFilter2Id), responseFilter2Instance);
    availableResponseFilters.register(ComponentId.fromString(responseFilter3Id), responseFilter3Instance);
    final FilterChainRepository filterChainRepository = new FilterChainRepository(new ChainsConfig(new ChainsConfig.Builder()), availableRequestFilters, availableResponseFilters, new ComponentRegistry<SecurityRequestFilter>(), new ComponentRegistry<SecurityResponseFilter>());
    // Set up the provider that we aim to test.
    final FilterBindingsProvider provider = new FilterBindingsProvider(new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<SecurityRequestFilter>());
    // Execute.
    final FilterBindings filterBindings = provider.get();
    // Verify.
    assertThat(filterBindings, is(not(nullValue())));
    assertThat(filterBindings.getRequestFilters(), containsFilters(requestFilter1Instance, requestFilter2Instance));
    assertThat(filterBindings.getRequestFilters(), not(containsFilters(requestFilter3Instance)));
    assertThat(filterBindings.getResponseFilters(), containsFilters(responseFilter1Instance, responseFilter3Instance));
    assertThat(filterBindings.getResponseFilters(), not(containsFilters(responseFilter2Instance)));
}
Also used : SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) ChainsConfig(com.yahoo.container.core.ChainsConfig) FilterBindings(com.yahoo.jdisc.http.server.FilterBindings) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerConfig(com.yahoo.jdisc.http.ServerConfig) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) FilterChainRepository(com.yahoo.container.http.filter.FilterChainRepository) ComponentId(com.yahoo.component.ComponentId) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) Test(org.junit.Test)

Example 8 with ComponentRegistry

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

the class FilterBindingsProviderTest method requireThatInstanceCanNotBeBothRequestAndResponseFilter.

@Test
public void requireThatInstanceCanNotBeBothRequestAndResponseFilter() {
    final String filterId = "filter";
    // Set up config.
    configBuilder.filter(new ServerConfig.Filter.Builder().id(filterId).binding("http://*/*"));
    // Set up registry.
    final DualRoleFilter filterInstance = mock(DualRoleFilter.class);
    final ComponentRegistry<RequestFilter> availableRequestFilters = new ComponentRegistry<>();
    availableRequestFilters.register(ComponentId.fromString(filterId), filterInstance);
    final FilterChainRepository filterChainRepository = new FilterChainRepository(new ChainsConfig(new ChainsConfig.Builder()), availableRequestFilters, new ComponentRegistry<>(), new ComponentRegistry<>(), new ComponentRegistry<>());
    try {
        new FilterBindingsProvider(new ComponentId("foo"), new ServerConfig(configBuilder), filterChainRepository, new ComponentRegistry<>());
        fail("Dual-role filter should not be accepted");
    } catch (RuntimeException e) {
        assertThat(e.getMessage(), containsString("Invalid config"));
    }
}
Also used : ChainsConfig(com.yahoo.container.core.ChainsConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ServerConfig(com.yahoo.jdisc.http.ServerConfig) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) SecurityResponseFilter(com.yahoo.jdisc.http.filter.SecurityResponseFilter) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) FilterChainRepository(com.yahoo.container.http.filter.FilterChainRepository) ComponentId(com.yahoo.component.ComponentId) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) SecurityRequestFilter(com.yahoo.jdisc.http.filter.SecurityRequestFilter) Test(org.junit.Test)

Example 9 with ComponentRegistry

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

the class FederationSearcherTest method custom_federation_target.

@Test
public void custom_federation_target() {
    ComponentId targetSelectorId = ComponentId.fromString("TargetSelector");
    ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
    targetSelectors.register(targetSelectorId, new TestTargetSelector());
    FederationSearcher searcher = new FederationSearcher(new FederationConfig(new FederationConfig.Builder().targetSelector(targetSelectorId.toString())), new StrictContractsConfig(new StrictContractsConfig.Builder()), targetSelectors);
    Result result = new Execution(searcher, Context.createContextStub()).search(new Query());
    HitGroup myChainGroup = (HitGroup) result.hits().get(0);
    assertThat(myChainGroup.getId(), is(new URI("source:myChain")));
    assertThat(myChainGroup.get(0).getId(), is(new URI("myHit")));
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) URI(com.yahoo.net.URI) Result(com.yahoo.search.Result) StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) Execution(com.yahoo.search.searchchain.Execution) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) TargetSelector(com.yahoo.search.federation.selection.TargetSelector) ComponentId(com.yahoo.component.ComponentId) FederationConfig(com.yahoo.search.federation.FederationConfig) HitGroup(com.yahoo.search.result.HitGroup) Test(org.junit.Test)

Example 10 with ComponentRegistry

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

the class FederationSearcherTest method target_selectors_can_have_multiple_targets.

@Test
public void target_selectors_can_have_multiple_targets() {
    ComponentId targetSelectorId = ComponentId.fromString("TestMultipleTargetSelector");
    ComponentRegistry<TargetSelector> targetSelectors = new ComponentRegistry<>();
    targetSelectors.register(targetSelectorId, new TestMultipleTargetSelector());
    FederationSearcher searcher = new FederationSearcher(new FederationConfig(new FederationConfig.Builder().targetSelector(targetSelectorId.toString())), new StrictContractsConfig(new StrictContractsConfig.Builder()), targetSelectors);
    Result result = new Execution(searcher, Context.createContextStub()).search(new Query());
    Iterator<Hit> hitsIterator = result.hits().deepIterator();
    Hit hit1 = hitsIterator.next();
    Hit hit2 = hitsIterator.next();
    assertThat(hit1.getSource(), is("chain1"));
    assertThat(hit2.getSource(), is("chain2"));
    assertThat((String) hit1.getField("data"), is("modifyTargetQuery:custom-data:1"));
    assertThat((String) hit2.getField("data"), is("modifyTargetQuery:custom-data:2"));
}
Also used : FederationSearcher(com.yahoo.search.federation.FederationSearcher) Query(com.yahoo.search.Query) Result(com.yahoo.search.Result) StrictContractsConfig(com.yahoo.search.federation.StrictContractsConfig) ErrorHit(com.yahoo.search.result.ErrorHit) Hit(com.yahoo.search.result.Hit) Execution(com.yahoo.search.searchchain.Execution) ComponentRegistry(com.yahoo.component.provider.ComponentRegistry) TargetSelector(com.yahoo.search.federation.selection.TargetSelector) ComponentId(com.yahoo.component.ComponentId) FederationConfig(com.yahoo.search.federation.FederationConfig) Test(org.junit.Test)

Aggregations

ComponentRegistry (com.yahoo.component.provider.ComponentRegistry)10 ComponentId (com.yahoo.component.ComponentId)7 Test (org.junit.Test)5 Query (com.yahoo.search.Query)3 Result (com.yahoo.search.Result)3 FederationConfig (com.yahoo.search.federation.FederationConfig)3 FederationSearcher (com.yahoo.search.federation.FederationSearcher)3 StrictContractsConfig (com.yahoo.search.federation.StrictContractsConfig)3 Execution (com.yahoo.search.searchchain.Execution)3 Chain (com.yahoo.component.chain.Chain)2 ChainsConfig (com.yahoo.container.core.ChainsConfig)2 FilterChainRepository (com.yahoo.container.http.filter.FilterChainRepository)2 CallStack (com.yahoo.docproc.CallStack)2 ServerConfig (com.yahoo.jdisc.http.ServerConfig)2 RequestFilter (com.yahoo.jdisc.http.filter.RequestFilter)2 ResponseFilter (com.yahoo.jdisc.http.filter.ResponseFilter)2 SecurityRequestFilter (com.yahoo.jdisc.http.filter.SecurityRequestFilter)2 SecurityResponseFilter (com.yahoo.jdisc.http.filter.SecurityResponseFilter)2 TargetSelector (com.yahoo.search.federation.selection.TargetSelector)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2