From 76bb30d6f06ace62dd12f4fbd618146e5c62d089 Mon Sep 17 00:00:00 2001 From: Bjørn Christian Seime Date: Mon, 9 Mar 2020 17:14:28 +0100 Subject: Remove standalone container activator The standalone container activator is no longer needed after pre-binding of server sockets was removed. --- .../standalone/StandaloneContainerActivator.java | 136 --------------------- .../StandaloneContainerActivatorTest.java | 106 ---------------- 2 files changed, 242 deletions(-) delete mode 100644 standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java delete mode 100644 standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java (limited to 'standalone-container/src') diff --git a/standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java b/standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java deleted file mode 100644 index dbf0b748eea..00000000000 --- a/standalone-container/src/main/java/com/yahoo/container/standalone/StandaloneContainerActivator.java +++ /dev/null @@ -1,136 +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.container.standalone; - -import com.google.inject.Binder; -import com.google.inject.Guice; -import com.google.inject.Module; -import com.google.inject.util.Modules; -import com.yahoo.jdisc.application.ContainerActivator; -import com.yahoo.jdisc.application.ContainerBuilder; -import com.yahoo.jdisc.application.DeactivatedContainer; -import com.yahoo.jdisc.application.OsgiFramework; -import com.yahoo.jdisc.http.ConnectorConfig; -import com.yahoo.vespa.model.VespaModel; -import com.yahoo.vespa.model.container.Container; -import com.yahoo.vespa.model.container.http.ConnectorFactory; -import com.yahoo.vespa.model.container.http.JettyHttpServer; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; - -/** - * @author Einar M R Rosenvinge - */ -public class StandaloneContainerActivator implements BundleActivator { - - @Override public void start(BundleContext bundleContext) {} - @Override public void stop(BundleContext bundleContext) {} - - static Container getContainer(Module... modules) { - Module activatorModule = new ActivatorModule(); - List allModules = new ArrayList<>(); - allModules.addAll(Arrays.asList(modules)); - allModules.add(activatorModule); - - StandaloneContainerApplication app = new StandaloneContainerApplication(Guice.createInjector(Modules.combine(allModules))); - return app.container(); - } - - static List getConnectorConfigs(Container container) { - return getConnectorConfigs(container.getHttpServer()); - } - - private static List getConnectorConfigs(JettyHttpServer jettyHttpServer) { - if (jettyHttpServer == null) - return Collections.emptyList(); - - return jettyHttpServer.getConnectorFactories().stream(). - map(StandaloneContainerActivator::getConnectorConfig). - collect(Collectors.toList()); - } - - private static ConnectorConfig getConnectorConfig(ConnectorFactory connectorFactory) { - return VespaModel.getConfig(ConnectorConfig.class, connectorFactory); - } - - - private static class ActivatorModule implements Module { - @Override - public void configure(Binder binder) { - binder.bind(OsgiFramework.class).toInstance(new DummyOsgiFramework()); - binder.bind(ContainerActivator.class).toInstance(new DummyActivatorForStandaloneContainerApp()); - } - } - - private static class DummyActivatorForStandaloneContainerApp implements ContainerActivator { - @Override - public ContainerBuilder newContainerBuilder() { - return new ContainerBuilder(new ArrayList()); - } - - @Override - public DeactivatedContainer activateContainer(ContainerBuilder builder) { - return new DeactivatedContainer() { - @Override - public Object appContext() { - return new Object(); - } - - @Override - public void notifyTermination(Runnable task) { - } - }; - } - } - - public static class DummyOsgiFramework implements OsgiFramework { - @Override - public List installBundle(String bundleLocation) { - throw new UnsupportedOperationException(); - } - - @Override - public void startBundles(List bundles, boolean privileged) { - throw new UnsupportedOperationException(); - } - - @Override - public void refreshPackages() { - throw new UnsupportedOperationException(); - } - - @Override - public BundleContext bundleContext() { - return null; - } - - @Override - public List bundles() { - return Collections.emptyList(); - } - - @Override - public List getBundles(Bundle requestingBundle) { - return Collections.emptyList(); - } - - @Override - public void allowDuplicateBundles(Collection bundles) { } - - @Override - public void start() { - } - - @Override - public void stop() { - } - } - -} diff --git a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java b/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java deleted file mode 100644 index f1c02b0149f..00000000000 --- a/standalone-container/src/test/java/com/yahoo/container/standalone/StandaloneContainerActivatorTest.java +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.container.standalone; - -import com.google.inject.Module; -import com.yahoo.io.IOUtils; -import com.yahoo.jdisc.http.ConnectorConfig; -import com.yahoo.vespa.defaults.Defaults; -import com.yahoo.vespa.model.container.Container; -import org.junit.Test; -import org.xml.sax.SAXException; - -import javax.xml.parsers.ParserConfigurationException; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.List; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.junit.Assert.assertThat; - -/** - * @author Einar M R Rosenvinge - */ -public class StandaloneContainerActivatorTest { - - private static String getJdiscXml(String contents) throws ParserConfigurationException, IOException, SAXException { - return "\n" + - "\n" + - " \n" + - contents + - " \n" + - ""; - } - - private static void writeApplicationPackage(String servicesXml, Path tmpDir) throws IOException { - FileWriter fw = new FileWriter(tmpDir.resolve("services.xml").toFile(), false); - fw.write(servicesXml); - fw.close(); - } - - @Test - public void requireThatPortsCanBeFoundBasic() throws IOException, ParserConfigurationException, SAXException { - final Path applicationDir = Files.createTempDirectory("application"); - try { - writeApplicationPackage(getJdiscXml(""), applicationDir); - StandaloneContainerActivator activator = new StandaloneContainerActivator(); - Container container = StandaloneContainerActivator.getContainer(newAppDirBinding(applicationDir)); - List ports = getPorts(activator, container); - assertThat(ports, is(singletonList(Defaults.getDefaults().vespaWebServicePort()))); - } finally { - IOUtils.recursiveDeleteDir(applicationDir.toFile()); - } - } - - private static List getPorts(StandaloneContainerActivator activator, Container container) { - return StandaloneContainerActivator.getConnectorConfigs(container).stream(). - map(ConnectorConfig::listenPort). - collect(toList()); - } - - @Test - public void requireThatPortsCanBeFoundNoHttp() throws IOException, ParserConfigurationException, SAXException { - final Path applicationDir = Files.createTempDirectory("application"); - try { - writeApplicationPackage(getJdiscXml(""), applicationDir); - StandaloneContainerActivator activator = new StandaloneContainerActivator(); - Container container = StandaloneContainerActivator.getContainer(newAppDirBinding(applicationDir)); - List ports = getPorts(activator, container); - assertThat(ports, empty()); - } finally { - IOUtils.recursiveDeleteDir(applicationDir.toFile()); - } - } - - @Test - public void requireThatPortsCanBeFoundHttpThreeServers() throws IOException, ParserConfigurationException, SAXException { - final Path applicationDir = Files.createTempDirectory("application"); - try { - final String contents = - "\n" + - " \n" + - " \n" + - " \n" + - "\n"; - writeApplicationPackage(getJdiscXml(contents), applicationDir); - StandaloneContainerActivator activator = new StandaloneContainerActivator(); - Container container = StandaloneContainerActivator.getContainer(newAppDirBinding(applicationDir)); - List ports = getPorts(activator, container); - assertThat(ports, is(asList(123, 456, 789))); - } finally { - IOUtils.recursiveDeleteDir(applicationDir.toFile()); - } - } - - private static Module newAppDirBinding(final Path applicationDir) { - return binder -> binder.bind(Path.class) - .annotatedWith(StandaloneContainerApplication.APPLICATION_PATH_NAME) - .toInstance(applicationDir); - } - -} -- cgit v1.2.3