Resolves code smells of OpenstackNetworkingUtil, RulePopulatorUtil and cli classes.
Change-Id: Id313b66f1b5303cea17477f3763496b405f08b87
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DeleteExternalPeerRouterCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DeleteExternalPeerRouterCommand.java
index 77bec0e..1188325 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DeleteExternalPeerRouterCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DeleteExternalPeerRouterCommand.java
@@ -54,7 +54,7 @@
try {
service.deleteExternalPeerRouter(ipAddress);
} catch (IllegalArgumentException e) {
- log.error("Exception occurred because of {}", e.toString());
+ log.error("Exception occurred because of {}", e);
}
print(FORMAT, "Router IP", "Mac Address", "VLAN ID");
List<ExternalPeerRouter> routers = Lists.newArrayList(service.externalPeerRouters());
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DirectPortListCompleter.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DirectPortListCompleter.java
index f2b1e20..fbf8100 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DirectPortListCompleter.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/DirectPortListCompleter.java
@@ -51,7 +51,7 @@
Iterator<String> it = set.iterator();
while (it.hasNext()) {
- strings.add(it.next().toString());
+ strings.add(it.next());
}
return delegate.complete(session, commandLine, candidates);
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackAddAclCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackAddAclCommand.java
index 0a527e0..35ba439 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackAddAclCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackAddAclCommand.java
@@ -40,7 +40,7 @@
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FORCED_ACL_RULE;
/**
- * Add acl.
+ * Adds a acl.
*/
@Service
@Command(scope = "onos", name = "openstack-add-acl",
@@ -68,16 +68,16 @@
InstancePortService instancePortService = AbstractShellCommand.get(InstancePortService.class);
- IpAddress srcIpAddress = null;
+ IpAddress srcIpAddress;
- IpAddress dstIpAddress = null;
+ IpAddress dstIpAddress;
try {
srcIpAddress = IpAddress.valueOf(srcIpStr);
dstIpAddress = IpAddress.valueOf(dstIpStr);
} catch (IllegalArgumentException e) {
- log.error("IllegalArgumentException occurred because of {}", e.toString());
+ log.error("IllegalArgumentException occurred because of {}", e);
return;
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRemoveAclCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRemoveAclCommand.java
index 70a2347..dde4c5a 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRemoveAclCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRemoveAclCommand.java
@@ -39,6 +39,9 @@
import static org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID;
import static org.onosproject.openstacknetworking.api.Constants.PRIORITY_FORCED_ACL_RULE;
+/**
+ * Removes the registered acl.
+ */
@Service
@Command(scope = "onos", name = "openstack-remove-acl",
description = "Remove acl rules to VM")
@@ -74,7 +77,7 @@
dstIpAddress = IpAddress.valueOf(dstIpStr);
} catch (IllegalArgumentException e) {
- log.error("IllegalArgumentException occurred because of {}", e.toString());
+ log.error("IllegalArgumentException occurred because of {}", e);
return;
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
index f9791cd..b881be8 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
@@ -153,7 +153,6 @@
private static final String ERR_FLOW = "Failed set flows for floating IP %s: ";
- private static final String FLAT = "FLAT";
private static final String VXLAN = "VXLAN";
private static final String VLAN = "VLAN";
private static final String DL_DST = "dl_dst=";
@@ -190,6 +189,7 @@
.readerFor(entityClazz)
.readValue(jsonTree);
} catch (Exception e) {
+ log.error("Exception occurred because of {}", e);
throw new IllegalArgumentException();
}
}
@@ -208,7 +208,7 @@
.writerFor(entityClazz)
.writeValueAsString(entity);
log.trace(strModelEntity);
- return (ObjectNode) mapper.readTree(strModelEntity.getBytes());
+ return (ObjectNode) mapper.readTree(strModelEntity.getBytes(Charsets.UTF_8));
} catch (IOException e) {
log.error("IOException occurred because of {}", e.toString());
throw new IllegalStateException();
@@ -351,7 +351,7 @@
return null;
}
} catch (AuthenticationException e) {
- log.error("Authentication failed due to {}", e.toString());
+ log.error("Authentication failed due to {}", e);
return null;
}
}
@@ -426,7 +426,6 @@
/**
* Adds router interfaces to openstack admin service.
- * TODO fix the logic to add router interface to router
*
* @param osPort port
* @param adminService openstack admin service
@@ -447,8 +446,8 @@
} else {
adminService.addRouterInterface(rIface);
}
- } catch (IOException ignore) {
- log.error("Exception occurred because of {}", ignore.toString());
+ } catch (IOException e) {
+ log.error("IOException occurred because of {}", e);
}
});
}
@@ -571,6 +570,12 @@
Objects.equals(routerInterface1.getTenantId(), routerInterface2.getTenantId());
}
+ /**
+ * Returns the vnic type of given port.
+ *
+ * @param portName port name
+ * @return vnit type
+ */
public static VnicType vnicType(String portName) {
if (portName.startsWith(PORT_NAME_PREFIX_VM) ||
portName.startsWith(PORT_NAME_VHOST_USER_PREFIX_VM)) {
@@ -672,7 +677,7 @@
responseWriter.write(response);
sessionOutputBuffer.flush();
- log.debug(headerBaos.toString());
+ log.debug(headerBaos.toString(Charsets.UTF_8.name()));
return headerBaos.toByteArray();
} catch (IOException | HttpException e) {
@@ -694,7 +699,7 @@
response.getEntity().writeTo(baos);
log.debug(response.toString());
- log.debug(baos.toString());
+ log.debug(baos.toString(Charsets.UTF_8.name()));
return baos.toByteArray();
} catch (IOException e) {
@@ -750,10 +755,11 @@
.append(srcIp)
.append(COMMA);
+ String modifiedDstIp = dstIp;
if (osNetService.networkType(srcInstancePort.networkId()).equals(VXLAN) ||
osNetService.networkType(srcInstancePort.networkId()).equals(VLAN)) {
if (srcIp.equals(dstIp)) {
- dstIp = osNetService.gatewayIp(srcInstancePort.portId());
+ modifiedDstIp = osNetService.gatewayIp(srcInstancePort.portId());
requestStringBuilder.append(DL_DST)
.append(DEFAULT_GATEWAY_MAC_STR).append(COMMA);
} else if (!osNetService.ipPrefix(srcInstancePort.portId()).contains(IpAddress.valueOf(dstIp))) {
@@ -763,12 +769,12 @@
}
} else {
if (srcIp.equals(dstIp)) {
- dstIp = osNetService.gatewayIp(srcInstancePort.portId());
+ modifiedDstIp = osNetService.gatewayIp(srcInstancePort.portId());
}
}
requestStringBuilder.append(NW_DST)
- .append(dstIp)
+ .append(modifiedDstIp)
.append("\n");
} else {
requestStringBuilder.append(COMMA)
@@ -785,7 +791,6 @@
requestStringBuilder.append(NW_DST)
.append(srcIp)
.append("\n");
-
}
return requestStringBuilder.toString();
@@ -817,7 +822,7 @@
log.debug("requestString: {}", requestString);
final InputStream inputStream =
- new ByteArrayInputStream(requestString.getBytes());
+ new ByteArrayInputStream(requestString.getBytes(Charsets.UTF_8));
OutputStream outputStream = new ByteArrayOutputStream();
OutputStream errStream = new ByteArrayOutputStream();
@@ -855,7 +860,7 @@
}
} catch (Exception e) {
- log.error("Exception occurred because of {}", e.toString());
+ log.error("Exception occurred because of {}", e);
}
return traceResult;
@@ -928,10 +933,7 @@
}
Router osRouter = osRouterAdminService.router(osRouterIface.getId());
- if (osRouter == null) {
- return null;
- }
- if (osRouter.getExternalGatewayInfo() == null) {
+ if (osRouter == null || osRouter.getExternalGatewayInfo() == null) {
return null;
}
@@ -1033,7 +1035,7 @@
}
private static boolean isDirectPort(String portName) {
- return portNamePrefixMap().values().stream().anyMatch(p -> portName.startsWith(p));
+ return portNamePrefixMap().values().stream().anyMatch(portName::startsWith);
}
/**
@@ -1101,16 +1103,21 @@
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
+ @Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
+ @Override
public void checkClientTrusted(X509Certificate[] certs,
String authType) {
+ return;
}
+ @Override
public void checkServerTrusted(X509Certificate[] certs,
String authType) {
+ return;
}
}
};
@@ -1126,7 +1133,7 @@
config.withSSLContext(sc);
} catch (Exception e) {
- log.error("Failed to access OpenStack service due to {}", e.toString());
+ log.error("Failed to access OpenStack service due to {}", e);
return null;
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/RulePopulatorUtil.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/RulePopulatorUtil.java
index 1f6c1eb..0466e3b 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/RulePopulatorUtil.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/RulePopulatorUtil.java
@@ -48,7 +48,6 @@
private static final String CT_FLAGS = "flags";
private static final String CT_ZONE = "zone";
private static final String CT_TABLE = "recircTable";
- private static final String CT = "niciraCt";
private static final String CT_STATE = "ctState";
private static final String CT_STATE_MASK = "ctStateMask";
private static final String CT_PRESENT_FLAGS = "presentFlags";
@@ -108,7 +107,7 @@
treatment.setPropertyValue(TUNNEL_DST, remoteIp);
return treatment;
} catch (ExtensionPropertyException e) {
- log.warn("Failed to get tunnelDst extension treatment for {}", deviceId);
+ log.warn("Failed to get tunnelDst extension treatment for {} because of {}", deviceId, e);
return null;
}
}
@@ -133,7 +132,7 @@
extensionSelector.setPropertyValue(CT_STATE, ctState);
extensionSelector.setPropertyValue(CT_STATE_MASK, ctSateMask);
} catch (Exception e) {
- log.error("Failed to set nicira match CT state");
+ log.error("Failed to set nicira match CT state because of {}", e);
return null;
}
@@ -292,7 +291,7 @@
natTreatment.setPropertyValue(CT_PRESENT_FLAGS, 0);
}
} catch (Exception e) {
- log.error("Failed to set NAT due to error : {}", e.getMessage());
+ log.error("Failed to set NAT due to error : {}", e);
return null;
}
@@ -308,7 +307,7 @@
ctTreatment.setPropertyValue(CT_TABLE, table > -1 ? table : 0xff);
ctTreatment.setPropertyValue("nestedActions", nat);
} catch (Exception e) {
- log.error("Failed to set CT due to error : {}", e.getMessage());
+ log.error("Failed to set CT due to error : {}", e);
return null;
}