mirror of https://github.com/dapr/java-sdk.git
Support App HTTP middleware Pipelines (#1271)
* supporting appHttpPipelines for middleware Signed-off-by: salaboy <Salaboy@gmail.com> * adding test with inline string Signed-off-by: salaboy <Salaboy@gmail.com> * fixing checkstyle Signed-off-by: salaboy <Salaboy@gmail.com> * adding license hearders and TODO references Signed-off-by: salaboy <Salaboy@gmail.com> * Move dependency management and plugin management to parent pom (#1260) * Clean up pom Signed-off-by: sirivarma <siri.varma@outlook.com> * downgrade dependency Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix thigns Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix class not found Signed-off-by: sirivarma <siri.varma@outlook.com> * Remove import Signed-off-by: sirivarma <siri.varma@outlook.com> * Address comments Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> * cleanup Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> * Fix deps Signed-off-by: siri-varma <siri.varma@outlook.com> * cleanup Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix deps Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix things Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix finals Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix finals Signed-off-by: siri-varma <siri.varma@outlook.com> * upgrade test containers to .5 Signed-off-by: sirivarma <siri.varma@outlook.com> * This is it Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix feedback Signed-off-by: sirivarma <siri.varma@outlook.com> * Add comment Signed-off-by: sirivarma <siri.varma@outlook.com> * Add comment Signed-off-by: sirivarma <siri.varma@outlook.com> * Change to properties Signed-off-by: sirivarma <siri.varma@outlook.com> --------- Signed-off-by: sirivarma <siri.varma@outlook.com> Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Signed-off-by: siri-varma <siri.varma@outlook.com> Co-authored-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Co-authored-by: salaboy <Salaboy@gmail.com> Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Signed-off-by: salaboy <Salaboy@gmail.com> * Update docker version for CI to fix flaky tests (#1276) * update docker version for ci Signed-off-by: salaboy <Salaboy@gmail.com> * adding DOCKER_HOST to all tests Signed-off-by: salaboy <Salaboy@gmail.com> * Move dependency management and plugin management to parent pom (#1260) * Clean up pom Signed-off-by: sirivarma <siri.varma@outlook.com> * downgrade dependency Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix thigns Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix class not found Signed-off-by: sirivarma <siri.varma@outlook.com> * Remove import Signed-off-by: sirivarma <siri.varma@outlook.com> * Address comments Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> * cleanup Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> * Fix deps Signed-off-by: siri-varma <siri.varma@outlook.com> * cleanup Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix deps Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix things Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix finals Signed-off-by: siri-varma <siri.varma@outlook.com> * Fix finals Signed-off-by: siri-varma <siri.varma@outlook.com> * upgrade test containers to .5 Signed-off-by: sirivarma <siri.varma@outlook.com> * This is it Signed-off-by: sirivarma <siri.varma@outlook.com> * Fix feedback Signed-off-by: sirivarma <siri.varma@outlook.com> * Add comment Signed-off-by: sirivarma <siri.varma@outlook.com> * Add comment Signed-off-by: sirivarma <siri.varma@outlook.com> * Change to properties Signed-off-by: sirivarma <siri.varma@outlook.com> --------- Signed-off-by: sirivarma <siri.varma@outlook.com> Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Signed-off-by: siri-varma <siri.varma@outlook.com> Co-authored-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Co-authored-by: salaboy <Salaboy@gmail.com> Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Signed-off-by: salaboy <Salaboy@gmail.com> * fixing flaky docker network Signed-off-by: salaboy <Salaboy@gmail.com> --------- Signed-off-by: salaboy <Salaboy@gmail.com> Signed-off-by: sirivarma <siri.varma@outlook.com> Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Signed-off-by: siri-varma <siri.varma@outlook.com> Co-authored-by: Siri Varma Vegiraju <siri.varma@outlook.com> Co-authored-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Signed-off-by: salaboy <Salaboy@gmail.com> * Change CountWordsAcitivy output format due to clashing (#1279) Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Signed-off-by: salaboy <Salaboy@gmail.com> * Bump codecov/codecov-action from 4.4.1 to 5.4.0 (#1278) Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 4.4.1 to 5.4.0. - [Release notes](https://github.com/codecov/codecov-action/releases) - [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/codecov/codecov-action/compare/v4.4.1...v5.4.0) --- updated-dependencies: - dependency-name: codecov/codecov-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Signed-off-by: salaboy <Salaboy@gmail.com> * Bump fossas/fossa-action from 1.3.3 to 1.6.0 (#1277) Bumps [fossas/fossa-action](https://github.com/fossas/fossa-action) from 1.3.3 to 1.6.0. - [Release notes](https://github.com/fossas/fossa-action/releases) - [Commits](https://github.com/fossas/fossa-action/compare/v1.3.3...v1.6.0) --- updated-dependencies: - dependency-name: fossas/fossa-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Signed-off-by: salaboy <Salaboy@gmail.com> * update instructions to cover podman (#1274) Signed-off-by: salaboy <Salaboy@gmail.com> Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Signed-off-by: salaboy <Salaboy@gmail.com> * following checkstyle Signed-off-by: salaboy <Salaboy@gmail.com> --------- Signed-off-by: salaboy <Salaboy@gmail.com> Signed-off-by: sirivarma <siri.varma@outlook.com> Signed-off-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Signed-off-by: siri-varma <siri.varma@outlook.com> Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Siri Varma Vegiraju <siri.varma@outlook.com> Co-authored-by: Siri Varma Vegiraju <svegiraju@microsoft.com> Co-authored-by: artur-ciocanu <artur.ciocanu@gmail.com> Co-authored-by: Cassie Coyle <cassie@diagrid.io> Co-authored-by: Matheus Cruz <56329339+mcruzdev@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
f0c35968f4
commit
de82451a38
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.testcontainers;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class AppHttpPipeline implements ConfigurationSettings {
|
||||
private List<ListEntry> handlers;
|
||||
|
||||
/**
|
||||
* Creates an AppHttpPipeline.
|
||||
*
|
||||
* @param handlers List of handlers for the AppHttpPipeline
|
||||
*/
|
||||
public AppHttpPipeline(List<ListEntry> handlers) {
|
||||
if (handlers != null) {
|
||||
this.handlers = Collections.unmodifiableList(handlers);
|
||||
}
|
||||
}
|
||||
|
||||
public List<ListEntry> getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
|
@ -19,20 +19,28 @@ package io.dapr.testcontainers;
|
|||
public class Configuration {
|
||||
private final String name;
|
||||
private final TracingConfigurationSettings tracing;
|
||||
private final AppHttpPipeline appHttpPipeline;
|
||||
|
||||
//@TODO: add httpPipeline
|
||||
//@TODO: add secrets
|
||||
//@TODO: add components
|
||||
//@TODO: add accessControl
|
||||
// @TODO: add secrets https://github.com/dapr/java-sdk/issues/1280
|
||||
// @TODO: add metrics https://github.com/dapr/java-sdk/issues/1281
|
||||
// @TODO: add logging https://github.com/dapr/java-sdk/issues/1282
|
||||
// @TODO: add middleware httpPipeline https://github.com/dapr/java-sdk/issues/1283
|
||||
// @TODO: add nameResolution https://github.com/dapr/java-sdk/issues/1284
|
||||
// @TODO: add disallow components https://github.com/dapr/java-sdk/issues/1285
|
||||
// @TODO: add mtls https://github.com/dapr/java-sdk/issues/1286
|
||||
|
||||
/**
|
||||
* Creates a new configuration.
|
||||
* @param name Configuration name.
|
||||
* @param tracing TracingConfigParameters tracing configuration parameters.
|
||||
*
|
||||
* @param name Configuration name.
|
||||
* @param tracing TracingConfigParameters tracing configuration
|
||||
* parameters.
|
||||
* @param appHttpPipeline AppHttpPipeline middleware configuration.
|
||||
*/
|
||||
public Configuration(String name, TracingConfigurationSettings tracing) {
|
||||
public Configuration(String name, TracingConfigurationSettings tracing, AppHttpPipeline appHttpPipeline) {
|
||||
this.name = name;
|
||||
this.tracing = tracing;
|
||||
this.appHttpPipeline = appHttpPipeline;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
@ -42,4 +50,8 @@ public class Configuration {
|
|||
public TracingConfigurationSettings getTracing() {
|
||||
return tracing;
|
||||
}
|
||||
|
||||
public AppHttpPipeline getAppHttpPipeline() {
|
||||
return appHttpPipeline;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright 2024 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.testcontainers;
|
||||
|
||||
public class ListEntry {
|
||||
private String name;
|
||||
private String type;
|
||||
|
||||
public ListEntry(String name, String type) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,15 @@
|
|||
package io.dapr.testcontainers.converter;
|
||||
|
||||
import io.dapr.testcontainers.AppHttpPipeline;
|
||||
import io.dapr.testcontainers.Configuration;
|
||||
import io.dapr.testcontainers.ListEntry;
|
||||
import io.dapr.testcontainers.OtelTracingConfigurationSettings;
|
||||
import io.dapr.testcontainers.TracingConfigurationSettings;
|
||||
import io.dapr.testcontainers.ZipkinTracingConfigurationSettings;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfigurationYamlConverter implements YamlConverter<Configuration> {
|
||||
|
@ -58,6 +61,17 @@ public class ConfigurationYamlConverter implements YamlConverter<Configuration>
|
|||
}
|
||||
|
||||
configurationSpec.put("tracing", tracingMap);
|
||||
|
||||
}
|
||||
|
||||
AppHttpPipeline appHttpPipeline = configuration.getAppHttpPipeline();
|
||||
if (appHttpPipeline != null) {
|
||||
|
||||
Map<String, Object> appHttpPipelineMap = new LinkedHashMap<>();
|
||||
List<ListEntry> handlers = appHttpPipeline.getHandlers();
|
||||
appHttpPipelineMap.put("handlers", handlers);
|
||||
configurationSpec.put("appHttpPipeline", appHttpPipelineMap);
|
||||
|
||||
}
|
||||
|
||||
configurationProps.put("spec", configurationSpec);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.dapr.testcontainers.converter;
|
||||
|
||||
import io.dapr.testcontainers.ListEntry;
|
||||
import io.dapr.testcontainers.MetadataEntry;
|
||||
import org.yaml.snakeyaml.DumperOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
@ -21,6 +22,7 @@ public class YamlMapperFactory {
|
|||
options.setPrettyFlow(true);
|
||||
Representer representer = new Representer(options);
|
||||
representer.addClassTag(MetadataEntry.class, Tag.MAP);
|
||||
representer.addClassTag(ListEntry.class, Tag.MAP);
|
||||
return new Yaml(representer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ class ComponentYamlConverterTest {
|
|||
assertFalse(kvstore.getMetadata().isEmpty());
|
||||
|
||||
String componentYaml = converter.convert(kvstore);
|
||||
String expectedComponentYaml =
|
||||
"apiVersion: dapr.io/v1alpha1\n"
|
||||
String expectedComponentYaml = "apiVersion: dapr.io/v1alpha1\n"
|
||||
+ "kind: Component\n"
|
||||
+ "metadata:\n"
|
||||
+ " name: statestore\n"
|
||||
|
@ -48,4 +47,46 @@ class ComponentYamlConverterTest {
|
|||
|
||||
assertEquals(expectedComponentYaml, componentYaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComponentWithInLineStringToYaml() {
|
||||
DaprContainer dapr = new DaprContainer("daprio/daprd")
|
||||
.withAppName("dapr-app")
|
||||
.withAppPort(8081)
|
||||
.withComponent(new Component(
|
||||
"alias",
|
||||
"middleware.http.routeralias",
|
||||
"v1",
|
||||
Map.of("routes", "{\n" +
|
||||
" \"/mall/activity/info\": \"/v1.0/invoke/srv.default/method/mall/activity/info\",\n" +
|
||||
" \"/hello/activity/{id}/info\": \"/v1.0/invoke/srv.default/method/hello/activity/info\",\n" + //
|
||||
" \"/hello/activity/{id}/user\": \"/v1.0/invoke/srv.default/method/hello/activity/user\"\n" + //
|
||||
"}")))
|
||||
.withAppChannelAddress("host.testcontainers.internal");
|
||||
|
||||
Set<Component> components = dapr.getComponents();
|
||||
assertEquals(1, components.size());
|
||||
|
||||
Component kvstore = components.iterator().next();
|
||||
assertFalse(kvstore.getMetadata().isEmpty());
|
||||
|
||||
String componentYaml = converter.convert(kvstore);
|
||||
String expectedComponentYaml = "apiVersion: dapr.io/v1alpha1\n"
|
||||
+ "kind: Component\n"
|
||||
+ "metadata:\n"
|
||||
+ " name: alias\n"
|
||||
+ "spec:\n"
|
||||
+ " type: middleware.http.routeralias\n"
|
||||
+ " version: v1\n"
|
||||
+ " metadata:\n"
|
||||
+ " - name: routes\n"
|
||||
+ " value: |-\n"
|
||||
+ " {\n"
|
||||
+ " \"/mall/activity/info\": \"/v1.0/invoke/srv.default/method/mall/activity/info\",\n"
|
||||
+ " \"/hello/activity/{id}/info\": \"/v1.0/invoke/srv.default/method/hello/activity/info\",\n"
|
||||
+ " \"/hello/activity/{id}/user\": \"/v1.0/invoke/srv.default/method/hello/activity/user\"\n"
|
||||
+ " }\n";
|
||||
|
||||
assertEquals(expectedComponentYaml, componentYaml);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
/*
|
||||
* Copyright 2025 The Dapr Authors
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package io.dapr.testcontainers.converter;
|
||||
|
||||
import io.dapr.testcontainers.AppHttpPipeline;
|
||||
import io.dapr.testcontainers.Configuration;
|
||||
import io.dapr.testcontainers.DaprContainer;
|
||||
import io.dapr.testcontainers.ListEntry;
|
||||
import io.dapr.testcontainers.OtelTracingConfigurationSettings;
|
||||
import io.dapr.testcontainers.TracingConfigurationSettings;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
@ -10,6 +25,9 @@ import org.yaml.snakeyaml.Yaml;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
class ConfigurationYamlConverterTest {
|
||||
private final Yaml MAPPER = YamlMapperFactory.create();
|
||||
private final ConfigurationYamlConverter converter = new ConfigurationYamlConverter(MAPPER);
|
||||
|
@ -28,10 +46,16 @@ class ConfigurationYamlConverterTest {
|
|||
null
|
||||
);
|
||||
|
||||
|
||||
List<ListEntry> handlers = new ArrayList<>();
|
||||
handlers.add(new ListEntry("alias", "middleware.http.routeralias"));
|
||||
|
||||
AppHttpPipeline appHttpPipeline = new AppHttpPipeline(handlers);
|
||||
|
||||
DaprContainer dapr = new DaprContainer("daprio/daprd")
|
||||
.withAppName("dapr-app")
|
||||
.withAppPort(8081)
|
||||
.withConfiguration(new Configuration("my-config", tracing))
|
||||
.withConfiguration(new Configuration("my-config", tracing, appHttpPipeline))
|
||||
.withAppChannelAddress("host.testcontainers.internal");
|
||||
|
||||
Configuration configuration = dapr.getConfiguration();
|
||||
|
@ -50,7 +74,11 @@ class ConfigurationYamlConverterTest {
|
|||
+ " otel:\n"
|
||||
+ " endpointAddress: localhost:4317\n"
|
||||
+ " isSecure: false\n"
|
||||
+ " protocol: grpc\n";
|
||||
+ " protocol: grpc\n"
|
||||
+ " appHttpPipeline:\n"
|
||||
+ " handlers:\n"
|
||||
+ " - name: alias\n"
|
||||
+ " type: middleware.http.routeralias\n";
|
||||
|
||||
assertEquals(expectedConfigurationYaml, configurationYaml);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue