Search in sources :

Example 1 with RouteConfig

use of io.aklivity.zilla.runtime.engine.config.RouteConfig in project zilla by aklivity.

the class BindingConfigsAdapter method adaptFromJson.

@Override
public BindingConfig[] adaptFromJson(JsonObject object) {
    List<BindingConfig> bindings = new LinkedList<>();
    for (String entry : object.keySet()) {
        JsonObject item = object.getJsonObject(entry);
        String type = item.getString(TYPE_NAME);
        route.adaptType(type);
        options.adaptType(type);
        NamespacedRef vault = item.containsKey(VAULT_NAME) ? NamespacedRef.of(item.getString(VAULT_NAME)) : null;
        KindConfig kind = this.kind.adaptFromJson(item.getJsonString(KIND_NAME));
        OptionsConfig opts = item.containsKey(OPTIONS_NAME) ? options.adaptFromJson(item.getJsonObject(OPTIONS_NAME)) : null;
        MutableInteger order = new MutableInteger();
        List<RouteConfig> routes = item.containsKey(ROUTES_NAME) ? item.getJsonArray(ROUTES_NAME).stream().map(JsonValue::asJsonObject).peek(o -> route.adaptFromJsonIndex(order.value++)).map(route::adaptFromJson).collect(toList()) : ROUTES_DEFAULT;
        RouteConfig exit = item.containsKey(EXIT_NAME) ? new RouteConfig(routes.size(), item.getString(EXIT_NAME)) : null;
        bindings.add(new BindingConfig(vault, entry, type, kind, opts, routes, exit));
    }
    return bindings.toArray(BindingConfig[]::new);
}
Also used : JsonValue(jakarta.json.JsonValue) Collections.emptyList(java.util.Collections.emptyList) JsonArrayBuilder(jakarta.json.JsonArrayBuilder) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) Json(jakarta.json.Json) JsonbAdapter(jakarta.json.bind.adapter.JsonbAdapter) JsonObjectBuilder(jakarta.json.JsonObjectBuilder) OptionsConfigAdapterSpi(io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) OptionsConfig(io.aklivity.zilla.runtime.engine.config.OptionsConfig) RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) JsonObject(jakarta.json.JsonObject) KindConfig(io.aklivity.zilla.runtime.engine.config.KindConfig) LinkedList(java.util.LinkedList) MutableInteger(org.agrona.collections.MutableInteger) NamespacedRef(io.aklivity.zilla.runtime.engine.config.NamespacedRef) OptionsConfig(io.aklivity.zilla.runtime.engine.config.OptionsConfig) MutableInteger(org.agrona.collections.MutableInteger) JsonValue(jakarta.json.JsonValue) JsonObject(jakarta.json.JsonObject) RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) NamespacedRef(io.aklivity.zilla.runtime.engine.config.NamespacedRef) LinkedList(java.util.LinkedList) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) KindConfig(io.aklivity.zilla.runtime.engine.config.KindConfig)

Example 2 with RouteConfig

use of io.aklivity.zilla.runtime.engine.config.RouteConfig in project zilla by aklivity.

the class BindingConfigsAdapterTest method shouldWriteBindingWithExit.

@Test
public void shouldWriteBindingWithExit() {
    BindingConfig[] bindings = { new BindingConfig(null, "test", "test", SERVER, null, emptyList(), new RouteConfig("test")) };
    String text = jsonb.toJson(bindings);
    assertThat(text, not(nullValue()));
    assertThat(text, equalTo("{\"test\":{\"type\":\"test\",\"kind\":\"server\",\"exit\":\"test\"}}"));
}
Also used : BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) Test(org.junit.Test)

Example 3 with RouteConfig

use of io.aklivity.zilla.runtime.engine.config.RouteConfig in project zilla by aklivity.

the class RouteConfigAdapterTest method shouldWriteRouteWhenMatch.

@Test
public void shouldWriteRouteWhenMatch() {
    RouteConfig route = new RouteConfig("test", singletonList(new TestConditionConfig("test")));
    String text = jsonb.toJson(route);
    assertThat(text, not(nullValue()));
    assertThat(text, equalTo("{\"exit\":\"test\",\"when\":[{\"match\":\"test\"}]}"));
}
Also used : RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) TestConditionConfig(io.aklivity.zilla.runtime.engine.internal.config.ConditionConfigAdapterTest.TestConditionConfig) Test(org.junit.Test)

Example 4 with RouteConfig

use of io.aklivity.zilla.runtime.engine.config.RouteConfig in project zilla by aklivity.

the class RouteConfigAdapterTest method shouldReadRouteWhenMatch.

@Test
public void shouldReadRouteWhenMatch() {
    String text = "{" + "\"exit\": \"test\"," + "\"when\":" + "[" + "{ \"match\": \"test\" }" + "]" + "}";
    RouteConfig route = jsonb.fromJson(text, RouteConfig.class);
    assertThat(route, not(nullValue()));
    assertThat(route.exit, equalTo("test"));
    assertThat(route.when, hasSize(1));
    assertThat(route.when, contains(instanceOf(TestConditionConfig.class)));
}
Also used : RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) Test(org.junit.Test)

Example 5 with RouteConfig

use of io.aklivity.zilla.runtime.engine.config.RouteConfig in project zilla by aklivity.

the class RouteConfigAdapterTest method shouldWriteRoute.

@Test
public void shouldWriteRoute() {
    RouteConfig route = new RouteConfig("test");
    String text = jsonb.toJson(route);
    assertThat(text, not(nullValue()));
    assertThat(text, equalTo("{\"exit\":\"test\"}"));
}
Also used : RouteConfig(io.aklivity.zilla.runtime.engine.config.RouteConfig) Test(org.junit.Test)

Aggregations

RouteConfig (io.aklivity.zilla.runtime.engine.config.RouteConfig)8 BindingConfig (io.aklivity.zilla.runtime.engine.config.BindingConfig)4 Test (org.junit.Test)4 JsonObject (jakarta.json.JsonObject)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Engine (io.aklivity.zilla.runtime.engine.Engine)1 EngineConfiguration (io.aklivity.zilla.runtime.engine.EngineConfiguration)1 ConditionConfig (io.aklivity.zilla.runtime.engine.config.ConditionConfig)1 KindConfig (io.aklivity.zilla.runtime.engine.config.KindConfig)1 NamespaceConfig (io.aklivity.zilla.runtime.engine.config.NamespaceConfig)1 NamespacedRef (io.aklivity.zilla.runtime.engine.config.NamespacedRef)1 OptionsConfig (io.aklivity.zilla.runtime.engine.config.OptionsConfig)1 OptionsConfigAdapterSpi (io.aklivity.zilla.runtime.engine.config.OptionsConfigAdapterSpi)1 VaultConfig (io.aklivity.zilla.runtime.engine.config.VaultConfig)1 WithConfig (io.aklivity.zilla.runtime.engine.config.WithConfig)1 EngineExtContext (io.aklivity.zilla.runtime.engine.ext.EngineExtContext)1 EngineExtSpi (io.aklivity.zilla.runtime.engine.ext.EngineExtSpi)1 Tuning (io.aklivity.zilla.runtime.engine.internal.Tuning)1 TestConditionConfig (io.aklivity.zilla.runtime.engine.internal.config.ConditionConfigAdapterTest.TestConditionConfig)1