*/
package org.opendaylight.ovsdb.utils.mdsal.utils;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collection;
import java.util.List;
import java.util.Set;
}
@Override
+ @SuppressFBWarnings("NN_NAKED_NOTIFY")
public void onDataTreeChanged(Collection<DataTreeModification<DataObject>> changes) {
if (!listen) {
return;
import com.esotericsoftware.yamlbeans.YamlException;
import com.esotericsoftware.yamlbeans.YamlReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.io.Reader;
+import java.io.Writer;
import java.net.InetSocketAddress;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
private boolean runDocker;
private boolean createOdlNetwork;
- class DockerComposeServiceInfo {
- public String name;
- public String port;
+ private static class DockerComposeServiceInfo {
+ String name;
+ String port;
}
private final Map<String, DockerComposeServiceInfo> dockerComposeServices = new HashMap<>();
ProcUtils.runProcess(60000, upCmd);
isRunning = true;
int waitSeconds = Integer.parseInt(envDockerWaitForPing);
- waitForOvsdbServers(waitSeconds * 1000);
+ waitForOvsdbServers(waitSeconds * 1000L);
}
private void setupEnvForDockerCompose(String venvWs) {
YamlReader yamlReader = null;
Map root = null;
try {
- yamlReader = new YamlReader(new FileReader(tmpDockerComposeFile));
+ yamlReader = new YamlReader(new InputStreamReader(new FileInputStream(tmpDockerComposeFile),
+ StandardCharsets.UTF_8));
root = (Map) yamlReader.read();
} catch (FileNotFoundException e) {
LOG.warn("DockerOvs.parseDockerComposeYaml error reading yaml file", e);
isRunning = false;
}
- tmpDockerComposeFile.delete();
+ if (!tmpDockerComposeFile.delete()) {
+ LOG.warn("Failed to delete {}", tmpDockerComposeFile);
+ }
}
/**
* checked to make sure the Open_Vswitch DB is present. Note that this thread will
* run until it succeeds unless its interrupt() method is called.
*/
- private class OvsdbPing extends Thread {
-
+ private static class OvsdbPing extends Thread {
private final String host;
private final int port;
private final AtomicInteger result;
* @param ovsNumber which OVS is this?
* @param result an AtomicInteger that is incremented upon a successful "ping"
*/
- OvsdbPing(int ovsNumber, AtomicInteger result) {
- this.host = getOvsdbAddress(ovsNumber);
- this.port = Integer.parseInt(getOvsdbPort(ovsNumber));
+ OvsdbPing(AtomicInteger result, String host, int port) {
+ this.host = host;
+ this.port = port;
this.result = result;
listDbsRequest = ByteBuffer.wrap(
- ("{\"method\": \"list_dbs\", \"params\": [], \"id\": " + port + "}").getBytes());
+ ("{\"method\": \"list_dbs\", \"params\": [], \"id\": " + port + "}").getBytes(StandardCharsets.UTF_8));
listDbsRequest.mark();
}
OvsdbPing[] pingers = new OvsdbPing[numOvs];
if (numOvs == 1) {
- pingers[0] = new OvsdbPing(0, numRunningOvs);
+ pingers[0] = new OvsdbPing(numRunningOvs, getOvsdbAddress(0), Integer.parseInt(getOvsdbPort(0)));
pingers[0].start();
} else {
for (int i = 0; i < numOvs; i++) {
- pingers[i] = new OvsdbPing(i + 1, numRunningOvs);
+ pingers[i] = new OvsdbPing(numRunningOvs, getOvsdbAddress(i + 1),
+ Integer.parseInt(getOvsdbPort(i + 1)));
pingers[i].start();
}
}
try {
tmpFile = File.createTempFile("ovsdb-it-tmp-", null);
- try (Reader in = new InputStreamReader(url.openStream());
- FileWriter out = new FileWriter(tmpFile)) {
+ try (Reader in = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8);
+ Writer out = new OutputStreamWriter(new FileOutputStream(tmpFile), StandardCharsets.UTF_8)) {
char[] buf = new char[1024];
int read;
while (-1 != (read = in.read(buf))) {
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
int exitValue = -1;
// Use a try block to guarantee stdout and stderr are closed
- try (BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream()));
- BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream()))) {
+ try (BufferedReader stdout = new BufferedReader(new InputStreamReader(proc.getInputStream(),
+ StandardCharsets.UTF_8));
+ BufferedReader stderr = new BufferedReader(new InputStreamReader(proc.getErrorStream(),
+ StandardCharsets.UTF_8))) {
exitValue = waitForExitValue(waitFor, proc);
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.ovsdb.utils.config.ConfigProperties;
import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils;
private final MdsalUtils mdsalUtils;
public static final String OPENFLOW_CONNECTION_PROTOCOL = "tcp";
public static final String OPENFLOW_SECURE_PROTOCOL = "ssl";
- public static short OPENFLOW_PORT = 6653;
+ public static final short OPENFLOW_PORT = 6653;
public static final String OVSDB_URI_PREFIX = "ovsdb";
public static final String BRIDGE_URI_PREFIX = "bridge";
private static final String DISABLE_IN_BAND = "disable-in-band";
return protocolList;
}
- public boolean addBridge(final ConnectionInfo connectionInfo, InstanceIdentifier<Node> bridgeIid,
- final String bridgeName, NodeId bridgeNodeId, final boolean setProtocolEntries,
- final Class<? extends OvsdbFailModeBase> failMode, final boolean setManagedBy,
- final Class<? extends DatapathTypeBase> dpType,
- final List<BridgeExternalIds> externalIds,
- final List<ControllerEntry> controllerEntries,
- final List<BridgeOtherConfigs> otherConfigs,
- final String dpid) throws InterruptedException {
- return addBridge(connectionInfo, bridgeIid, bridgeName, bridgeNodeId, setProtocolEntries, failMode,
- setManagedBy, dpType, externalIds, controllerEntries, otherConfigs, dpid);
- }
-
/*
* base method for adding test bridges. Other helper methods used to create bridges should utilize this method.
*
if (controllersStr.isEmpty()) {
LOG.warn("Failed to determine OpenFlow controller ip address");
} else if (LOG.isDebugEnabled()) {
- controllerIpStr = "";
- for (String currControllerIpStr : controllersStr) {
- controllerIpStr += " " + currControllerIpStr;
- }
- LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(), controllerIpStr);
+ LOG.debug("Found {} OpenFlow Controller(s) :{}", controllersStr.size(),
+ controllersStr.stream().collect(Collectors.joining(" ")));
}
return controllersStr;
return false;
}
- if (dbVersion != null && !dbVersion.isEmpty() && minVersion != null
- && !minVersion.isEmpty()) {
- if (Integer.valueOf(dbVersionMatcher.group(1)).equals(Integer.valueOf(minVersionMatcher.group(1)))
- && Integer.valueOf(dbVersionMatcher.group(2)).equals(Integer.valueOf(minVersionMatcher.group(2)))
- && Integer.valueOf(dbVersionMatcher.group(3)).equals(Integer.valueOf(minVersionMatcher.group(3)))) {
+ if (dbVersion != null && !dbVersion.isEmpty() && minVersion != null && !minVersion.isEmpty()) {
+ final int dbVersionMatch1 = Integer.parseInt(dbVersionMatcher.group(1));
+ final int dbVersionMatch2 = Integer.parseInt(dbVersionMatcher.group(2));
+ final int dbVersionMatch3 = Integer.parseInt(dbVersionMatcher.group(3));
+ final int minVersionMatch1 = Integer.parseInt(minVersionMatcher.group(1));
+ final int minVersionMatch2 = Integer.parseInt(minVersionMatcher.group(2));
+ final int minVersionMatch3 = Integer.parseInt(minVersionMatcher.group(3));
+ if (dbVersionMatch1 == minVersionMatch1 && dbVersionMatch2 == minVersionMatch2
+ && dbVersionMatch3 == minVersionMatch3) {
return true;
}
- if (Integer.valueOf(dbVersionMatcher.group(1)).intValue()
- > Integer.valueOf(minVersionMatcher.group(1)).intValue()) {
+ if (dbVersionMatch1 > minVersionMatch1) {
return true;
}
- if (Integer.valueOf(dbVersionMatcher.group(1)).intValue()
- < Integer.valueOf(minVersionMatcher.group(1)).intValue()) {
+ if (dbVersionMatch1 < minVersionMatch1) {
return false;
}
// major version is equal
- if (Integer.valueOf(dbVersionMatcher.group(2)).intValue()
- > Integer.valueOf(minVersionMatcher.group(2)).intValue()) {
+ if (dbVersionMatch2 > minVersionMatch2) {
return true;
}
- if (Integer.valueOf(dbVersionMatcher.group(2)).intValue()
- < Integer.valueOf(minVersionMatcher.group(2)).intValue()) {
+ if (dbVersionMatch2 < minVersionMatch2) {
return false;
}
- if (Integer.valueOf(dbVersionMatcher.group(3)).intValue()
- > Integer.valueOf(minVersionMatcher.group(3)).intValue()) {
+ if (dbVersionMatch3 > minVersionMatch3) {
return true;
}
}