Search in sources :

Example 21 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeWebResource method deleteNode.

/**
 * Removes a set of KubeVirt nodes' config from the JSON input stream.
 *
 * @param hostname host name contained in KubeVirt nodes configuration
 * @return 204 NO_CONTENT, 400 BAD_REQUEST if the JSON is malformed, and
 * 304 NOT_MODIFIED without the updated config
 */
@DELETE
@Path("{hostname}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, REMOVE));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    KubevirtNode existing = service.node(nullIsIllegal(hostname, HOST_NAME + ERROR_MESSAGE));
    if (existing == null) {
        log.warn("There is no node configuration to delete : {}", hostname);
        return Response.notModified().build();
    } else {
        service.removeNode(hostname);
    }
    return Response.noContent().build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 22 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeWebResource method initNode.

/**
 * Initializes KubeVirt node.
 *
 * @param hostname hostname of KubeVirt node
 * @return 200 OK with init result, 404 not found, 500 server error
 */
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("init/{hostname}")
public Response initNode(@PathParam("hostname") String hostname) {
    log.trace(String.format(MESSAGE_NODE, QUERY));
    KubevirtNodeAdminService service = get(KubevirtNodeAdminService.class);
    KubevirtNode node = service.node(hostname);
    if (node == null) {
        log.error("Given node {} does not exist", hostname);
        return Response.serverError().build();
    }
    KubevirtNode updated = node.updateState(INIT);
    service.updateNode(updated);
    return ok(mapper().createObjectNode()).build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeAdminService(org.onosproject.kubevirtnode.api.KubevirtNodeAdminService) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 23 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeCodecTest method getKubevirtNode.

private KubevirtNode getKubevirtNode(String resourceName) throws IOException {
    InputStream jsonStream = KubevirtNodeCodecTest.class.getResourceAsStream(resourceName);
    JsonNode json = context.mapper().readTree(jsonStream);
    MatcherAssert.assertThat(json, notNullValue());
    KubevirtNode node = kubevirtNodeCodec.decode((ObjectNode) json, context);
    assertThat(node, notNullValue());
    return node;
}
Also used : DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeJsonMatcher.matchesKubevirtNode(org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 24 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeManagerTest method testUpdateNodeStateComplete.

/**
 * Checks if updating a node state to complete generates proper events.
 */
@Test
public void testUpdateNodeStateComplete() {
    KubevirtNode updated = DefaultKubevirtNode.from(WORKER_2).state(KubevirtNodeState.COMPLETE).build();
    target.updateNode(updated);
    assertEquals(ERR_NOT_MATCH, updated, target.node(WORKER_2_HOSTNAME));
    validateEvents(KUBEVIRT_NODE_UPDATED, KUBEVIRT_NODE_COMPLETE);
}
Also used : DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNodeTest(org.onosproject.kubevirtnode.api.KubevirtNodeTest) Test(org.junit.Test)

Example 25 with KubevirtNode

use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.

the class KubevirtNodeCodec method decode.

@Override
public KubevirtNode decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    String hostname = nullIsIllegal(json.get(HOST_NAME).asText(), HOST_NAME + MISSING_MESSAGE);
    String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
    String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
    KubevirtNode.Builder nodeBuilder = DefaultKubevirtNode.builder().hostname(hostname).type(KubevirtNode.Type.valueOf(type)).state(KubevirtNodeState.INIT).managementIp(IpAddress.valueOf(mIp));
    if (json.get(DATA_IP) != null) {
        nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
    }
    JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
    if (intBridgeJson != null) {
        nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
    }
    JsonNode tunBridgeJson = json.get(TUNNEL_BRIDGE);
    if (tunBridgeJson != null) {
        nodeBuilder.tunBridge(DeviceId.deviceId(tunBridgeJson.asText()));
    }
    // parse physical interfaces
    List<KubevirtPhyInterface> phyIntfs = new ArrayList<>();
    JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
    if (phyIntfsJson != null) {
        final JsonCodec<KubevirtPhyInterface> phyIntfCodec = context.codec(KubevirtPhyInterface.class);
        IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
            ObjectNode intfJson = get(phyIntfsJson, i);
            phyIntfs.add(phyIntfCodec.decode(intfJson, context));
        });
    }
    nodeBuilder.phyIntfs(phyIntfs);
    JsonNode externalBridgeJson = json.get(GATEWAY_BRIDGE_NAME);
    if (externalBridgeJson != null) {
        nodeBuilder.gatewayBridgeName(externalBridgeJson.asText());
    }
    log.trace("node is {}", nodeBuilder.build().toString());
    return nodeBuilder.build();
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) DefaultKubevirtNode(org.onosproject.kubevirtnode.api.DefaultKubevirtNode) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KubevirtPhyInterface(org.onosproject.kubevirtnode.api.KubevirtPhyInterface) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)46 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)11 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)11 KubevirtNodeAdminService (org.onosproject.kubevirtnode.api.KubevirtNodeAdminService)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)10 TrafficSelector (org.onosproject.net.flow.TrafficSelector)10 DefaultKubevirtNode (org.onosproject.kubevirtnode.api.DefaultKubevirtNode)9 PortNumber (org.onosproject.net.PortNumber)9 Produces (javax.ws.rs.Produces)8 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 Path (javax.ws.rs.Path)6 Test (org.junit.Test)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 GET (javax.ws.rs.GET)5 KubevirtNodeService (org.onosproject.kubevirtnode.api.KubevirtNodeService)5 KubevirtNodeJsonMatcher.matchesKubevirtNode (org.onosproject.kubevirtnode.codec.KubevirtNodeJsonMatcher.matchesKubevirtNode)5 MacAddress (org.onlab.packet.MacAddress)4 KubevirtPhyInterface (org.onosproject.kubevirtnode.api.KubevirtPhyInterface)4 Device (org.onosproject.net.Device)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3