_authcookie variable.
+ * Logs into the Nicira API. The cookie is stored in the _authcookie variable.
*
* The method returns false if the login failed or the connection could not be made.
+ *
*/
protected void login() throws NiciraNvpApiException {
String url;
- if (_host == null || _host.isEmpty() ||
- _adminuser == null || _adminuser.isEmpty() ||
- _adminpass == null || _adminpass.isEmpty()) {
+ if (host == null || host.isEmpty() ||
+ adminuser == null || adminuser.isEmpty() ||
+ adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
}
try {
- url = new URL(_protocol, _host, "/ws.v1/login").toString();
+ url = new URL(protocol, host, "/ws.v1/login").toString();
} catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
}
PostMethod pm = new PostMethod(url);
- pm.addParameter("username", _adminuser);
- pm.addParameter("password", _adminpass);
+ pm.addParameter("username", adminuser);
+ pm.addParameter("password", adminpass);
try {
- _client.executeMethod(pm);
+ client.executeMethod(pm);
} catch (HttpException e) {
throw new NiciraNvpApiException("Nicira NVP API login failed ", e);
} catch (IOException e) {
@@ -189,44 +191,47 @@ public class NiciraNvpApi {
// Extract the version for later use
if (pm.getResponseHeader("Server") != null) {
- _nvpversion = pm.getResponseHeader("Server").getValue();
- s_logger.debug("NVP Controller reports version " + _nvpversion);
+ nvpVersion = pm.getResponseHeader("Server").getValue();
+ s_logger.debug("NVP Controller reports version " + nvpVersion);
}
// Success; the cookie required for login is kept in _client
}
- public LogicalSwitch createLogicalSwitch(LogicalSwitch logicalSwitch) throws NiciraNvpApiException {
- String uri = "/ws.v1/lswitch";
+ public LogicalSwitch createLogicalSwitch(final LogicalSwitch logicalSwitch) throws NiciraNvpApiException {
+ String uri = SWITCH_URI_PREFIX;
LogicalSwitch createdLogicalSwitch = executeCreateObject(logicalSwitch, new TypeToken(){}.getType(), uri, Collections.emptyMap());
return createdLogicalSwitch;
}
- public void deleteLogicalSwitch(String uuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lswitch/" + uuid;
+ public void deleteLogicalSwitch(final String uuid) throws NiciraNvpApiException {
+ String uri = SWITCH_URI_PREFIX + uuid;
executeDeleteObject(uri);
}
- public LogicalSwitchPort createLogicalSwitchPort(String logicalSwitchUuid, LogicalSwitchPort logicalSwitchPort) throws NiciraNvpApiException {
- String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport";
- LogicalSwitchPort createdLogicalSwitchPort = executeCreateObject(logicalSwitchPort, new TypeToken(){}.getType(), uri, Collections.emptyMap());;
+ public LogicalSwitchPort createLogicalSwitchPort(final String logicalSwitchUuid, final LogicalSwitchPort logicalSwitchPort)
+ throws NiciraNvpApiException {
+ String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport";
+ LogicalSwitchPort createdLogicalSwitchPort = executeCreateObject(logicalSwitchPort,
+ new TypeToken(){}.getType(), uri, Collections.emptyMap());
return createdLogicalSwitchPort;
}
- public void modifyLogicalSwitchPortAttachment(String logicalSwitchUuid, String logicalSwitchPortUuid, Attachment attachment) throws NiciraNvpApiException {
- String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid + "/attachment";
+ public void modifyLogicalSwitchPortAttachment(final String logicalSwitchUuid, final String logicalSwitchPortUuid,
+ Attachment attachment) throws NiciraNvpApiException {
+ String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid + "/attachment";
executeUpdateObject(attachment, uri, Collections.emptyMap());
}
- public void deleteLogicalSwitchPort(String logicalSwitchUuid, String logicalSwitchPortUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid;
+ public void deleteLogicalSwitchPort(final String logicalSwitchUuid, final String logicalSwitchPortUuid) throws NiciraNvpApiException {
+ String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid;
executeDeleteObject(uri);
}
- public String findLogicalSwitchPortUuidByVifAttachmentUuid(String logicalSwitchUuid, String vifAttachmentUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport";
+ public String findLogicalSwitchPortUuidByVifAttachmentUuid(final String logicalSwitchUuid, final String vifAttachmentUuid) throws NiciraNvpApiException {
+ String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport";
Map params = new HashMap();
params.put("attachment_vif_uuid", vifAttachmentUuid);
params.put("fields", "uuid");
@@ -248,8 +253,9 @@ public class NiciraNvpApi {
return ccs;
}
- public NiciraNvpList findLogicalSwitchPortsByUuid(String logicalSwitchUuid, String logicalSwitchPortUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport";
+ public NiciraNvpList findLogicalSwitchPortsByUuid(final String logicalSwitchUuid,
+ final String logicalSwitchPortUuid) throws NiciraNvpApiException {
+ String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport";
Map params = new HashMap();
params.put("uuid", logicalSwitchPortUuid);
params.put("fields", "uuid");
@@ -263,64 +269,66 @@ public class NiciraNvpApi {
return lspl;
}
- public LogicalRouterConfig createLogicalRouter(LogicalRouterConfig logicalRouterConfig) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter";
+ public LogicalRouterConfig createLogicalRouter(final LogicalRouterConfig logicalRouterConfig) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX;
LogicalRouterConfig lrc = executeCreateObject(logicalRouterConfig, new TypeToken(){}.getType(), uri, Collections.emptyMap());
return lrc;
}
- public void deleteLogicalRouter(String logicalRouterUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid;
+ public void deleteLogicalRouter(final String logicalRouterUuid) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid;
executeDeleteObject(uri);
}
- public LogicalRouterPort createLogicalRouterPort(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
+ public LogicalRouterPort createLogicalRouterPort(final String logicalRouterUuid, final LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport";
LogicalRouterPort lrp = executeCreateObject(logicalRouterPort, new TypeToken(){}.getType(), uri, Collections.emptyMap());
return lrp;
}
- public void deleteLogicalRouterPort(String logicalRouterUuid, String logicalRouterPortUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPortUuid;
+ public void deleteLogicalRouterPort(final String logicalRouterUuid, final String logicalRouterPortUuid) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport/" + logicalRouterPortUuid;
executeDeleteObject(uri);
}
- public void modifyLogicalRouterPort(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPort.getUuid();
+ public void modifyLogicalRouterPort(final String logicalRouterUuid, final LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport/" + logicalRouterPort.getUuid();
executeUpdateObject(logicalRouterPort, uri, Collections.emptyMap());
}
- public void modifyLogicalRouterPortAttachment(String logicalRouterUuid, String logicalRouterPortUuid, Attachment attachment) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPortUuid + "/attachment";
+ public void modifyLogicalRouterPortAttachment(final String logicalRouterUuid, final String logicalRouterPortUuid,
+ final Attachment attachment) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport/" + logicalRouterPortUuid + "/attachment";
executeUpdateObject(attachment, uri, Collections.emptyMap());
}
- public NatRule createLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat";
+ public NatRule createLogicalRouterNatRule(final String logicalRouterUuid, final NatRule natRule) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat";
return executeCreateObject(natRule, new TypeToken(){}.getType(), uri, Collections.emptyMap());
}
- public void modifyLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat/" + natRule.getUuid();
+ public void modifyLogicalRouterNatRule(final String logicalRouterUuid, final NatRule natRule) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat/" + natRule.getUuid();
executeUpdateObject(natRule, uri, Collections.emptyMap());
}
- public void deleteLogicalRouterNatRule(String logicalRouterUuid, UUID natRuleUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat/" + natRuleUuid.toString();
+ public void deleteLogicalRouterNatRule(final String logicalRouterUuid, final UUID natRuleUuid) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat/" + natRuleUuid.toString();
executeDeleteObject(uri);
}
- public NiciraNvpList findLogicalRouterPortByGatewayServiceAndVlanId(String logicalRouterUuid, String gatewayServiceUuid, long vlanId) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
+ public NiciraNvpList findLogicalRouterPortByGatewayServiceAndVlanId(
+ final String logicalRouterUuid, final String gatewayServiceUuid, final long vlanId) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport";
Map params = new HashMap();
params.put("attachment_gwsvc_uuid", gatewayServiceUuid);
params.put("attachment_vlan", "0");
@@ -329,28 +337,29 @@ public class NiciraNvpApi {
return executeRetrieveObject(new TypeToken>(){}.getType(), uri, params);
}
- public LogicalRouterConfig findOneLogicalRouterByUuid(String logicalRouterUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid;
+ public LogicalRouterConfig findOneLogicalRouterByUuid(final String logicalRouterUuid) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid;
return executeRetrieveObject(new TypeToken(){}.getType(), uri, Collections.emptyMap());
}
- public void updateLogicalRouterPortConfig(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport" + logicalRouterPort.getUuid();
+ public void updateLogicalRouterPortConfig(final String logicalRouterUuid, final LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport" + logicalRouterPort.getUuid();
executeUpdateObject(logicalRouterPort, uri, Collections.emptyMap());
}
- public NiciraNvpList findNatRulesByLogicalRouterUuid(String logicalRouterUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat";
+ public NiciraNvpList findNatRulesByLogicalRouterUuid(final String logicalRouterUuid) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat";
Map params = new HashMap();
params.put("fields","*");
return executeRetrieveObject(new TypeToken>(){}.getType(), uri, params);
}
- public NiciraNvpList findLogicalRouterPortByGatewayServiceUuid(String logicalRouterUuid, String l3GatewayServiceUuid) throws NiciraNvpApiException {
- String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
+ public NiciraNvpList findLogicalRouterPortByGatewayServiceUuid(final String logicalRouterUuid,
+ final String l3GatewayServiceUuid) throws NiciraNvpApiException {
+ String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport";
Map params = new HashMap();
params.put("fields", "*");
params.put("attachment_gwsvc_uuid", l3GatewayServiceUuid);
@@ -358,18 +367,18 @@ public class NiciraNvpApi {
return executeRetrieveObject(new TypeToken>(){}.getType(), uri, params);
}
- protected void executeUpdateObject(T newObject, String uri, Map parameters) throws NiciraNvpApiException {
- if (_host == null || _host.isEmpty() ||
- _adminuser == null || _adminuser.isEmpty() ||
- _adminpass == null || _adminpass.isEmpty()) {
+ protected void executeUpdateObject(final T newObject, final String uri, final Map parameters) throws NiciraNvpApiException {
+ if (host == null || host.isEmpty() ||
+ adminuser == null || adminuser.isEmpty() ||
+ adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
}
PutMethod pm = (PutMethod) createMethod("put", uri);
- pm.setRequestHeader("Content-Type", "application/json");
+ pm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
try {
pm.setRequestEntity(new StringRequestEntity(
- _gson.toJson(newObject),"application/json", null));
+ gson.toJson(newObject),JSON_CONTENT_TYPE, null));
} catch (UnsupportedEncodingException e) {
throw new NiciraNvpApiException("Failed to encode json request body", e);
}
@@ -385,18 +394,19 @@ public class NiciraNvpApi {
pm.releaseConnection();
}
- protected T executeCreateObject(T newObject, Type returnObjectType, String uri, Map parameters) throws NiciraNvpApiException {
- if (_host == null || _host.isEmpty() ||
- _adminuser == null || _adminuser.isEmpty() ||
- _adminpass == null || _adminpass.isEmpty()) {
+ protected T executeCreateObject(final T newObject, final Type returnObjectType, final String uri,
+ final Map parameters) throws NiciraNvpApiException {
+ if (host == null || host.isEmpty() ||
+ adminuser == null || adminuser.isEmpty() ||
+ adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
}
PostMethod pm = (PostMethod) createMethod("post", uri);
- pm.setRequestHeader("Content-Type", "application/json");
+ pm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
try {
pm.setRequestEntity(new StringRequestEntity(
- _gson.toJson(newObject),"application/json", null));
+ gson.toJson(newObject),JSON_CONTENT_TYPE, null));
} catch (UnsupportedEncodingException e) {
throw new NiciraNvpApiException("Failed to encode json request body", e);
}
@@ -412,7 +422,7 @@ public class NiciraNvpApi {
T result;
try {
- result = (T)_gson.fromJson(pm.getResponseBodyAsString(), TypeToken.get(newObject.getClass()).getType());
+ result = (T)gson.fromJson(pm.getResponseBodyAsString(), TypeToken.get(newObject.getClass()).getType());
} catch (IOException e) {
throw new NiciraNvpApiException("Failed to decode json response body", e);
} finally {
@@ -422,15 +432,15 @@ public class NiciraNvpApi {
return result;
}
- protected void executeDeleteObject(String uri) throws NiciraNvpApiException {
- if (_host == null || _host.isEmpty() ||
- _adminuser == null || _adminuser.isEmpty() ||
- _adminpass == null || _adminpass.isEmpty()) {
+ protected void executeDeleteObject(final String uri) throws NiciraNvpApiException {
+ if (host == null || host.isEmpty() ||
+ adminuser == null || adminuser.isEmpty() ||
+ adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
}
DeleteMethod dm = (DeleteMethod) createMethod("delete", uri);
- dm.setRequestHeader("Content-Type", "application/json");
+ dm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
executeMethod(dm);
@@ -443,15 +453,16 @@ public class NiciraNvpApi {
dm.releaseConnection();
}
- protected T executeRetrieveObject(Type returnObjectType, String uri, Map parameters) throws NiciraNvpApiException {
- if (_host == null || _host.isEmpty() ||
- _adminuser == null || _adminuser.isEmpty() ||
- _adminpass == null || _adminpass.isEmpty()) {
+ protected T executeRetrieveObject(final Type returnObjectType, final String uri,
+ final Map parameters) throws NiciraNvpApiException {
+ if (host == null || host.isEmpty() ||
+ adminuser == null || adminuser.isEmpty() ||
+ adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
}
GetMethod gm = (GetMethod) createMethod("get", uri);
- gm.setRequestHeader("Content-Type", "application/json");
+ gm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
if (parameters != null && !parameters.isEmpty()) {
List nameValuePairs = new ArrayList(parameters.size());
for (Entry e : parameters.entrySet()) {
@@ -471,7 +482,7 @@ public class NiciraNvpApi {
T returnValue;
try {
- returnValue = (T)_gson.fromJson(gm.getResponseBodyAsString(), returnObjectType);
+ returnValue = (T)gson.fromJson(gm.getResponseBodyAsString(), returnObjectType);
} catch (IOException e) {
s_logger.error("IOException while retrieving response body",e);
throw new NiciraNvpApiException(e);
@@ -481,14 +492,14 @@ public class NiciraNvpApi {
return returnValue;
}
- protected void executeMethod(HttpMethodBase method) throws NiciraNvpApiException {
+ protected void executeMethod(final HttpMethodBase method) throws NiciraNvpApiException {
try {
- _client.executeMethod(method);
+ client.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
method.releaseConnection();
// login and try again
login();
- _client.executeMethod(method);
+ client.executeMethod(method);
}
} catch (HttpException e) {
s_logger.error("HttpException caught while trying to connect to the Nicira NVP Controller", e);
@@ -501,15 +512,15 @@ public class NiciraNvpApi {
}
}
- private String responseToErrorMessage(HttpMethodBase method) {
+ private String responseToErrorMessage(final HttpMethodBase method) {
assert method.isRequestSent() : "no use getting an error message unless the request is sent";
- if ("text/html".equals(method.getResponseHeader("Content-Type").getValue())) {
+ if (TEXT_HTML_CONTENT_TYPE.equals(method.getResponseHeader(CONTENT_TYPE).getValue())) {
// The error message is the response content
// Safety margin of 1024 characters, anything longer is probably useless
// and will clutter the logs
try {
- return method.getResponseBodyAsString(1024);
+ return method.getResponseBodyAsString(BODY_RESP_MAX_LEN);
} catch (IOException e) {
s_logger.debug("Error while loading response body", e);
}
@@ -531,22 +542,22 @@ public class NiciraNvpApi {
public TrustingProtocolSocketFactory() throws IOException {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {
- new X509TrustManager() {
- @Override
- public X509Certificate[] getAcceptedIssuers() {
- return null;
- }
-
- @Override
- public void checkClientTrusted(X509Certificate[] certs, String authType) {
- // Trust always
- }
-
- @Override
- public void checkServerTrusted(X509Certificate[] certs, String authType) {
- // Trust always
- }
+ new X509TrustManager() {
+ @Override
+ public X509Certificate[] getAcceptedIssuers() {
+ return null;
}
+
+ @Override
+ public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
+ // Trust always
+ }
+
+ @Override
+ public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
+ // Trust always
+ }
+ }
};
try {
@@ -562,26 +573,25 @@ public class NiciraNvpApi {
}
@Override
- public Socket createSocket(String host, int port) throws IOException,
- UnknownHostException {
+ public Socket createSocket(final String host, final int port) throws IOException {
return ssf.createSocket(host, port);
}
@Override
- public Socket createSocket(String address, int port, InetAddress localAddress,
- int localPort) throws IOException, UnknownHostException {
+ public Socket createSocket(final String address, final int port, final InetAddress localAddress,
+ final int localPort) throws IOException, UnknownHostException {
return ssf.createSocket(address, port, localAddress, localPort);
}
@Override
- public Socket createSocket(Socket socket, String host, int port,
- boolean autoClose) throws IOException, UnknownHostException {
+ public Socket createSocket(final Socket socket, final String host, final int port,
+ final boolean autoClose) throws IOException, UnknownHostException {
return ssf.createSocket(socket, host, port, autoClose);
}
@Override
- public Socket createSocket(String host, int port, InetAddress localAddress,
- int localPort, HttpConnectionParams params) throws IOException,
+ public Socket createSocket(final String host, final int port, final InetAddress localAddress,
+ final int localPort, final HttpConnectionParams params) throws IOException,
UnknownHostException, ConnectTimeoutException {
int timeout = params.getConnectionTimeout();
if (timeout == 0) {
@@ -594,16 +604,15 @@ public class NiciraNvpApi {
return s;
}
}
-
-
}
public static class NatRuleAdapter implements JsonDeserializer {
@Override
- public NatRule deserialize(JsonElement jsonElement, Type type,
- JsonDeserializationContext context) throws JsonParseException {
+ public NatRule deserialize(final JsonElement jsonElement, final Type type,
+ final JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject();
+
if (!jsonObject.has("type")) {
throw new JsonParseException("Deserializing as a NatRule, but no type present in the json object");
}
@@ -611,8 +620,7 @@ public class NiciraNvpApi {
String natRuleType = jsonObject.get("type").getAsString();
if ("SourceNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, SourceNatRule.class);
- }
- else if ("DestinationNatRule".equals(natRuleType)) {
+ } else if ("DestinationNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, DestinationNatRule.class);
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApiException.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApiException.java
index db34a15d7b8..facc5ab59e3 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApiException.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpApiException.java
@@ -21,15 +21,15 @@ public class NiciraNvpApiException extends Exception {
public NiciraNvpApiException() {
}
- public NiciraNvpApiException(String message) {
+ public NiciraNvpApiException(final String message) {
super(message);
}
- public NiciraNvpApiException(Throwable cause) {
+ public NiciraNvpApiException(final Throwable cause) {
super(cause);
}
- public NiciraNvpApiException(String message, Throwable cause) {
+ public NiciraNvpApiException(final String message, final Throwable cause) {
super(message, cause);
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpList.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpList.java
index 9d78e84e0eb..ba6ff974790 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpList.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpList.java
@@ -20,10 +20,10 @@ import java.util.List;
public class NiciraNvpList {
private List results;
- private int result_count;
+ private int resultCount;
public List getResults() {
- return results;
+ return this.results;
}
public void setResults(List results) {
@@ -31,15 +31,15 @@ public class NiciraNvpList {
}
public int getResultCount() {
- return result_count;
+ return resultCount;
}
- public void setResultCount(int result_count) {
- this.result_count = result_count;
+ public void setResultCount(int resultCount) {
+ this.resultCount = resultCount;
}
public boolean isEmpty() {
- return result_count == 0;
+ return this.resultCount == 0;
}
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
index a5dd3bd1206..0b69cc981c8 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
@@ -19,6 +19,7 @@ package com.cloud.network.nicira;
import org.apache.log4j.Logger;
public class NiciraNvpTag {
+ private static final int TAG_MAX_LEN = 40;
private static final Logger s_logger = Logger.getLogger(NiciraNvpTag.class);
private String scope;
private String tag;
@@ -29,7 +30,7 @@ public class NiciraNvpTag {
this.scope = scope;
if (tag.length() > 40) {
s_logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters");
- this.tag = tag.substring(0, 40);
+ this.tag = tag.substring(0, TAG_MAX_LEN);
} else {
this.tag = tag;
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/PatchAttachment.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/PatchAttachment.java
index 137f0710f18..ebad6f98bcc 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/PatchAttachment.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/PatchAttachment.java
@@ -21,18 +21,19 @@ package com.cloud.network.nicira;
*/
public class PatchAttachment extends Attachment {
private final String type = "PatchAttachment";
- private String peer_port_uuid;
+ private String peerPortUuid;
public PatchAttachment(String peerPortUuid) {
- peer_port_uuid = peerPortUuid;
+ this.peerPortUuid = peerPortUuid;
}
public String getPeerPortUuid() {
- return peer_port_uuid;
+ return peerPortUuid;
}
public void setPeerPortUuid(String peerPortUuid) {
- peer_port_uuid = peerPortUuid;
+ this.peerPortUuid = peerPortUuid;
}
+
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/RouterNextHop.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/RouterNextHop.java
index a204e557adb..7622c68c287 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/RouterNextHop.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/RouterNextHop.java
@@ -20,19 +20,18 @@ package com.cloud.network.nicira;
*
*/
public class RouterNextHop {
- private String gateway_ip_address;
- private String type = "RouterNextHop";
+ private String gatewayIpAddress;
+ private final String type = "RouterNextHop";
public RouterNextHop(String gatewayIpAddress) {
- gateway_ip_address = gatewayIpAddress;
+ this.gatewayIpAddress = gatewayIpAddress;
}
public String getGatewayIpAddress() {
- return gateway_ip_address;
+ return gatewayIpAddress;
}
- public void setGatewayIpAddress(String gateway_ip_address) {
- this.gateway_ip_address = gateway_ip_address;
+ public void setGatewayIpAddress(String gatewayIpAddress) {
+ this.gatewayIpAddress = gatewayIpAddress;
}
-
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplictRoutingConfig.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplictRoutingConfig.java
index 1228deb3f5d..bbe1cb56ea2 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplictRoutingConfig.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SingleDefaultRouteImplictRoutingConfig.java
@@ -20,19 +20,18 @@ package com.cloud.network.nicira;
*
*/
public class SingleDefaultRouteImplictRoutingConfig extends RoutingConfig {
- public RouterNextHop default_route_next_hop;
+ public RouterNextHop defaultRouteNextHop;
public String type = "SingleDefaultRouteImplicitRoutingConfig";
public SingleDefaultRouteImplictRoutingConfig(RouterNextHop routerNextHop) {
- default_route_next_hop = routerNextHop;
+ defaultRouteNextHop = routerNextHop;
}
public RouterNextHop getDefaultRouteNextHop() {
- return default_route_next_hop;
+ return defaultRouteNextHop;
}
- public void setDefaultRouteNextHop(RouterNextHop default_route_next_hop) {
- this.default_route_next_hop = default_route_next_hop;
+ public void setDefaultRouteNextHop(RouterNextHop defaultRouteNextHop) {
+ this.defaultRouteNextHop = defaultRouteNextHop;
}
-
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java
index 910f83028f5..db1bdb4976c 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/SourceNatRule.java
@@ -29,7 +29,7 @@ public class SourceNatRule extends NatRule {
return toSourceIpAddressMax;
}
- public void setToSourceIpAddressMax(String toSourceIpAddressMax) {
+ public void setToSourceIpAddressMax(final String toSourceIpAddressMax) {
this.toSourceIpAddressMax = toSourceIpAddressMax;
}
@@ -37,7 +37,7 @@ public class SourceNatRule extends NatRule {
return toSourceIpAddressMin;
}
- public void setToSourceIpAddressMin(String toSourceIpAddressMin) {
+ public void setToSourceIpAddressMin(final String toSourceIpAddressMin) {
this.toSourceIpAddressMin = toSourceIpAddressMin;
}
@@ -45,7 +45,7 @@ public class SourceNatRule extends NatRule {
return toSourcePort;
}
- public void setToSourcePort(Integer toSourcePort) {
+ public void setToSourcePort(final Integer toSourcePort) {
this.toSourcePort = toSourcePort;
}
@@ -67,7 +67,7 @@ public class SourceNatRule extends NatRule {
}
@Override
- public boolean equals(Object obj) {
+ public boolean equals(final Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
@@ -94,7 +94,7 @@ public class SourceNatRule extends NatRule {
}
@Override
- public boolean equalsIgnoreUuid(Object obj) {
+ public boolean equalsIgnoreUuid(final Object obj) {
if (this == obj)
return true;
if (!super.equalsIgnoreUuid(obj))
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java
index 9c5f44d642b..a5047e01e21 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/TransportZoneBinding.java
@@ -17,30 +17,30 @@
package com.cloud.network.nicira;
public class TransportZoneBinding {
- private String zone_uuid;
- private String transport_type;
+ private String zoneUuid;
+ private String transportType;
public TransportZoneBinding() {}
- public TransportZoneBinding(String zone_uuid, String transport_type) {
- this.zone_uuid = zone_uuid;
- this.transport_type = transport_type;
+ public TransportZoneBinding(String zoneUuid, String transportType) {
+ this.zoneUuid = zoneUuid;
+ this.transportType = transportType;
}
- public String getZone_uuid() {
- return zone_uuid;
+ public String getZoneUuid() {
+ return zoneUuid;
}
- public void setZone_uuid(String zone_uuid) {
- this.zone_uuid = zone_uuid;
+ public void setZoneUuid(String zoneUuid) {
+ this.zoneUuid = zoneUuid;
}
- public String getTransport_type() {
- return transport_type;
+ public String getTransportType() {
+ return transportType;
}
- public void setTransport_type(String transport_type) {
- this.transport_type = transport_type;
+ public void setTransportType(String transportType) {
+ this.transportType = transportType;
}
}
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java
index 3a0b5f31905..7b37ac151f1 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/VifAttachment.java
@@ -18,21 +18,21 @@ package com.cloud.network.nicira;
public class VifAttachment extends Attachment {
private final String type = "VifAttachment";
- private String vif_uuid;
+ private String vifUuid;
public VifAttachment() {
}
- public VifAttachment(String vifUuid) {
- vif_uuid = vifUuid;
+ public VifAttachment(final String vifUuid) {
+ this.vifUuid = vifUuid;
}
- public String getVif_uuid() {
- return vif_uuid;
+ public String getVifUuid() {
+ return vifUuid;
}
- public void setVif_uuid(String vif_uuid) {
- this.vif_uuid = vif_uuid;
+ public void setVifUuid(String vifUuid) {
+ this.vifUuid = vifUuid;
}
public String getType() {
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java
index 3ab5f2bc49c..c04c9ba5ea8 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/resource/NiciraNvpResource.java
@@ -82,39 +82,41 @@ import com.cloud.network.nicira.VifAttachment;
import com.cloud.resource.ServerResource;
public class NiciraNvpResource implements ServerResource {
+ private static final int NAME_MAX_LEN = 40;
+
private static final Logger s_logger = Logger.getLogger(NiciraNvpResource.class);
- private String _name;
- private String _guid;
- private String _zoneId;
- private int _numRetries;
+ private String name;
+ private String guid;
+ private String zoneId;
+ private int numRetries;
- private NiciraNvpApi _niciraNvpApi;
+ private NiciraNvpApi niciraNvpApi;
protected NiciraNvpApi createNiciraNvpApi() {
return new NiciraNvpApi();
}
@Override
- public boolean configure(String name, Map params)
+ public boolean configure(String ignoredName, final Map params)
throws ConfigurationException {
- _name = (String) params.get("name");
- if (_name == null) {
+ name = (String) params.get("name");
+ if (name == null) {
throw new ConfigurationException("Unable to find name");
}
- _guid = (String)params.get("guid");
- if (_guid == null) {
+ guid = (String)params.get("guid");
+ if (guid == null) {
throw new ConfigurationException("Unable to find the guid");
}
- _zoneId = (String) params.get("zoneId");
- if (_zoneId == null) {
+ zoneId = (String) params.get("zoneId");
+ if (zoneId == null) {
throw new ConfigurationException("Unable to find zone");
}
- _numRetries = 2;
+ numRetries = 2;
String ip = (String) params.get("ip");
if (ip == null) {
@@ -131,9 +133,9 @@ public class NiciraNvpResource implements ServerResource {
throw new ConfigurationException("Unable to find admin password");
}
- _niciraNvpApi = createNiciraNvpApi();
- _niciraNvpApi.setControllerAddress(ip);
- _niciraNvpApi.setAdminCredentials(adminuser,adminpass);
+ niciraNvpApi = createNiciraNvpApi();
+ niciraNvpApi.setControllerAddress(ip);
+ niciraNvpApi.setAdminCredentials(adminuser,adminpass);
return true;
}
@@ -150,7 +152,7 @@ public class NiciraNvpResource implements ServerResource {
@Override
public String getName() {
- return _name;
+ return name;
}
@Override
@@ -162,9 +164,9 @@ public class NiciraNvpResource implements ServerResource {
@Override
public StartupCommand[] initialize() {
StartupNiciraNvpCommand sc = new StartupNiciraNvpCommand();
- sc.setGuid(_guid);
- sc.setName(_name);
- sc.setDataCenter(_zoneId);
+ sc.setGuid(guid);
+ sc.setName(name);
+ sc.setDataCenter(zoneId);
sc.setPod("");
sc.setPrivateIpAddress("");
sc.setStorageIpAddress("");
@@ -173,9 +175,9 @@ public class NiciraNvpResource implements ServerResource {
}
@Override
- public PingCommand getCurrentStatus(long id) {
+ public PingCommand getCurrentStatus(final long id) {
try {
- ControlClusterStatus ccs = _niciraNvpApi.getControlClusterStatus();
+ ControlClusterStatus ccs = niciraNvpApi.getControlClusterStatus();
if (!"stable".equals(ccs.getClusterStatus())) {
s_logger.error("ControlCluster state is not stable: "
+ ccs.getClusterStatus());
@@ -189,11 +191,11 @@ public class NiciraNvpResource implements ServerResource {
}
@Override
- public Answer executeRequest(Command cmd) {
- return executeRequest(cmd, _numRetries);
+ public Answer executeRequest(final Command cmd) {
+ return executeRequest(cmd, numRetries);
}
- public Answer executeRequest(Command cmd, int numRetries) {
+ public Answer executeRequest(final Command cmd, final int numRetries) {
if (cmd instanceof ReadyCommand) {
return executeRequest((ReadyCommand) cmd);
}
@@ -247,18 +249,18 @@ public class NiciraNvpResource implements ServerResource {
}
@Override
- public void setAgentControl(IAgentControl agentControl) {
+ public void setAgentControl(final IAgentControl agentControl) {
}
- private Answer executeRequest(CreateLogicalSwitchCommand cmd, int numRetries) {
+ private Answer executeRequest(final CreateLogicalSwitchCommand cmd, int numRetries) {
LogicalSwitch logicalSwitch = new LogicalSwitch();
- logicalSwitch.setDisplay_name(truncate("lswitch-" + cmd.getName(), 40));
- logicalSwitch.setPort_isolation_enabled(false);
+ logicalSwitch.setDisplayName(truncate("lswitch-" + cmd.getName(), NAME_MAX_LEN));
+ logicalSwitch.setPortIsolationEnabled(false);
// Set transport binding
List ltzb = new ArrayList();
ltzb.add(new TransportZoneBinding(cmd.getTransportUuid(), cmd.getTransportType()));
- logicalSwitch.setTransport_zones(ltzb);
+ logicalSwitch.setTransportZones(ltzb);
// Tags set to scope cs_account and account name
List tags = new ArrayList();
@@ -266,7 +268,7 @@ public class NiciraNvpResource implements ServerResource {
logicalSwitch.setTags(tags);
try {
- logicalSwitch = _niciraNvpApi.createLogicalSwitch(logicalSwitch);
+ logicalSwitch = niciraNvpApi.createLogicalSwitch(logicalSwitch);
return new CreateLogicalSwitchAnswer(cmd, true, "Logicalswitch " + logicalSwitch.getUuid() + " created", logicalSwitch.getUuid());
} catch (NiciraNvpApiException e) {
if (numRetries > 0) {
@@ -279,9 +281,9 @@ public class NiciraNvpResource implements ServerResource {
}
- private Answer executeRequest(DeleteLogicalSwitchCommand cmd, int numRetries) {
+ private Answer executeRequest(final DeleteLogicalSwitchCommand cmd, int numRetries) {
try {
- _niciraNvpApi.deleteLogicalSwitch(cmd.getLogicalSwitchUuid());
+ niciraNvpApi.deleteLogicalSwitch(cmd.getLogicalSwitchUuid());
return new DeleteLogicalSwitchAnswer(cmd, true, "Logicalswitch " + cmd.getLogicalSwitchUuid() + " deleted");
} catch (NiciraNvpApiException e) {
if (numRetries > 0) {
@@ -293,7 +295,7 @@ public class NiciraNvpResource implements ServerResource {
}
}
- private Answer executeRequest(CreateLogicalSwitchPortCommand cmd, int numRetries) {
+ private Answer executeRequest(final CreateLogicalSwitchPortCommand cmd, int numRetries) {
String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
String attachmentUuid = cmd.getAttachmentUuid();
@@ -303,12 +305,12 @@ public class NiciraNvpResource implements ServerResource {
tags.add(new NiciraNvpTag("cs_account",cmd.getOwnerName()));
LogicalSwitchPort logicalSwitchPort = new LogicalSwitchPort(attachmentUuid, tags, true);
- LogicalSwitchPort newPort = _niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort);
+ LogicalSwitchPort newPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort);
try {
- _niciraNvpApi.modifyLogicalSwitchPortAttachment(cmd.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid));
+ niciraNvpApi.modifyLogicalSwitchPortAttachment(cmd.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid));
} catch (NiciraNvpApiException ex) {
s_logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport");
- _niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), newPort.getUuid());
+ niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), newPort.getUuid());
throw (ex); // Rethrow the original exception
}
return new CreateLogicalSwitchPortAnswer(cmd, true, "Logical switch port " + newPort.getUuid() + " created", newPort.getUuid());
@@ -323,9 +325,9 @@ public class NiciraNvpResource implements ServerResource {
}
- private Answer executeRequest(DeleteLogicalSwitchPortCommand cmd, int numRetries) {
+ private Answer executeRequest(final DeleteLogicalSwitchPortCommand cmd, int numRetries) {
try {
- _niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), cmd.getLogicalSwitchPortUuid());
+ niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), cmd.getLogicalSwitchPortUuid());
return new DeleteLogicalSwitchPortAnswer(cmd, true, "Logical switch port " + cmd.getLogicalSwitchPortUuid() + " deleted");
} catch (NiciraNvpApiException e) {
if (numRetries > 0) {
@@ -337,7 +339,7 @@ public class NiciraNvpResource implements ServerResource {
}
}
- private Answer executeRequest(UpdateLogicalSwitchPortCommand cmd, int numRetries) {
+ private Answer executeRequest(final UpdateLogicalSwitchPortCommand cmd, int numRetries) {
String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid();
String attachmentUuid = cmd.getAttachmentUuid();
@@ -347,7 +349,7 @@ public class NiciraNvpResource implements ServerResource {
List tags = new ArrayList();
tags.add(new NiciraNvpTag("cs_account",cmd.getOwnerName()));
- _niciraNvpApi.modifyLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid, new VifAttachment(attachmentUuid));
+ niciraNvpApi.modifyLogicalSwitchPortAttachment(logicalSwitchUuid, logicalSwitchPortUuid, new VifAttachment(attachmentUuid));
return new UpdateLogicalSwitchPortAnswer(cmd, true, "Attachment for " + logicalSwitchPortUuid + " updated", logicalSwitchPortUuid);
} catch (NiciraNvpApiException e) {
if (numRetries > 0) {
@@ -360,12 +362,12 @@ public class NiciraNvpResource implements ServerResource {
}
- private Answer executeRequest(FindLogicalSwitchPortCommand cmd, int numRetries) {
+ private Answer executeRequest(final FindLogicalSwitchPortCommand cmd, int numRetries) {
String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid();
try {
- NiciraNvpList ports = _niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid);
+ NiciraNvpList ports = niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid);
if (ports.getResultCount() == 0) {
return new FindLogicalSwitchPortAnswer(cmd, false, "Logical switchport " + logicalSwitchPortUuid + " not found", null);
}
@@ -382,7 +384,7 @@ public class NiciraNvpResource implements ServerResource {
}
}
- private Answer executeRequest(CreateLogicalRouterCommand cmd, int numRetries) {
+ private Answer executeRequest(final CreateLogicalRouterCommand cmd, int numRetries) {
String routerName = cmd.getName();
String gatewayServiceUuid = cmd.getGatewayServiceUuid();
String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
@@ -401,11 +403,11 @@ public class NiciraNvpResource implements ServerResource {
try {
// Create the Router
LogicalRouterConfig lrc = new LogicalRouterConfig();
- lrc.setDisplayName(truncate(routerName, 40));
+ lrc.setDisplayName(truncate(routerName, NAME_MAX_LEN));
lrc.setTags(tags);
lrc.setRoutingConfig(new SingleDefaultRouteImplictRoutingConfig(
new RouterNextHop(publicNetworkNextHopIp)));
- lrc = _niciraNvpApi.createLogicalRouter(lrc);
+ lrc = niciraNvpApi.createLogicalRouter(lrc);
// store the switchport for rollback
LogicalSwitchPort lsp = null;
@@ -414,40 +416,40 @@ public class NiciraNvpResource implements ServerResource {
// Create the outside port for the router
LogicalRouterPort lrpo = new LogicalRouterPort();
lrpo.setAdminStatusEnabled(true);
- lrpo.setDisplayName(truncate(routerName + "-outside-port", 40));
+ lrpo.setDisplayName(truncate(routerName + "-outside-port", NAME_MAX_LEN));
lrpo.setTags(tags);
List outsideIpAddresses = new ArrayList();
outsideIpAddresses.add(publicNetworkIpAddress);
lrpo.setIpAddresses(outsideIpAddresses);
- lrpo = _niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpo);
+ lrpo = niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpo);
// Attach the outside port to the gateway service on the correct VLAN
L3GatewayAttachment attachment = new L3GatewayAttachment(gatewayServiceUuid);
if (cmd.getVlanId() != 0) {
attachment.setVlanId(cmd.getVlanId());
}
- _niciraNvpApi.modifyLogicalRouterPortAttachment(lrc.getUuid(), lrpo.getUuid(), attachment);
+ niciraNvpApi.modifyLogicalRouterPortAttachment(lrc.getUuid(), lrpo.getUuid(), attachment);
// Create the inside port for the router
LogicalRouterPort lrpi = new LogicalRouterPort();
lrpi.setAdminStatusEnabled(true);
- lrpi.setDisplayName(truncate(routerName + "-inside-port", 40));
+ lrpi.setDisplayName(truncate(routerName + "-inside-port", NAME_MAX_LEN));
lrpi.setTags(tags);
List insideIpAddresses = new ArrayList();
insideIpAddresses.add(internalNetworkAddress);
lrpi.setIpAddresses(insideIpAddresses);
- lrpi = _niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpi);
+ lrpi = niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpi);
// Create the inside port on the lswitch
- lsp = new LogicalSwitchPort(truncate(routerName + "-inside-port", 40), tags, true);
- lsp = _niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lsp);
+ lsp = new LogicalSwitchPort(truncate(routerName + "-inside-port", NAME_MAX_LEN), tags, true);
+ lsp = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lsp);
// Attach the inside router port to the lswitch port with a PatchAttachment
- _niciraNvpApi.modifyLogicalRouterPortAttachment(lrc.getUuid(), lrpi.getUuid(),
+ niciraNvpApi.modifyLogicalRouterPortAttachment(lrc.getUuid(), lrpi.getUuid(),
new PatchAttachment(lsp.getUuid()));
// Attach the inside lswitch port to the router with a PatchAttachment
- _niciraNvpApi.modifyLogicalSwitchPortAttachment(logicalSwitchUuid, lsp.getUuid(),
+ niciraNvpApi.modifyLogicalSwitchPortAttachment(logicalSwitchUuid, lsp.getUuid(),
new PatchAttachment(lrpi.getUuid()));
// Setup the source nat rule
@@ -458,14 +460,14 @@ public class NiciraNvpResource implements ServerResource {
match.setSourceIpAddresses(internalNetworkAddress);
snr.setMatch(match);
snr.setOrder(200);
- _niciraNvpApi.createLogicalRouterNatRule(lrc.getUuid(), snr);
+ niciraNvpApi.createLogicalRouterNatRule(lrc.getUuid(), snr);
} catch (NiciraNvpApiException e) {
// We need to destroy the router if we already created it
// this will also take care of any router ports and rules
try {
- _niciraNvpApi.deleteLogicalRouter(lrc.getUuid());
+ niciraNvpApi.deleteLogicalRouter(lrc.getUuid());
if (lsp != null) {
- _niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lsp.getUuid());
+ niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lsp.getUuid());
}
} catch (NiciraNvpApiException ex) {}
@@ -483,9 +485,9 @@ public class NiciraNvpResource implements ServerResource {
}
}
- private Answer executeRequest(DeleteLogicalRouterCommand cmd, int numRetries) {
+ private Answer executeRequest(final DeleteLogicalRouterCommand cmd, int numRetries) {
try {
- _niciraNvpApi.deleteLogicalRouter(cmd.getLogicalRouterUuid());
+ niciraNvpApi.deleteLogicalRouter(cmd.getLogicalRouterUuid());
return new DeleteLogicalRouterAnswer(cmd, true, "Logical Router deleted (uuid " + cmd.getLogicalRouterUuid() + ")");
} catch (NiciraNvpApiException e) {
if (numRetries > 0) {
@@ -497,15 +499,15 @@ public class NiciraNvpResource implements ServerResource {
}
}
- private Answer executeRequest(ConfigurePublicIpsOnLogicalRouterCommand cmd, int numRetries) {
+ private Answer executeRequest(final ConfigurePublicIpsOnLogicalRouterCommand cmd, int numRetries) {
try {
- NiciraNvpList ports = _niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(cmd.getLogicalRouterUuid(), cmd.getL3GatewayServiceUuid());
+ NiciraNvpList ports = niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(cmd.getLogicalRouterUuid(), cmd.getL3GatewayServiceUuid());
if (ports.getResultCount() != 1) {
return new ConfigurePublicIpsOnLogicalRouterAnswer(cmd, false, "No logical router ports found, unable to set ip addresses");
}
LogicalRouterPort lrp = ports.getResults().get(0);
lrp.setIpAddresses(cmd.getPublicCidrs());
- _niciraNvpApi.modifyLogicalRouterPort(cmd.getLogicalRouterUuid(), lrp);
+ niciraNvpApi.modifyLogicalRouterPort(cmd.getLogicalRouterUuid(), lrp);
return new ConfigurePublicIpsOnLogicalRouterAnswer(cmd, true, "Configured " + cmd.getPublicCidrs().size() +
" ip addresses on logical router uuid " + cmd.getLogicalRouterUuid());
@@ -520,9 +522,9 @@ public class NiciraNvpResource implements ServerResource {
}
- private Answer executeRequest(ConfigureStaticNatRulesOnLogicalRouterCommand cmd, int numRetries) {
+ private Answer executeRequest(final ConfigureStaticNatRulesOnLogicalRouterCommand cmd, int numRetries) {
try {
- NiciraNvpList existingRules = _niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid());
+ NiciraNvpList existingRules = niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid());
// Rules of the game (also known as assumptions-that-will-make-stuff-break-later-on)
// A SourceNat rule with a match other than a /32 cidr is assumed to be the "main" SourceNat rule
// Any other SourceNat rule should have a corresponding DestinationNat rule
@@ -555,10 +557,10 @@ public class NiciraNvpResource implements ServerResource {
if (incoming != null && outgoing != null) {
if (rule.revoked()) {
s_logger.debug("Deleting incoming rule " + incoming.getUuid());
- _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), incoming.getUuid());
+ niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), incoming.getUuid());
s_logger.debug("Deleting outgoing rule " + outgoing.getUuid());
- _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
+ niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
}
}
else {
@@ -568,15 +570,15 @@ public class NiciraNvpResource implements ServerResource {
break;
}
- rulepair[0] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
+ rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
s_logger.debug("Created " + natRuleToString(rulepair[0]));
try {
- rulepair[1] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
+ rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
s_logger.debug("Created " + natRuleToString(rulepair[1]));
} catch (NiciraNvpApiException ex) {
s_logger.debug("Failed to create SourceNatRule, rolling back DestinationNatRule");
- _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0].getUuid());
+ niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0].getUuid());
throw ex; // Rethrow original exception
}
@@ -593,9 +595,9 @@ public class NiciraNvpResource implements ServerResource {
}
}
- private Answer executeRequest(ConfigurePortForwardingRulesOnLogicalRouterCommand cmd, int numRetries) {
+ private Answer executeRequest(final ConfigurePortForwardingRulesOnLogicalRouterCommand cmd, int numRetries) {
try {
- NiciraNvpList existingRules = _niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid());
+ NiciraNvpList existingRules = niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid());
// Rules of the game (also known as assumptions-that-will-make-stuff-break-later-on)
// A SourceNat rule with a match other than a /32 cidr is assumed to be the "main" SourceNat rule
// Any other SourceNat rule should have a corresponding DestinationNat rule
@@ -637,10 +639,10 @@ public class NiciraNvpResource implements ServerResource {
if (incoming != null && outgoing != null) {
if (rule.revoked()) {
s_logger.debug("Deleting incoming rule " + incoming.getUuid());
- _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), incoming.getUuid());
+ niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), incoming.getUuid());
s_logger.debug("Deleting outgoing rule " + outgoing.getUuid());
- _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
+ niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
}
}
else {
@@ -650,15 +652,15 @@ public class NiciraNvpResource implements ServerResource {
break;
}
- rulepair[0] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
+ rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
s_logger.debug("Created " + natRuleToString(rulepair[0]));
try {
- rulepair[1] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
+ rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
s_logger.debug("Created " + natRuleToString(rulepair[1]));
} catch (NiciraNvpApiException ex) {
s_logger.warn("NiciraNvpApiException during create call, rolling back previous create");
- _niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0].getUuid());
+ niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0].getUuid());
throw ex; // Rethrow the original exception
}
@@ -676,20 +678,20 @@ public class NiciraNvpResource implements ServerResource {
}
- private Answer executeRequest(ReadyCommand cmd) {
+ private Answer executeRequest(final ReadyCommand cmd) {
return new ReadyAnswer(cmd);
}
- private Answer executeRequest(MaintainCommand cmd) {
+ private Answer executeRequest(final MaintainCommand cmd) {
return new MaintainAnswer(cmd);
}
- private Answer retry(Command cmd, int numRetries) {
+ private Answer retry(final Command cmd, final int numRetries) {
s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries);
return executeRequest(cmd, numRetries);
}
- private String natRuleToString(NatRule rule) {
+ private String natRuleToString(final NatRule rule) {
StringBuilder natRuleStr = new StringBuilder();
natRuleStr.append("Rule ");
@@ -726,7 +728,7 @@ public class NiciraNvpResource implements ServerResource {
return natRuleStr.toString();
}
- private String truncate(String string, int length) {
+ private String truncate(final String string, final int length) {
if (string.length() <= length) {
return string;
}
@@ -735,7 +737,7 @@ public class NiciraNvpResource implements ServerResource {
}
}
- protected NatRule[] generateStaticNatRulePair(String insideIp, String outsideIp) {
+ protected NatRule[] generateStaticNatRulePair(final String insideIp, final String outsideIp) {
NatRule[] rulepair = new NatRule[2];
rulepair[0] = new DestinationNatRule();
rulepair[0].setType("DestinationNatRule");
@@ -760,8 +762,9 @@ public class NiciraNvpResource implements ServerResource {
}
- protected NatRule[] generatePortForwardingRulePair(String insideIp, int[] insidePorts, String outsideIp, int[] outsidePorts, String protocol) {
- // Start with a basic static nat rule, then add port and protocol details
+ protected NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts,
+ final String outsideIp, final int[] outsidePorts, final String protocol) {
+ // Start with a basic static nat rule, then add port and protocol details
NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp);
((DestinationNatRule)rulepair[0]).setToDestinationPort(insidePorts[0]);
@@ -791,15 +794,13 @@ public class NiciraNvpResource implements ServerResource {
}
@Override
- public void setName(String name) {
+ public void setName(final String name) {
// TODO Auto-generated method stub
-
}
@Override
- public void setConfigParams(Map params) {
+ public void setConfigParams(final Map params) {
// TODO Auto-generated method stub
-
}
@Override
@@ -815,9 +816,8 @@ public class NiciraNvpResource implements ServerResource {
}
@Override
- public void setRunLevel(int level) {
+ public void setRunLevel(final int level) {
// TODO Auto-generated method stub
-
}
}
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/element/NiciraNvpElementTest.java b/plugins/network-elements/nicira-nvp/test/com/cloud/network/element/NiciraNvpElementTest.java
index 9202241e989..97f5f2f21e7 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/element/NiciraNvpElementTest.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/element/NiciraNvpElementTest.java
@@ -72,59 +72,60 @@ import com.cloud.vm.ReservationContext;
public class NiciraNvpElementTest {
- NiciraNvpElement _element = new NiciraNvpElement();
- NetworkOrchestrationService _networkManager = mock(NetworkOrchestrationService.class);
- NetworkModel _networkModel = mock(NetworkModel.class);
- NetworkServiceMapDao _ntwkSrvcDao = mock(NetworkServiceMapDao.class);
- AgentManager _agentManager = mock(AgentManager.class);
- HostDao _hostDao = mock(HostDao.class);
- NiciraNvpDao _niciraNvpDao = mock(NiciraNvpDao.class);
- NiciraNvpRouterMappingDao _niciraNvpRouterMappingDao = mock(NiciraNvpRouterMappingDao.class);
+ private static final long NETWORK_ID = 42L;
+ NiciraNvpElement element = new NiciraNvpElement();
+ NetworkOrchestrationService networkManager = mock(NetworkOrchestrationService.class);
+ NetworkModel networkModel = mock(NetworkModel.class);
+ NetworkServiceMapDao ntwkSrvcDao = mock(NetworkServiceMapDao.class);
+ AgentManager agentManager = mock(AgentManager.class);
+ HostDao hostDao = mock(HostDao.class);
+ NiciraNvpDao niciraNvpDao = mock(NiciraNvpDao.class);
+ NiciraNvpRouterMappingDao niciraNvpRouterMappingDao = mock(NiciraNvpRouterMappingDao.class);
@Before
public void setUp() throws ConfigurationException {
- _element._resourceMgr = mock(ResourceManager.class);
- _element._networkManager = _networkManager;
- _element._ntwkSrvcDao = _ntwkSrvcDao;
- _element._networkModel = _networkModel;
- _element._agentMgr = _agentManager;
- _element._hostDao = _hostDao;
- _element._niciraNvpDao = _niciraNvpDao;
- _element._niciraNvpRouterMappingDao = _niciraNvpRouterMappingDao;
+ element.resourceMgr = mock(ResourceManager.class);
+ element.networkManager = networkManager;
+ element.ntwkSrvcDao = ntwkSrvcDao;
+ element.networkModel = networkModel;
+ element.agentMgr = agentManager;
+ element.hostDao = hostDao;
+ element.niciraNvpDao = niciraNvpDao;
+ element.niciraNvpRouterMappingDao = niciraNvpRouterMappingDao;
// Standard responses
- when(_networkModel.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(true);
+ when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
- _element.configure("NiciraNvpTestElement", Collections. emptyMap());
+ element.configure("NiciraNvpTestElement", Collections. emptyMap());
}
@Test
public void canHandleTest() {
Network net = mock(Network.class);
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
- when(net.getId()).thenReturn(42L);
+ when(net.getId()).thenReturn(NETWORK_ID);
- when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
+ when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
// Golden path
- assertTrue(_element.canHandle(net, Service.Connectivity));
+ assertTrue(element.canHandle(net, Service.Connectivity));
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
// Only broadcastdomaintype lswitch is supported
- assertFalse(_element.canHandle(net, Service.Connectivity));
+ assertFalse(element.canHandle(net, Service.Connectivity));
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
- when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(false);
+ when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(false);
// No nvp provider in the network
- assertFalse(_element.canHandle(net, Service.Connectivity));
+ assertFalse(element.canHandle(net, Service.Connectivity));
- when(_networkModel.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(false);
- when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
+ when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(false);
+ when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
// NVP provider does not provide Connectivity for this network
- assertFalse(_element.canHandle(net, Service.Connectivity));
+ assertFalse(element.canHandle(net, Service.Connectivity));
- when(_networkModel.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(true);
+ when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
// Only service Connectivity is supported
- assertFalse(_element.canHandle(net, Service.Dhcp));
+ assertFalse(element.canHandle(net, Service.Dhcp));
}
@@ -132,10 +133,10 @@ public class NiciraNvpElementTest {
public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
- when(network.getId()).thenReturn(42L);
+ when(network.getId()).thenReturn(NETWORK_ID);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@@ -148,19 +149,17 @@ public class NiciraNvpElementTest {
ReservationContext context = mock(ReservationContext.class);
when(context.getDomain()).thenReturn(dom);
when(context.getAccount()).thenReturn(acc);
-
- // assertTrue(_element.implement(network, offering, dest, context));
}
@Test
public void applyIpTest() throws ResourceUnavailableException {
Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
- when(network.getId()).thenReturn(42L);
- when(network.getPhysicalNetworkId()).thenReturn(42L);
+ when(network.getId()).thenReturn(NETWORK_ID);
+ when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@@ -186,23 +185,23 @@ public class NiciraNvpElementTest {
List deviceList = new ArrayList();
NiciraNvpDeviceVO nndVO = mock(NiciraNvpDeviceVO.class);
NiciraNvpRouterMappingVO nnrmVO = mock(NiciraNvpRouterMappingVO.class);
- when(_niciraNvpRouterMappingDao.findByNetworkId(42L)).thenReturn(nnrmVO);
+ when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(nnrmVO);
when(nnrmVO.getLogicalRouterUuid()).thenReturn("abcde");
- when(nndVO.getHostId()).thenReturn(42L);
+ when(nndVO.getHostId()).thenReturn(NETWORK_ID);
HostVO hvo = mock(HostVO.class);
- when(hvo.getId()).thenReturn(42L);
+ when(hvo.getId()).thenReturn(NETWORK_ID);
when(hvo.getDetail("l3gatewayserviceuuid")).thenReturn("abcde");
- when(_hostDao.findById(42L)).thenReturn(hvo);
+ when(hostDao.findById(NETWORK_ID)).thenReturn(hvo);
deviceList.add(nndVO);
- when(_niciraNvpDao.listByPhysicalNetwork(42L)).thenReturn(deviceList);
+ when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(deviceList);
ConfigurePublicIpsOnLogicalRouterAnswer answer = mock(ConfigurePublicIpsOnLogicalRouterAnswer.class);
when(answer.getResult()).thenReturn(true);
- when(_agentManager.easySend(eq(42L), any(ConfigurePublicIpsOnLogicalRouterCommand.class))).thenReturn(answer);
+ when(agentManager.easySend(eq(NETWORK_ID), any(ConfigurePublicIpsOnLogicalRouterCommand.class))).thenReturn(answer);
- assertTrue(_element.applyIps(network, ipAddresses, services));
+ assertTrue(element.applyIps(network, ipAddresses, services));
- verify(_agentManager, atLeast(1)).easySend(eq(42L),
+ verify(agentManager, atLeast(1)).easySend(eq(NETWORK_ID),
argThat(new ArgumentMatcher() {
@Override
public boolean matches(Object argument) {
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java b/plugins/network-elements/nicira-nvp/test/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
index 42e436f315d..bdcbfee5248 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
@@ -70,6 +70,7 @@ import com.cloud.user.Account;
import com.cloud.vm.ReservationContext;
public class NiciraNvpGuestNetworkGuruTest {
+ private static final long NETWORK_ID = 42L;
PhysicalNetworkDao physnetdao = mock(PhysicalNetworkDao.class);
NiciraNvpDao nvpdao = mock(NiciraNvpDao.class);
DataCenterDao dcdao = mock(DataCenterDao.class);
@@ -87,14 +88,14 @@ public class NiciraNvpGuestNetworkGuruTest {
public void setUp() {
guru = new NiciraNvpGuestNetworkGuru();
((GuestNetworkGuru) guru)._physicalNetworkDao = physnetdao;
- guru._physicalNetworkDao = physnetdao;
- guru._niciraNvpDao = nvpdao;
+ guru.physicalNetworkDao = physnetdao;
+ guru.niciraNvpDao = nvpdao;
guru._dcDao = dcdao;
- guru._ntwkOfferingSrvcDao = nosd;
- guru._networkModel = netmodel;
- guru._hostDao = hostdao;
- guru._agentMgr = agentmgr;
- guru._networkDao = netdao;
+ guru.ntwkOfferingSrvcDao = nosd;
+ guru.networkModel = netmodel;
+ guru.hostDao = hostdao;
+ guru.agentMgr = agentmgr;
+ guru.networkDao = netdao;
DataCenterVO dc = mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
@@ -106,15 +107,15 @@ public class NiciraNvpGuestNetworkGuruTest {
@Test
public void testCanHandle() {
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
- when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(true);
+ when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
@@ -142,18 +143,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
- when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(true);
+ when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
@@ -169,13 +170,13 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections. emptyList());
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections. emptyList());
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@@ -192,13 +193,13 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections. emptyList());
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections. emptyList());
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@@ -215,18 +216,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
- when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
+ when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
@@ -241,25 +242,25 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
- when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
+ when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
- when(network.getPhysicalNetworkId()).thenReturn(42L);
+ when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
DeployDestination dest = mock(DeployDestination.class);
@@ -270,9 +271,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
- when(niciraHost.getId()).thenReturn(42L);
+ when(niciraHost.getId()).thenReturn(NETWORK_ID);
- when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
+ when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
@@ -284,11 +285,11 @@ public class NiciraNvpGuestNetworkGuruTest {
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
- when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
+ when(agentmgr.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null);
- verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
+ verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
}
@Test
@@ -296,18 +297,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
- when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
+ when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
mock(DeploymentPlan.class);
@@ -316,7 +317,7 @@ public class NiciraNvpGuestNetworkGuruTest {
when(network.getState()).thenReturn(State.Implementing);
when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
- when(network.getPhysicalNetworkId()).thenReturn(42L);
+ when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
DeployDestination dest = mock(DeployDestination.class);
@@ -327,9 +328,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
- when(niciraHost.getId()).thenReturn(42L);
+ when(niciraHost.getId()).thenReturn(NETWORK_ID);
- when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
+ when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
@@ -341,13 +342,13 @@ public class NiciraNvpGuestNetworkGuruTest {
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
- when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
+ when(agentmgr.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null);
assertTrue(implementednetwork.getCidr().equals("10.1.1.0/24"));
assertTrue(implementednetwork.getGateway().equals("10.1.1.1"));
- verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
+ verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
}
@Test
@@ -355,25 +356,25 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
- when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
+ when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
- when(network.getPhysicalNetworkId()).thenReturn(42L);
+ when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
DeployDestination dest = mock(DeployDestination.class);
@@ -384,9 +385,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
- when(niciraHost.getId()).thenReturn(42L);
+ when(niciraHost.getId()).thenReturn(NETWORK_ID);
- when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
+ when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
@@ -398,11 +399,11 @@ public class NiciraNvpGuestNetworkGuruTest {
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
//when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
- when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
+ when(agentmgr.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork == null);
- verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
+ verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
}
@Test
@@ -410,18 +411,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
- when(physnet.getId()).thenReturn(42L);
+ when(physnet.getId()).thenReturn(NETWORK_ID);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
- when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
+ when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
- when(offering.getId()).thenReturn(42L);
+ when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
- when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
+ when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
mock(DeploymentPlan.class);
@@ -430,8 +431,8 @@ public class NiciraNvpGuestNetworkGuruTest {
when(network.getState()).thenReturn(State.Implementing);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
- when(network.getPhysicalNetworkId()).thenReturn(42L);
- when(netdao.findById(42L)).thenReturn(network);
+ when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
+ when(netdao.findById(NETWORK_ID)).thenReturn(network);
DeployDestination dest = mock(DeployDestination.class);
@@ -442,9 +443,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
- when(niciraHost.getId()).thenReturn(42L);
+ when(niciraHost.getId()).thenReturn(NETWORK_ID);
- when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
+ when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
@@ -455,15 +456,15 @@ public class NiciraNvpGuestNetworkGuruTest {
DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
- when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
+ when(agentmgr.easySend(eq(NETWORK_ID), (Command)any())).thenReturn(answer);
NetworkProfile implementednetwork = mock(NetworkProfile.class);
- when(implementednetwork.getId()).thenReturn(42L);
+ when(implementednetwork.getId()).thenReturn(NETWORK_ID);
when(implementednetwork.getBroadcastUri()).thenReturn(new URI("lswitch:aaaa"));
when(offering.getSpecifyVlan()).thenReturn(false);
guru.shutdown(implementednetwork, offering);
- verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
+ verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
verify(implementednetwork, times(1)).setBroadcastUri(null);
}
}
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiTest.java b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiTest.java
index 1467d4711dd..21d2e7f593d 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiTest.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraNvpApiTest.java
@@ -40,87 +40,87 @@ import org.junit.Before;
import org.junit.Test;
public class NiciraNvpApiTest {
- NiciraNvpApi _api;
- HttpClient _client = mock(HttpClient.class);
- HttpMethod _method;
+ NiciraNvpApi api;
+ HttpClient client = mock(HttpClient.class);
+ HttpMethod method;
@Before
public void setUp() {
HttpClientParams hmp = mock(HttpClientParams.class);
- when (_client.getParams()).thenReturn(hmp);
- _api = new NiciraNvpApi() {
+ when (client.getParams()).thenReturn(hmp);
+ api = new NiciraNvpApi() {
@Override
protected HttpClient createHttpClient() {
- return _client;
+ return client;
}
@Override
protected HttpMethod createMethod(String type, String uri) {
- return _method;
+ return method;
}
};
- _api.setAdminCredentials("admin", "adminpass");
- _api.setControllerAddress("localhost");
+ api.setAdminCredentials("admin", "adminpass");
+ api.setControllerAddress("localhost");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutHostname() throws NiciraNvpApiException {
- _api.setControllerAddress(null);
- _api.login();
+ api.setControllerAddress(null);
+ api.login();
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutCredentials() throws NiciraNvpApiException {
- _api.setAdminCredentials(null, null);
- _api.login();
+ api.setAdminCredentials(null, null);
+ api.login();
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutHostname() throws NiciraNvpApiException {
- _api.setControllerAddress(null);
- _api.executeUpdateObject(new String(), "/", Collections. emptyMap());
+ api.setControllerAddress(null);
+ api.executeUpdateObject(new String(), "/", Collections. emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutCredentials() throws NiciraNvpApiException {
- _api.setAdminCredentials(null, null);
- _api.executeUpdateObject(new String(), "/", Collections. emptyMap());
+ api.setAdminCredentials(null, null);
+ api.executeUpdateObject(new String(), "/", Collections. emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectWithoutHostname() throws NiciraNvpApiException {
- _api.setControllerAddress(null);
- _api.executeCreateObject(new String(), String.class, "/", Collections. emptyMap());
+ api.setControllerAddress(null);
+ api.executeCreateObject(new String(), String.class, "/", Collections. emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectWithoutCredentials() throws NiciraNvpApiException {
- _api.setAdminCredentials(null, null);
- _api.executeCreateObject(new String(), String.class, "/", Collections. emptyMap());
+ api.setAdminCredentials(null, null);
+ api.executeCreateObject(new String(), String.class, "/", Collections. emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutHostname() throws NiciraNvpApiException {
- _api.setControllerAddress(null);
- _api.executeDeleteObject("/");
+ api.setControllerAddress(null);
+ api.executeDeleteObject("/");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutCredentials() throws NiciraNvpApiException {
- _api.setAdminCredentials(null, null);
- _api.executeDeleteObject("/");
+ api.setAdminCredentials(null, null);
+ api.executeDeleteObject("/");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutHostname() throws NiciraNvpApiException {
- _api.setControllerAddress(null);
- _api.executeRetrieveObject(String.class, "/", Collections. emptyMap());
+ api.setControllerAddress(null);
+ api.executeRetrieveObject(String.class, "/", Collections. emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutCredentials() throws NiciraNvpApiException {
- _api.setAdminCredentials(null, null);
- _api.executeDeleteObject("/");
+ api.setAdminCredentials(null, null);
+ api.executeDeleteObject("/");
}
@Test
@@ -128,7 +128,7 @@ public class NiciraNvpApiTest {
GetMethod gm = mock(GetMethod.class);
when(gm.getStatusCode()).thenReturn(HttpStatus.SC_OK);
- _api.executeMethod(gm);
+ api.executeMethod(gm);
verify(gm, times(1)).getStatusCode();
}
@@ -138,172 +138,172 @@ public class NiciraNvpApiTest {
@Test (expected=NiciraNvpApiException.class)
public void executeMethodTestWithLogin() throws NiciraNvpApiException, HttpException, IOException {
GetMethod gm = mock(GetMethod.class);
- when(_client.executeMethod((HttpMethod)any())).thenThrow(new HttpException());
+ when(client.executeMethod((HttpMethod)any())).thenThrow(new HttpException());
when(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED);
- _api.executeMethod(gm);
+ api.executeMethod(gm);
verify(gm, times(1)).getStatusCode();
}
@Test
public void testExecuteCreateObject() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch();
- _method = mock(PostMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_CREATED);
- when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
- ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections. emptyMap());
+ method = mock(PostMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_CREATED);
+ when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
+ ls = api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections. emptyMap());
assertTrue("aaaa".equals(ls.getUuid()));
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectFailure() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch();
- _method = mock(PostMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ method = mock(PostMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
- when(_method.getResponseHeader("Content-Type")).thenReturn(header);
- when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
- when(_method.isRequestSent()).thenReturn(true);
+ when(method.getResponseHeader("Content-Type")).thenReturn(header);
+ when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
+ when(method.isRequestSent()).thenReturn(true);
try {
- ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections. emptyMap());
+ ls = api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections. emptyMap());
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectException() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch();
- when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
- _method = mock(PostMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ when(client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
+ method = mock(PostMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
- when(_method.getResponseHeader("Content-Type")).thenReturn(header);
- when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
+ when(method.getResponseHeader("Content-Type")).thenReturn(header);
+ when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
try {
- ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections. emptyMap());
+ ls = api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections. emptyMap());
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
@Test
public void testExecuteUpdateObject() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch();
- _method = mock(PutMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
- _api.executeUpdateObject(ls, "/", Collections. emptyMap());
- verify(_method, times(1)).releaseConnection();
- verify(_client, times(1)).executeMethod(_method);
+ method = mock(PutMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
+ api.executeUpdateObject(ls, "/", Collections. emptyMap());
+ verify(method, times(1)).releaseConnection();
+ verify(client, times(1)).executeMethod(method);
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectFailure() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch();
- _method = mock(PutMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ method = mock(PutMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
- when(_method.getResponseHeader("Content-Type")).thenReturn(header);
- when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
- when(_method.isRequestSent()).thenReturn(true);
+ when(method.getResponseHeader("Content-Type")).thenReturn(header);
+ when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
+ when(method.isRequestSent()).thenReturn(true);
try {
- _api.executeUpdateObject(ls, "/", Collections. emptyMap());
+ api.executeUpdateObject(ls, "/", Collections. emptyMap());
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectException() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch();
- _method = mock(PutMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
- when(_client.executeMethod((HttpMethod) any())).thenThrow(new IOException());
+ method = mock(PutMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
+ when(client.executeMethod((HttpMethod) any())).thenThrow(new IOException());
try {
- _api.executeUpdateObject(ls, "/", Collections. emptyMap());
+ api.executeUpdateObject(ls, "/", Collections. emptyMap());
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
@Test
public void testExecuteDeleteObject() throws NiciraNvpApiException, IOException {
- _method = mock(DeleteMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
- _api.executeDeleteObject("/");
- verify(_method, times(1)).releaseConnection();
- verify(_client, times(1)).executeMethod(_method);
+ method = mock(DeleteMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
+ api.executeDeleteObject("/");
+ verify(method, times(1)).releaseConnection();
+ verify(client, times(1)).executeMethod(method);
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectFailure() throws NiciraNvpApiException, IOException {
- _method = mock(DeleteMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ method = mock(DeleteMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
- when(_method.getResponseHeader("Content-Type")).thenReturn(header);
- when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
- when(_method.isRequestSent()).thenReturn(true);
+ when(method.getResponseHeader("Content-Type")).thenReturn(header);
+ when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
+ when(method.isRequestSent()).thenReturn(true);
try {
- _api.executeDeleteObject("/");
+ api.executeDeleteObject("/");
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectException() throws NiciraNvpApiException, IOException {
- _method = mock(DeleteMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
- when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
+ method = mock(DeleteMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
+ when(client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
try {
- _api.executeDeleteObject("/");
+ api.executeDeleteObject("/");
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
@Test
public void testExecuteRetrieveObject() throws NiciraNvpApiException, IOException {
- _method = mock(GetMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
- when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
- _api.executeRetrieveObject(LogicalSwitch.class, "/", Collections. emptyMap());
- verify(_method, times(1)).releaseConnection();
- verify(_client, times(1)).executeMethod(_method);
+ method = mock(GetMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
+ when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
+ api.executeRetrieveObject(LogicalSwitch.class, "/", Collections. emptyMap());
+ verify(method, times(1)).releaseConnection();
+ verify(client, times(1)).executeMethod(method);
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectFailure() throws NiciraNvpApiException, IOException {
- _method = mock(GetMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
- when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
+ method = mock(GetMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html");
- when(_method.getResponseHeader("Content-Type")).thenReturn(header);
- when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
- when(_method.isRequestSent()).thenReturn(true);
+ when(method.getResponseHeader("Content-Type")).thenReturn(header);
+ when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
+ when(method.isRequestSent()).thenReturn(true);
try {
- _api.executeRetrieveObject(LogicalSwitch.class, "/", Collections. emptyMap());
+ api.executeRetrieveObject(LogicalSwitch.class, "/", Collections. emptyMap());
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectException() throws NiciraNvpApiException, IOException {
- _method = mock(GetMethod.class);
- when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
- when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
- when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
+ method = mock(GetMethod.class);
+ when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
+ when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
+ when(client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
try {
- _api.executeRetrieveObject(LogicalSwitch.class, "/", Collections. emptyMap());
+ api.executeRetrieveObject(LogicalSwitch.class, "/", Collections. emptyMap());
} finally {
- verify(_method, times(1)).releaseConnection();
+ verify(method, times(1)).releaseConnection();
}
}
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java
index fd13e07ab59..abf98d4683f 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java
@@ -17,7 +17,7 @@
package com.cloud.network.nicira;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
public class NiciraTagTest {
@Test
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java b/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
index 78465e42041..eceec2a5fe6 100644
--- a/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/resource/NiciraNvpResourceTest.java
@@ -84,68 +84,67 @@ import com.cloud.network.nicira.NiciraNvpList;
import com.cloud.network.nicira.SourceNatRule;
public class NiciraNvpResourceTest {
- NiciraNvpApi _nvpApi = mock(NiciraNvpApi.class);
- NiciraNvpResource _resource;
- Map _parameters;
+ NiciraNvpApi nvpApi = mock(NiciraNvpApi.class);
+ NiciraNvpResource resource;
+ Map parameters;
@Before
public void setUp() throws ConfigurationException {
- _resource = new NiciraNvpResource() {
+ resource = new NiciraNvpResource() {
@Override
protected NiciraNvpApi createNiciraNvpApi() {
- return _nvpApi;
+ return nvpApi;
}
};
- _parameters = new HashMap();
- _parameters.put("name","nvptestdevice");
- _parameters.put("ip","127.0.0.1");
- _parameters.put("adminuser","adminuser");
- _parameters.put("guid", "aaaaa-bbbbb-ccccc");
- _parameters.put("zoneId", "blublub");
- _parameters.put("adminpass","adminpass");
+ parameters = new HashMap();
+ parameters.put("name","nvptestdevice");
+ parameters.put("ip","127.0.0.1");
+ parameters.put("adminuser","adminuser");
+ parameters.put("guid", "aaaaa-bbbbb-ccccc");
+ parameters.put("zoneId", "blublub");
+ parameters.put("adminpass","adminpass");
}
@Test (expected=ConfigurationException.class)
public void resourceConfigureFailure() throws ConfigurationException {
- _resource.configure("NiciraNvpResource", Collections.emptyMap());
+ resource.configure("NiciraNvpResource", Collections.emptyMap());
}
@Test
public void resourceConfigure() throws ConfigurationException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- verify(_nvpApi).setAdminCredentials("adminuser", "adminpass");
- verify(_nvpApi).setControllerAddress("127.0.0.1");
-
- assertTrue("nvptestdevice".equals(_resource.getName()));
+ verify(nvpApi).setAdminCredentials("adminuser", "adminpass");
+ verify(nvpApi).setControllerAddress("127.0.0.1");
+ assertTrue("Incorrect resource name", "nvptestdevice".equals(resource.getName()));
/* Pretty lame test, but here to assure this plugin fails
* if the type name ever changes from L2Networking
*/
- assertTrue(_resource.getType() == Host.Type.L2Networking);
+ assertTrue("Incorrect resource type", resource.getType() == Host.Type.L2Networking);
}
@Test
public void testInitialization() throws ConfigurationException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- StartupCommand[] sc = _resource.initialize();
+ StartupCommand[] sc = resource.initialize();
assertTrue(sc.length ==1);
- assertTrue("aaaaa-bbbbb-ccccc".equals(sc[0].getGuid()));
- assertTrue("nvptestdevice".equals(sc[0].getName()));
- assertTrue("blublub".equals(sc[0].getDataCenter()));
+ assertTrue("Incorrect startup command GUID", "aaaaa-bbbbb-ccccc".equals(sc[0].getGuid()));
+ assertTrue("Incorrect NVP device name", "nvptestdevice".equals(sc[0].getName()));
+ assertTrue("Incorrect Data Center", "blublub".equals(sc[0].getDataCenter()));
}
@Test
public void testPingCommandStatusOk() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
ControlClusterStatus ccs = mock(ControlClusterStatus.class);
when(ccs.getClusterStatus()).thenReturn("stable");
- when(_nvpApi.getControlClusterStatus()).thenReturn(ccs);
+ when(nvpApi.getControlClusterStatus()).thenReturn(ccs);
- PingCommand ping = _resource.getCurrentStatus(42);
+ PingCommand ping = resource.getCurrentStatus(42);
assertTrue(ping != null);
assertTrue(ping.getHostId() == 42);
assertTrue(ping.getHostType() == Host.Type.L2Networking);
@@ -153,98 +152,98 @@ public class NiciraNvpResourceTest {
@Test
public void testPingCommandStatusFail() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
ControlClusterStatus ccs = mock(ControlClusterStatus.class);
when(ccs.getClusterStatus()).thenReturn("unstable");
- when(_nvpApi.getControlClusterStatus()).thenReturn(ccs);
+ when(nvpApi.getControlClusterStatus()).thenReturn(ccs);
- PingCommand ping = _resource.getCurrentStatus(42);
+ PingCommand ping = resource.getCurrentStatus(42);
assertTrue(ping == null);
}
@Test
public void testPingCommandStatusApiException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
ControlClusterStatus ccs = mock(ControlClusterStatus.class);
when(ccs.getClusterStatus()).thenReturn("unstable");
- when(_nvpApi.getControlClusterStatus()).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.getControlClusterStatus()).thenThrow(new NiciraNvpApiException());
- PingCommand ping = _resource.getCurrentStatus(42);
+ PingCommand ping = resource.getCurrentStatus(42);
assertTrue(ping == null);
}
@Test
public void testRetries() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
- when(_nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException()).thenThrow(new NiciraNvpApiException()).thenReturn(ls);
+ when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException()).thenThrow(new NiciraNvpApiException()).thenReturn(ls);
- CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)_parameters.get("guid"), "stt", "loigicalswitch","owner");
- CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) _resource.executeRequest(clsc);
+ CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)parameters.get("guid"), "stt", "loigicalswitch","owner");
+ CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertTrue(clsa.getResult());
}
@Test
public void testCreateLogicalSwitch() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
- when(_nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenReturn(ls);
+ when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenReturn(ls);
- CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)_parameters.get("guid"), "stt", "loigicalswitch","owner");
- CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) _resource.executeRequest(clsc);
+ CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)parameters.get("guid"), "stt", "loigicalswitch","owner");
+ CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertTrue(clsa.getResult());
assertTrue("cccc".equals(clsa.getLogicalSwitchUuid()));
}
@Test
public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc");
- when(_nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.createLogicalSwitch((LogicalSwitch) any())).thenThrow(new NiciraNvpApiException());
- CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)_parameters.get("guid"), "stt", "loigicalswitch","owner");
- CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) _resource.executeRequest(clsc);
+ CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)parameters.get("guid"), "stt", "loigicalswitch","owner");
+ CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertFalse(clsa.getResult());
}
@Test
public void testDeleteLogicalSwitch() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc");
- DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) _resource.executeRequest(dlsc);
+ DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) resource.executeRequest(dlsc);
assertTrue(dlsa.getResult());
}
@Test
public void testDeleteLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- doThrow(new NiciraNvpApiException()).when(_nvpApi).deleteLogicalSwitch((String)any());
+ doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalSwitch((String)any());
DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc");
- DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) _resource.executeRequest(dlsc);
+ DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) resource.executeRequest(dlsc);
assertFalse(dlsa.getResult());
}
@Test
public void testCreateLogicalSwitchPort() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lsp.getUuid()).thenReturn("eeee");
- when(_nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenReturn(lsp);
+ when(nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenReturn(lsp);
CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
- CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) _resource.executeRequest(clspc);
+ CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
assertTrue(clspa.getResult());
assertTrue("eeee".equals(clspa.getLogicalSwitchPortUuid()));
@@ -252,91 +251,91 @@ public class NiciraNvpResourceTest {
@Test
public void testCreateLogicalSwitchPortApiExceptionInCreate() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lsp.getUuid()).thenReturn("eeee");
- when(_nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenThrow(new NiciraNvpApiException());
CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
- CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) _resource.executeRequest(clspc);
+ CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
assertFalse(clspa.getResult());
}
@Test
public void testCreateLogicalSwitchPortApiExceptionInModify() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lsp.getUuid()).thenReturn("eeee");
- when(_nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenReturn(lsp);
- doThrow(new NiciraNvpApiException()).when(_nvpApi).modifyLogicalSwitchPortAttachment((String)any(), (String)any(), (Attachment)any());
+ when(nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenReturn(lsp);
+ doThrow(new NiciraNvpApiException()).when(nvpApi).modifyLogicalSwitchPortAttachment((String)any(), (String)any(), (Attachment)any());
CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
- CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) _resource.executeRequest(clspc);
+ CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
assertFalse(clspa.getResult());
- verify(_nvpApi, atLeastOnce()).deleteLogicalSwitchPort((String) any(), (String) any());
+ verify(nvpApi, atLeastOnce()).deleteLogicalSwitchPort((String) any(), (String) any());
}
@Test
public void testDeleteLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- doThrow(new NiciraNvpApiException()).when(_nvpApi).deleteLogicalSwitchPort((String) any(), (String) any());
- DeleteLogicalSwitchPortAnswer dlspa = (DeleteLogicalSwitchPortAnswer) _resource.executeRequest(new DeleteLogicalSwitchPortCommand("aaaa","bbbb"));
+ doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalSwitchPort((String) any(), (String) any());
+ DeleteLogicalSwitchPortAnswer dlspa = (DeleteLogicalSwitchPortAnswer) resource.executeRequest(new DeleteLogicalSwitchPortCommand("aaaa","bbbb"));
assertFalse(dlspa.getResult());
}
@Test
public void testUpdateLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- doThrow(new NiciraNvpApiException()).when(_nvpApi).modifyLogicalSwitchPortAttachment((String) any(), (String) any(), (Attachment) any());
- UpdateLogicalSwitchPortAnswer dlspa = (UpdateLogicalSwitchPortAnswer) _resource.executeRequest(
+ doThrow(new NiciraNvpApiException()).when(nvpApi).modifyLogicalSwitchPortAttachment((String) any(), (String) any(), (Attachment) any());
+ UpdateLogicalSwitchPortAnswer dlspa = (UpdateLogicalSwitchPortAnswer) resource.executeRequest(
new UpdateLogicalSwitchPortCommand("aaaa","bbbb","cccc","owner","nicname"));
assertFalse(dlspa.getResult());
}
@Test
public void testFindLogicalSwitchPort() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
@SuppressWarnings("unchecked")
NiciraNvpList lspl = mock(NiciraNvpList.class);
when(lspl.getResultCount()).thenReturn(1);
- when(_nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenReturn(lspl);
+ when(nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenReturn(lspl);
- FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) _resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
+ FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
assertTrue(flspa.getResult());
}
@Test
public void testFindLogicalSwitchPortNotFound() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
@SuppressWarnings("unchecked")
NiciraNvpList lspl = mock(NiciraNvpList.class);
when(lspl.getResultCount()).thenReturn(0);
- when(_nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenReturn(lspl);
+ when(nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenReturn(lspl);
- FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) _resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
+ FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
assertFalse(flspa.getResult());
}
@Test
public void testFindLogicalSwitchPortApiException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- when(_nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.findLogicalSwitchPortsByUuid("aaaa", "bbbb")).thenThrow(new NiciraNvpApiException());
- FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) _resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
+ FindLogicalSwitchPortAnswer flspa = (FindLogicalSwitchPortAnswer) resource.executeRequest(new FindLogicalSwitchPortCommand("aaaa", "bbbb"));
assertFalse(flspa.getResult());
}
@Test
public void testCreateLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalRouterConfig lrc = mock(LogicalRouterConfig.class);
LogicalRouterPort lrp = mock(LogicalRouterPort.class);
@@ -344,46 +343,46 @@ public class NiciraNvpResourceTest {
when(lrc.getUuid()).thenReturn("ccccc");
when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
when(lsp.getUuid()).thenReturn("fffff");
- when(_nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
- when(_nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp);
- when(_nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp);
+ when(nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
+ when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp);
+ when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp);
CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
- CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) _resource.executeRequest(clrc);
+ CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
assertTrue(clra.getResult());
assertTrue("ccccc".equals(clra.getLogicalRouterUuid()));
- verify(_nvpApi, atLeast(1)).createLogicalRouterNatRule((String) any(), (NatRule) any());
+ verify(nvpApi, atLeast(1)).createLogicalRouterNatRule((String) any(), (NatRule) any());
}
@Test
public void testCreateLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- when(_nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenThrow(new NiciraNvpApiException());
CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
- CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) _resource.executeRequest(clrc);
+ CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
assertFalse(clra.getResult());
}
@Test
public void testCreateLogicalRouterApiExceptionRollbackRouter() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalRouterConfig lrc = mock(LogicalRouterConfig.class);
when(lrc.getUuid()).thenReturn("ccccc");
- when(_nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
- when(_nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
+ when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenThrow(new NiciraNvpApiException());
CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
- CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) _resource.executeRequest(clrc);
+ CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
assertFalse(clra.getResult());
- verify(_nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
+ verify(nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
}
@Test
public void testCreateLogicalRouterApiExceptionRollbackRouterAndSwitchPort() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
LogicalRouterConfig lrc = mock(LogicalRouterConfig.class);
LogicalRouterPort lrp = mock(LogicalRouterPort.class);
@@ -391,30 +390,30 @@ public class NiciraNvpResourceTest {
when(lrc.getUuid()).thenReturn("ccccc");
when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
when(lsp.getUuid()).thenReturn("fffff");
- when(_nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
- when(_nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp);
- when(_nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp);
- when(_nvpApi.createLogicalRouterNatRule((String) any(), (NatRule)any())).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
+ when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp);
+ when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp);
+ when(nvpApi.createLogicalRouterNatRule((String) any(), (NatRule)any())).thenThrow(new NiciraNvpApiException());
CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner");
- CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) _resource.executeRequest(clrc);
+ CreateLogicalRouterAnswer clra = (CreateLogicalRouterAnswer) resource.executeRequest(clrc);
assertFalse(clra.getResult());
- verify(_nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
- verify(_nvpApi, atLeast(1)).deleteLogicalSwitchPort(eq("bbbbb"), eq("fffff"));
+ verify(nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
+ verify(nvpApi, atLeast(1)).deleteLogicalSwitchPort(eq("bbbbb"), eq("fffff"));
}
@Test
public void testDeleteLogicalRouterApiException() throws ConfigurationException,NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
- doThrow(new NiciraNvpApiException()).when(_nvpApi).deleteLogicalRouter(eq("aaaaa"));
- DeleteLogicalRouterAnswer dlspa = (DeleteLogicalRouterAnswer) _resource.executeRequest(new DeleteLogicalRouterCommand("aaaaa"));
+ doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalRouter(eq("aaaaa"));
+ DeleteLogicalRouterAnswer dlspa = (DeleteLogicalRouterAnswer) resource.executeRequest(new DeleteLogicalRouterCommand("aaaaa"));
assertFalse(dlspa.getResult());
}
@Test
public void testConfigurePublicIpsOnLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
ConfigurePublicIpsOnLogicalRouterCommand cmd = mock(ConfigurePublicIpsOnLogicalRouterCommand.class);
@SuppressWarnings("unchecked")
@@ -422,18 +421,18 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
when(cmd.getL3GatewayServiceUuid()).thenReturn("bbbbb");
- doThrow(new NiciraNvpApiException()).when(_nvpApi).modifyLogicalRouterPort((String) any(), (LogicalRouterPort) any());
- when(_nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa","bbbbb")).thenReturn(list);
+ doThrow(new NiciraNvpApiException()).when(nvpApi).modifyLogicalRouterPort((String) any(), (LogicalRouterPort) any());
+ when(nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa","bbbbb")).thenReturn(list);
ConfigurePublicIpsOnLogicalRouterAnswer answer =
- (ConfigurePublicIpsOnLogicalRouterAnswer) _resource.executeRequest(cmd);
+ (ConfigurePublicIpsOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertFalse(answer.getResult());
}
@Test
public void testConfigureStaticNatRulesOnLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
/* StaticNat
* Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10
@@ -450,18 +449,18 @@ public class NiciraNvpResourceTest {
// Mock the api find call
@SuppressWarnings("unchecked")
NiciraNvpList storedRules = mock(NiciraNvpList.class);
- when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
+ when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
// Mock the api create calls
- NatRule[] rulepair = _resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
+ NatRule[] rulepair = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
rulepair[0].setUuid(UUID.randomUUID());
rulepair[1].setUuid(UUID.randomUUID());
- when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
+ when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
- ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
+ ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertTrue(a.getResult());
- verify(_nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
+ verify(nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
@Override
public boolean matches(Object argument) {
NatRule rule = (NatRule) argument;
@@ -479,7 +478,7 @@ public class NiciraNvpResourceTest {
@Test
public void testConfigureStaticNatRulesOnLogicalRouterExistingRules() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
/* StaticNat
* Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10
@@ -494,22 +493,22 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls
- NatRule[] rulepair = _resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
+ NatRule[] rulepair = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
rulepair[0].setUuid(UUID.randomUUID());
rulepair[1].setUuid(UUID.randomUUID());
- when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
+ when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
// Mock the api find call
@SuppressWarnings("unchecked")
NiciraNvpList storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair));
- when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
+ when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
- ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
+ ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertTrue(a.getResult());
- verify(_nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
+ verify(nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
@Override
public boolean matches(Object argument) {
NatRule rule = (NatRule) argument;
@@ -527,7 +526,7 @@ public class NiciraNvpResourceTest {
@Test
public void testConfigureStaticNatRulesOnLogicalRouterRemoveRules() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
/* StaticNat
* Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10
@@ -542,24 +541,24 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls
- NatRule[] rulepair = _resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
+ NatRule[] rulepair = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
final UUID rule0Uuid = UUID.randomUUID();
final UUID rule1Uuid = UUID.randomUUID();
rulepair[0].setUuid(rule0Uuid);
rulepair[1].setUuid(rule1Uuid);
- when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
+ when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
// Mock the api find call
@SuppressWarnings("unchecked")
NiciraNvpList storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair));
- when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
+ when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
- ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
+ ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertTrue(a.getResult());
- verify(_nvpApi, atLeast(2)).deleteLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
+ verify(nvpApi, atLeast(2)).deleteLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
@Override
public boolean matches(Object argument) {
UUID uuid = (UUID) argument;
@@ -572,7 +571,7 @@ public class NiciraNvpResourceTest {
@Test
public void testConfigureStaticNatRulesOnLogicalRouterRollback() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
/* StaticNat
* Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10
@@ -587,26 +586,26 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls
- NatRule[] rulepair = _resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
+ NatRule[] rulepair = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
rulepair[0].setUuid(UUID.randomUUID());
rulepair[1].setUuid(UUID.randomUUID());
- when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenThrow(new NiciraNvpApiException());
+ when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenThrow(new NiciraNvpApiException());
// Mock the api find call
@SuppressWarnings("unchecked")
NiciraNvpList storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(0);
- when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
+ when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
- ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
+ ConfigureStaticNatRulesOnLogicalRouterAnswer a = (ConfigureStaticNatRulesOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertFalse(a.getResult());
- verify(_nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq(rulepair[0].getUuid()));
+ verify(nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq(rulepair[0].getUuid()));
}
@Test
public void testConfigurePortForwardingRulesOnLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
/* StaticNat
* Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10
@@ -623,18 +622,18 @@ public class NiciraNvpResourceTest {
// Mock the api find call
@SuppressWarnings("unchecked")
NiciraNvpList storedRules = mock(NiciraNvpList.class);
- when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
+ when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
// Mock the api create calls
- NatRule[] rulepair = _resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 8080, 8080 }, "11.11.11.11", new int[] { 80, 80}, "tcp");
+ NatRule[] rulepair = resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 8080, 8080 }, "11.11.11.11", new int[] { 80, 80}, "tcp");
rulepair[0].setUuid(UUID.randomUUID());
rulepair[1].setUuid(UUID.randomUUID());
- when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
+ when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
- ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
+ ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertTrue(a.getResult());
- verify(_nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
+ verify(nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
@Override
public boolean matches(Object argument) {
NatRule rule = (NatRule) argument;
@@ -652,7 +651,7 @@ public class NiciraNvpResourceTest {
@Test
public void testConfigurePortForwardingRulesOnLogicalRouterExistingRules() throws ConfigurationException, NiciraNvpApiException {
- _resource.configure("NiciraNvpResource", _parameters);
+ resource.configure("NiciraNvpResource", parameters);
/* StaticNat
* Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10
@@ -667,22 +666,22 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls
- NatRule[] rulepair = _resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 8080, 8080 }, "11.11.11.11", new int[] { 80, 80}, "tcp");
+ NatRule[] rulepair = resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 8080, 8080 }, "11.11.11.11", new int[] { 80, 80}, "tcp");
rulepair[0].setUuid(UUID.randomUUID());
rulepair[1].setUuid(UUID.randomUUID());
- when(_nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
+ when(nvpApi.createLogicalRouterNatRule(eq("aaaaa"), (NatRule)any())).thenReturn(rulepair[0]).thenReturn(rulepair[1]);
// Mock the api find call
@SuppressWarnings("unchecked")
NiciraNvpList storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair));
- when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
+ when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
- ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd);
+ ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertTrue(a.getResult());
- verify(_nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher() {
+ verify(nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher