diff options
Diffstat (limited to 'config-model')
8 files changed, 121 insertions, 123 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java index 60435decb04..538b2f0f957 100644 --- a/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java +++ b/config-model/src/main/java/com/yahoo/config/model/test/MockApplicationPackage.java @@ -6,6 +6,10 @@ import com.yahoo.config.application.api.ComponentInfo; import com.yahoo.config.application.api.UnparsedConfigDefinition; import com.yahoo.config.application.api.ApplicationFile; import com.yahoo.component.Version; +import com.yahoo.config.provision.ApplicationId; +import com.yahoo.config.provision.ApplicationName; +import com.yahoo.config.provision.InstanceName; +import com.yahoo.config.provision.TenantName; import com.yahoo.io.IOUtils; import com.yahoo.path.Path; import com.yahoo.io.reader.NamedReader; @@ -73,13 +77,23 @@ public class MockApplicationPackage implements ApplicationPackage { this.failOnValidateXml = failOnValidateXml; queryProfileRegistry = new QueryProfileXMLReader().read(asNamedReaderList(queryProfileType), asNamedReaderList(queryProfile)); - applicationMetaData = new ApplicationMetaData(DEPLOYED_BY_USER, "dir", 0L, false, APPLICATION_NAME, "checksum", APPLICATION_GENERATION, 0L); + applicationMetaData = new ApplicationMetaData(DEPLOYED_BY_USER, + "dir", + 0L, + false, + ApplicationId.from(TenantName.defaultName(), + ApplicationName.from(APPLICATION_NAME), + InstanceName.defaultName()), + "checksum", + APPLICATION_GENERATION, + 0L); } /** Returns the root of this application package relative to the current dir */ protected File root() { return root; } @Override + @SuppressWarnings("deprecation") public String getApplicationName() { return "mock application"; } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainer.java b/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainer.java index 01168c59442..8dff6aeb830 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainer.java @@ -58,19 +58,6 @@ public class MetricsProxyContainer extends Container implements addMetricsProxyComponent(VespaServices.class); } - int metricsRpcPortOffset() { - if (numHttpServerPorts != 2) { - throw new IllegalArgumentException("expecting 2 http server ports"); - } - if (numMessageBusPorts() != 0) { - throw new IllegalArgumentException("expecting 0 message bus ports"); - } - if (numRpcPorts() != 1) { - throw new IllegalArgumentException("expecting 1 rpc port"); - } - return numHttpServerPorts + numMessageBusPorts() + numRpcPorts(); - } - @Override protected ContainerServiceType myServiceType() { return METRICS_PROXY_CONTAINER; @@ -88,30 +75,42 @@ public class MetricsProxyContainer extends Container implements return true; } + private int metricsRpcPort; + // Must have predictable ports for both http and rpc. @Override public void allocatePorts(int start, PortAllocBridge from) { if (start == 0) start = BASEPORT; - from.wantPort(start++, "http"); + if (getHttp() != null) { + throw new IllegalArgumentException("unexpected HTTP setup"); + } + allocatedSearchPort = from.wantPort(start++, "http"); + portsMeta.on(0).tag("http").tag("query").tag("external").tag("state"); + + // XXX remove: from.wantPort(start++, "http/1"); - from.wantPort(start++, "rpc/admin"); - from.wantPort(start++, "rpc/metrics"); - } + portsMeta.on(1).tag("unused"); - @Override - public int getPortCount() { - return metricsRpcPortOffset() + 1; + if (numMessageBusPorts() != 0) { + throw new IllegalArgumentException("expecting 0 message bus ports"); + } + if (numRpcPorts() != 1) { + throw new IllegalArgumentException("expecting 1 rpc port"); + } + allocatedRpcPort = from.wantPort(start++, "rpc/admin"); + portsMeta.on(2).tag("rpc").tag("admin"); + metricsRpcPort = from.wantPort(start++, "rpc/metrics"); + portsMeta.on(3).tag("rpc").tag("metrics"); } @Override - protected void tagServers() { - super.tagServers(); - portsMeta.on(metricsRpcPortOffset()).tag("rpc").tag("metrics"); + public int getPortCount() { + return 4; } @Override public void getConfig(RpcConnectorConfig.Builder builder) { - builder.port(getRelativePort(metricsRpcPortOffset())); + builder.port(metricsRpcPort); } @Override diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java index 3bc68e4a879..7e2d6680827 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/Container.java @@ -75,8 +75,6 @@ public abstract class Container extends AbstractService implements private final JettyHttpServer defaultHttpServer = new JettyHttpServer(new ComponentId("DefaultHttpServer")); - protected final int numHttpServerPorts; - protected Container(AbstractConfigProducer parent, String name, int index) { this(parent, name, false, index); } @@ -89,13 +87,7 @@ public abstract class Container extends AbstractService implements this.index = index; if (getHttp() == null) { - // TODO Vespa 8: set to 1. The second (health) port has not been used since Vespa 6 or earlier. - numHttpServerPorts = 2; addChild(defaultHttpServer); - } else if (getHttp().getHttpServer() == null) { - numHttpServerPorts = 0; - } else { - numHttpServerPorts = getHttp().getHttpServer().getConnectorFactories().size(); } addBuiltinHandlers(); @@ -142,7 +134,16 @@ public abstract class Container extends AbstractService implements public JettyHttpServer getDefaultHttpServer() { return defaultHttpServer; } - + + public JettyHttpServer getHttpServer() { + Http http = getHttp(); + if (http == null) { + return defaultHttpServer; + } else { + return http.getHttpServer(); + } + } + /** Returns the index of this node. The index of a given node is stable through changes with best effort. */ public final int index() { return index; } @@ -159,25 +160,6 @@ public abstract class Container extends AbstractService implements if (getHttp() == null) { initDefaultJettyConnector(); } - - tagServers(); - } - - protected void tagServers() { - int offset = 0; - if (numHttpServerPorts > 0) { - portsMeta.on(offset++).tag("http").tag("query").tag("external").tag("state"); - } - - for (int i = 1; i < numHttpServerPorts; i++) - portsMeta.on(offset++).tag("http").tag("external"); - - if (messageBusEnabled()) { - portsMeta.on(offset++).tag("rpc").tag("messaging"); - } - if (rpcServerEnabled()) { - portsMeta.on(offset++).tag("rpc").tag("admin"); - } } private int getPort(ConnectorFactory connectorFactory) { @@ -228,22 +210,24 @@ public abstract class Container extends AbstractService implements * @return the number of ports needed by the Container */ public int getPortCount() { - // TODO Vespa 8: remove +2, only here for historical reasons - int httpPorts = (getHttp() != null) ? 0 : numHttpServerPorts + 2; + int httpPorts = (getHttp() != null) ? 0 : 2; return httpPorts + numMessageBusPorts() + numRpcPorts(); } @Override public void allocatePorts(int start, PortAllocBridge from) { if (start == 0) start = BASEPORT; - int off = 2; + int offset = 0; if (getHttp() == null) { if (requireSpecificPorts) { - from.requirePort(start, "http"); + allocatedSearchPort = from.requirePort(start, "http"); } else { - from.allocatePort("http"); + allocatedSearchPort = from.allocatePort("http"); } + portsMeta.on(offset++).tag("http").tag("query").tag("external").tag("state"); + // XXX unused - remove: from.allocatePort("http/1"); + portsMeta.on(offset++).tag("http").tag("external"); } else if (getHttp().getHttpServer() == null) { // no http server ports } else { @@ -251,24 +235,24 @@ public abstract class Container extends AbstractService implements int port = getPort(connectorFactory); String name = "http/" + connectorFactory.getName(); from.requirePort(port, name); + if (offset == 0) { + portsMeta.on(offset++).tag("http").tag("query").tag("external").tag("state"); + } else { + portsMeta.on(offset++).tag("http").tag("external"); + } } } if (messageBusEnabled()) { - from.allocatePort("messaging"); - ++off; + allocatedMessagingPort = from.allocatePort("messaging"); + portsMeta.on(offset++).tag("rpc").tag("messaging"); } if (rpcServerEnabled()) { - from.allocatePort("rpc/admin"); - ++off; - } - // TODO: remove this - if (getHttp() == null) { - from.allocatePort("unused/" + off); - ++off; - from.allocatePort("unused/" + off); + allocatedRpcPort = from.allocatePort("rpc/admin"); + portsMeta.on(offset++).tag("rpc").tag("admin"); } } + protected int allocatedSearchPort = 0; /** * @return the actual search port * TODO: Remove. Use {@link #getPortsMeta()} and check tags in conjunction with {@link #getRelativePort(int)}. @@ -276,21 +260,19 @@ public abstract class Container extends AbstractService implements public int getSearchPort() { if (getHttp() != null) throw new AssertionError("getSearchPort must not be used when http section is present."); - - return getRelativePort(0); + return allocatedSearchPort; } + protected int allocatedRpcPort = 0; private int getRpcPort() { - return rpcServerEnabled() ? getRelativePort(numHttpServerPorts + numMessageBusPorts()) : 0; + return allocatedRpcPort; } - protected int numRpcPorts() { return rpcServerEnabled() ? 1 : 0; } - + protected int allocatedMessagingPort = 0; private int getMessagingPort() { - return messageBusEnabled() ? getRelativePort(numHttpServerPorts) : 0; + return allocatedMessagingPort; } - protected int numMessageBusPorts() { return messageBusEnabled() ? 1 : 0; } @Override diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java index 15caebb19cc..4e043b0f2bf 100755 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ContainerCluster.java @@ -449,11 +449,11 @@ public abstract class ContainerCluster<CONTAINER extends Container> @Override public void getConfig(ApplicationMetadataConfig.Builder builder) { if (applicationMetaData != null) { - builder.name(applicationMetaData.getApplicationName()). + builder.name(applicationMetaData.getApplicationId().application().value()). user(applicationMetaData.getDeployedByUser()). path(applicationMetaData.getDeployPath()). timestamp(applicationMetaData.getDeployTimestamp()). - checksum(applicationMetaData.getCheckSum()). + checksum(applicationMetaData.getChecksum()). generation(applicationMetaData.getGeneration()); } } diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java index 2343fbf4452..f4c7f49a9a0 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/xml/ContainerModelBuilder.java @@ -634,10 +634,10 @@ public class ContainerModelBuilder extends ConfigModelBuilder<ContainerModel> { ClusterSpec.Id.from(cluster.getName()), deployState.getWantedNodeVespaVersion(), false); - Capacity capacity = Capacity.fromNodeCount(1, - Optional.empty(), - false, - ! deployState.getProperties().isBootstrap()); + Capacity capacity = Capacity.fromCount(1, + Optional.empty(), + false, + ! deployState.getProperties().isBootstrap()); return hostSystem.allocateHosts(clusterSpec, capacity, 1, logger).keySet().iterator().next(); } } else { diff --git a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java index ec9d631dec5..8a8b23bb0c8 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java +++ b/config-model/src/test/java/com/yahoo/config/model/ApplicationDeployTest.java @@ -10,6 +10,7 @@ import com.yahoo.config.model.application.provider.Bundle; import com.yahoo.config.model.application.provider.DeployData; import com.yahoo.config.model.application.provider.FilesApplicationPackage; import com.yahoo.config.model.deploy.DeployState; +import com.yahoo.config.provision.ApplicationId; import com.yahoo.path.Path; import com.yahoo.document.DataType; import com.yahoo.document.config.DocumentmanagerConfig; @@ -33,19 +34,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.regex.Pattern; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.Matchers.contains; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -60,7 +59,6 @@ public class ApplicationDeployTest { @Test public void testVespaModel() throws SAXException, IOException { ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "app1"); - assertThat(tester.app().getApplicationName(), is("app1")); VespaModel model = new VespaModel(tester.app()); List<SearchDefinition> searchDefinitions = tester.getSearchDefinitions(); assertEquals(searchDefinitions.size(), 5); @@ -92,8 +90,7 @@ public class ApplicationDeployTest { List<FilesApplicationPackage.Component> components = tester.app().getComponents(); assertEquals(1, components.size()); - Map<String, Bundle.DefEntry> defEntriesByName = - defEntries2map(components.get(0).getDefEntries()); + Map<String, Bundle.DefEntry> defEntriesByName = defEntries2map(components.get(0).getDefEntries()); assertEquals(5, defEntriesByName.size()); Bundle.DefEntry def1 = defEntriesByName.get("test-namespace"); @@ -106,15 +103,14 @@ public class ApplicationDeployTest { // Check that getFilename works ArrayList<String> sdFileNames = new ArrayList<>(); - for (SearchDefinition sd : searchDefinitions) { + for (SearchDefinition sd : searchDefinitions) sdFileNames.add(sd.getFilename()); - } Collections.sort(sdFileNames); - assertThat(sdFileNames.get(0), is("laptop.sd")); - assertThat(sdFileNames.get(1), is("music.sd")); - assertThat(sdFileNames.get(2), is("pc.sd")); - assertThat(sdFileNames.get(3), is("product.sd")); - assertThat(sdFileNames.get(4), is("sock.sd")); + assertEquals("laptop.sd", sdFileNames.get(0)); + assertEquals("music.sd", sdFileNames.get(1)); + assertEquals("pc.sd", sdFileNames.get(2)); + assertEquals("product.sd", sdFileNames.get(3)); + assertEquals("sock.sd", sdFileNames.get(4)); } @Test @@ -146,10 +142,8 @@ public class ApplicationDeployTest { String appDir = "src/test/cfg/application/app_sdbundles"; ApplicationPackageTester tester = ApplicationPackageTester.create(appDir); VespaModel model = new VespaModel(tester.app()); - // Check that the resulting documentmanager config contains those types DocumentmanagerConfig.Builder b = new DocumentmanagerConfig.Builder(); model.getConfig(b, VespaModel.ROOT_CONFIGID); - //String docMan = model.getConfig("documentmanager", "").toString(); DocumentmanagerConfig dc = b.build(); String docMan=ConfigInstance.serialize(dc).toString(); int pFlags = Pattern.MULTILINE + Pattern.DOTALL; @@ -169,8 +163,8 @@ public class ApplicationDeployTest { public void include_dirs_are_included() { ApplicationPackageTester tester = ApplicationPackageTester.create(TESTDIR + "include_dirs"); - List<String> includeDirs = tester.app().getUserIncludeDirs(); - assertThat(includeDirs, contains("jdisc_dir", "dir1", "dir2", "empty_dir")); + Set<String> includeDirs = new HashSet<>(tester.app().getUserIncludeDirs()); + assertEquals(Set.of("jdisc_dir", "dir1", "dir2", "empty_dir"), includeDirs); } @Test @@ -186,7 +180,8 @@ public class ApplicationDeployTest { FilesApplicationPackage.fromFile(appDir); fail("Expected exception due to non-existent include dir"); } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("Cannot include directory 'non-existent', as it does not exist")); + assertEquals("Cannot include directory 'non-existent', as it does not exist. Directory must reside in application package, and path must be given relative to application package.", + e.getMessage()); } } @@ -231,7 +226,7 @@ public class ApplicationDeployTest { ApplicationPackageTester.create(tmpDir.getAbsolutePath()); fail("Expected exception"); } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), containsString("element \"delay\" not allowed here")); + assertEquals("XML error in deployment.xml: element \"delay\" not allowed here; expected the element end-tag or element \"region\" [8:25], input:\n", e.getMessage()); } } @@ -264,28 +259,36 @@ public class ApplicationDeployTest { File tmp = Files.createTempDir(); String appPkg = TESTDIR + "app1"; IOUtils.copyDirectory(new File(appPkg), tmp); - DeployData deployData = new DeployData("foo", "bar", "baz", 13l, false, 1337l, 3l); + ApplicationId applicationId = ApplicationId.from("tenant1", "application1", "instance1"); + DeployData deployData = new DeployData("foo", + "bar", + applicationId, + 13L, + false, + 1337L, + 3L); FilesApplicationPackage app = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData); app.writeMetaData(); FilesApplicationPackage newApp = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData); ApplicationMetaData meta = newApp.getMetaData(); - assertThat(meta.getDeployedByUser(), is("foo")); - assertThat(meta.getDeployPath(), is("bar")); - assertThat(meta.getDeployTimestamp(), is(13L)); - assertThat(meta.getGeneration(), is(1337L)); - assertThat(meta.getPreviousActiveGeneration(), is(3L)); - String checkSum = meta.getCheckSum(); - assertNotNull(checkSum); + assertEquals("foo", meta.getDeployedByUser()); + assertEquals("bar", meta.getDeployPath()); + assertEquals(applicationId, meta.getApplicationId()); + assertEquals(13L, (long)meta.getDeployTimestamp()); + assertEquals(1337L, (long)meta.getGeneration()); + assertEquals(3L, meta.getPreviousActiveGeneration()); + String checksum = meta.getChecksum(); + assertNotNull(checksum); assertTrue((new File(tmp, "hosts.xml")).delete()); FilesApplicationPackage app2 = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData); - String app2CheckSum = app2.getMetaData().getCheckSum(); - assertThat(app2CheckSum, is(not(checkSum))); + String app2Checksum = app2.getMetaData().getChecksum(); + assertNotEquals(checksum, app2Checksum); assertTrue((new File(tmp, "files/foo.json")).delete()); FilesApplicationPackage app3 = FilesApplicationPackage.fromFileWithDeployData(tmp, deployData); - String app3CheckSum = app3.getMetaData().getCheckSum(); - assertThat(app3CheckSum, is(not(app2CheckSum))); + String app3Checksum = app3.getMetaData().getChecksum(); + assertNotEquals(app2Checksum, app3Checksum); } @Test @@ -322,7 +325,8 @@ public class ApplicationDeployTest { FilesApplicationPackage.getComponents(new File("src/test/cfg/application/validation/invalidjar_app")); fail(); } catch (IllegalArgumentException e) { - assertThat(e.getMessage(), is("Error opening jar file 'invalid.jar'. Please check that this is a valid jar file")); + assertEquals("Error opening jar file 'invalid.jar'. Please check that this is a valid jar file", + e.getMessage()); } } @@ -340,15 +344,15 @@ public class ApplicationDeployTest { DeployState deployState = new DeployState.Builder().applicationPackage(app).build(); ConfigDefinition def = deployState.getConfigDefinition(new ConfigDefinitionKey("baz", "xyzzy")).get(); - assertThat(def.getNamespace(), is("xyzzy")); + assertEquals("xyzzy", def.getNamespace()); def = deployState.getConfigDefinition(new ConfigDefinitionKey("foo", "qux")).get(); - assertThat(def.getNamespace(), is("qux")); + assertEquals("qux", def.getNamespace()); // A config def without version in filename and version in file header def = deployState.getConfigDefinition(new ConfigDefinitionKey("bar", "xyzzy")).get(); - assertThat(def.getNamespace(), is("xyzzy")); - assertThat(def.getName(), is("bar")); + assertEquals("xyzzy", def.getNamespace()); + assertEquals("bar", def.getName()); } @Test(expected=IllegalArgumentException.class) diff --git a/config-model/src/test/java/com/yahoo/config/model/ApplicationPackageTester.java b/config-model/src/test/java/com/yahoo/config/model/ApplicationPackageTester.java index ab321ac5835..87b6efa83d6 100644 --- a/config-model/src/test/java/com/yahoo/config/model/ApplicationPackageTester.java +++ b/config-model/src/test/java/com/yahoo/config/model/ApplicationPackageTester.java @@ -33,8 +33,7 @@ public class ApplicationPackageTester { this.applicationPackage = applicationPackage; } catch (IOException e) { - throw new IllegalArgumentException("Could not create an application package from '" + - applicationPackageDir + "'", e); + throw new IllegalArgumentException("Could not create an application package from '" + applicationPackageDir + "'", e); } } diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java index ef56a42cf1a..97b520f9803 100644 --- a/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java +++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/metricsproxy/MetricsProxyContainerTest.java @@ -72,7 +72,7 @@ public class MetricsProxyContainerTest { VespaModel model = getModel(servicesWithContent(), self_hosted); MetricsProxyContainer container = (MetricsProxyContainer)model.id2producer().get(CONTAINER_CONFIG_ID); - int offset = container.metricsRpcPortOffset(); + int offset = 3; assertEquals(2, container.getPortsMeta().getTagsAt(offset).size()); assertTrue(container.getPortsMeta().getTagsAt(offset).contains("rpc")); assertTrue(container.getPortsMeta().getTagsAt(offset).contains("metrics")); @@ -86,7 +86,7 @@ public class MetricsProxyContainerTest { VespaModel model = getModel(servicesWithContent(), self_hosted); MetricsProxyContainer container = (MetricsProxyContainer)model.id2producer().get(CONTAINER_CONFIG_ID); - int offset = container.metricsRpcPortOffset() - 1; + int offset = 2; assertEquals(2, container.getPortsMeta().getTagsAt(offset).size()); assertTrue(container.getPortsMeta().getTagsAt(offset).contains("rpc")); assertTrue(container.getPortsMeta().getTagsAt(offset).contains("admin")); |