diff options
50 files changed, 383 insertions, 796 deletions
diff --git a/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGenerator.java b/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGenerator.java index 54719aca1aa..a5f143fe50a 100644 --- a/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGenerator.java +++ b/athenz-identity-provider-service/src/main/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGenerator.java @@ -88,7 +88,7 @@ public class IdentityDocumentGenerator { HostName.getLocalhost(), node.hostname(), Instant.now(), - null); + node.ipAddresses()); } private static String toZoneDnsSuffix(Zone zone, String dnsSuffix) { diff --git a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGeneratorTest.java b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGeneratorTest.java index 74dbc591fc6..4e84fefbe53 100644 --- a/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGeneratorTest.java +++ b/athenz-identity-provider-service/src/test/java/com/yahoo/vespa/hosted/athenz/instanceproviderservice/identitydocument/IdentityDocumentGeneratorTest.java @@ -2,9 +2,6 @@ package com.yahoo.vespa.hosted.athenz.instanceproviderservice.identitydocument; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.google.common.collect.ImmutableSet; import com.yahoo.component.Version; import com.yahoo.config.provision.ApplicationId; @@ -17,8 +14,6 @@ import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; -import com.yahoo.vespa.athenz.identityprovider.api.VespaUniqueInstanceId; -import com.yahoo.vespa.athenz.identityprovider.api.bindings.IdentityDocument; import com.yahoo.vespa.athenz.identityprovider.api.bindings.ProviderUniqueId; import com.yahoo.vespa.athenz.identityprovider.api.bindings.SignedIdentityDocument; import com.yahoo.vespa.hosted.athenz.instanceproviderservice.AutoGeneratedKeyProvider; @@ -29,17 +24,13 @@ import com.yahoo.vespa.hosted.provision.NodeRepository; import com.yahoo.vespa.hosted.provision.node.Allocation; import com.yahoo.vespa.hosted.provision.node.Generation; import com.yahoo.vespa.hosted.provision.testutils.MockNodeFlavors; -import org.hamcrest.CoreMatchers; import org.junit.Test; -import java.time.Instant; import java.util.HashSet; import java.util.Optional; import static com.yahoo.vespa.hosted.athenz.instanceproviderservice.TestUtils.getAthenzProviderConfig; -import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -97,20 +88,4 @@ public class IdentityDocumentGeneratorTest { signedIdentityDocument.rawIdentityDocument, signedIdentityDocument.signature)); } - - @Test - public void does_not_include_ipaddresses_field() throws JsonProcessingException { - IdentityDocument identityDocument = new IdentityDocument( - ProviderUniqueId.fromVespaUniqueInstanceId(VespaUniqueInstanceId.fromDottedString("1.cluster.instance.application.tenant.region.environment")), - "cfg", - "tenanthost", - Instant.now(), - null); - - ObjectMapper mapper = new ObjectMapper(); - mapper.registerModule(new JavaTimeModule()); - String value = mapper.writeValueAsString(identityDocument); - System.out.println("value = " + value); - assertThat(value, not(CoreMatchers.containsString("ip-addresses"))); - } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/search/ContainerSearch.java b/config-model/src/main/java/com/yahoo/vespa/model/container/search/ContainerSearch.java index db81191f0cf..5afba6fa373 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/search/ContainerSearch.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/search/ContainerSearch.java @@ -176,7 +176,6 @@ public class ContainerSearch extends ContainerSubsystem<SearchChains> scB.rankprofiles(new QrSearchersConfig.Searchcluster.Rankprofiles.Builder().configid(sys.getConfigId())); scB.indexingmode(QrSearchersConfig.Searchcluster.Indexingmode.Enum.valueOf(sys.getIndexingModeName())); if (sys instanceof IndexedSearchCluster) { - scB.rowbits(sys.getRowBits()); for (Dispatch tld: ((IndexedSearchCluster)sys).getTLDs()) { scB.dispatcher(new QrSearchersConfig.Searchcluster.Dispatcher.Builder(). host(tld.getHostname()). diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java index daa0b4f4830..95a507ede21 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantBuilder.java @@ -197,12 +197,9 @@ public class TenantBuilder { } } - - public LocalSessionRepo getLocalSessionRepo() { - return localSessionRepo; - } - public TenantApplications getApplicationRepo() { return applicationRepo; } + + public TenantName getTenantName() { return tenant; } } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java index caa15699bbf..8f4a90ef85f 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/tenant/TenantRepository.java @@ -27,6 +27,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -70,16 +71,27 @@ public class TenantRepository implements ConnectionStateListener, PathChildrenCa private final MetricUpdater metricUpdater; private final ExecutorService pathChildrenExecutor = Executors.newFixedThreadPool(1, ThreadFactoryFactory.getThreadFactory(TenantRepository.class.getName())); private final ScheduledExecutorService checkForRemovedApplicationsService = new ScheduledThreadPoolExecutor(1); - private final Curator.DirectoryCache directoryCache; + private final Optional<Curator.DirectoryCache> directoryCache; /** - * New instance from the tenants in the given component registry's ZooKeeper data. + * Creates a new tenant repository * * @param globalComponentRegistry a {@link com.yahoo.vespa.config.server.GlobalComponentRegistry} */ @Inject public TenantRepository(GlobalComponentRegistry globalComponentRegistry) { + this(globalComponentRegistry, true); + } + + /** + * Creates a new tenant repository + * + * @param globalComponentRegistry a {@link com.yahoo.vespa.config.server.GlobalComponentRegistry} + * @param useZooKeeperWatchForTenantChanges set to false for tests where you want to control adding and deleting + * tenants yourself + */ + public TenantRepository(GlobalComponentRegistry globalComponentRegistry, boolean useZooKeeperWatchForTenantChanges) { this.globalComponentRegistry = globalComponentRegistry; this.curator = globalComponentRegistry.getCurator(); metricUpdater = globalComponentRegistry.getMetrics().getOrCreateMetricUpdater(Collections.emptyMap()); @@ -90,9 +102,13 @@ public class TenantRepository implements ConnectionStateListener, PathChildrenCa createSystemTenants(globalComponentRegistry.getConfigserverConfig()); curator.create(vespaPath); - this.directoryCache = curator.createDirectoryCache(tenantsPath.getAbsolute(), false, false, pathChildrenExecutor); - directoryCache.start(); - directoryCache.addListener(this); + if (useZooKeeperWatchForTenantChanges) { + this.directoryCache = Optional.of(curator.createDirectoryCache(tenantsPath.getAbsolute(), false, false, pathChildrenExecutor)); + this.directoryCache.get().start(); + this.directoryCache.get().addListener(this); + } else { + this.directoryCache = Optional.empty(); + } log.log(LogLevel.DEBUG, "Creating all tenants"); createTenants(); notifyTenantsLoaded(); @@ -103,42 +119,20 @@ public class TenantRepository implements ConnectionStateListener, PathChildrenCa TimeUnit.SECONDS); } - /** - * New instance containing the given tenants. Creates no system tenants and no Zookeeper watches. For testing only. - * @param globalComponentRegistry a {@link com.yahoo.vespa.config.server.GlobalComponentRegistry} instance - * @param tenants a collection of {@link Tenant}s - */ - // TODO: Get rid of the second argument and let callers use addTenant() instead - public TenantRepository(GlobalComponentRegistry globalComponentRegistry, Collection<Tenant> tenants) { - this.globalComponentRegistry = globalComponentRegistry; - this.curator = globalComponentRegistry.getCurator(); - metricUpdater = globalComponentRegistry.getMetrics().getOrCreateMetricUpdater(Collections.emptyMap()); - this.tenantListeners.add(globalComponentRegistry.getTenantListener()); - curator.create(tenantsPath); - this.directoryCache = curator.createDirectoryCache(tenantsPath.getAbsolute(), false, false, pathChildrenExecutor); - this.tenants.putAll(addTenants(tenants)); - } - private void notifyTenantsLoaded() { for (TenantListener tenantListener : tenantListeners) { tenantListener.onTenantsLoaded(); } } - // Pre-condition: tenants path needs to exist in zk - private LinkedHashMap<TenantName, Tenant> addTenants(Collection<Tenant> newTenants) { - LinkedHashMap<TenantName, Tenant> tenants = new LinkedHashMap<>(); - for (Tenant t : newTenants) { - tenants.put(t.getName(), t); - } - log.log(LogLevel.DEBUG, "TenantRepository at startup: " + tenants); - metricUpdater.setTenants(this.tenants.size()); - return tenants; - } - public synchronized void addTenant(TenantName tenantName) { - writeTenantPath(tenantName); - createTenant(tenantName); + addTenant(TenantBuilder.create(globalComponentRegistry, tenantName)); + } + + // For testing + public synchronized void addTenant(TenantBuilder builder) { + writeTenantPath(builder.getTenantName()); + createTenant(builder); } /** @@ -186,11 +180,17 @@ public class TenantRepository implements ConnectionStateListener, PathChildrenCa } private void createTenant(TenantName tenantName) { + createTenant(TenantBuilder.create(globalComponentRegistry, tenantName)); + } + + // TODO: Fix exception handling and make method return tenant + private void createTenant(TenantBuilder builder) { + TenantName tenantName = builder.getTenantName(); if (tenants.containsKey(tenantName)) return; try { - log.log(LogLevel.DEBUG, "Creating tenant '" + tenantName + "'"); - Tenant tenant = TenantBuilder.create(globalComponentRegistry, tenantName).build(); + log.log(LogLevel.INFO, "Creating tenant '" + tenantName + "'"); + Tenant tenant = builder.build(); notifyNewTenant(tenant); tenants.putIfAbsent(tenantName, tenant); } catch (Exception e) { @@ -340,7 +340,7 @@ public class TenantRepository implements ConnectionStateListener, PathChildrenCa } public void close() { - directoryCache.close(); + directoryCache.ifPresent(Curator.DirectoryCache::close); pathChildrenExecutor.shutdown(); checkForRemovedApplicationsService.shutdown(); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java index a3bea6b6c86..266833ac7f3 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/deploy/DeployTester.java @@ -106,7 +106,7 @@ public class DeployTester { provisioner); try { this.testApp = new File(appPath); - this.tenantRepository = new TenantRepository(componentRegistry, Collections.emptySet()); + this.tenantRepository = new TenantRepository(componentRegistry); tenantRepository.addTenant(tenantName); } catch (Exception e) { diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java index c34dbe76a43..221d134c0f5 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationContentHandlerTest.java @@ -6,12 +6,15 @@ import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.HttpRequest; -import com.yahoo.container.logging.AccessLog; import com.yahoo.jdisc.Response; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.http.ContentHandlerTestBase; import com.yahoo.vespa.config.server.session.Session; +import com.yahoo.vespa.config.server.tenant.Tenant; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; +import com.yahoo.vespa.config.server.tenant.TenantRepository; import org.junit.Before; import org.junit.Test; @@ -24,39 +27,46 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; /** - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class ApplicationContentHandlerTest extends ContentHandlerTestBase { + private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + private final Clock clock = componentRegistry.getClock(); private ApplicationHandler handler; - private TenantName tenant1 = TenantName.from("mofet"); - private TenantName tenant2 = TenantName.from("bla"); + private TenantName tenantName1 = TenantName.from("mofet"); + private TenantName tenantName2 = TenantName.from("bla"); private String baseServer = "http://foo:1337"; private ApplicationId idTenant1 = new ApplicationId.Builder() - .tenant(tenant1) + .tenant(tenantName1) .applicationName("foo").instanceName("quux").build(); private ApplicationId idTenant2 = new ApplicationId.Builder() - .tenant(tenant2) + .tenant(tenantName2) .applicationName("foo").instanceName("quux").build(); private MockSession session2; @Before - public void setupHandler() throws Exception { - TestTenantBuilder testTenantBuilder = new TestTenantBuilder(); - testTenantBuilder.createTenant(tenant1); - testTenantBuilder.createTenant(tenant2); + public void setupHandler() { + TenantRepository tenantRepository = new TenantRepository(componentRegistry, false); + tenantRepository.addTenant(TenantBuilder.create(componentRegistry, tenantName1)); + tenantRepository.addTenant(TenantBuilder.create(componentRegistry, tenantName2)); + session2 = new MockSession(2l, FilesApplicationPackage.fromFile(new File("src/test/apps/content"))); - testTenantBuilder.tenants().get(tenant1).getLocalSessionRepo().addSession(session2); - testTenantBuilder.tenants().get(tenant2).getLocalSessionRepo().addSession(new MockSession(3l, FilesApplicationPackage.fromFile(new File("src/test/apps/content2")))); - testTenantBuilder.tenants().get(tenant1).getApplicationRepo().createPutApplicationTransaction(idTenant1, 2l).commit(); - testTenantBuilder.tenants().get(tenant2).getApplicationRepo().createPutApplicationTransaction(idTenant2, 3l).commit(); + Tenant tenant1 = tenantRepository.getTenant(tenantName1); + tenant1.getLocalSessionRepo().addSession(session2); + tenant1.getApplicationRepo().createPutApplicationTransaction(idTenant1, 2l).commit(); + + MockSession session3 = new MockSession(3l, FilesApplicationPackage.fromFile(new File("src/test/apps/content2"))); + Tenant tenant2 = tenantRepository.getTenant(tenantName2); + tenant2.getLocalSessionRepo().addSession(session3); + tenant2.getApplicationRepo().createPutApplicationTransaction(idTenant2, 3l).commit(); + handler = new ApplicationHandler(ApplicationHandler.testOnlyContext(), Zone.defaultZone(), - new ApplicationRepository(testTenantBuilder.createTenants(), + new ApplicationRepository(tenantRepository, new MockProvisioner(), - Clock.systemUTC())); + clock)); pathPrefix = createPath(idTenant1, Zone.defaultZone()); baseUrl = baseServer + pathPrefix; } @@ -76,7 +86,7 @@ public class ApplicationContentHandlerTest extends ContentHandlerTestBase { } @Test - public void require_that_nonexistant_application_returns_not_found() throws IOException { + public void require_that_nonexistant_application_returns_not_found() { assertNotFound(HttpRequest.createTestRequest(baseServer + createPath(new ApplicationId.Builder() .tenant("tenant") .applicationName("notexist").instanceName("baz").build(), Zone.defaultZone()), diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java index fada72f6e8f..06c64acab33 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ApplicationHandlerTest.java @@ -35,6 +35,7 @@ import com.yahoo.vespa.config.server.session.RemoteSession; import com.yahoo.vespa.config.server.session.SessionContext; import com.yahoo.vespa.config.server.session.SessionZooKeeperClient; import com.yahoo.vespa.config.server.tenant.Tenant; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.curator.mock.MockCurator; import com.yahoo.vespa.model.VespaModelFactory; @@ -80,11 +81,17 @@ public class ApplicationHandlerTest { @Before public void setup() { - TestTenantBuilder testBuilder = new TestTenantBuilder(); - testBuilder.createTenant(mytenantName).withReloadHandler(new MockReloadHandler()); - testBuilder.createTenant(foobar).withReloadHandler(new MockReloadHandler()); + TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + tenantRepository = new TenantRepository(componentRegistry, false); + + TenantBuilder tenantBuilder1 = TenantBuilder.create(componentRegistry, mytenantName) + .withReloadHandler(new MockReloadHandler()); + tenantRepository.addTenant(tenantBuilder1); + + TenantBuilder tenantBuilder2 = TenantBuilder.create(componentRegistry, foobar) + .withReloadHandler(new MockReloadHandler()); + tenantRepository.addTenant(tenantBuilder2); - tenantRepository = testBuilder.createTenants(); provisioner = new SessionHandlerTest.MockProvisioner(); mockHandler = createMockApplicationHandler( provisioner, diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java index 4d4b03e2d4c..537ab5a9f3e 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HostHandlerTest.java @@ -10,6 +10,7 @@ import com.yahoo.vespa.config.server.host.HostRegistries; import com.yahoo.vespa.config.server.host.HostRegistry; import com.yahoo.vespa.config.server.http.HandlerTest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; import com.yahoo.vespa.config.server.tenant.TenantRepository; import org.junit.Before; import org.junit.Test; @@ -36,11 +37,12 @@ public class HostHandlerTest { private HostHandler hostHandler; @Before - public void setup() throws Exception { - TestTenantBuilder testBuilder = new TestTenantBuilder(); - testBuilder.createTenant(mytenant).withReloadHandler(new MockReloadHandler()); - - tenantRepository = testBuilder.createTenants(); + public void setup() { + TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + tenantRepository = new TenantRepository(componentRegistry, false); + TenantBuilder tb = TenantBuilder.create(componentRegistry, mytenant) + .withReloadHandler(new MockReloadHandler()); + tenantRepository.addTenant(tb); handler = createHostHandler(); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java index 463574e08e8..5226ff38ce3 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpGetConfigHandlerTest.java @@ -12,7 +12,9 @@ import java.util.Collections; import java.util.HashSet; import com.yahoo.config.provision.TenantName; +import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.http.HttpErrorResponse; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; import com.yahoo.vespa.config.server.tenant.TenantRepository; import org.junit.Before; import org.junit.Test; @@ -40,17 +42,15 @@ public class HttpGetConfigHandlerTest { private HttpGetConfigHandler handler; @Before - public void setUp() throws Exception { + public void setUp() { mockRequestHandler = new MockRequestHandler(); mockRequestHandler.setAllConfigs(new HashSet<ConfigKey<?>>() {{ add(new ConfigKey<>("bar", "myid", "foo")); - }} ); - TestTenantBuilder tb = new TestTenantBuilder(); - tb.createTenant(tenant).withRequestHandler(mockRequestHandler).build(); - TenantRepository tenantRepository = tb.createTenants(); - handler = new HttpGetConfigHandler( - HttpGetConfigHandler.testOnlyContext(), - tenantRepository); + }} ); + TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + TenantRepository tenantRepository = new TenantRepository(componentRegistry, false); + tenantRepository.addTenant(TenantBuilder.create(componentRegistry, tenant).withRequestHandler(mockRequestHandler)); + handler = new HttpGetConfigHandler(HttpGetConfigHandler.testOnlyContext(), tenantRepository); } @Test diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java index 365fb3ed1f0..750ad1c9fc0 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/HttpListConfigsHandlerTest.java @@ -6,7 +6,9 @@ import com.yahoo.config.provision.Zone; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.vespa.config.ConfigKey; +import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.rpc.MockRequestHandler; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.config.server.http.HandlerTest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; @@ -26,30 +28,33 @@ import static com.yahoo.jdisc.http.HttpResponse.Status.*; import static com.yahoo.jdisc.http.HttpRequest.Method.GET; /** - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class HttpListConfigsHandlerTest { - + + private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + private MockRequestHandler mockRequestHandler; private HttpListConfigsHandler handler; private HttpListNamedConfigsHandler namedHandler; @Before - public void setUp() throws Exception { + public void setUp() { mockRequestHandler = new MockRequestHandler(); mockRequestHandler.setAllConfigs(new HashSet<ConfigKey<?>>() {{ add(new ConfigKey<>("bar", "conf/id", "foo")); }} ); - TestTenantBuilder tb = new TestTenantBuilder(); - tb.createTenant(TenantName.from("mytenant")).withRequestHandler(mockRequestHandler).build(); - TenantRepository tenantRepository = tb.createTenants(); - handler = new HttpListConfigsHandler( - HttpListConfigsHandler.testOnlyContext(), - tenantRepository, Zone.defaultZone()); - namedHandler = new HttpListNamedConfigsHandler( - HttpListConfigsHandler.testOnlyContext(), - tenantRepository, Zone.defaultZone()); + TenantName tenantName = TenantName.from("mytenant"); + TenantRepository tenantRepository = new TenantRepository(componentRegistry, false); + TenantBuilder tenantBuilder = TenantBuilder.create(componentRegistry, tenantName) + .withRequestHandler(mockRequestHandler); + tenantRepository.addTenant(tenantBuilder); + handler = new HttpListConfigsHandler(HttpListConfigsHandler.testOnlyContext(), + tenantRepository, + Zone.defaultZone()); + namedHandler = new HttpListNamedConfigsHandler(HttpListConfigsHandler.testOnlyContext(), + tenantRepository, + Zone.defaultZone()); } @Test diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java index eeaed92bd65..f57e7f09b39 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/ListApplicationsHandlerTest.java @@ -6,8 +6,10 @@ import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.jdisc.http.HttpRequest.Method; import com.yahoo.jdisc.Response; +import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.http.SessionHandlerTest; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; import com.yahoo.vespa.config.server.tenant.TenantRepository; import org.junit.Test; import org.junit.Before; @@ -21,27 +23,27 @@ import static org.junit.Assert.assertThat; import static com.yahoo.jdisc.http.HttpRequest.Method.*; /** - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class ListApplicationsHandlerTest { + private static final TenantName mytenant = TenantName.from("mytenant"); + private static final TenantName foobar = TenantName.from("foobar"); + + private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + private TenantApplications applicationRepo, applicationRepo2; private ListApplicationsHandler handler; @Before - public void setup() throws Exception { - TestTenantBuilder testBuilder = new TestTenantBuilder(); - TenantName mytenant = TenantName.from("mytenant"); - TenantName foobar = TenantName.from("foobar"); - testBuilder.createTenant(mytenant); - testBuilder.createTenant(foobar); - applicationRepo = testBuilder.tenants().get(mytenant).getApplicationRepo(); - applicationRepo2 = testBuilder.tenants().get(foobar).getApplicationRepo(); - TenantRepository tenantRepository = testBuilder.createTenants(); - handler = new ListApplicationsHandler( - ListApplicationsHandler.testOnlyContext(), - tenantRepository, - new Zone(Environment.dev, RegionName.from("us-east"))); + public void setup() { + TenantRepository tenantRepository = new TenantRepository(componentRegistry, false); + tenantRepository.addTenant(TenantBuilder.create(componentRegistry, mytenant)); + tenantRepository.addTenant(TenantBuilder.create(componentRegistry, foobar)); + applicationRepo = tenantRepository.getTenant(mytenant).getApplicationRepo(); + applicationRepo2 = tenantRepository.getTenant(foobar).getApplicationRepo(); + handler = new ListApplicationsHandler(ListApplicationsHandler.testOnlyContext(), + tenantRepository, + new Zone(Environment.dev, RegionName.from("us-east"))); } @Test diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java index da21dccf580..e14e59b9fe7 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionActiveHandlerTest.java @@ -39,9 +39,9 @@ import com.yahoo.vespa.config.server.session.RemoteSession; import com.yahoo.vespa.config.server.session.RemoteSessionRepo; import com.yahoo.vespa.config.server.session.Session; import com.yahoo.vespa.config.server.session.SessionContext; -import com.yahoo.vespa.config.server.session.SessionFactory; import com.yahoo.vespa.config.server.session.SessionTest; import com.yahoo.vespa.config.server.session.SessionZooKeeperClient; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.config.server.zookeeper.ConfigCurator; import com.yahoo.vespa.curator.Curator; @@ -86,6 +86,8 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { private MockProvisioner hostProvisioner; private VespaModelFactory modelFactory; private TestComponentRegistry componentRegistry; + private TenantRepository tenantRepository; + private SessionActiveHandler handler; @Before public void setup() { @@ -102,6 +104,14 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { .configCurator(configCurator) .modelFactoryRegistry(new ModelFactoryRegistry(Collections.singletonList(modelFactory))) .build(); + TenantBuilder tenantBuilder = TenantBuilder.create(componentRegistry, tenantName) + .withSessionFactory(new MockSessionFactory()) + .withLocalSessionRepo(localRepo) + .withRemoteSessionRepo(remoteSessionRepo) + .withApplicationRepo(applicationRepo); + tenantRepository = new TenantRepository(componentRegistry, false); + tenantRepository.addTenant(tenantBuilder); + handler = createHandler(); } @Test @@ -119,7 +129,7 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { @Test public void testUnknownSession() { - HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.ACTIVE, 9999L, "?timeout=1.0")); + HttpResponse response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.ACTIVE, 9999L, "?timeout=1.0")); assertEquals(response.getStatus(), NOT_FOUND); } @@ -152,7 +162,7 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { @Test public void testAlreadyActivatedSession() throws Exception { activateAndAssertOK(1, 0); - HttpResponse response = createHandler().handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.ACTIVE, 1l)); + HttpResponse response = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.ACTIVE, 1l)); String message = getRenderedString(response); assertThat(message, response.getStatus(), Is.is(BAD_REQUEST)); assertThat(message, containsString("Session 1 is already active")); @@ -245,7 +255,7 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { } private void testUnsupportedMethod(com.yahoo.container.jdisc.HttpRequest request) throws Exception { - HttpResponse response = createHandler().handle(request); + HttpResponse response = handler.handle(request); HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, METHOD_NOT_ALLOWED, HttpErrorResponse.errorCodes.METHOD_NOT_ALLOWED, @@ -256,7 +266,6 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { private long sessionId; private RemoteSession session; - private SessionHandler handler; private HttpResponse actResponse; private Session.Status initialStatus; private DeployData deployData; @@ -303,7 +312,6 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { session = createRemoteSession(sessionId, initialStatus, zkClient, clock); addLocalSession(sessionId, deployData, zkClient); metaData = localRepo.getSession(sessionId).getMetaData(); - handler = createHandler(); actResponse = handler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.ACTIVE, sessionId, subPath)); return this; } @@ -342,20 +350,11 @@ public class SessionActiveHandlerTest extends SessionHandlerTest { zkc.writeApplicationId(id); } - private SessionHandler createHandler() { - final SessionFactory sessionFactory = new MockSessionFactory(); - TestTenantBuilder testTenantBuilder = new TestTenantBuilder(); - testTenantBuilder.createTenant(tenantName) - .withSessionFactory(sessionFactory) - .withLocalSessionRepo(localRepo) - .withRemoteSessionRepo(remoteSessionRepo) - .withApplicationRepo(applicationRepo) - .build(); - return new SessionActiveHandler( - SessionActiveHandler.testOnlyContext(), - new ApplicationRepository(testTenantBuilder.createTenants(), hostProvisioner, clock), - testTenantBuilder.createTenants(), - Zone.defaultZone()); + private SessionActiveHandler createHandler() { + return new SessionActiveHandler(SessionActiveHandler.testOnlyContext(), + new ApplicationRepository(tenantRepository, hostProvisioner, clock), + tenantRepository, + Zone.defaultZone()); } } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java index e4841930cc8..1428e384f2b 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionContentHandlerTest.java @@ -5,13 +5,15 @@ import com.google.common.io.Files; import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.provision.TenantName; import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.logging.AccessLog; import com.yahoo.jdisc.Response; import com.yahoo.jdisc.http.HttpRequest; import com.yahoo.text.Utf8; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.http.ContentHandlerTestBase; import com.yahoo.vespa.config.server.http.SessionHandlerTest; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; +import com.yahoo.vespa.config.server.tenant.TenantRepository; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Ignore; @@ -22,22 +24,28 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.time.Clock; -import java.util.concurrent.Executor; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; /** - * @author lulf - * @since 5.1 + * @author Ulf Lilleengen */ public class SessionContentHandlerTest extends ContentHandlerTestBase { private static final TenantName tenant = TenantName.from("contenttest"); + + private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + private final Clock clock = componentRegistry.getClock(); + + private TenantRepository tenantRepository; private SessionContentHandler handler = null; @Before public void setupHandler() throws Exception { + tenantRepository = new TenantRepository(componentRegistry, false); + tenantRepository.addTenant(TenantBuilder.create(componentRegistry, tenant)); + tenantRepository.getTenant(tenant).getLocalSessionRepo().addSession(new MockSession(1L, FilesApplicationPackage.fromFile(createTestApp()))); handler = createHandler(); pathPrefix = "/application/v2/tenant/" + tenant + "/session/"; baseUrl = "http://foo:1337/application/v2/tenant/" + tenant + "/session/1/content/"; @@ -54,14 +62,14 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase { @Test @Ignore - public void require_that_mkdir_with_body_is_illegal() throws IOException { + public void require_that_mkdir_with_body_is_illegal(){ HttpResponse response = put("/foobio/", "foo"); assertNotNull(response); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST)); } @Test - public void require_that_nonexistant_session_returns_not_found() throws IOException { + public void require_that_nonexistant_session_returns_not_found() { HttpResponse response = doRequest(HttpRequest.Method.GET, "/test.txt", 2l); assertNotNull(response); assertThat(response.getStatus(), is(Response.Status.NOT_FOUND)); @@ -73,7 +81,7 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase { } @Test - public void require_that_file_write_without_body_is_illegal() throws IOException { + public void require_that_file_write_without_body_is_illegal() { HttpResponse response = doRequest(HttpRequest.Method.PUT, "/foobio.txt"); assertNotNull(response); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST)); @@ -136,7 +144,7 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase { is("{\"prepared\":\"http://foo:1337" + pathPrefix + "1/prepared\"}")); } - protected File createTestApp() throws IOException { + private File createTestApp() throws IOException { File testApp = Files.createTempDir(); FileUtils.copyDirectory(new File("src/test/apps/content"), testApp); return testApp; @@ -146,26 +154,22 @@ public class SessionContentHandlerTest extends ContentHandlerTestBase { return doRequest(method, path, 1l); } - protected HttpResponse doRequest(HttpRequest.Method method, String path, long sessionId) { + private HttpResponse doRequest(HttpRequest.Method method, String path, long sessionId) { return handler.handle(SessionHandlerTest.createTestRequest(pathPrefix, method, Cmd.CONTENT, sessionId, path)); } - protected HttpResponse doRequest(HttpRequest.Method method, String path, InputStream data) { + private HttpResponse doRequest(HttpRequest.Method method, String path, InputStream data) { return doRequest(method, path, 1l, data); } - protected HttpResponse doRequest(HttpRequest.Method method, String path, long sessionId, InputStream data) { + private HttpResponse doRequest(HttpRequest.Method method, String path, long sessionId, InputStream data) { return handler.handle(SessionHandlerTest.createTestRequest(pathPrefix, method, Cmd.CONTENT, sessionId, path, data)); } - private SessionContentHandler createHandler() throws Exception { - TestTenantBuilder testTenantBuilder = new TestTenantBuilder(); - testTenantBuilder.createTenant(tenant).getLocalSessionRepo().addSession(new MockSession(1l, FilesApplicationPackage.fromFile(createTestApp()))); + private SessionContentHandler createHandler() { return new SessionContentHandler( SessionContentHandler.testOnlyContext(), - new ApplicationRepository(testTenantBuilder.createTenants(), - new SessionHandlerTest.MockProvisioner(), - Clock.systemUTC()), - testTenantBuilder.createTenants()); + new ApplicationRepository(tenantRepository, new SessionHandlerTest.MockProvisioner(), clock), + tenantRepository); } } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java index 73579b94086..7c0e410d244 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionCreateHandlerTest.java @@ -1,13 +1,13 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.config.server.http.v2; -import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.TenantName; import com.yahoo.container.jdisc.HttpRequest; import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.vespa.config.server.ApplicationRepository; +import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.MemoryTenantApplications; import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.http.CompressedApplicationInputStreamTest; @@ -15,7 +15,7 @@ import com.yahoo.vespa.config.server.http.HandlerTest; import com.yahoo.vespa.config.server.http.HttpErrorResponse; import com.yahoo.vespa.config.server.http.SessionHandlerTest; import com.yahoo.vespa.config.server.session.LocalSessionRepo; -import com.yahoo.vespa.config.server.session.SessionFactory; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; import com.yahoo.vespa.config.server.tenant.TenantRepository; import org.junit.Before; import org.junit.Ignore; @@ -40,7 +40,6 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; /** * @author hmusum @@ -48,9 +47,11 @@ import static org.junit.Assert.fail; public class SessionCreateHandlerTest extends SessionHandlerTest { private static final TenantName tenant = TenantName.from("test"); - private static final HashMap<String, String> postHeaders = new HashMap<>(); + private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + private final Clock clock = componentRegistry.getClock(); + private String pathPrefix = "/application/v2/session/"; private String createdMessage = " created.\""; private String tenantMessage = ""; @@ -58,15 +59,24 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { public File testApp = new File("src/test/apps/app"); private LocalSessionRepo localSessionRepo; private TenantApplications applicationRepo; + private TenantRepository tenantRepository; + private MockSessionFactory sessionFactory; static { postHeaders.put(ApplicationApiHandler.contentTypeHeader, ApplicationApiHandler.APPLICATION_X_GZIP); } @Before - public void setupRepo() throws Exception { + public void setupRepo() { applicationRepo = new MemoryTenantApplications(); localSessionRepo = new LocalSessionRepo(Clock.systemUTC()); + tenantRepository = new TenantRepository(componentRegistry, false); + sessionFactory = new MockSessionFactory(); + TenantBuilder tenantBuilder = TenantBuilder.create(componentRegistry, tenant) + .withSessionFactory(sessionFactory) + .withLocalSessionRepo(localSessionRepo) + .withApplicationRepo(applicationRepo); + tenantRepository.addTenant(tenantBuilder); pathPrefix = "/application/v2/tenant/" + tenant + "/session/"; createdMessage = " for tenant '" + tenant + "' created.\""; tenantMessage = ",\"tenant\":\"test\""; @@ -98,20 +108,18 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { public void require_that_application_name_is_given_from_parameter() throws IOException { Map<String, String> params = Collections.singletonMap("name", "ulfio"); File outFile = CompressedApplicationInputStreamTest.createTarFile(); - MockSessionFactory factory = new MockSessionFactory(); - createHandler(factory).handle(post(outFile, postHeaders, params)); - assertTrue(factory.createCalled); - assertThat(factory.applicationName, is("ulfio")); + createHandler().handle(post(outFile, postHeaders, params)); + assertTrue(sessionFactory.createCalled); + assertThat(sessionFactory.applicationName, is("ulfio")); } private void assertFromParameter(String expected, String from) throws IOException { HttpRequest request = post(Collections.singletonMap("from", from)); - MockSessionFactory factory = new MockSessionFactory(); - factory.applicationPackage = testApp; - HttpResponse response = createHandler(factory).handle(request); + sessionFactory.applicationPackage = testApp; + HttpResponse response = createHandler().handle(request); assertNotNull(response); assertThat(response.getStatus(), is(OK)); - assertTrue(factory.createFromCalled); + assertTrue(sessionFactory.createFromCalled); assertThat(SessionHandlerTest.getRenderedString(response), is("{\"log\":[]" + tenantMessage + ",\"session-id\":\"" + expected + "\",\"prepared\":\"http://" + hostname + ":" + port + pathPrefix + expected + "/prepared\",\"content\":\"http://" + hostname + ":" + port + pathPrefix + @@ -139,9 +147,8 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { @Test public void require_that_session_factory_is_called() throws IOException { - MockSessionFactory sessionFactory = new MockSessionFactory(); File outFile = CompressedApplicationInputStreamTest.createTarFile(); - createHandler(sessionFactory).handle(post(outFile)); + createHandler().handle(post(outFile)); assertTrue(sessionFactory.createCalled); } @@ -155,10 +162,9 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { @Test public void require_internal_error_when_exception() throws IOException { - MockSessionFactory factory = new MockSessionFactory(); - factory.doThrow = true; + sessionFactory.doThrow = true; File outFile = CompressedApplicationInputStreamTest.createTarFile(); - HttpResponse response = createHandler(factory).handle(post(outFile)); + HttpResponse response = createHandler().handle(post(outFile)); HandlerTest.assertHttpStatusCodeErrorCodeAndMessage(response, INTERNAL_SERVER_ERROR, HttpErrorResponse.errorCodes.INTERNAL_SERVER_ERROR, "foo"); @@ -166,9 +172,8 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { @Test public void require_that_handler_unpacks_application() throws IOException { - MockSessionFactory sessionFactory = new MockSessionFactory(); File outFile = CompressedApplicationInputStreamTest.createTarFile(); - createHandler(sessionFactory).handle(post(outFile)); + createHandler().handle(post(outFile)); assertTrue(sessionFactory.createCalled); final File applicationPackage = sessionFactory.applicationPackage; assertNotNull(applicationPackage); @@ -181,7 +186,7 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { @Test public void require_that_session_is_stored_in_repo() throws IOException { File outFile = CompressedApplicationInputStreamTest.createTarFile(); - createHandler(new MockSessionFactory()).handle(post(outFile)); + createHandler().handle(post(outFile)); assertNotNull(localSessionRepo.getSession(0l)); } @@ -217,37 +222,13 @@ public class SessionCreateHandlerTest extends SessionHandlerTest { } private SessionCreateHandler createHandler() { - try { - return createHandler(new MockSessionFactory()); - } catch (Exception e) { - e.printStackTrace(); - fail(e.getMessage()); - } - return null; - } - - private SessionCreateHandler createHandler(SessionFactory sessionFactory) { - try { - TestTenantBuilder testBuilder = new TestTenantBuilder(); - testBuilder.createTenant(tenant).withSessionFactory(sessionFactory) - .withLocalSessionRepo(localSessionRepo) - .withApplicationRepo(applicationRepo); - return createHandler(testBuilder.createTenants()); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - private SessionCreateHandler createHandler(TenantRepository tenantRepository) throws Exception { - TestTenantBuilder testTenantBuilder = new TestTenantBuilder(); - final ConfigserverConfig configserverConfig = new ConfigserverConfig(new ConfigserverConfig.Builder()); return new SessionCreateHandler( SessionCreateHandler.testOnlyContext(), - new ApplicationRepository(testTenantBuilder.createTenants(), + new ApplicationRepository(tenantRepository, new SessionHandlerTest.MockProvisioner(), - Clock.systemUTC()), - tenantRepository, configserverConfig); + clock), + tenantRepository, + componentRegistry.getConfigserverConfig()); } diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java index 1759cd68062..149bec7ab79 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/SessionPrepareHandlerTest.java @@ -3,7 +3,6 @@ package com.yahoo.vespa.config.server.http.v2; import com.google.common.collect.ImmutableMap; import com.google.common.util.concurrent.UncheckedTimeoutException; -import com.yahoo.cloud.config.ConfigserverConfig; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.config.application.api.DeployLogger; import com.yahoo.config.model.api.ServiceInfo; @@ -13,7 +12,6 @@ import com.yahoo.config.provision.ApplicationLockException; import com.yahoo.config.provision.OutOfCapacityException; import com.yahoo.config.provision.TenantName; import com.yahoo.container.jdisc.HttpResponse; -import com.yahoo.container.logging.AccessLog; import com.yahoo.jdisc.http.HttpRequest; import com.yahoo.path.Path; import com.yahoo.slime.JsonDecoder; @@ -23,13 +21,14 @@ import com.yahoo.vespa.config.server.ApplicationRepository; import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.host.HostRegistry; -import com.yahoo.vespa.config.server.application.TenantApplications; import com.yahoo.vespa.config.server.application.MemoryTenantApplications; import com.yahoo.vespa.config.server.configchange.ConfigChangeActions; import com.yahoo.vespa.config.server.configchange.MockRefeedAction; import com.yahoo.vespa.config.server.configchange.MockRestartAction; import com.yahoo.vespa.config.server.http.*; import com.yahoo.vespa.config.server.session.*; +import com.yahoo.vespa.config.server.tenant.TenantBuilder; +import com.yahoo.vespa.config.server.tenant.TenantRepository; import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.mock.MockCurator; import org.junit.Before; @@ -57,30 +56,36 @@ import static org.junit.Assert.assertThat; /** * @author hmusum - * - * @since 5.1.14 */ public class SessionPrepareHandlerTest extends SessionHandlerTest { private static final TenantName tenant = TenantName.from("test"); - private TestTenantBuilder builder; + + private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); + private final Clock clock = componentRegistry.getClock(); private Curator curator; - private SessionZooKeeperClient zooKeeperClient; private LocalSessionRepo localRepo; - private TenantApplications applicationRepo; private String preparedMessage = " prepared.\"}"; private String tenantMessage = ""; + private RemoteSessionRepo remoteSessionRepo; + private TenantRepository tenantRepository; @Before - public void setupRepo() throws Exception { - applicationRepo = new MemoryTenantApplications(); + public void setupRepo() { curator = new MockCurator(); - localRepo = new LocalSessionRepo(Clock.systemUTC()); + localRepo = new LocalSessionRepo(clock); pathPrefix = "/application/v2/tenant/" + tenant + "/session/"; preparedMessage = " for tenant '" + tenant + "' prepared.\""; tenantMessage = ",\"tenant\":\"" + tenant + "\""; - builder = new TestTenantBuilder(); + tenantRepository = new TenantRepository(componentRegistry, false); + remoteSessionRepo = new RemoteSessionRepo(tenant); + TenantBuilder tenantBuilder = TenantBuilder.create(componentRegistry, tenant) + .withSessionFactory(new MockSessionFactory()) + .withLocalSessionRepo(localRepo) + .withRemoteSessionRepo(remoteSessionRepo) + .withApplicationRepo(new MemoryTenantApplications()); + tenantRepository.addTenant(tenantBuilder); } @Test @@ -144,30 +149,31 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { } /** - * A mock remote session repo based on contents of local repo + * A mock remote session repo based on contents of local repo. Only works when there is just one session in local repo */ - private RemoteSessionRepo fromLocalSessionRepo(LocalSessionRepo localRepo, Clock clock) { - RemoteSessionRepo remoteRepo = new RemoteSessionRepo(tenant); + // TODO: Fix this mess + private SessionZooKeeperClient fromLocalSessionRepo(LocalSessionRepo localRepo) { + SessionZooKeeperClient zooKeeperClient = null; for (LocalSession ls : localRepo.listSessions()) { - zooKeeperClient = new MockSessionZKClient(curator, tenant, ls.getSessionId()); if (ls.getStatus()!=null) zooKeeperClient.writeStatus(ls.getStatus()); RemoteSession remSess = new RemoteSession(tenant, ls.getSessionId(), new TestComponentRegistry.Builder().curator(curator).build(), zooKeeperClient, clock); - remoteRepo.addSession(remSess); + remoteSessionRepo.addSession(remSess); } - return remoteRepo; + return zooKeeperClient; } @Test public void require_get_response_activate_url_on_ok() throws Exception { MockSession session = new MockSession(1, null); localRepo.addSession(session); - SessionHandler sessHandler = createHandler(fromLocalSessionRepo(localRepo, Clock.systemUTC())); + SessionHandler sessHandler = createHandler(); sessHandler.handle(SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L)); session.setStatus(Session.Status.PREPARE); + SessionZooKeeperClient zooKeeperClient = fromLocalSessionRepo(localRepo); zooKeeperClient.writeStatus(Session.Status.PREPARE); HttpResponse getResponse = sessHandler.handle( SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.GET, Cmd.PREPARED, 1L)); @@ -179,8 +185,9 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { public void require_get_response_error_on_not_prepared() throws Exception { MockSession session = new MockSession(1, null); localRepo.addSession(session); - SessionHandler sessHandler = createHandler(fromLocalSessionRepo(localRepo, Clock.systemUTC())); + SessionHandler sessHandler = createHandler(); session.setStatus(Session.Status.NEW); + SessionZooKeeperClient zooKeeperClient = fromLocalSessionRepo(localRepo); zooKeeperClient.writeStatus(Session.Status.NEW); HttpResponse getResponse = sessHandler.handle( SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.GET, Cmd.PREPARED, 1L)); @@ -201,7 +208,7 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { MockSession session = new MockSession(1, null); localRepo.addSession(session); session.setStatus(Session.Status.ACTIVATE); - SessionHandler sessionHandler = createHandler(fromLocalSessionRepo(localRepo, Clock.systemUTC())); + SessionHandler sessionHandler = createHandler(); HttpResponse putResponse = sessionHandler.handle( SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.PUT, Cmd.PREPARED, 1L)); assertHttpStatusCodeErrorCodeAndMessage(putResponse, BAD_REQUEST, @@ -213,7 +220,7 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { public void require_get_response_error_when_session_id_does_not_exist() throws Exception { MockSession session = new MockSession(1, null); localRepo.addSession(session); - SessionHandler sessHandler = createHandler(fromLocalSessionRepo(localRepo, Clock.systemUTC())); + SessionHandler sessHandler = createHandler(); HttpResponse getResponse = sessHandler.handle( SessionHandlerTest.createTestRequest(pathPrefix, HttpRequest.Method.GET, Cmd.PREPARED, 9999L)); assertHttpStatusCodeErrorCodeAndMessage(getResponse, NOT_FOUND, @@ -235,12 +242,15 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { @Test public void require_that_preparing_with_multiple_tenants_work() throws Exception { - // Need different repos for 'default' tenant as opposed to the 'test' tenant - LocalSessionRepo localRepoDefault = new LocalSessionRepo(Clock.systemUTC()); - final TenantName defaultTenant = TenantName.defaultName(); - addTenant(defaultTenant, localRepoDefault, new RemoteSessionRepo(tenant), new MockSessionFactory()); - addTestTenant(); - final SessionHandler handler = createHandler(builder); + // Need different repo for 'test2' tenant + LocalSessionRepo localRepoDefault = new LocalSessionRepo(clock); + final TenantName defaultTenant = TenantName.from("test2"); + TenantBuilder defaultTenantBuilder = TenantBuilder.create(componentRegistry, defaultTenant) + .withLocalSessionRepo(localRepoDefault) + .withRemoteSessionRepo(new RemoteSessionRepo(defaultTenant)) + .withSessionFactory(new MockSessionFactory()); + tenantRepository.addTenant(defaultTenantBuilder); + final SessionHandler handler = createHandler(); long sessionId = 1; // Deploy with default tenant @@ -370,39 +380,16 @@ public class SessionPrepareHandlerTest extends SessionHandlerTest { } private SessionHandler createHandler() { - return createHandler(addTestTenant()); - } - - private SessionHandler createHandler(RemoteSessionRepo remoteSessionRepo) { - return createHandler(addTenant(tenant, localRepo, remoteSessionRepo, new MockSessionFactory())); - } - - private TestTenantBuilder addTestTenant() { - return addTenant(tenant, localRepo, new RemoteSessionRepo(tenant), new MockSessionFactory()); - } - - private SessionHandler createHandler(TestTenantBuilder builder) { - final ConfigserverConfig configserverConfig = new ConfigserverConfig(new ConfigserverConfig.Builder()); return new SessionPrepareHandler( SessionPrepareHandler.testOnlyContext(), - new ApplicationRepository(builder.createTenants(), + new ApplicationRepository(tenantRepository, new MockProvisioner(), - Clock.systemUTC()), - builder.createTenants(), configserverConfig); + clock), + tenantRepository, + componentRegistry.getConfigserverConfig()); } - private TestTenantBuilder addTenant(TenantName tenantName, - LocalSessionRepo localSessionRepo, - RemoteSessionRepo remoteSessionRepo, - SessionFactory sessionFactory) { - builder.createTenant(tenantName).withSessionFactory(sessionFactory) - .withLocalSessionRepo(localSessionRepo) - .withRemoteSessionRepo(remoteSessionRepo) - .withApplicationRepo(applicationRepo); - return builder; - } - public static class SessionThrowingException extends LocalSession { private final RuntimeException exception; diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TestTenantBuilder.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TestTenantBuilder.java deleted file mode 100644 index 03f55c7ff1e..00000000000 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TestTenantBuilder.java +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.http.v2; - -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.yahoo.config.provision.TenantName; -import com.yahoo.vespa.config.server.GlobalComponentRegistry; -import com.yahoo.vespa.config.server.TestComponentRegistry; -import com.yahoo.vespa.config.server.application.MemoryTenantApplications; -import com.yahoo.vespa.config.server.session.LocalSessionRepo; -import com.yahoo.vespa.config.server.session.RemoteSessionRepo; -import com.yahoo.vespa.config.server.tenant.Tenant; -import com.yahoo.vespa.config.server.tenant.TenantBuilder; -import com.yahoo.vespa.config.server.tenant.TenantRepository; - -import java.util.*; - -/** - * Test utility for creating tenantRepository used for testing and setup wiring of tenant stuff. - * - * @author Ulf Lilleengen - */ -public class TestTenantBuilder { - - private GlobalComponentRegistry componentRegistry; - private Map<TenantName, TenantBuilder> tenantMap = new HashMap<>(); - - public TestTenantBuilder() { - componentRegistry = new TestComponentRegistry.Builder().build(); - } - - public TenantBuilder createTenant(TenantName tenantName) { - MemoryTenantApplications applicationRepo = new MemoryTenantApplications(); - TenantBuilder builder = TenantBuilder.create(componentRegistry, tenantName) - .withSessionFactory(new SessionCreateHandlerTest.MockSessionFactory()) - .withLocalSessionRepo(new LocalSessionRepo(componentRegistry.getClock())) - .withRemoteSessionRepo(new RemoteSessionRepo(tenantName)) - .withApplicationRepo(applicationRepo); - tenantMap.put(tenantName, builder); - return builder; - } - - public Map<TenantName, TenantBuilder> tenants() { - return Collections.unmodifiableMap(tenantMap); - } - - public TenantRepository createTenants() { - Collection<Tenant> tenantList = Collections2.transform(tenantMap.values(), new Function<TenantBuilder, Tenant>() { - @Override - public Tenant apply(TenantBuilder builder) { - try { - return builder.build(); - } catch (Exception e) { - throw new IllegalArgumentException("Unable to build tenant", e); - } - } - }); - return new TenantRepository(componentRegistry, tenantList); - } -} diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java index ee1b8e5707d..3598af57593 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantRepositoryTest.java @@ -18,7 +18,6 @@ import org.junit.Test; import org.xml.sax.SAXException; import java.io.IOException; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Set; @@ -129,8 +128,8 @@ public class TenantRepositoryTest extends TestWithCurator { } @Test - public void testTenantsChanged() throws Exception { - tenantRepository = new TenantRepository(globalComponentRegistry, new ArrayList<>()); + public void testTenantsChanged() { + tenantRepository = new TenantRepository(globalComponentRegistry); tenantRepository.addTenant(tenant2); tenantRepository.createTenants(); Set<TenantName> allTenants = tenantRepository.getAllTenantNames(); diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java index f3216764a5d..1975899355c 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/tenant/TenantTest.java @@ -3,10 +3,9 @@ package com.yahoo.vespa.config.server.tenant; import com.google.common.testing.EqualsTester; import com.yahoo.config.provision.TenantName; +import com.yahoo.vespa.config.server.TestComponentRegistry; import com.yahoo.vespa.config.server.TestWithCurator; import com.yahoo.vespa.config.server.application.MemoryTenantApplications; -import com.yahoo.vespa.config.server.http.v2.TestTenantBuilder; -import com.yahoo.vespa.config.server.tenant.Tenant; import org.junit.Before; import org.junit.Test; @@ -19,6 +18,7 @@ import static org.junit.Assert.*; * @since 5.3 */ public class TenantTest extends TestWithCurator { + private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build(); private Tenant t1; private Tenant t2; @@ -26,15 +26,20 @@ public class TenantTest extends TestWithCurator { private Tenant t4; @Before - public void setupTenant() throws Exception { + public void setupTenant() { t1 = createTenant("foo"); t2 = createTenant("foo"); t3 = createTenant("bar"); t4 = createTenant("baz"); } - private Tenant createTenant(String name) throws Exception { - return new TestTenantBuilder().createTenant(TenantName.from(name)).build(); + private Tenant createTenant(String name) { + TenantRepository tenantRepository = new TenantRepository(componentRegistry, false); + TenantName tenantName = TenantName.from(name); + TenantBuilder tenantBuilder = TenantBuilder.create(componentRegistry, tenantName) + .withApplicationRepo(new MemoryTenantApplications()); + tenantRepository.addTenant(tenantBuilder); + return tenantRepository.getTenant(tenantName); } @Test diff --git a/container-core/src/main/resources/configdefinitions/qr-searchers.def b/container-core/src/main/resources/configdefinitions/qr-searchers.def index a688749da6d..1f2906f45ff 100644 --- a/container-core/src/main/resources/configdefinitions/qr-searchers.def +++ b/container-core/src/main/resources/configdefinitions/qr-searchers.def @@ -80,9 +80,7 @@ searchcluster[].storagecluster.routespec string default="" searchcluster[].dispatcher[].host string searchcluster[].dispatcher[].port int -## The number of least significant bits of the part id used to specify the -## row number (the rest of the bits specifies the column). Don't touch -## this unless you know why you are doing it. +## Not used. TODO: Remove on Vespa 7 searchcluster[].rowbits int default=0 # Per dispatcher config-id might be nice to have, remove it until needed. diff --git a/container-dependency-versions/pom.xml b/container-dependency-versions/pom.xml index 008062a64e0..912ccf7e963 100644 --- a/container-dependency-versions/pom.xml +++ b/container-dependency-versions/pom.xml @@ -435,7 +435,7 @@ <properties> <bouncycastle.version>1.58</bouncycastle.version> - <felix.version>4.4.1</felix.version> + <felix.version>4.6.1</felix.version> <findbugs.version>1.3.9</findbugs.version> <guava.version>18.0</guava.version> <guice.version>3.0</guice.version> diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/RestrictedBundleContext.java b/container-disc/src/main/java/com/yahoo/container/jdisc/RestrictedBundleContext.java index 313e26ba8d4..c9cc8dfdfa4 100644 --- a/container-disc/src/main/java/com/yahoo/container/jdisc/RestrictedBundleContext.java +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/RestrictedBundleContext.java @@ -45,6 +45,11 @@ public class RestrictedBundleContext implements BundleContext { } @Override + public <S> ServiceRegistration<S> registerService(Class<S> aClass, ServiceFactory<S> serviceFactory, Dictionary<String, ?> dictionary) { + return null; + } + + @Override public ServiceReference<?>[] getServiceReferences(String localHostname, String localHostname2) throws InvalidSyntaxException { if (wrapped == null) { return new ServiceReference<?>[0]; @@ -100,6 +105,11 @@ public class RestrictedBundleContext implements BundleContext { return wrapped.ungetService(serviceReference); } + @Override + public <S> ServiceObjects<S> getServiceObjects(ServiceReference<S> serviceReference) { + return null; + } + //--------------------- diff --git a/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java b/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java index c1b0e9ccb37..19f8f9130dc 100644 --- a/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java +++ b/container-search/src/main/java/com/yahoo/fs4/GetDocSumsPacket.java @@ -122,9 +122,6 @@ public class GetDocSumsPacket extends Packet { Hit h = i.next(); if (h instanceof FastHit) { FastHit hit = (FastHit)h; - if (hit.shouldIgnoreRowBits()) { - flags |= GDFLAG_IGNORE_ROW; - } QueryPacketData tag = hit.getQueryPacketData(); if (tag != null) { this.queryPacketData = tag; diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java index 258f0dec9ff..40364824774 100644 --- a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java @@ -195,7 +195,6 @@ public class ClusterSearcher extends Searcher { int dispatchIndex) { return new ClusterParams(searchclusterIndex, "sc" + searchclusterIndex + ".num" + dispatchIndex, - searchClusterConfig.rowbits(), emulConfig); } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheParams.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheParams.java index ef87f684460..cad055d3512 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheParams.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/CacheParams.java @@ -9,6 +9,7 @@ package com.yahoo.prelude.fastsearch; * @author arnej27959 */ public class CacheParams { + public int cacheMegaBytes = 0; public double cacheTimeOutSeconds = 0; public CacheControl cacheControl = null; diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/ClusterParams.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/ClusterParams.java index 54b0b1280f9..f95f303e87c 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/ClusterParams.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/ClusterParams.java @@ -10,32 +10,31 @@ import com.yahoo.container.search.LegacyEmulationConfig; * @author arnej27959 */ public class ClusterParams { + public final int clusterNumber; public final String searcherName; - public final int rowBits; public final LegacyEmulationConfig emulation; /** - * for compatibility - **/ - public ClusterParams(int number, String name, int rowbits) { - this(number, name, rowbits, new LegacyEmulationConfig(new LegacyEmulationConfig.Builder())); + * For compatibility + */ + public ClusterParams(int number, String name) { + this(number, name, new LegacyEmulationConfig(new LegacyEmulationConfig.Builder())); } /** - * for testcases only - **/ + * For testcases only + */ public ClusterParams(String name) { - this(0, name, 0); + this(0, name); } /** - * make up full ClusterParams - **/ - public ClusterParams(int number, String name, int rowbits, LegacyEmulationConfig cfg) { + * Make up full ClusterParams + */ + public ClusterParams(int number, String name, LegacyEmulationConfig cfg) { this.clusterNumber = number; this.searcherName = name; - this.rowBits = rowbits; this.emulation = cfg; } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java index b3eaee8698a..288fd084d0b 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastHit.java @@ -19,38 +19,20 @@ import com.yahoo.data.access.simple.Value.StringValue; */ public class FastHit extends Hit { - public static final String SUMMARY = "summary"; // TODO: Remove on Vespa 7 + private static final GlobalId emptyGlobalId = new GlobalId(new byte[GlobalId.LENGTH]); - private static final long serialVersionUID = 298098891191029589L; - - /** The global id of this document in the backend node which produced it */ - private GlobalId globalId = new GlobalId(new byte[GlobalId.LENGTH]); + /** The index of the content node this hit originated at */ + private int distributionKey = 0; - /** Part ID */ + /** The local identifier of the content store for this hit on the node it originated at */ private int partId; - /** DistributionKey (needed to generate getDocsumPacket, for two-phase search) */ - private int distributionKey = 0; + /** The global id of this document in the backend node which produced it */ + private GlobalId globalId = emptyGlobalId; - /** The index uri of this. Lazily set */ + /** Full information pointing to the location of further data for this hit. Lazily set */ private URI indexUri = null; - /** - * The number of least significant bits in the part id which specifies the - * row in the search cluster which produced this hit. The other bits - * specifies the column. 0 if not known. - */ - private int rowBits = 0; - - /** - * Whether or not to ignore the row bits. If this is set, FastSearcher is - * allowed to choose an appropriate row. - */ - private boolean ignoreRowBits = false; - - /** Whether to use the row number in the index uri, see FastSearcher for details */ - private boolean useRowInIndexUri = true; - private transient QueryPacketData queryPacketData = null; private transient CacheKey cacheKey = null; @@ -70,8 +52,8 @@ public class FastHit extends Hit { super.setField("uri", uri); // TODO: Remove on Vespa 7 setRelevance(new Relevance(relevance)); setSource(source); - types().add(SUMMARY); // TODO: Remove on Vespa 7 - setPartId(0, 0); + types().add("summary"); + setPartId(0); } @Override @@ -117,7 +99,7 @@ public class FastHit extends Hit { URI uri = super.getId(); if (uri != null) return uri; - // TODO: Remove, this should be one of the last vestiges of URL field magic + // TODO: Remove on Vespa 7, this should be one of the last vestiges of URL field magic if (fields().containsKey("uri")) { // trigger decoding Object o = getField("uri"); @@ -137,11 +119,7 @@ public class FastHit extends Hit { public URI getIndexUri() { if (indexUri != null) return indexUri; - String rowString = "-"; - if (useRowInIndexUri) - rowString = String.valueOf(getRow()); - - indexUri = new URI("index:" + getSourceNumber() + "/" + getColumn() + "/" + rowString + "/" + asHexString(getGlobalId())); + indexUri = new URI("index:" + getSourceNumber() + "/" + getPartId() + "/" + asHexString(getGlobalId())); return indexUri; } @@ -165,37 +143,8 @@ public class FastHit extends Hit { * highest row number are the row bits, the rest are column bits. * * @param partId partition id - * @param rowBits number of bits to encode row number */ - public void setPartId(int partId, int rowBits) { - this.partId = partId; - this.rowBits = rowBits; - } - - /** - * Sets whether to use the row in the index uri. See FastSearcher for details. - */ - public void setUseRowInIndexUri(boolean useRowInIndexUri) { - this.useRowInIndexUri = useRowInIndexUri; - } - - /** - * Returns the column number where this hit originated, or partId if not known - */ - public int getColumn() { - return partId >>> rowBits; - } - - /** - * Returns the row number where this hit originated, or 0 if not known - * */ - public int getRow() { - if (rowBits == 0) { - return 0; - } - - return partId & ((1 << rowBits) - 1); - } + public void setPartId(int partId) { this.partId = partId; } /** * <p>Returns a field value from this Hit. The value is either a stored value from the Document represented by @@ -230,19 +179,7 @@ public class FastHit extends Hit { */ @Override public Object getField(String key) { - Object value = super.getField(key); - - if (value instanceof LazyValue) { - return getAndCacheLazyValue(key, (LazyValue) value); - } else { - return value; - } - } - - private Object getAndCacheLazyValue(String key, LazyValue value) { - Object forcedValue = value.getValue(key); - setField(key, forcedValue); - return forcedValue; + return super.getField(key); } /** Returns false - this is a concrete hit containing requested content */ @@ -250,20 +187,12 @@ public class FastHit extends Hit { return false; } - /** - * Only needed when fetching summaries in 2 phase. - * - * @return distribution key of node where the hit originated from - */ + /** Returns the index of the node this hit originated at */ public int getDistributionKey() { return distributionKey; } - /** - * Only needed when fetching summaries in 2 phase. - * - * @param distributionKey Of node where you find this hit. - */ + /** Returns the index of the node this hit originated at */ public void setDistributionKey(int distributionKey) { this.distributionKey = distributionKey; } @@ -287,20 +216,6 @@ public class FastHit extends Hit { } /** - * Set a field to behave like a string type summary field, not decoding raw - * data till actually used. Added to make testing lazy docsum functionality - * easier. This is not a method to be used for efficiency, as it causes - * object allocations. - * - * @param fieldName the name of the field to insert undecoded UTF-8 into - * @param value an array of valid UTF-8 data - */ - @Beta - public void setLazyStringField(String fieldName, byte[] value) { - setField(fieldName, new LazyString(new StringField(fieldName), new StringValue(value))); - } - - /** * Add the binary data common for the query packet to a Vespa backend and a * summary fetch packet to a Vespa backend. This method can only be called * once for a single hit. @@ -336,27 +251,6 @@ public class FastHit extends Hit { this.cacheKey = cacheKey; } - public void setIgnoreRowBits(boolean ignoreRowBits) { - this.ignoreRowBits = ignoreRowBits; - } - - public boolean shouldIgnoreRowBits() { - return ignoreRowBits; - } - - public boolean fieldIsNotDecoded(String name) { - return super.getField(name) instanceof LazyValue; - } - - public RawField fetchFieldAsUtf8(String fieldName) { - Object value = super.getField(fieldName); - if (value instanceof LazyValue) { - return ((LazyValue) value).getFieldAsUtf8(fieldName); - } else { - throw new IllegalStateException("Field " + fieldName + " has already been decoded:" + value); - } - } - public static final class RawField { private final boolean needXmlEscape; @@ -373,30 +267,4 @@ public class FastHit extends Hit { } - private static abstract class LazyValue { - abstract Object getValue(String fieldName); - abstract RawField getFieldAsUtf8(String fieldName); - } - - private static class LazyString extends LazyValue { - - private final Inspector value; - private final DocsumField fieldType; - - LazyString(DocsumField fieldType, Inspector value) { - assert(value.type() == Type.STRING); - this.value = value; - this.fieldType = fieldType; - } - - Object getValue(String fieldName) { - return value.asString(); - } - - RawField getFieldAsUtf8(String fieldName) { - return new RawField(fieldType, value.asUtf8()); - } - - } - } diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java index 740deaa7ca1..7d5b91ab1e3 100644 --- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java +++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/VespaBackEndSearcher.java @@ -53,9 +53,6 @@ import java.util.logging.Level; @SuppressWarnings("deprecation") public abstract class VespaBackEndSearcher extends PingableSearcher { - private static final CompoundName grouping=new CompoundName("grouping"); - private static final CompoundName combinerows=new CompoundName("combinerows"); - protected static final CompoundName PACKET_COMPRESSION_LIMIT = new CompoundName("packetcompressionlimit"); protected static final CompoundName PACKET_COMPRESSION_TYPE = new CompoundName("packetcompressiontype"); protected static final CompoundName TRACE_DISABLE = new CompoundName("trace.disable"); @@ -77,12 +74,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { /** Cache wrapper */ protected CacheControl cacheControl = null; - /** - * The number of last significant bits in the partId which specifies the - * row number in this backend, - * the rest specifies the column. 0 if not known. - */ - private int rowBits = 0; + /** Searchcluster number */ private int sourceNumber; @@ -177,7 +169,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { DocumentdbInfoConfig documentdbInfoConfig) { this.name = clusterParams.searcherName; this.sourceNumber = clusterParams.clusterNumber; - this.rowBits = clusterParams.rowBits; Validator.ensureNotNull("Name of Vespa backend integration", getName()); @@ -535,7 +526,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { FastHit hit = new FastHit(); hit.setQuery(myQuery); - hit.setUseRowInIndexUri(useRowInIndexUri(result)); hit.setFillable(); hit.setCached(true); @@ -565,10 +555,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { return filledAllOfEm; } - private boolean useRowInIndexUri(Result result) { - return ! ((result.getQuery().properties().getString(grouping) != null) || result.getQuery().properties().getBoolean(combinerows)); - } - private void extractDocumentInfo(FastHit hit, DocumentInfo document) { hit.setSourceNumber(sourceNumber); hit.setSource(getName()); @@ -579,7 +565,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { hit.setDistributionKey(document.getDistributionKey()); hit.setGlobalId(document.getGlobalId()); - hit.setPartId(document.getPartId(), rowBits); + hit.setPartId(document.getPartId()); } protected PacketWrapper cacheLookupTwoPhase(CacheKey cacheKey, Result result, String summaryClass) { @@ -637,7 +623,7 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { * @param queryPacketData binary data from first phase of search, or null * @param cacheKey the key this hit should match in the packet cache, or null */ - protected boolean addUnfilledHits(Result result, List<DocumentInfo> documents, boolean fromCache, QueryPacketData queryPacketData, CacheKey cacheKey) { + boolean addUnfilledHits(Result result, List<DocumentInfo> documents, boolean fromCache, QueryPacketData queryPacketData, CacheKey cacheKey) { boolean allHitsOK = true; Query myQuery = result.getQuery(); @@ -650,7 +636,6 @@ public abstract class VespaBackEndSearcher extends PingableSearcher { hit.setQueryPacketData(queryPacketData); hit.setCacheKey(cacheKey); - hit.setUseRowInIndexUri(useRowInIndexUri(result)); hit.setFillable(); hit.setCached(fromCache); diff --git a/container-search/src/main/java/com/yahoo/prelude/templates/DefaultTemplateSet.java b/container-search/src/main/java/com/yahoo/prelude/templates/DefaultTemplateSet.java index 4aa8dea355b..ba7388a11a0 100644 --- a/container-search/src/main/java/com/yahoo/prelude/templates/DefaultTemplateSet.java +++ b/container-search/src/main/java/com/yahoo/prelude/templates/DefaultTemplateSet.java @@ -148,17 +148,17 @@ public class DefaultTemplateSet extends UserTemplate<XMLWriter> { } @Override - public void error(Context context, XMLWriter writer) throws IOException { + public void error(Context context, XMLWriter writer) { ErrorMessage error=((Result)context.get("result")).hits().getError(); writer.openTag(ERROR).attribute(CODE,error.getCode()).content(error.getMessage(),false).closeTag(); } @Override - public void noHits(Context context, XMLWriter writer) throws IOException { + public void noHits(Context context, XMLWriter writer) { // no hits, do nothing :) } - protected static void renderCoverageAttributes(Coverage coverage, XMLWriter writer) throws IOException { + protected static void renderCoverageAttributes(Coverage coverage, XMLWriter writer) { if (coverage == null) return; writer.attribute(COVERAGE_DOCS,coverage.getDocs()); writer.attribute(COVERAGE_NODES,coverage.getNodes()); @@ -211,7 +211,7 @@ public class DefaultTemplateSet extends UserTemplate<XMLWriter> { } - protected void renderId(URI uri, XMLWriter writer) throws IOException { + protected void renderId(URI uri, XMLWriter writer) { if (uri != null) { writer.openTag(ID).content(uri.stringValue(),false).closeTag(); } @@ -228,7 +228,7 @@ public class DefaultTemplateSet extends UserTemplate<XMLWriter> { } } - private void renderSyntheticRelevancyField(Hit hit, XMLWriter writer) throws IOException { + private void renderSyntheticRelevancyField(Hit hit, XMLWriter writer) { final String relevancyFieldName = "relevancy"; final Relevance relevance = hit.getRelevance(); @@ -248,7 +248,7 @@ public class DefaultTemplateSet extends UserTemplate<XMLWriter> { writeCloseFieldElement(writer); } - private void writeOpenFieldElement(String fieldName, XMLWriter writer) throws IOException { + private void writeOpenFieldElement(String fieldName, XMLWriter writer) { Utf8String utf8 = fieldNameMap.get(fieldName); if (utf8 == null) { utf8 = new Utf8String(fieldName); @@ -258,34 +258,19 @@ public class DefaultTemplateSet extends UserTemplate<XMLWriter> { writer.closeStartTag(); } - private void writeCloseFieldElement(XMLWriter writer) throws IOException { // TODO: Collapse + private void writeCloseFieldElement(XMLWriter writer) { writer.closeTag(); } - protected void renderFieldContent(Context context, Hit hit, - String name, XMLWriter writer) - throws IOException { - - boolean dumpedRaw = false; - if (hit instanceof FastHit && ((FastHit)hit).fieldIsNotDecoded(name)) { - writer.closeStartTag(); - if ((writer.getWriter() instanceof ByteWriter) && context.isUtf8Output()) { - dumpedRaw = dumpBytes((ByteWriter) writer.getWriter(), (FastHit) hit, name); - } - if (dumpedRaw) { - writer.content("",false); // let the xml writer note that this tag had content - } - } - if (!dumpedRaw) { - String xmlval = hit.getFieldXML(name); - if (xmlval == null) { - xmlval = "(null)"; - } - writer.escapedContent(xmlval,false); + protected void renderFieldContent(Context context, Hit hit, String name, XMLWriter writer) { + String xmlval = hit.getFieldXML(name); + if (xmlval == null) { + xmlval = "(null)"; } + writer.escapedContent(xmlval,false); } - private void renderSimpleField(String fieldName, Object fieldValue, XMLWriter writer) throws IOException { + private void renderSimpleField(String fieldName, Object fieldValue, XMLWriter writer) { writeOpenFieldElement(fieldName, writer); writer.content(fieldValue.toString(),false); writeCloseFieldElement(writer); diff --git a/container-search/src/main/java/com/yahoo/prelude/templates/UserTemplate.java b/container-search/src/main/java/com/yahoo/prelude/templates/UserTemplate.java index ee058876d16..ac1583b0577 100644 --- a/container-search/src/main/java/com/yahoo/prelude/templates/UserTemplate.java +++ b/container-search/src/main/java/com/yahoo/prelude/templates/UserTemplate.java @@ -292,20 +292,6 @@ public abstract class UserTemplate<T extends Writer> extends GenericTemplateSet public static boolean dumpBytes(ByteWriter writer, FastHit hit, String fieldName) throws java.io.IOException { - FastHit.RawField asBytes; - try { - asBytes = hit.fetchFieldAsUtf8(fieldName); - } catch (RuntimeException e) { - asBytes = null; - } - if (asBytes != null) { - if (asBytes.needXmlEscape()) { - dumpAndXMLQuoteUTF8(writer, asBytes.getUtf8()); - } else { - writer.append(asBytes.getUtf8()); - } - return true; - } return false; } diff --git a/container-search/src/main/java/com/yahoo/search/grouping/vespa/HitConverter.java b/container-search/src/main/java/com/yahoo/search/grouping/vespa/HitConverter.java index d910c10c2be..a095f6dc686 100644 --- a/container-search/src/main/java/com/yahoo/search/grouping/vespa/HitConverter.java +++ b/container-search/src/main/java/com/yahoo/search/grouping/vespa/HitConverter.java @@ -47,7 +47,7 @@ class HitConverter implements ResultBuilder.HitConverter { FastHit hit = new FastHit(); hit.setRelevance(groupHit.getRank()); hit.setGlobalId(groupHit.getGlobalId()); - hit.setPartId(groupHit.getPath(), 0); + hit.setPartId(groupHit.getPath()); hit.setDistributionKey(groupHit.getDistributionKey()); hit.setFillable(); hit.setSearcherSpecificMetaData(searcher, summaryClass); diff --git a/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java index 11dcafba7bf..7859358fe50 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/DefaultRenderer.java @@ -73,8 +73,6 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> // this is shared between umpteen threads by design private final CopyOnWriteHashMap<String, Utf8String> fieldNameMap = new CopyOnWriteHashMap<>(); - private boolean utf8Output = false; - private XMLWriter writer; public DefaultRenderer() { @@ -92,13 +90,11 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> @Override public void init() { super.init(); - utf8Output = false; writer = null; } @Override public String getEncoding() { - if (getResult() == null || getResult().getQuery() == null || getResult().getQuery().getModel().getEncoding() == null) { @@ -119,7 +115,6 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> private void header(XMLWriter writer, Result result) throws IOException { // TODO: move setting this to Result - utf8Output = "utf-8".equalsIgnoreCase(getRequestedEncoding(result.getQuery())); writer.xmlHeader(getRequestedEncoding(result.getQuery())); writer.openTag(RESULT).attribute(TOTAL_HIT_COUNT, String.valueOf(result.getTotalHitCount())); renderCoverageAttributes(result.getCoverage(false), writer); @@ -128,9 +123,7 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> } private void renderTime(XMLWriter writer, Result result) { - if (!result.getQuery().getPresentation().getTiming()) { - return; - } + if ( ! result.getQuery().getPresentation().getTiming()) return; final String threeDecimals = "%.3f"; final double milli = .001d; @@ -159,13 +152,11 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> writer.attribute(RESULTS,coverage.getResultSets()); } - public void error(XMLWriter writer, Result result) throws IOException { ErrorMessage error = result.hits().getError(); writer.openTag(ERROR).attribute(CODE,error.getCode()).content(error.getMessage(),false).closeTag(); } - @SuppressWarnings("UnusedParameters") protected void emptyResult(XMLWriter writer, Result result) throws IOException {} @@ -180,63 +171,43 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> } } - - private void renderSingularHit(XMLWriter writer, Hit hit) throws IOException { + private void renderSingularHit(XMLWriter writer, Hit hit) { writer.openTag(HIT); renderHitAttributes(writer, hit); writer.closeStartTag(); renderHitFields(writer, hit); } - private void renderHitFields(XMLWriter writer, Hit hit) throws IOException { + private void renderHitFields(XMLWriter writer, Hit hit) { renderSyntheticRelevanceField(writer, hit); for (Iterator<Map.Entry<String, Object>> it = hit.fieldIterator(); it.hasNext(); ) { renderField(writer, hit, it); } } - private void renderField(XMLWriter writer, Hit hit, Iterator<Map.Entry<String, Object>> it) throws IOException { - Map.Entry<String, Object> entry = it.next(); - boolean isProbablyNotDecoded = false; - if (hit instanceof FastHit) { - FastHit f = (FastHit) hit; - isProbablyNotDecoded = f.fieldIsNotDecoded(entry.getKey()); - } - renderGenericFieldPossiblyNotDecoded(writer, hit, entry, isProbablyNotDecoded); + private void renderField(XMLWriter writer, Hit hit, Iterator<Map.Entry<String, Object>> it) { + renderGenericField(writer, hit, it.next()); } - private void renderGenericFieldPossiblyNotDecoded(XMLWriter writer, Hit hit, Map.Entry<String, Object> entry, boolean probablyNotDecoded) throws IOException { + private void renderGenericField(XMLWriter writer, Hit hit, Map.Entry<String, Object> entry) { String fieldName = entry.getKey(); // skip depending on hit type if (fieldName.startsWith("$")) return; // Don't render fields that start with $ // TODO: Move to should render writeOpenFieldElement(writer, fieldName); - renderFieldContentPossiblyNotDecoded(writer, hit, probablyNotDecoded, fieldName); + renderFieldContent(writer, hit, fieldName); writeCloseFieldElement(writer); } - private void renderFieldContentPossiblyNotDecoded(XMLWriter writer, Hit hit, boolean probablyNotDecoded, String fieldName) throws IOException { - boolean dumpedRaw = false; - if (probablyNotDecoded && (hit instanceof FastHit)) { - writer.closeStartTag(); - if ((writer.getWriter() instanceof ByteWriter) && utf8Output) { - dumpedRaw = UserTemplate.dumpBytes((ByteWriter) writer.getWriter(), (FastHit) hit, fieldName); - } - if (dumpedRaw) { - writer.content("", false); // let the xml writer note that this tag had content - } - } - if (!dumpedRaw) { - String xmlval = hit.getFieldXML(fieldName); - if (xmlval == null) { - xmlval = "(null)"; - } - writer.escapedContent(xmlval, false); - } + private void renderFieldContent(XMLWriter writer, Hit hit, String fieldName) { + String xmlval = hit.getFieldXML(fieldName); + if (xmlval == null) + xmlval = "(null)"; + writer.escapedContent(xmlval, false); } - private void renderSyntheticRelevanceField(XMLWriter writer, Hit hit) throws IOException { + private void renderSyntheticRelevanceField(XMLWriter writer, Hit hit) { final String relevancyFieldName = "relevancy"; final Relevance relevance = hit.getRelevance(); @@ -246,17 +217,17 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> } } - private void renderSimpleField(XMLWriter writer, String relevancyFieldName, Relevance relevance) throws IOException { + private void renderSimpleField(XMLWriter writer, String relevancyFieldName, Relevance relevance) { writeOpenFieldElement(writer, relevancyFieldName); writer.content(relevance.toString(), false); writeCloseFieldElement(writer); } - private void writeCloseFieldElement(XMLWriter writer) throws IOException { + private void writeCloseFieldElement(XMLWriter writer) { writer.closeTag(); } - private void writeOpenFieldElement(XMLWriter writer, String relevancyFieldName) throws IOException { + private void writeOpenFieldElement(XMLWriter writer, String relevancyFieldName) { Utf8String utf8 = fieldNameMap.get(relevancyFieldName); if (utf8 == null) { utf8 = new Utf8String(relevancyFieldName); @@ -266,7 +237,7 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> writer.closeStartTag(); } - private void renderHitAttributes(XMLWriter writer, Hit hit) throws IOException { + private void renderHitAttributes(XMLWriter writer, Hit hit) { writer.attribute(TYPE, hit.getTypeString()); if (hit.getRelevance() != null) { writer.attribute(RELEVANCY, hit.getRelevance().toString()); @@ -285,20 +256,20 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> } } - private void renderGroup(XMLWriter writer, HitGroup hit) throws IOException { + private void renderGroup(XMLWriter writer, HitGroup hit) { writer.openTag(GROUP); renderHitAttributes(writer, hit); writer.closeStartTag(); } - private void renderHitGroupOfTypeGroupHit(XMLWriter writer, HitGroup hit) throws IOException { + private void renderHitGroupOfTypeGroupHit(XMLWriter writer, HitGroup hit) { writer.openTag(HIT); renderHitAttributes(writer, hit); renderId(writer, hit); writer.closeStartTag(); } - private void renderId(XMLWriter writer, HitGroup hit) throws IOException { + private void renderId(XMLWriter writer, HitGroup hit) { URI uri = hit.getId(); if (uri != null) { writer.openTag(ID).content(uri.stringValue(),false).closeTag(); @@ -420,17 +391,13 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> } @Override - public void beginList(DataList<?> list) - throws IOException { - if (getRecursionLevel() == 1) { - return; - } + public void beginList(DataList<?> list) throws IOException { + if (getRecursionLevel() == 1) return; + HitGroup hit = (HitGroup) list; boolean renderedSimple = simpleRenderHit(writer, hit); + if (renderedSimple) return; - if (renderedSimple) { - return; - } renderHitGroup(writer, hit); } @@ -438,25 +405,20 @@ public final class DefaultRenderer extends AsynchronousSectionedRenderer<Result> public void data(Data data) throws IOException { Hit hit = (Hit) data; boolean renderedSimple = simpleRenderHit(writer, hit); + if (renderedSimple) return; - if (renderedSimple) { - return; - } renderSingularHit(writer, hit); writer.closeTag(); } @Override - public void endList(DataList<?> list) - throws IOException { - if (getRecursionLevel() == 1) { - return; - } - writer.closeTag(); + public void endList(DataList<?> list) { + if (getRecursionLevel() > 1) + writer.closeTag(); } @Override - public void endResponse() throws IOException { + public void endResponse() { writer.closeTag(); writer.close(); } diff --git a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java index c39f0387d46..34b02b1bee8 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/JsonRenderer.java @@ -533,10 +533,6 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { if (fieldName.startsWith(VESPA_HIDDEN_FIELD_PREFIX)) return false; - RenderDecision r = lazyRenderAwareCheck(fieldName, hit); - if (r != RenderDecision.DO_NOT_KNOW) return r.booleanValue(); - - // this will trigger field decoding, so it is important the lazy decoding magic is done first Object field = hit.getField(fieldName); if (field instanceof CharSequence && ((CharSequence) field).length() == 0) return false; @@ -549,18 +545,6 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { return true; } - private RenderDecision lazyRenderAwareCheck(String fieldName, Hit hit) { - if ( ! (hit instanceof FastHit)) return RenderDecision.DO_NOT_KNOW; - - FastHit asFastHit = (FastHit) hit; - if (asFastHit.fieldIsNotDecoded(fieldName)) { - FastHit.RawField rawField = asFastHit.fetchFieldAsUtf8(fieldName); - if (rawField != null) - return rawField.getUtf8().length == 0 ? RenderDecision.NO : RenderDecision.YES; - } - return RenderDecision.DO_NOT_KNOW; - } - private void renderSpecialCasesForGrouping(Hit hit) throws IOException { if (hit instanceof AbstractList) { renderGroupingListSyntheticFields((AbstractList) hit); @@ -633,9 +617,7 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { private void renderField(String fieldName, Hit hit) throws IOException { generator.writeFieldName(fieldName); - if ( ! tryDirectRendering(fieldName, hit)) { - renderFieldContents(hit.getField(fieldName)); - } + renderFieldContents(hit.getField(fieldName)); } private void renderFieldContents(Object field) throws IOException { @@ -718,26 +700,6 @@ public class JsonRenderer extends AsynchronousSectionedRenderer<Result> { generator.writeEndObject(); } - /** - * Really a private method, but package access for testability. - */ - boolean tryDirectRendering(String fieldName, Hit hit) throws IOException { - boolean renderedAsUtf8 = false; - if (hit instanceof FastHit) { - FastHit f = (FastHit) hit; - if (f.fieldIsNotDecoded(fieldName)) { - FastHit.RawField r = f.fetchFieldAsUtf8(fieldName); - if (r != null) { - byte[] utf8 = r.getUtf8(); - - generator.writeUTF8String(utf8, 0, utf8.length); - renderedAsUtf8 = true; - } - } - } - return renderedAsUtf8; - } - @Override public void data(Data data) throws IOException { Preconditions.checkArgument(data instanceof Hit, diff --git a/container-search/src/main/java/com/yahoo/search/rendering/SyncDefaultRenderer.java b/container-search/src/main/java/com/yahoo/search/rendering/SyncDefaultRenderer.java index f63ff122b63..6613211a91e 100644 --- a/container-search/src/main/java/com/yahoo/search/rendering/SyncDefaultRenderer.java +++ b/container-search/src/main/java/com/yahoo/search/rendering/SyncDefaultRenderer.java @@ -257,62 +257,41 @@ public final class SyncDefaultRenderer extends Renderer { } } - private void renderSingularHit(XMLWriter writer, Hit hit) throws IOException { + private void renderSingularHit(XMLWriter writer, Hit hit) { writer.openTag(HIT); renderHitAttributes(writer, hit); writer.closeStartTag(); renderHitFields(writer, hit); } - private void renderHitFields(XMLWriter writer, Hit hit) throws IOException { + private void renderHitFields(XMLWriter writer, Hit hit) { renderSyntheticRelevanceField(writer, hit); for (Iterator<Map.Entry<String, Object>> it = hit.fieldIterator(); it.hasNext(); ) { renderField(writer, hit, it); } } - private void renderField(XMLWriter writer, Hit hit, Iterator<Map.Entry<String, Object>> it) throws IOException { + private void renderField(XMLWriter writer, Hit hit, Iterator<Map.Entry<String, Object>> it) { Map.Entry<String, Object> entry = it.next(); - boolean isProbablyNotDecoded = false; - if (hit instanceof FastHit) { - FastHit f = (FastHit) hit; - isProbablyNotDecoded = f.fieldIsNotDecoded(entry.getKey()); - } - renderGenericFieldPossiblyNotDecoded(writer, hit, entry, isProbablyNotDecoded); - } - - private void renderGenericFieldPossiblyNotDecoded(XMLWriter writer, Hit hit, Map.Entry<String, Object> entry, boolean probablyNotDecoded) throws IOException { String fieldName = entry.getKey(); - if (!shouldRenderField(hit, fieldName)) return; + if ( ! shouldRenderField(hit, fieldName)) return; if (fieldName.startsWith("$")) return; // Don't render fields that start with $ // TODO: Move to should render writeOpenFieldElement(writer, fieldName); - renderFieldContentPossiblyNotDecoded(writer, hit, probablyNotDecoded, fieldName); + renderFieldContent(writer, hit, fieldName); writeCloseFieldElement(writer); } - private void renderFieldContentPossiblyNotDecoded(XMLWriter writer, Hit hit, boolean probablyNotDecoded, String fieldName) throws IOException { - boolean dumpedRaw = false; - if (probablyNotDecoded && (hit instanceof FastHit)) { - writer.closeStartTag(); - if ((writer.getWriter() instanceof ByteWriter) && context.isUtf8Output()) { - dumpedRaw = UserTemplate.dumpBytes((ByteWriter) writer.getWriter(), (FastHit) hit, fieldName); - } - if (dumpedRaw) { - writer.content("", false); // let the xml writer note that this tag had content - } - } - if (!dumpedRaw) { - String xmlval = hit.getFieldXML(fieldName); - if (xmlval == null) { - xmlval = "(null)"; - } - writer.escapedContent(xmlval, false); + private void renderFieldContent(XMLWriter writer, Hit hit, String fieldName) { + String xmlval = hit.getFieldXML(fieldName); + if (xmlval == null) { + xmlval = "(null)"; } + writer.escapedContent(xmlval, false); } - private void renderSyntheticRelevanceField(XMLWriter writer, Hit hit) throws IOException { + private void renderSyntheticRelevanceField(XMLWriter writer, Hit hit) { final String relevancyFieldName = "relevancy"; final Relevance relevance = hit.getRelevance(); @@ -321,17 +300,17 @@ public final class SyncDefaultRenderer extends Renderer { } } - private void renderSimpleField(XMLWriter writer, String relevancyFieldName, Relevance relevance) throws IOException { + private void renderSimpleField(XMLWriter writer, String relevancyFieldName, Relevance relevance) { writeOpenFieldElement(writer, relevancyFieldName); writer.content(relevance.toString(), false); writeCloseFieldElement(writer); } - private void writeCloseFieldElement(XMLWriter writer) throws IOException { + private void writeCloseFieldElement(XMLWriter writer) { writer.closeTag(); } - private void writeOpenFieldElement(XMLWriter writer, String relevancyFieldName) throws IOException { + private void writeOpenFieldElement(XMLWriter writer, String relevancyFieldName) { Utf8String utf8 = fieldNameMap.get(relevancyFieldName); if (utf8 == null) { utf8 = new Utf8String(relevancyFieldName); @@ -346,7 +325,7 @@ public final class SyncDefaultRenderer extends Renderer { return true; } - private void renderHitAttributes(XMLWriter writer, Hit hit) throws IOException { + private void renderHitAttributes(XMLWriter writer, Hit hit) { writer.attribute(TYPE, hit.getTypeString()); if (hit.getRelevance() != null) { writer.attribute(RELEVANCY, hit.getRelevance().toString()); @@ -365,20 +344,20 @@ public final class SyncDefaultRenderer extends Renderer { } } - private void renderGroup(XMLWriter writer, HitGroup hit) throws IOException { + private void renderGroup(XMLWriter writer, HitGroup hit) { writer.openTag(GROUP); renderHitAttributes(writer, hit); writer.closeStartTag(); } - private void renderHitGroupOfTypeGroupHit(XMLWriter writer, HitGroup hit) throws IOException { + private void renderHitGroupOfTypeGroupHit(XMLWriter writer, HitGroup hit) { writer.openTag(HIT); renderHitAttributes(writer, hit); renderId(writer, hit); writer.closeStartTag(); } - private void renderId(XMLWriter writer, HitGroup hit) throws IOException { + private void renderId(XMLWriter writer, HitGroup hit) { URI uri = hit.getId(); if (uri != null) { writer.openTag(ID).content(uri.stringValue(),false).closeTag(); diff --git a/container-search/src/test/java/com/yahoo/fs4/test/FastHitTestCase.java b/container-search/src/test/java/com/yahoo/fs4/test/FastHitTestCase.java deleted file mode 100644 index c0223aab568..00000000000 --- a/container-search/src/test/java/com/yahoo/fs4/test/FastHitTestCase.java +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.fs4.test; - -import com.yahoo.prelude.fastsearch.FastHit; -import org.junit.Test; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a> - */ -public class FastHitTestCase { - - @Test - public void requireThatIgnoreRowBitsIsFalseByDefault() { - FastHit hit = new FastHit(); - assertFalse(hit.shouldIgnoreRowBits()); - } - - @Test - public void requireThatIgnoreRowBitsCanBeSet() { - FastHit hit = new FastHit(); - hit.setIgnoreRowBits(true); - assertTrue(hit.shouldIgnoreRowBits()); - } -} diff --git a/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java b/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java index 679bc96c06b..c284a073704 100644 --- a/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java +++ b/container-search/src/test/java/com/yahoo/fs4/test/GetDocSumsPacketTestCase.java @@ -19,7 +19,7 @@ import static org.junit.Assert.assertNull; /** * Tests the GetDocsumsPacket * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud */ public class GetDocSumsPacketTestCase { @@ -33,14 +33,7 @@ public class GetDocSumsPacketTestCase { @Test public void testEncodingWithQuery() throws BufferTooSmallException { - FastHit hit = new FastHit(); - hit.setIgnoreRowBits(true); - assertPacket(true, hit, new byte[] { 0, 0, 0, 57, 0, 0, 0, -37, 0, 0, 40, 21, 0, 0, 0, 0, IGNORE, IGNORE, IGNORE, - IGNORE, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 0x03, 0, 0, 0, 7, - 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 1, 0, 0, 0, 6, 4, 0, 3, 102, 111, 111, 0, 0, 0, 3 }); - - hit = new FastHit(); - hit.setIgnoreRowBits(false); + Hit hit = new FastHit(); assertPacket(true, hit, new byte[] {0, 0, 0, 57, 0, 0, 0, -37, 0, 0, 40, 21, 0, 0, 0, 0, IGNORE, IGNORE, IGNORE, IGNORE, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 0x03, 0, 0, 0, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 1, 0, 0, 0, 6, 4, 0, 3, 102, 111, 111, 0, 0, 0, 2}); @@ -48,15 +41,7 @@ public class GetDocSumsPacketTestCase { @Test public void testEncodingWithoutQuery() throws BufferTooSmallException { - FastHit hit = new FastHit(); - hit.setIgnoreRowBits(true); - assertPacket(false, hit, new byte[] { 0, 0, 0, 43, 0, 0, 0, -37, 0, 0, 40, 17, 0, 0, 0, 0, IGNORE, IGNORE, IGNORE, - IGNORE, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 0x03, 0, 0, 0, 7, - 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 3 - }); - - hit = new FastHit(); - hit.setIgnoreRowBits(false); + Hit hit = new FastHit(); assertPacket(false, hit, new byte[] { 0, 0, 0, 43, 0, 0, 0, -37, 0, 0, 40, 17, 0, 0, 0, 0, IGNORE, IGNORE, IGNORE, IGNORE, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 0x03, 0, 0, 0, 7, 100, 101, 102, 97, 117, 108, 116, 0, 0, 0, 2 }); diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java index c2a50884b2b..c179851ba00 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/SlimeSummaryTestCase.java @@ -107,7 +107,7 @@ public class SlimeSummaryTestCase { DocsumDefinitionSet set = createDocsumDefinitionSet(summary_cf); byte[] docsum = makeTimeout(); FastHit hit = new FastHit(); - assertEquals("Hit hit index:0/0/0/000000000000000000000000 (relevance null) [fasthit, globalid: 0 0 0 0 0 0 0 0 0 0 0 0, partId: 0, distributionkey: 0] failed: Timed out....", set.lazyDecode("default", docsum, hit)); + assertEquals("Hit hit index:0/0/000000000000000000000000 (relevance null) [fasthit, globalid: 0 0 0 0 0 0 0 0 0 0 0 0, partId: 0, distributionkey: 0] failed: Timed out....", set.lazyDecode("default", docsum, hit)); } @Test diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java index b0bbdda32df..f8aa5e01853 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/DocsumDefinitionTestCase.java @@ -72,7 +72,7 @@ public class DocsumDefinitionTestCase { assertEquals("1", hit.getField("EXTINFOSOURCE").toString()); assertEquals("10", hit.getField("LANG1").toString()); assertEquals("352", hit.getField("WORDS").toString()); - assertEquals("index:0/0/0/" + FastHit.asHexString(hit.getGlobalId()), hit.getId().toString()); + assertEquals("index:0/0/" + FastHit.asHexString(hit.getGlobalId()), hit.getId().toString()); } public static GlobalId createGlobalId(int docId) { diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java index 3cfd8b337fc..7d905d286fc 100644 --- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java +++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTestCase.java @@ -545,7 +545,7 @@ public class FastSearcherTestCase { hit.getField("TITLE")); assertEquals("352", hit.getField("WORDS").toString()); assertEquals(2003., hit.getRelevance().getScore(), 0.01d); - assertEquals("index:0/234/0/" + FastHit.asHexString(hit.getGlobalId()), hit.getId().toString()); + assertEquals("index:0/234/" + FastHit.asHexString(hit.getGlobalId()), hit.getId().toString()); assertEquals("9190", hit.getField("BYTES").toString()); assertEquals("testhittype", hit.getSource()); } diff --git a/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java b/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java index ed421be1947..0191b1a799b 100644 --- a/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/dispatch/FillTestCase.java @@ -133,7 +133,7 @@ public class FillTestCase { private FastHit createHit(int sourceNodeId, int hitId) { FastHit hit = new FastHit("hit:" + hitId, 1.0); - hit.setPartId(sourceNodeId, 0); + hit.setPartId(sourceNodeId); hit.setDistributionKey(sourceNodeId); hit.setGlobalId(client.globalIdFrom(hitId)); return hit; diff --git a/container-search/src/test/java/com/yahoo/search/grouping/vespa/HitConverterTestCase.java b/container-search/src/test/java/com/yahoo/search/grouping/vespa/HitConverterTestCase.java index e5fe0111655..49f5642af4e 100644 --- a/container-search/src/test/java/com/yahoo/search/grouping/vespa/HitConverterTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/grouping/vespa/HitConverterTestCase.java @@ -22,7 +22,7 @@ import org.junit.Test; import static org.junit.Assert.*; /** - * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a> + * @author Simon Thoresen */ public class HitConverterTestCase { @@ -35,11 +35,11 @@ public class HitConverterTestCase { HitConverter converter = new HitConverter(new MySearcher(), new Query()); Hit hit = converter.toSearchHit("default", new FS4Hit(1, createGlobalId(2), 3).setContext(new Hit("hit:ctx"))); assertNotNull(hit); - assertEquals(new URI("index:0/1/0/" + FastHit.asHexString(createGlobalId(2))), hit.getId()); + assertEquals(new URI("index:0/1/" + FastHit.asHexString(createGlobalId(2))), hit.getId()); hit = converter.toSearchHit("default", new FS4Hit(4, createGlobalId(5), 6).setContext(new Hit("hit:ctx"))); assertNotNull(hit); - assertEquals(new URI("index:0/4/0/" + FastHit.asHexString(createGlobalId(5))), hit.getId()); + assertEquals(new URI("index:0/4/" + FastHit.asHexString(createGlobalId(5))), hit.getId()); } @Test diff --git a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java index 791e95403ab..defabc7463b 100644 --- a/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/rendering/JsonRendererTestCase.java @@ -680,26 +680,6 @@ public class JsonRendererTestCase { } @Test - public void testLazyDecoding() throws IOException { - FastHit f = new FastHit("http://a.b/c", 0.5); - String checkWeCanDecode = "bamse"; - String dontCare = "don't care"; - final String fieldName = "checkWeCanDecode"; - f.setLazyStringField(fieldName, Utf8.toBytes(checkWeCanDecode)); - final String fieldName2 = "dontCare"; - f.setLazyStringField(fieldName2, Utf8.toBytes(dontCare)); - assertEquals(checkWeCanDecode, f.getField(fieldName)); - - JsonGenerator mock = Mockito.mock(JsonGenerator.class); - - renderer.setGenerator(mock); - assertTrue(renderer.tryDirectRendering(fieldName2, f)); - - byte[] expectedBytes = Utf8.toBytes(dontCare); - Mockito.verify(mock, times(1)).writeUTF8String(expectedBytes, 0, expectedBytes.length); - } - - @Test public void testHitWithSource() throws IOException, InterruptedException, ExecutionException { String expected = "{\n" + " \"root\": {\n" diff --git a/document/src/main/java/com/yahoo/document/GlobalId.java b/document/src/main/java/com/yahoo/document/GlobalId.java index e2d3e4510f4..95e35c9280c 100644 --- a/document/src/main/java/com/yahoo/document/GlobalId.java +++ b/document/src/main/java/com/yahoo/document/GlobalId.java @@ -12,6 +12,8 @@ import java.util.Arrays; * Implements an incredibly light-weight version of the document global id. There is a lot of functionality in the C++ * version of this that is missing. However, this should be sufficient for now. * + * This is immutable (by contract - not enforcable due to exposing the raw byte array). + * * @author Simon Thoresen */ public class GlobalId implements Comparable { @@ -72,21 +74,19 @@ public class GlobalId implements Comparable { /** * Returns the raw byte array that constitutes this global id. - * - * @return The byte array. + * The returned value MUST NOT be modified. */ public byte[] getRawId() { return raw; } - // Inherit doc from Object. @Override public int hashCode() { return Arrays.hashCode(raw); } public BucketId toBucketId() { - /** + /* * Explanation time: since Java was designed so mankind could suffer, * shift ops on bytes have an implicit int conversion with sign-extend. * When a byte is negative, you end up with an int/long with a 0xFFFFFF diff --git a/standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala b/standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala index 02ff2c60ce6..ac8636de2cb 100644 --- a/standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala +++ b/standalone-container/src/main/scala/com/yahoo/application/container/impl/ClassLoaderOsgiFramework.scala @@ -199,6 +199,8 @@ final class ClassLoaderOsgiFramework extends OsgiFramework { override def getDataFile(filename: String) = throw new UnsupportedOperationException override def createFilter(filter: String) = throw new UnsupportedOperationException + override def registerService[S](aClass: Class[S], serviceFactory: ServiceFactory[S], dictionary: Dictionary[String, _]): ServiceRegistration[S] = throw new UnsupportedOperationException + override def getServiceObjects[S](serviceReference: ServiceReference[S]): ServiceObjects[S] = throw new UnsupportedOperationException } } diff --git a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/bindings/IdentityDocument.java b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/bindings/IdentityDocument.java index e792038e4c2..127a9de16ca 100644 --- a/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/bindings/IdentityDocument.java +++ b/vespa-athenz/src/main/java/com/yahoo/vespa/athenz/identityprovider/api/bindings/IdentityDocument.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.athenz.identityprovider.api.bindings; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import java.time.Instant; @@ -13,7 +12,6 @@ import java.util.Set; * @author bjorncs */ @JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(JsonInclude.Include.NON_NULL) public class IdentityDocument { @JsonProperty("provider-unique-id") diff --git a/vespalog/src/main/java/com/yahoo/log/event/Count.java b/vespalog/src/main/java/com/yahoo/log/event/Count.java index 175e8b9f69f..1915e151908 100644 --- a/vespalog/src/main/java/com/yahoo/log/event/Count.java +++ b/vespalog/src/main/java/com/yahoo/log/event/Count.java @@ -23,7 +23,7 @@ public class Count extends Event { @Override public Event setValue (String name, String value) { if (name.equals("value")) { - super.setValue(name, Long.toString((new Double(value)).longValue())); + super.setValue(name, Long.toString((Double.valueOf(value)).longValue())); } else { super.setValue(name , value); } diff --git a/vespalog/src/main/java/com/yahoo/log/event/Event.java b/vespalog/src/main/java/com/yahoo/log/event/Event.java index 76fdf16c4ef..a897292af91 100644 --- a/vespalog/src/main/java/com/yahoo/log/event/Event.java +++ b/vespalog/src/main/java/com/yahoo/log/event/Event.java @@ -322,7 +322,7 @@ public abstract class Event implements Serializable { Event event; try { - event = (Event) Class.forName(className).newInstance(); + event = (Event) Class.forName(className).getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException e) { event = new Unknown().setName(eventName); diff --git a/vespalog/src/test/java/com/yahoo/log/LogSetupTestCase.java b/vespalog/src/test/java/com/yahoo/log/LogSetupTestCase.java index 70eb65b1463..d476b111e4f 100644 --- a/vespalog/src/test/java/com/yahoo/log/LogSetupTestCase.java +++ b/vespalog/src/test/java/com/yahoo/log/LogSetupTestCase.java @@ -20,6 +20,8 @@ import static org.hamcrest.CoreMatchers.is; * * @author Bjorn Borud */ +// TODO: Remove annotation and replace setMillis with setInstant when we don't support Java 8 anymore. +@SuppressWarnings("deprecation") public class LogSetupTestCase { // For testing zookeeper log records protected static LogRecord zookeeperLogRecord; diff --git a/vespalog/src/test/java/com/yahoo/log/VespaFormatterTestCase.java b/vespalog/src/test/java/com/yahoo/log/VespaFormatterTestCase.java index 5dac2e34786..9da71b2ad2e 100644 --- a/vespalog/src/test/java/com/yahoo/log/VespaFormatterTestCase.java +++ b/vespalog/src/test/java/com/yahoo/log/VespaFormatterTestCase.java @@ -14,6 +14,8 @@ import static org.hamcrest.CoreMatchers.is; /** * @author Bjorn Borud */ +// TODO: Remove annotation and replace setMillis with setInstant when we don't support Java 8 anymore. +@SuppressWarnings("deprecation") public class VespaFormatterTestCase { private String hostname; diff --git a/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java b/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java index 3e51d194a5e..5cbd130c05a 100644 --- a/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java +++ b/vespalog/src/test/java/com/yahoo/log/VespaLogHandlerTestCase.java @@ -20,6 +20,8 @@ import static org.junit.Assert.*; /** * @author Bjorn Borud */ +// TODO: Remove annotation and replace setMillis with setInstant when we don't support Java 8 anymore. +@SuppressWarnings("deprecation") public class VespaLogHandlerTestCase { protected static String hostname; protected static String pid; |