use of com.hotels.styx.routing.config.StyxObjectDefinition in project styx by ExpediaGroup.
the class ServiceProviderHandler method serialise.
private static String serialise(String name, StyxObjectRecord<StyxService> record) {
List<String> tags = List.copyOf(record.getTags());
StyxObjectDefinition objectDef = new StyxObjectDefinition(name, record.getType(), tags, record.getConfig());
JsonNode node = YAML_MAPPER.valueToTree(objectDef);
((ObjectNode) node).set("config", record.getConfig());
try {
return YAML_MAPPER.writeValueAsString(node);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
use of com.hotels.styx.routing.config.StyxObjectDefinition in project styx by ExpediaGroup.
the class ServiceProviderHandlerTest method returnsAllProviders.
@Test
public void returnsAllProviders() throws IOException {
StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore();
ServiceProviderHandler handler = new ServiceProviderHandler(store);
HttpRequest request = HttpRequest.get("/admin/service/providers").build();
HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
assertThat(response.status(), equalTo(OK));
List<StyxObjectDefinition> actualProviders = extractProviders(response.bodyAs(UTF_8));
assertThat(actualProviders.size(), equalTo(store.entrySet().size()));
for (StyxObjectDefinition actual : actualProviders) {
Optional<StyxObjectRecord<StyxService>> rec = store.get(actual.name());
assertTrue(rec.isPresent());
validateProvider(actual, rec.get());
}
}
use of com.hotels.styx.routing.config.StyxObjectDefinition in project styx by ExpediaGroup.
the class ServiceProviderHandlerTest method returnsNamedProvider.
@Test
public void returnsNamedProvider() throws IOException {
StyxObjectStore<StyxObjectRecord<StyxService>> store = createTestStore();
ServiceProviderHandler handler = new ServiceProviderHandler(store);
HttpRequest request = HttpRequest.get("/admin/service/provider/object2").build();
HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
assertThat(response.status(), equalTo(OK));
StyxObjectDefinition actualProvider = deserialiseProvider(response.bodyAs(UTF_8));
assertThat(actualProvider, notNullValue());
assertThat(actualProvider.name(), equalTo("object2"));
validateProvider(actualProvider, store.get("object2").get());
}
use of com.hotels.styx.routing.config.StyxObjectDefinition in project styx by ExpediaGroup.
the class StyxServerComponents method readComponents.
// CHECKSTYLE:ON
private static Map<String, StyxObjectDefinition> readComponents(JsonNode root) {
Map<String, StyxObjectDefinition> handlers = new HashMap<>();
root.fields().forEachRemaining(entry -> {
String name = entry.getKey();
StyxObjectDefinition handlerDef = new JsonNodeConfig(entry.getValue()).as(StyxObjectDefinition.class);
handlers.put(name, handlerDef);
});
return handlers;
}
Aggregations