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();
}
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();
}
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;
}
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);
}
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();
}
Aggregations