import com.google.gson.JsonObject;
import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
+import java.io.UncheckedIOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
final String base = "http://127.0.0.1:8080/controller/nb/v2/neutron";
@Test
- public void test() {
+ public void test() throws IOException, InterruptedException {
NeutronNetworkTests.runTests(base);
NeutronSubnetTests.runTests(base);
NeutronPortTests.runTests(base);
Neutron_Bug4027_Tests.runTests(base);
}
- static HttpURLConnection httpURLConnectionFactoryGet(URL url) throws Exception {
+ static HttpURLConnection httpURLConnectionFactoryGet(URL url) throws IOException {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("Content-Type", "application/json");
return httpConn;
}
- static HttpURLConnection httpURLConnectionFactoryDelete(URL url) throws Exception {
+ static HttpURLConnection httpURLConnectionFactoryDelete(URL url) throws IOException {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("DELETE");
httpConn.setRequestProperty("Content-Type", "application/json");
return httpConn;
}
- static HttpURLConnection httpURLConnectionFactoryPost(URL url, String content) throws Exception {
+ static HttpURLConnection httpURLConnectionFactoryPost(URL url, String content) throws IOException {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/json");
return httpConn;
}
- static HttpURLConnection httpURLConnectionFactoryPut(URL url, String content) throws Exception {
+ static HttpURLConnection httpURLConnectionFactoryPut(URL url, String content) throws IOException {
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("PUT");
httpConn.setRequestProperty("Content-Type", "application/json");
URL url = new URL(url_s);
HttpURLConnection httpConn = httpURLConnectionFactoryPost(url, content);
Assert.assertEquals(context, 201, httpConn.getResponseCode());
- } catch (Exception e) {
- e.printStackTrace(); // temporary, remove me
- Assert.assertFalse("E2E Tests Failed", true);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
}
}
URL url = new URL(url_s);
HttpURLConnection httpConn = httpURLConnectionFactoryPut(url, content);
Assert.assertEquals(context, 200, httpConn.getResponseCode());
- } catch (Exception e) {
- e.printStackTrace(); // temporary, remove me
- Assert.assertFalse("E2E Tests Failed", true);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
}
}
URL url = new URL(url_s);
HttpURLConnection httpConn = httpURLConnectionFactoryGet(url);
Assert.assertEquals(context, responseCode, httpConn.getResponseCode());
- } catch (Exception e) {
- e.printStackTrace(); // temporary, remove me
- Assert.assertFalse("E2E Tests Failed", true);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
}
}
URL url = new URL(url_s);
HttpURLConnection httpConn = httpURLConnectionFactoryDelete(url);
Assert.assertEquals(context, responseCode, httpConn.getResponseCode());
- } catch (Exception e) {
- e.printStackTrace(); // temporary, remove me
- Assert.assertFalse("E2E Tests Failed", true);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
}
}
response.append(inputLine);
}
in.close();
- } catch (Exception e) {
- e.printStackTrace(); // temporary, remove me
- Assert.assertFalse("E2E Tests Failed", true);
-
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
}
return response.toString();
}
package org.opendaylight.neutron.e2etest;
+import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import org.junit.Assert;
this.base = base;
}
- public void network_collection_get_test_with_wait() {
+ public void network_collection_get_test_with_wait() throws IOException, InterruptedException {
String url_s = base + "/networks";
- try {
- int i = 0;
- while (i < TIMEOUT) {
- URL url = new URL(url_s);
- HttpURLConnection httpConn = ITNeutronE2E.httpURLConnectionFactoryGet(url);
- if (httpConn.getResponseCode() != 200) {
- LOGGER.info("trial " + Integer.toString(i) + ": failed with: "
- + Integer.toString(httpConn.getResponseCode()));
- Thread.sleep(1000);
- i += 1;
- } else {
- Assert.assertEquals("Network Collection GET failed", 200, httpConn.getResponseCode());
- return;
- }
+ int i = 0;
+ while (i < TIMEOUT) {
+ URL url = new URL(url_s);
+ HttpURLConnection httpConn = ITNeutronE2E.httpURLConnectionFactoryGet(url);
+ if (httpConn.getResponseCode() != 200) {
+ LOGGER.info("trial " + Integer.toString(i) + ": failed with: "
+ + Integer.toString(httpConn.getResponseCode()));
+ Thread.sleep(1000);
+ i += 1;
+ } else {
+ Assert.assertEquals("Network Collection GET failed", 200, httpConn.getResponseCode());
+ return;
}
- Assert.assertFalse("Network Collection GET with wait failed", true);
- } catch (Exception e) {
- Assert.assertFalse("E2E Tests Failed", true);
}
+ Assert.assertFalse("Network Collection GET with wait failed", true);
}
//TODO handle SB check
ITNeutronE2E.test_delete(url, "Network Element Delete Failed");
}
- public static void runTests(String base) {
+ public static void runTests(String base) throws IOException, InterruptedException {
NeutronNetworkTests network_tester = new NeutronNetworkTests(base);
network_tester.network_collection_get_test_with_wait();
String createJsonString = network_tester.singleton_network_create_test();
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
if (services != null) {
return bCtx.getService(services[0]);
}
- } catch (Exception e) {
+ } catch (InvalidSyntaxException e) {
LOGGER.error("Error in getInstances", e);
}
return null;
if (parts.length != 2) {
return;
}
- try {
- int length = Integer.parseInt(parts[1]);
- BigInteger lowAddress_bi = NeutronSubnetIPAllocationPool.convertV6(parts[0]);
- String lowAddress = NeutronSubnetIPAllocationPool.bigIntegerToIP(lowAddress_bi.add(BigInteger.ONE));
- BigInteger mask = BigInteger.ONE.shiftLeft(length).subtract(BigInteger.ONE);
- String highAddress = NeutronSubnetIPAllocationPool
- .bigIntegerToIP(lowAddress_bi.add(mask).subtract(BigInteger.ONE));
- if (gatewayIP == null || ("").equals(gatewayIP)) {
- gatewayIP = lowAddress;
- }
- if (allocationPools.size() < 1) {
- NeutronSubnetIPAllocationPool source = new NeutronSubnetIPAllocationPool(lowAddress,
- highAddress);
- allocationPools = source.splitPoolV6(gatewayIP);
- }
- } catch (Exception e) {
- LOGGER.warn("Failure in initDefault()", e);
- return;
+
+ int length = Integer.parseInt(parts[1]);
+ BigInteger lowAddress_bi = NeutronSubnetIPAllocationPool.convertV6(parts[0]);
+ String lowAddress = NeutronSubnetIPAllocationPool.bigIntegerToIP(lowAddress_bi.add(BigInteger.ONE));
+ BigInteger mask = BigInteger.ONE.shiftLeft(length).subtract(BigInteger.ONE);
+ String highAddress = NeutronSubnetIPAllocationPool
+ .bigIntegerToIP(lowAddress_bi.add(mask).subtract(BigInteger.ONE));
+ if (gatewayIP == null || ("").equals(gatewayIP)) {
+ gatewayIP = lowAddress;
+ }
+ if (allocationPools.size() < 1) {
+ NeutronSubnetIPAllocationPool source = new NeutronSubnetIPAllocationPool(lowAddress,
+ highAddress);
+ allocationPools = source.splitPoolV6(gatewayIP);
}
}
}
import java.math.BigInteger;
import java.net.Inet6Address;
import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
}
try {
return new BigInteger(((Inet6Address) InetAddress.getByName(inputString)).getAddress());
- } catch (Exception e) {
+ } catch (UnknownHostException e) {
LOGGER.error("convertV6 error", e);
return BigInteger.ZERO;
}
static String bigIntegerToIP(BigInteger b) {
try {
return Inet6Address.getByAddress(b.toByteArray()).getHostAddress();
- } catch (Exception e) {
+ } catch (UnknownHostException e) {
LOGGER.error("bigIntegerToIP", e);
return "ERROR";
}
/*
* remove it and return 204 status
*/
- boolean exist = false;
- try {
- exist = neutronCRUD.remove(uuid);
- } catch (Exception e) {
- final String resourceName = getResourceName();
- LOGGER.debug("exception during remove {} {} {}", resourceName, uuid, e);
- throw new InternalServerErrorException("Could not delete " + resourceName);
- }
- if (!exist) {
+ if (!neutronCRUD.remove(uuid)) {
throw new ResourceNotFoundException(uuidNoExist());
}
<suppress checks="TypeName"
files="."
/>
- <suppress checks="IllegalCatch"
- files="."
- />
- <suppress checks="RegexpSinglelineJava"
- files="."
- />
</suppressions>
return result;
}
- // this method uses reflection to update an object from it's delta.
-
- protected boolean overwrite(Object target, Object delta) {
- final Method[] methods = target.getClass().getMethods();
-
- for (final Method toMethod : methods) {
- if (toMethod.getDeclaringClass().equals(target.getClass()) && toMethod.getName().startsWith("set")) {
-
- final String toName = toMethod.getName();
- final String fromName = toName.replace("set", "get");
-
- try {
- final Method fromMethod = delta.getClass().getMethod(fromName);
- final Object value = fromMethod.invoke(delta, (Object[]) null);
- if (value != null) {
- toMethod.invoke(target, value);
- }
- } catch (final Exception e) {
- LOGGER.error("Error in overwrite", e);
- return false;
- }
- }
- }
- return true;
- }
-
@Override
public void close() throws Exception {
// TODO Auto-generated method stub