Search in sources :

Example 1 with StyxObjectDefinition

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);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with StyxObjectDefinition

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());
    }
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with StyxObjectDefinition

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());
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) HttpResponse(com.hotels.styx.api.HttpResponse) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with StyxObjectDefinition

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;
}
Also used : JsonNodeConfig(com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig) HashMap(java.util.HashMap) StyxObjectDefinition(com.hotels.styx.routing.config.StyxObjectDefinition)

Aggregations

StyxObjectDefinition (com.hotels.styx.routing.config.StyxObjectDefinition)4 StyxObjectRecord (com.hotels.styx.StyxObjectRecord)2 HttpRequest (com.hotels.styx.api.HttpRequest)2 HttpResponse (com.hotels.styx.api.HttpResponse)2 Test (org.junit.jupiter.api.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 JsonNodeConfig (com.hotels.styx.infrastructure.configuration.yaml.JsonNodeConfig)1 HashMap (java.util.HashMap)1