diff options
author | gjoranv <gv@verizonmedia.com> | 2021-07-11 21:24:07 +0200 |
---|---|---|
committer | gjoranv <gv@verizonmedia.com> | 2021-07-11 21:24:07 +0200 |
commit | 14306113d9e3304c9c9e9d4e71bfbe368f343e82 (patch) | |
tree | 5a852daf03132c13c6887578b53f7f52e90885c3 | |
parent | 241bc373520984276f98fa03475b9883f935d241 (diff) |
Remove Jersey/rest-api support from config-model.
6 files changed, 1 insertions, 467 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java index 317ed0f66c7..59e9b1a2b4d 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainerCluster.java @@ -34,8 +34,6 @@ import com.yahoo.vespa.model.container.component.Handler; import com.yahoo.vespa.model.container.component.Servlet; import com.yahoo.vespa.model.container.component.SystemBindingPattern; import com.yahoo.vespa.model.container.configserver.ConfigserverCluster; -import com.yahoo.vespa.model.container.jersey.Jersey2Servlet; -import com.yahoo.vespa.model.container.jersey.RestApi; import com.yahoo.vespa.model.container.xml.PlatformBundles; import com.yahoo.vespa.model.utils.FileSender; @@ -80,7 +78,6 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat private final Set<FileReference> applicationBundles = new LinkedHashSet<>(); private final ConfigProducerGroup<Servlet> servletGroup; - private final ConfigProducerGroup<RestApi> restApiGroup; private final Set<String> previousHosts; private ContainerModelEvaluation modelEvaluation; @@ -95,7 +92,6 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat public ApplicationContainerCluster(AbstractConfigProducer<?> parent, String configSubId, String clusterId, DeployState deployState) { super(parent, configSubId, clusterId, deployState, true); this.tlsClientAuthority = deployState.tlsClientAuthority(); - restApiGroup = new ConfigProducerGroup<>(this, "rest-api"); servletGroup = new ConfigProducerGroup<>(this, "servlet"); previousHosts = deployState.getPreviousModel().stream() .map(Model::allocatedHosts) @@ -121,8 +117,6 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat if (modelEvaluation != null) modelEvaluation.prepare(containers); sendUserConfiguredFiles(deployState); - for (RestApi restApi : restApiGroup.getComponents()) - restApi.prepare(); } private void addAndSendApplicationBundles(DeployState deployState) { @@ -166,15 +160,6 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat this.modelEvaluation = modelEvaluation; } - public final void addRestApi(RestApi restApi) { - restApiGroup.addComponent(ComponentId.fromString(restApi.getBindingPath()), restApi); - } - - public Map<ComponentId, RestApi> getRestApiMap() { - return restApiGroup.getComponentMap(); - } - - public Map<ComponentId, Servlet> getServletMap() { return servletGroup.getComponentMap(); } @@ -183,18 +168,12 @@ public final class ApplicationContainerCluster extends ContainerCluster<Applicat servletGroup.addComponent(servlet.getGlobalComponentId(), servlet); } - // Returns all servlets, including rest-api/jersey servlets. public Collection<Servlet> getAllServlets() { return allServlets().collect(Collectors.toCollection(ArrayList::new)); } private Stream<Servlet> allServlets() { - return Stream.concat(allJersey2Servlets(), - servletGroup.getComponents().stream()); - } - - private Stream<Jersey2Servlet> allJersey2Servlets() { - return restApiGroup.getComponents().stream().map(RestApi::getJersey2Servlet); + return servletGroup.getComponents().stream(); } public void setMemoryPercentage(Integer memoryPercentage) { this.memoryPercentage = memoryPercentage; diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/Jersey2Servlet.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/Jersey2Servlet.java deleted file mode 100644 index 06775d59654..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/Jersey2Servlet.java +++ /dev/null @@ -1,36 +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.model.container.jersey; - -import com.yahoo.component.ComponentId; -import com.yahoo.component.ComponentSpecification; -import com.yahoo.component.VersionSpecification; -import com.yahoo.container.bundle.BundleInstantiationSpecification; -import com.yahoo.osgi.provider.model.ComponentModel; -import com.yahoo.vespa.model.container.component.Servlet; - -/** - * @author Tony Vaagenes - */ -public class Jersey2Servlet extends Servlet { - - public static final String BUNDLE = "container-jersey2"; - public static final String CLASS = "com.yahoo.container.servlet.jersey.JerseyServletProvider"; - public static final String BINDING_SUFFIX = "/*"; - - private static final ComponentId REST_API_NAMESPACE = ComponentId.fromString("rest-api"); - - public Jersey2Servlet(String bindingPath) { - super(new ComponentModel( - new BundleInstantiationSpecification(idSpecFromPath(bindingPath), - ComponentSpecification.fromString(CLASS), - ComponentSpecification.fromString(BUNDLE))), - bindingPath + BINDING_SUFFIX); - } - - private static ComponentSpecification idSpecFromPath(String path) { - return new ComponentSpecification(RestApi.idFromPath(path), - VersionSpecification.emptyVersionSpecification, - REST_API_NAMESPACE); - } - -} diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java deleted file mode 100644 index be8209bcc4e..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApi.java +++ /dev/null @@ -1,52 +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.model.container.jersey; - -import com.yahoo.config.model.producer.AbstractConfigProducer; - -/** - * Represents a rest-api - * - * @author gjoranv - */ -public class RestApi extends AbstractConfigProducer<AbstractConfigProducer<?>> { - - private final String bindingPath; - private final Jersey2Servlet jerseyServlet; - private RestApiContext restApiContext; - - public RestApi(String bindingPath) { - super(idFromPath(bindingPath)); - this.bindingPath = bindingPath; - - jerseyServlet = createJersey2Servlet(this.bindingPath); - addChild(jerseyServlet); - } - - public static String idFromPath(String path) { - return path.replaceAll("/", "|"); - } - - private Jersey2Servlet createJersey2Servlet(String bindingPath) { - return new Jersey2Servlet(bindingPath); - } - - public String getBindingPath() { - return bindingPath; - } - - public void setRestApiContext(RestApiContext restApiContext) { - this.restApiContext = restApiContext; - addChild(restApiContext); - jerseyServlet.inject(restApiContext); - } - - public RestApiContext getContext() { return restApiContext; } - - public Jersey2Servlet getJersey2Servlet() { - return jerseyServlet; - } - - public void prepare() { - restApiContext.prepare(); - } -} diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java deleted file mode 100644 index 390539b643a..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/RestApiContext.java +++ /dev/null @@ -1,141 +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.model.container.jersey; - -import com.yahoo.config.model.producer.AbstractConfigProducer; -import com.yahoo.container.bundle.BundleInstantiationSpecification; -import com.yahoo.container.di.config.JerseyBundlesConfig; -import com.yahoo.container.di.config.JerseyInjectionConfig; -import com.yahoo.container.di.config.JerseyInjectionConfig.Inject; -import com.yahoo.osgi.provider.model.ComponentModel; -import com.yahoo.vespa.model.container.ApplicationContainerCluster; -import com.yahoo.vespa.model.container.component.Component; -import com.yahoo.vespa.model.container.component.SimpleComponent; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Predicate; -import java.util.logging.Logger; - -/** - * @author gjoranv - */ -public class RestApiContext extends SimpleComponent implements - JerseyBundlesConfig.Producer, - JerseyInjectionConfig.Producer -{ - private static final Logger log = Logger.getLogger(RestApi.class.getName()); - public static final String CONTAINER_CLASS = "com.yahoo.container.di.config.RestApiContext"; - - private final List<BundleInfo> bundles = new ArrayList<>(); - - // class name -> componentId - private final Map<String, String> injectComponentForClass = new LinkedHashMap<>(); - - private final String bindingPath; - - private ApplicationContainerCluster containerCluster; - - public RestApiContext(AbstractConfigProducer<?> ancestor, String bindingPath) { - super(componentModel(bindingPath)); - this.bindingPath = bindingPath; - - if (ancestor instanceof ApplicationContainerCluster) - containerCluster = (ApplicationContainerCluster)ancestor; - - } - - private static ComponentModel componentModel(String bindingPath) { - return new ComponentModel(BundleInstantiationSpecification.getFromStrings( - CONTAINER_CLASS + "-" + RestApi.idFromPath(bindingPath), - CONTAINER_CLASS, - null)); - } - - @Override - public void getConfig(JerseyBundlesConfig.Builder builder) { - builder.bundles(createBundlesConfig(bundles)); - } - - private List<JerseyBundlesConfig.Bundles.Builder> createBundlesConfig(List<BundleInfo> bundles) { - List<JerseyBundlesConfig.Bundles.Builder> builders = new ArrayList<>(); - for (BundleInfo b : bundles) { - builders.add( - new JerseyBundlesConfig.Bundles.Builder() - .spec(b.spec) - .packages(b.getPackagesToScan()) - ); - } - return builders; - } - - public void addBundles(Collection<BundleInfo> newBundles) { - bundles.addAll(newBundles); - } - - @Override - public void getConfig(JerseyInjectionConfig.Builder builder) { - for (Map.Entry<String, String> i : injectComponentForClass.entrySet()) { - builder.inject(new Inject.Builder() - .forClass(i.getKey()) - .instance(i.getValue())); - } - } - - @Override - public void validate() throws Exception { - super.validate(); - - if (bundles.isEmpty()) - log.warning("No bundles in rest-api '" + bindingPath + - "' - components will only be loaded from classpath."); - } - - public void prepare() { - if (containerCluster == null) return; - - containerCluster.getAllComponents().stream(). - filter(isCycleGeneratingComponent.negate()). - forEach(this::inject); - } - - - /* - * Example problem - * - * RestApiContext -> ApplicationStatusHandler -> ComponentRegistry<HttpServer> -> JettyHttpServer -> ComponentRegistry<Jersey2Servlet> -> RestApiContext - */ - private Predicate<Component> isCycleGeneratingComponent = component -> { - switch (component.getClassId().getName()) { - case CONTAINER_CLASS: - case Jersey2Servlet.CLASS: - case "com.yahoo.jdisc.http.server.jetty.JettyHttpServer": - case "com.yahoo.container.handler.observability.ApplicationStatusHandler": - return true; - default: - return false; - } - }; - - public static class BundleInfo { - // SymbolicName[:Version] - public final String spec; - - private final List<String> packagesToScan = new ArrayList<>(); - - public BundleInfo(String spec) { - this.spec = spec; - } - - public List<String> getPackagesToScan() { - return packagesToScan; - } - - public void addPackageToScan(String pkg) { - packagesToScan.add(pkg); - } - } - -} diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java b/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java deleted file mode 100644 index 4aa5882119f..00000000000 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/jersey/xml/RestApiBuilder.java +++ /dev/null @@ -1,67 +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.model.container.jersey.xml; - -import com.yahoo.config.model.deploy.DeployState; -import com.yahoo.config.model.producer.AbstractConfigProducer; -import com.yahoo.text.XML; -import com.yahoo.vespa.model.builder.xml.dom.VespaDomBuilder; -import com.yahoo.vespa.model.container.jersey.RestApi; -import com.yahoo.vespa.model.container.jersey.RestApiContext; -import org.w3c.dom.Element; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * @author gjoranv - * @since 5.6 - */ -public class RestApiBuilder extends VespaDomBuilder.DomConfigProducerBuilder<RestApi> { - - @Override - protected RestApi doBuild(DeployState deployState, AbstractConfigProducer ancestor, Element spec) { - String bindingPath = spec.getAttribute("path"); - RestApi restApi = new RestApi(bindingPath); - - restApi.setRestApiContext(createRestApiContext(ancestor, spec, bindingPath)); - return restApi; - } - - private RestApiContext createRestApiContext(AbstractConfigProducer ancestor, Element spec, String bindingPath) { - RestApiContext restApiContext = new RestApiContext(ancestor, bindingPath); - - restApiContext.addBundles(getBundles(spec)); - - return restApiContext; - } - - private List<RestApiContext.BundleInfo> getBundles(Element spec) { - List<RestApiContext.BundleInfo> bundles = new ArrayList<>(); - for (Element bundleElement : XML.getChildren(spec, "components")) { - bundles.add(getBundle(bundleElement)); - } - return bundles; - } - - private RestApiContext.BundleInfo getBundle(Element bundleElement) { - RestApiContext.BundleInfo bundle = new RestApiContext.BundleInfo(bundleElement.getAttribute("bundle")); - - for (Element packageElement : XML.getChildren(bundleElement, "package")) - bundle.addPackageToScan(XML.getValue(packageElement)); - - return bundle; - } - - // TODO: use for naming injected components instead - private Map<String, String> getInjections(Element spec) { - Map<String, String> injectForClass = new LinkedHashMap<>(); - for (Element injectElement : XML.getChildren(spec, "inject")) { - injectForClass.put(injectElement.getAttribute("for-class"), - injectElement.getAttribute("component")); - } - return injectForClass; - } - -} diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java deleted file mode 100644 index c858024f749..00000000000 --- a/config-model/src/test/java/com/yahoo/vespa/model/container/jersey/xml/RestApiTest.java +++ /dev/null @@ -1,149 +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.model.container.jersey.xml; - -import com.yahoo.component.ComponentId; -import com.yahoo.config.model.test.TestUtil; -import com.yahoo.container.ComponentsConfig; -import com.yahoo.container.di.config.JerseyBundlesConfig; -import com.yahoo.jdisc.http.ServletPathsConfig; -import com.yahoo.vespa.model.container.component.Component; -import com.yahoo.vespa.model.container.jersey.Jersey2Servlet; -import com.yahoo.vespa.model.container.jersey.RestApi; -import com.yahoo.vespa.model.container.jersey.RestApiContext; -import com.yahoo.vespa.model.container.xml.ContainerModelBuilderTestBase; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.w3c.dom.Element; - -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; - -/** - * @author gjoranv - * @author bjorncs - */ -@Ignore // TODO: remove test -public class RestApiTest extends ContainerModelBuilderTestBase { - private static final String PATH = "rest/api"; - private static final String REST_API_CONTEXT_ID = RestApiContext.CONTAINER_CLASS + "-" + RestApi.idFromPath(PATH); - private static final String INJECTED_COMPONENT_ID = "injectedHandler"; - private static final String CLUSTER_ID = "container"; - - private static final Element restApiXml = TestUtil.parse( - "<container version=\"1.0\" id=\"" + CLUSTER_ID + "\">", - " <rest-api path=\"" + PATH + "\">", - " <components bundle=\"my-jersey-bundle:1.0\">", - " <package>com.yahoo.foo</package>", - " </components>", - " </rest-api>", - " <handler id=\"" + INJECTED_COMPONENT_ID + "\" />", - "</container>"); - - private RestApi restApi; - private Jersey2Servlet servlet; - private RestApiContext context; - - @Before - public void setup() throws Exception { - createModel(root, restApiXml); - root.validate(); - getContainerCluster(CLUSTER_ID).prepare(root.getDeployState()); - restApi = getContainerCluster(CLUSTER_ID).getRestApiMap().values().iterator().next(); - servlet = restApi.getJersey2Servlet(); - context = restApi.getContext(); - } - - @Test - public void jersey2_servlet_has_correct_binding_path() { - assertThat(servlet, not(nullValue())); - assertThat(servlet.bindingPath, is(PATH + "/*")); - } - - @Test - public void jersey2_servlet_has_correct_bundle_spec() { - assertThat(servlet.model.bundleInstantiationSpec.bundle.stringValue(), is(Jersey2Servlet.BUNDLE)); - } - - @Test - public void rest_api_path_is_included_in_servlet_config() { - ServletPathsConfig config = root.getConfig(ServletPathsConfig.class, servlet.getConfigId()); - assertThat(config.servlets(servlet.getComponentId().stringValue()).path(), is(PATH + "/*")); - } - - @Test - public void resource_bundles_are_included_in_config() { - JerseyBundlesConfig config = root.getConfig(JerseyBundlesConfig.class, context.getConfigId()); - assertThat(config.bundles().size(), is(1)); - assertThat(config.bundles(0).spec(), is("my-jersey-bundle:1.0")); - } - - @Test - public void packages_to_scan_are_included_in_config() { - JerseyBundlesConfig config = root.getConfig(JerseyBundlesConfig.class, context.getConfigId()); - assertThat(config.bundles(0).packages(), contains("com.yahoo.foo")); - } - - @Test - public void jersey2_servlet_is_included_in_components_config() { - ComponentsConfig config = root.getConfig(ComponentsConfig.class, CLUSTER_ID); - assertThat(config.toString(), containsString(".id \"" + servlet.getComponentId().stringValue() + "\"")); - } - - @Test - public void restApiContext_is_included_in_components_config() { - ComponentsConfig config = root.getConfig(ComponentsConfig.class, CLUSTER_ID); - assertThat(config.toString(), containsString(".id \"" + REST_API_CONTEXT_ID + "\"")); - } - - @Test - public void all_non_restApi_components_are_injected_to_RestApiContext() { - ComponentsConfig componentsConfig = root.getConfig(ComponentsConfig.class, CLUSTER_ID); - - Set<ComponentId> clusterChildrenComponentIds = getContainerCluster(CLUSTER_ID).getAllComponents().stream() - .map(Component::getComponentId) - .collect(Collectors.toSet()); - - Set<ComponentId> restApiChildrenComponentIds = restApi.getChildren().values().stream() - .map(child -> ((Component<?, ?>) child).getComponentId()) - .collect(Collectors.toSet()); - - //TODO: try replacing with filtering against RestApiContext.isCycleGeneratingComponent - ComponentId cycleInducingComponents = ComponentId.fromString("com.yahoo.container.handler.observability.ApplicationStatusHandler"); - - Set<ComponentId> expectedInjectedConfigIds = new HashSet<>(clusterChildrenComponentIds); - expectedInjectedConfigIds.removeAll(restApiChildrenComponentIds); - expectedInjectedConfigIds.remove(cycleInducingComponents); - - Set<ComponentId> injectedConfigIds = restApiContextConfig(componentsConfig).inject().stream() - .map(inject -> ComponentId.fromString(inject.id())) - .collect(Collectors.toSet()); - - // Verify that the two sets are equal. Split in two asserts to get decent failure messages. - assertThat( - "Not all required components are injected", - injectedConfigIds, - containsInAnyOrder(expectedInjectedConfigIds.toArray())); - assertThat( - "We inject some components that should not be injected", - expectedInjectedConfigIds, - containsInAnyOrder(injectedConfigIds.toArray())); - } - - private static ComponentsConfig.Components restApiContextConfig(ComponentsConfig config) { - return config.components().stream() - .filter(component -> component.classId().equals(RestApiContext.CONTAINER_CLASS)) - .findFirst() - .get(); - } - -} |