use of org.onosproject.k8snetworking.api.K8sPort in project onos by opennetworkinglab.
the class K8sSwitchingHostProvider method processPortRemoved.
/**
* Processes port removal event.
*
* @param port ONOS port
*/
private void processPortRemoved(Port port) {
ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
Set<Host> hosts = hostService.getConnectedHosts(connectPoint);
hosts.forEach(h -> hostProviderService.hostVanished(h.id()));
K8sPort k8sPort = portToK8sPortByName(port);
if (k8sPort == null) {
k8sPort = portToK8sPortByMac(port);
if (k8sPort == null) {
log.warn(ERR_ADD_HOST + "Kubernetes port for {} not found", port);
return;
}
}
k8sNetworkService.removePort(k8sPort.portId());
}
use of org.onosproject.k8snetworking.api.K8sPort in project onos by opennetworkinglab.
the class K8sPortWebResource method updatePort.
/**
* Updates the port with the specified identifier.
*
* @param id port identifier
* @param input port JSON input stream
* @return 200 OK with the updated port, 400 BAD_REQUEST if the requested
* port does not exist
* @onos.rsModel K8sPort
*/
@PUT
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updatePort(@PathParam("id") String id, InputStream input) {
log.trace(String.format(MESSAGE, "UPDATED"));
try {
ObjectNode jsonTree = readTreeFromStream(mapper(), input);
JsonNode specifiedPortId = jsonTree.get("portId");
if (specifiedPortId != null && !specifiedPortId.asText().equals(id)) {
throw new IllegalArgumentException(PORT_INVALID);
}
final K8sPort port = codec(K8sPort.class).decode(jsonTree, this);
adminService.updatePort(port);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
return Response.ok().build();
}
use of org.onosproject.k8snetworking.api.K8sPort in project onos by opennetworkinglab.
the class K8sPortCodecTest method testK8sPortDecode.
/**
* Tests the kubernetes port decoding.
*/
@Test
public void testK8sPortDecode() throws IOException {
K8sPort port = getK8sPort("K8sPort.json");
assertEquals("network-1", port.networkId());
assertEquals("port-1", port.portId());
assertEquals("00:11:22:33:44:55", port.macAddress().toString());
assertEquals("10.10.10.10", port.ipAddress().toString());
assertEquals("of:0000000000000001", port.deviceId().toString());
assertEquals("1", port.portNumber().toString());
assertEquals("ACTIVE", port.state().name());
}
use of org.onosproject.k8snetworking.api.K8sPort in project onos by opennetworkinglab.
the class K8sPortCodecTest method getK8sPort.
/**
* Reads in an kubernetes port from the given resource and decodes it.
*
* @param resourceName resource to use to read the JSON for the rule
* @return decoded kubernetes port
* @throws IOException if processing the resource fails
*/
private K8sPort getK8sPort(String resourceName) throws IOException {
InputStream jsonStream = K8sPortCodecTest.class.getResourceAsStream(resourceName);
JsonNode json = context.mapper().readTree(jsonStream);
MatcherAssert.assertThat(json, notNullValue());
K8sPort port = k8sPortCodec.decode((ObjectNode) json, context);
assertThat(port, notNullValue());
return port;
}
use of org.onosproject.k8snetworking.api.K8sPort in project onos by opennetworkinglab.
the class K8sPortCodecTest method testK8sPortEncode.
/**
* Tests the kubernetes port encoding.
*/
@Test
public void testK8sPortEncode() {
K8sPort port = DefaultK8sPort.builder().networkId("network-1").portId("port-1").deviceId(DeviceId.deviceId("of:0000000000000001")).ipAddress(IpAddress.valueOf("10.10.10.2")).macAddress(MacAddress.valueOf("00:11:22:33:44:55")).portNumber(PortNumber.portNumber(1)).state(ACTIVE).build();
ObjectNode nodeJson = k8sPortCodec.encode(port, context);
assertThat(nodeJson, matchesK8sPort(port));
}
Aggregations