Search in sources :

Example 6 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtListFloatingIpCommand method json.

private String json(List<KubevirtFloatingIp> fips) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (KubevirtFloatingIp fip : fips) {
        result.add(jsonForEntity(fip, KubevirtFloatingIp.class));
    }
    return prettyJson(mapper, result.toString());
}
Also used : KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtFloatingIpCodec method decode.

@Override
public KubevirtFloatingIp decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String id = nullIsIllegal(json.get(ID).asText(), ID + MISSING_MESSAGE);
    String routerName = nullIsIllegal(json.get(ROUTER_NAME).asText(), ROUTER_NAME + MISSING_MESSAGE);
    String floatingIp = nullIsIllegal(json.get(FLOATING_IP).asText(), FLOATING_IP + MISSING_MESSAGE);
    String networkName = nullIsIllegal(json.get(NETWORK_NAME).asText(), NETWORK_NAME + MISSING_MESSAGE);
    KubevirtFloatingIp.Builder builder = DefaultKubevirtFloatingIp.builder().id(id).routerName(routerName).networkName(networkName).floatingIp(IpAddress.valueOf(floatingIp));
    JsonNode podName = json.get(POD_NAME);
    if (podName != null) {
        builder.podName(podName.asText());
    }
    JsonNode vmName = json.get(VM_NAME);
    if (vmName != null) {
        builder.vmName(vmName.asText());
    }
    JsonNode fixedIp = json.get(FIXED_IP);
    if (fixedIp != null) {
        builder.fixedIp(IpAddress.valueOf(fixedIp.asText()));
    }
    return builder.build();
}
Also used : DefaultKubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.DefaultKubevirtFloatingIp) KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 8 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtFloatingIpCodecTest method testKubevirtFloatingIpDecode.

@Test
public void testKubevirtFloatingIpDecode() throws IOException {
    KubevirtFloatingIp floatingIp = getKubevirtFloatingIp("KubevirtFloatingIp.json");
    assertEquals("fip-1", floatingIp.id());
    assertEquals("router-1", floatingIp.routerName());
    assertEquals("flat-1", floatingIp.networkName());
    assertEquals("10.10.10.10", floatingIp.floatingIp().toString());
    assertEquals("pod-1", floatingIp.podName());
    assertEquals("vm-1", floatingIp.vmName());
    assertEquals("20.20.20.20", floatingIp.fixedIp().toString());
}
Also used : DefaultKubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.DefaultKubevirtFloatingIp) KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp(org.onosproject.kubevirtnetworking.codec.KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp) KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) Test(org.junit.Test)

Example 9 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtFloatingIpCodecTest method testKubevirtFloatingIpEncode.

/**
 * Tests the kubevirt floating IP encoding.
 */
@Test
public void testKubevirtFloatingIpEncode() {
    KubevirtFloatingIp floatingIp = DefaultKubevirtFloatingIp.builder().id("fip-id").routerName("router-1").networkName("flat-1").floatingIp(IpAddress.valueOf("10.10.10.10")).podName("pod-1").vmName("vm-1").fixedIp(IpAddress.valueOf("20.20.20.20")).build();
    ObjectNode floatingIpJson = kubevirtFloatingIpCodec.encode(floatingIp, context);
    assertThat(floatingIpJson, matchesKubevirtFloatingIp(floatingIp));
}
Also used : DefaultKubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.DefaultKubevirtFloatingIp) KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp(org.onosproject.kubevirtnetworking.codec.KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp) KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Test(org.junit.Test)

Example 10 with KubevirtFloatingIp

use of org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp in project onos by opennetworkinglab.

the class KubevirtFloatingIpCodecTest method getKubevirtFloatingIp.

private KubevirtFloatingIp getKubevirtFloatingIp(String resourceName) throws IOException {
    InputStream jsonStream = KubevirtFloatingIpCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    MatcherAssert.assertThat(json, notNullValue());
    KubevirtFloatingIp fip = kubevirtFloatingIpCodec.decode((ObjectNode) json, context);
    assertThat(fip, notNullValue());
    return fip;
}
Also used : DefaultKubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.DefaultKubevirtFloatingIp) KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp(org.onosproject.kubevirtnetworking.codec.KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp) KubevirtFloatingIp(org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

KubevirtFloatingIp (org.onosproject.kubevirtnetworking.api.KubevirtFloatingIp)10 DefaultKubevirtFloatingIp (org.onosproject.kubevirtnetworking.api.DefaultKubevirtFloatingIp)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 KubevirtRouterService (org.onosproject.kubevirtnetworking.api.KubevirtRouterService)3 KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp (org.onosproject.kubevirtnetworking.codec.KubevirtFloatingIpJsonMatcher.matchesKubevirtFloatingIp)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2 Test (org.junit.Test)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Path (javax.ws.rs.Path)1 KubevirtNetworkingUtil.genFormatString (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)1 IndexTableId (org.onosproject.net.flow.IndexTableId)1