[ONOS-6449] Fix arista driver to support interface name with slash, Fix HttpSBControllerImpl because mediaType.getType() only return primary type
Change-Id: I9540bc298ee8b3c6ea2e5c6659dd12b006bbb79b
diff --git a/drivers/arista/src/main/java/org/onosproject/drivers/arista/DeviceDescriptionDiscoveryAristaImpl.java b/drivers/arista/src/main/java/org/onosproject/drivers/arista/DeviceDescriptionDiscoveryAristaImpl.java
index c4edb18..2c3cfd8 100644
--- a/drivers/arista/src/main/java/org/onosproject/drivers/arista/DeviceDescriptionDiscoveryAristaImpl.java
+++ b/drivers/arista/src/main/java/org/onosproject/drivers/arista/DeviceDescriptionDiscoveryAristaImpl.java
@@ -59,7 +59,7 @@
private static final String ETHERNET = "Ethernet";
private static final String MANAGEMENT = "Management";
private static final String INTERFACE_TYPE = "interfaceType";
- private static final int WEIGHTING_FACTOR_MANAGEMENT_INTERFACE = 100;
+ private static final int WEIGHTING_FACTOR_MANAGEMENT_INTERFACE = 10000;
private static final String JSONRPC = "jsonrpc";
private static final String METHOD = "method";
private static final String RUN_CMDS = "runCmds";
@@ -107,7 +107,7 @@
String response = controller.post(deviceId, API_ENDPOINT,
new ByteArrayInputStream(sendObjNode.toString().getBytes()),
- MediaType.APPLICATION_JSON, String.class);
+ MediaType.APPLICATION_JSON_TYPE, String.class);
try {
ObjectNode node = (ObjectNode) mapper.readTree(response);
@@ -143,7 +143,7 @@
private int getPortNumber(String interfaceName) {
if (interfaceName.startsWith(ETHERNET)) {
- return Integer.valueOf(interfaceName.substring(ETHERNET.length()));
+ return Integer.valueOf(interfaceName.substring(ETHERNET.length()).replace('/', '0'));
} else {
return Integer.valueOf(interfaceName.substring(MANAGEMENT.length())).intValue()
+ WEIGHTING_FACTOR_MANAGEMENT_INTERFACE;
diff --git a/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java b/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
index 550e346..9065b08 100644
--- a/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
+++ b/protocols/rest/api/src/main/java/org/onosproject/protocol/http/ctl/HttpSBControllerImpl.java
@@ -160,9 +160,8 @@
Response response = null;
if (payload != null) {
try {
- response = wt.request(mediaType).post(
- Entity.entity(IOUtils.toString(payload, StandardCharsets.UTF_8), mediaType)
- );
+ response = wt.request(mediaType)
+ .post(Entity.entity(IOUtils.toString(payload, StandardCharsets.UTF_8), mediaType));
} catch (IOException e) {
log.error("Cannot do POST {} request on device {} because can't read payload", request, device);
}
@@ -185,13 +184,13 @@
Response response = null;
if (payload != null) {
try {
- response = wt.request(mediaType.getType()).put(Entity.entity(IOUtils.
- toString(payload, StandardCharsets.UTF_8), mediaType.getType()));
+ response = wt.request(mediaType).put(Entity.entity(IOUtils.
+ toString(payload, StandardCharsets.UTF_8), mediaType));
} catch (IOException e) {
log.error("Cannot do PUT {} request on device {} because can't read payload", request, device);
}
} else {
- response = wt.request(mediaType.getType()).put(Entity.entity(null, mediaType.getType()));
+ response = wt.request(mediaType).put(Entity.entity(null, mediaType));
}
if (response == null) {
@@ -209,7 +208,7 @@
public InputStream get(DeviceId device, String request, MediaType mediaType) {
WebTarget wt = getWebTarget(device, request);
- Response s = wt.request(mediaType.getType()).get();
+ Response s = wt.request(mediaType).get();
if (checkReply(s)) {
return new ByteArrayInputStream(s.readEntity((String.class)).getBytes(StandardCharsets.UTF_8));
@@ -236,7 +235,7 @@
}
if (payload != null) {
StringEntity input = new StringEntity(IOUtils.toString(payload, StandardCharsets.UTF_8));
- input.setContentType(mediaType.getType());
+ input.setContentType(mediaType.toString());
httprequest.setEntity(input);
}
CloseableHttpClient httpClient;
@@ -265,7 +264,7 @@
// FIXME: do we need to delete an entry by enclosing data in DELETE
// request?
// wouldn't it be nice to use PUT to implement the similar concept?
- Response response = wt.request(mediaType.getType()).delete();
+ Response response = wt.request(mediaType).delete();
return response.getStatus();
}