use of io.aklivity.zilla.runtime.engine.config.NamespaceConfig in project zilla by aklivity.
the class NamespaceConfigAdapterTest method shouldWriteNamespaceWithVault.
@Test
public void shouldWriteNamespaceWithVault() {
VaultConfig vault = new VaultConfig("default", "test", null);
NamespaceConfig config = new NamespaceConfig("test", emptyList(), singletonList(vault), emptyList());
String text = jsonb.toJson(config);
assertThat(text, not(nullValue()));
assertThat(text, equalTo("{\"name\":\"test\",\"vaults\":{\"default\":{\"type\":\"test\"}}}"));
}
use of io.aklivity.zilla.runtime.engine.config.NamespaceConfig in project zilla by aklivity.
the class NamespaceConfigAdapterTest method shouldWriteNamespaceWithNamespace.
@Test
public void shouldWriteNamespaceWithNamespace() {
NamespaceRef reference = new NamespaceRef("test", emptyMap());
NamespaceConfig config = new NamespaceConfig("test", singletonList(reference), emptyList(), emptyList());
String text = jsonb.toJson(config);
assertThat(text, not(nullValue()));
assertThat(text, equalTo("{\"name\":\"test\",\"references\":[{\"name\":\"test\"}]}"));
}
use of io.aklivity.zilla.runtime.engine.config.NamespaceConfig in project zilla by aklivity.
the class NamespaceConfigAdapterTest method shouldReadNamespaceWithNamespace.
@Test
public void shouldReadNamespaceWithNamespace() {
String text = "{" + "\"name\": \"test\"," + "\"references\":" + "[" + "{" + "\"name\": \"test\"" + "}" + "]" + "}";
NamespaceConfig config = jsonb.fromJson(text, NamespaceConfig.class);
assertThat(config, not(nullValue()));
assertThat(config.name, equalTo("test"));
assertThat(config.bindings, emptyCollectionOf(BindingConfig.class));
assertThat(config.vaults, emptyCollectionOf(VaultConfig.class));
assertThat(config.references, hasSize(1));
assertThat(config.references.get(0).name, equalTo("test"));
assertThat(config.references.get(0).links, equalTo(emptyMap()));
}
use of io.aklivity.zilla.runtime.engine.config.NamespaceConfig in project zilla by aklivity.
the class ConfigureTask method call.
@Override
public Void call() throws Exception {
String configText;
if (configURL == null) {
configText = "{\"name\":\"default\"}";
} else if ("https".equals(configURL.getProtocol()) || "https".equals(configURL.getProtocol())) {
HttpClient client = HttpClient.newBuilder().version(HTTP_2).followRedirects(NORMAL).build();
HttpRequest request = HttpRequest.newBuilder().GET().uri(configURL.toURI()).build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
String body = response.body();
configText = body;
} else {
URLConnection connection = configURL.openConnection();
try (InputStream input = connection.getInputStream()) {
configText = new String(input.readAllBytes(), UTF_8);
}
}
if (config.configSyntaxMustache()) {
configText = Mustache.resolve(configText, System::getenv);
}
logger.accept(configText);
List<String> errors = new LinkedList<>();
parse: try {
InputStream schemaInput = Engine.class.getResourceAsStream("internal/schema/engine.schema.json");
JsonProvider schemaProvider = JsonProvider.provider();
JsonReader schemaReader = schemaProvider.createReader(schemaInput);
JsonObject schemaObject = schemaReader.readObject();
for (URL schemaType : schemaTypes) {
InputStream schemaPatchInput = schemaType.openStream();
JsonReader schemaPatchReader = schemaProvider.createReader(schemaPatchInput);
JsonArray schemaPatchArray = schemaPatchReader.readArray();
JsonPatch schemaPatch = schemaProvider.createPatch(schemaPatchArray);
schemaObject = schemaPatch.apply(schemaObject);
}
JsonParser schemaParser = schemaProvider.createParserFactory(null).createParser(new StringReader(schemaObject.toString()));
JsonValidationService service = JsonValidationService.newInstance();
ProblemHandler handler = service.createProblemPrinter(errors::add);
JsonSchemaReader reader = service.createSchemaReader(schemaParser);
JsonSchema schema = new UniquePropertyKeysSchema(reader.read());
JsonProvider provider = service.createJsonProvider(schema, parser -> handler);
provider.createReader(new StringReader(configText)).read();
if (!errors.isEmpty()) {
break parse;
}
JsonbConfig config = new JsonbConfig().withAdapters(new NamespaceAdapter());
Jsonb jsonb = JsonbBuilder.newBuilder().withProvider(provider).withConfig(config).build();
NamespaceConfig namespace = jsonb.fromJson(configText, NamespaceConfig.class);
if (!errors.isEmpty()) {
break parse;
}
namespace.id = supplyId.applyAsInt(namespace.name);
for (BindingConfig binding : namespace.bindings) {
binding.id = NamespacedId.id(namespace.id, supplyId.applyAsInt(binding.entry));
if (binding.vault != null) {
binding.vault.id = NamespacedId.id(supplyId.applyAsInt(ofNullable(binding.vault.namespace).orElse(namespace.name)), supplyId.applyAsInt(binding.vault.name));
}
// TODO: consider route exit namespace
for (RouteConfig route : binding.routes) {
route.id = NamespacedId.id(namespace.id, supplyId.applyAsInt(route.exit));
}
// TODO: consider binding exit namespace
if (binding.exit != null) {
binding.exit.id = NamespacedId.id(namespace.id, supplyId.applyAsInt(binding.exit.exit));
}
tuning.affinity(binding.id, tuning.affinity(binding.id));
}
for (VaultConfig vault : namespace.vaults) {
vault.id = NamespacedId.id(namespace.id, supplyId.applyAsInt(vault.name));
}
CompletableFuture<Void> future = CompletableFuture.completedFuture(null);
for (DispatchAgent dispatcher : dispatchers) {
future = CompletableFuture.allOf(future, dispatcher.attach(namespace));
}
future.join();
extensions.forEach(e -> e.onConfigured(context));
} catch (Throwable ex) {
errorHandler.onError(ex);
}
if (!errors.isEmpty()) {
errors.forEach(msg -> errorHandler.onError(new JsonException(msg)));
}
return null;
}
use of io.aklivity.zilla.runtime.engine.config.NamespaceConfig in project zilla by aklivity.
the class NamespaceConfigAdapterTest method shouldWriteNamespaceWithBinding.
@Test
public void shouldWriteNamespaceWithBinding() {
BindingConfig binding = new BindingConfig(null, "test", "test", SERVER, null, emptyList(), null);
NamespaceConfig namespace = new NamespaceConfig("test", emptyList(), emptyList(), singletonList(binding));
String text = jsonb.toJson(namespace);
assertThat(text, not(nullValue()));
assertThat(text, equalTo("{\"name\":\"test\",\"bindings\":{\"test\":{\"type\":\"test\",\"kind\":\"server\"}}}"));
}
Aggregations