Checkstyle adjustments in code and configuration

This commit is contained in:
afornie 2013-11-18 12:12:07 +01:00 committed by Daan Hoogland
parent 709b70c6d1
commit 876b7e492f
63 changed files with 1286 additions and 1223 deletions

View File

@ -26,14 +26,28 @@
<property name="eachLine" value="true"/> <property name="eachLine" value="true"/>
</module> </module>
<module name="TreeWalker">
<module name="LineLength">
<property name="max" value="180"/>
</module>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="TypeName"/>
<module name="AvoidStarImport"/>
</module>
<module name="RegexpSingleline"> <module name="RegexpSingleline">
<!-- \s matches whitespace character, $ matches end of line. --> <!-- \s matches whitespace character, $ matches end of line.-->
<property name="format" value="\s+$"/> <property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/> <property name="message" value="Line has trailing spaces."/>
</module> </module>
<module name="TreeWalker">
<module name="RedundantImport"/> <!-- some modules that we should soon add
<module name="UnusedImports"/> <module name="MagicNumber"/> -->
</module>
<!-- some modules that we should soon add -->
</module> </module>

View File

@ -42,7 +42,7 @@
</dependencies> </dependencies>
<executions> <executions>
<execution> <execution>
<phase>process-sources</phase> <phase>process-classes</phase>
<goals> <goals>
<goal>check</goal> <goal>check</goal>
</goals> </goals>

View File

@ -21,11 +21,16 @@ package com.cloud.agent.api;
*/ */
public class ConfigurePortForwardingRulesOnLogicalRouterAnswer extends Answer { public class ConfigurePortForwardingRulesOnLogicalRouterAnswer extends Answer {
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(Command command, boolean success, String details) { public ConfigurePortForwardingRulesOnLogicalRouterAnswer(
final Command command,
final boolean success,
final String details) {
super(command, success, details); super(command, success, details);
} }
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(Command command, Exception e) { public ConfigurePortForwardingRulesOnLogicalRouterAnswer(
final Command command,
final Exception e) {
super(command, e); super(command, e);
} }

View File

@ -28,7 +28,7 @@ public class ConfigurePortForwardingRulesOnLogicalRouterCommand extends Command
private String logicalRouterUuid; private String logicalRouterUuid;
private List<PortForwardingRuleTO> rules; private List<PortForwardingRuleTO> rules;
public ConfigurePortForwardingRulesOnLogicalRouterCommand(String logicalRouterUuid, List<PortForwardingRuleTO> rules) { public ConfigurePortForwardingRulesOnLogicalRouterCommand(final String logicalRouterUuid, final List<PortForwardingRuleTO> rules) {
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
this.rules = rules; this.rules = rules;
} }
@ -37,7 +37,7 @@ public class ConfigurePortForwardingRulesOnLogicalRouterCommand extends Command
return logicalRouterUuid; return logicalRouterUuid;
} }
public void setLogicalRouterUuid(String logicalRouterUuid) { public void setLogicalRouterUuid(final String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
} }
@ -45,12 +45,11 @@ public class ConfigurePortForwardingRulesOnLogicalRouterCommand extends Command
return rules; return rules;
} }
public void setRules(List<PortForwardingRuleTO> rules) { public void setRules(final List<PortForwardingRuleTO> rules) {
this.rules = rules; this.rules = rules;
} }
/* /* (non-Javadoc)
* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence() * @see com.cloud.agent.api.Command#executeInSequence()
*/ */
@Override @Override

View File

@ -18,11 +18,13 @@ package com.cloud.agent.api;
public class ConfigurePublicIpsOnLogicalRouterAnswer extends Answer { public class ConfigurePublicIpsOnLogicalRouterAnswer extends Answer {
public ConfigurePublicIpsOnLogicalRouterAnswer(Command command, boolean success, String details) { public ConfigurePublicIpsOnLogicalRouterAnswer(final Command command,
final boolean success, final String details) {
super(command, success, details); super(command, success, details);
} }
public ConfigurePublicIpsOnLogicalRouterAnswer(Command command, Exception e) { public ConfigurePublicIpsOnLogicalRouterAnswer(final Command command,
final Exception e) {
super(command, e); super(command, e);
} }

View File

@ -24,7 +24,8 @@ public class ConfigurePublicIpsOnLogicalRouterCommand extends Command {
private String l3GatewayServiceUuid; private String l3GatewayServiceUuid;
private List<String> publicCidrs; private List<String> publicCidrs;
public ConfigurePublicIpsOnLogicalRouterCommand(String logicalRouterUuid, String l3GatewayServiceUuid, List<String> publicCidrs) { public ConfigurePublicIpsOnLogicalRouterCommand(final String logicalRouterUuid,
final String l3GatewayServiceUuid, final List<String> publicCidrs) {
super(); super();
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
this.publicCidrs = publicCidrs; this.publicCidrs = publicCidrs;
@ -35,7 +36,7 @@ public class ConfigurePublicIpsOnLogicalRouterCommand extends Command {
return logicalRouterUuid; return logicalRouterUuid;
} }
public void setLogicalRouterUuid(String logicalRouterUuid) { public void setLogicalRouterUuid(final String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
} }
@ -43,7 +44,7 @@ public class ConfigurePublicIpsOnLogicalRouterCommand extends Command {
return l3GatewayServiceUuid; return l3GatewayServiceUuid;
} }
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) { public void setL3GatewayServiceUuid(final String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid; this.l3GatewayServiceUuid = l3GatewayServiceUuid;
} }
@ -51,7 +52,7 @@ public class ConfigurePublicIpsOnLogicalRouterCommand extends Command {
return publicCidrs; return publicCidrs;
} }
public void setPublicCidrs(List<String> publicCidrs) { public void setPublicCidrs(final List<String> publicCidrs) {
this.publicCidrs = publicCidrs; this.publicCidrs = publicCidrs;
} }

View File

@ -26,7 +26,8 @@ public class ConfigureStaticNatRulesOnLogicalRouterAnswer extends Answer {
* @param success * @param success
* @param details * @param details
*/ */
public ConfigureStaticNatRulesOnLogicalRouterAnswer(Command command, boolean success, String details) { public ConfigureStaticNatRulesOnLogicalRouterAnswer(final Command command,
final boolean success, final String details) {
super(command, success, details); super(command, success, details);
} }
@ -34,7 +35,8 @@ public class ConfigureStaticNatRulesOnLogicalRouterAnswer extends Answer {
* @param command * @param command
* @param e * @param e
*/ */
public ConfigureStaticNatRulesOnLogicalRouterAnswer(Command command, Exception e) { public ConfigureStaticNatRulesOnLogicalRouterAnswer(final Command command,
final Exception e) {
super(command, e); super(command, e);
} }

View File

@ -28,7 +28,8 @@ public class ConfigureStaticNatRulesOnLogicalRouterCommand extends Command {
private String logicalRouterUuid; private String logicalRouterUuid;
private List<StaticNatRuleTO> rules; private List<StaticNatRuleTO> rules;
public ConfigureStaticNatRulesOnLogicalRouterCommand(String logicalRouterUuid, List<StaticNatRuleTO> rules) { public ConfigureStaticNatRulesOnLogicalRouterCommand(
final String logicalRouterUuid, final List<StaticNatRuleTO> rules) {
super(); super();
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
this.rules = rules; this.rules = rules;
@ -39,7 +40,7 @@ public class ConfigureStaticNatRulesOnLogicalRouterCommand extends Command {
return logicalRouterUuid; return logicalRouterUuid;
} }
public void setLogicalRouterUuid(String logicalRouterUuid) { public void setLogicalRouterUuid(final String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
} }
@ -47,12 +48,11 @@ public class ConfigureStaticNatRulesOnLogicalRouterCommand extends Command {
return rules; return rules;
} }
public void setRules(List<StaticNatRuleTO> rules) { public void setRules(final List<StaticNatRuleTO> rules) {
this.rules = rules; this.rules = rules;
} }
/* /* (non-Javadoc)
* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence() * @see com.cloud.agent.api.Command#executeInSequence()
*/ */
@Override @Override

View File

@ -21,20 +21,20 @@ package com.cloud.agent.api;
*/ */
public class CreateLogicalRouterAnswer extends Answer { public class CreateLogicalRouterAnswer extends Answer {
private String _logicalRouterUuid; private String logicalRouterUuid;
public CreateLogicalRouterAnswer(Command command, boolean success, public CreateLogicalRouterAnswer(final Command command, final boolean success,
String details, String logicalRouterUuid) { final String details, final String logicalRouterUuid) {
super(command, success, details); super(command, success, details);
_logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
} }
public CreateLogicalRouterAnswer(Command command, Exception e) { public CreateLogicalRouterAnswer(final Command command, final Exception e) {
super(command, e); super(command, e);
} }
public String getLogicalRouterUuid() { public String getLogicalRouterUuid() {
return _logicalRouterUuid; return logicalRouterUuid;
} }
} }

View File

@ -20,28 +20,28 @@ package com.cloud.agent.api;
* *
*/ */
public class CreateLogicalRouterCommand extends Command { public class CreateLogicalRouterCommand extends Command {
private String _gatewayServiceUuid; private String gatewayServiceUuid;
private String _logicalSwitchUuid; private String logicalSwitchUuid;
private long _vlanId; private long vlanId;
private String _name; private String name;
private String _ownerName; private String ownerName;
private String _publicIpCidr; private String publicIpCidr;
private String _publicNextHop; private String publicNextHop;
private String _internalIpCidr; private String internalIpCidr;
public CreateLogicalRouterCommand(String gatewayServiceUuid, long vlanId, public CreateLogicalRouterCommand(final String gatewayServiceUuid, final long vlanId,
String logicalSwitchUuid, String name, final String logicalSwitchUuid, final String name,
String publicIpCidr, String publicNextHop, final String publicIpCidr, final String publicNextHop,
String internalIpCidr, String ownerName) { final String internalIpCidr, final String ownerName) {
super(); super();
_gatewayServiceUuid = gatewayServiceUuid; this.gatewayServiceUuid = gatewayServiceUuid;
_logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
_vlanId = vlanId; this.vlanId = vlanId;
_name = name; this.name = name;
_ownerName = ownerName; this.ownerName = ownerName;
_publicIpCidr = publicIpCidr; this.publicIpCidr = publicIpCidr;
_publicNextHop = publicNextHop; this.publicNextHop = publicNextHop;
_internalIpCidr = internalIpCidr; this.internalIpCidr = internalIpCidr;
} }
@Override @Override
@ -50,66 +50,66 @@ public class CreateLogicalRouterCommand extends Command {
} }
public String getGatewayServiceUuid() { public String getGatewayServiceUuid() {
return _gatewayServiceUuid; return gatewayServiceUuid;
} }
public void setGatewayServiceUuid(String gatewayServiceUuid) { public void setGatewayServiceUuid(final String gatewayServiceUuid) {
_gatewayServiceUuid = gatewayServiceUuid; this.gatewayServiceUuid = gatewayServiceUuid;
} }
public String getLogicalSwitchUuid() { public String getLogicalSwitchUuid() {
return _logicalSwitchUuid; return logicalSwitchUuid;
} }
public void setLogicalSwitchUuid(String logicalSwitchUuid) { public void setLogicalSwitchUuid(final String logicalSwitchUuid) {
_logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
} }
public long getVlanId() { public long getVlanId() {
return _vlanId; return vlanId;
} }
public void setVlanId(long vlanId) { public void setVlanId(final long vlanId) {
_vlanId = vlanId; this.vlanId = vlanId;
} }
public String getName() { public String getName() {
return _name; return name;
} }
public void setName(String name) { public void setName(final String name) {
_name = name; this.name = name;
} }
public String getOwnerName() { public String getOwnerName() {
return _ownerName; return ownerName;
} }
public void setOwnerName(String ownerName) { public void setOwnerName(final String ownerName) {
_ownerName = ownerName; this.ownerName = ownerName;
} }
public String getPublicIpCidr() { public String getPublicIpCidr() {
return _publicIpCidr; return publicIpCidr;
} }
public void setPublicIpCidr(String publicIpCidr) { public void setPublicIpCidr(final String publicIpCidr) {
_publicIpCidr = publicIpCidr; this.publicIpCidr = publicIpCidr;
} }
public String getInternalIpCidr() { public String getInternalIpCidr() {
return _internalIpCidr; return internalIpCidr;
} }
public void setInternalIpCidr(String internalIpCidr) { public void setInternalIpCidr(final String internalIpCidr) {
_internalIpCidr = internalIpCidr; this.internalIpCidr = internalIpCidr;
} }
public String getPublicNextHop() { public String getPublicNextHop() {
return _publicNextHop; return publicNextHop;
} }
public void setPublicNextHop(String publicNextHop) { public void setPublicNextHop(final String publicNextHop) {
_publicNextHop = publicNextHop; this.publicNextHop = publicNextHop;
} }
} }

View File

@ -17,20 +17,20 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class CreateLogicalSwitchAnswer extends Answer { public class CreateLogicalSwitchAnswer extends Answer {
private String _logicalSwitchUuid; private String logicalSwitchUuid;
public CreateLogicalSwitchAnswer(Command command, boolean success, public CreateLogicalSwitchAnswer(final Command command, final boolean success,
String details, String logicalSwitchUuid) { final String details, final String logicalSwitchUuid) {
super(command, success, details); super(command, success, details);
_logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
} }
public CreateLogicalSwitchAnswer(Command command, Exception e) { public CreateLogicalSwitchAnswer(final Command command, final Exception e) {
super(command, e); super(command, e);
} }
public String getLogicalSwitchUuid() { public String getLogicalSwitchUuid() {
return _logicalSwitchUuid; return logicalSwitchUuid;
} }
} }

View File

@ -18,16 +18,17 @@ package com.cloud.agent.api;
public class CreateLogicalSwitchCommand extends Command { public class CreateLogicalSwitchCommand extends Command {
private String _transportUuid; private final String transportUuid;
private String _transportType; private final String transportType;
private String _name; private final String name;
private String _ownerName; private final String ownerName;
public CreateLogicalSwitchCommand(String transportUuid, String transportType, String name, String ownerName) { public CreateLogicalSwitchCommand(final String transportUuid, final String transportType,
_transportUuid = transportUuid; final String name, final String ownerName) {
_transportType = transportType; this.transportUuid = transportUuid;
_name = name; this.transportType = transportType;
_ownerName = ownerName; this.name = name;
this.ownerName = ownerName;
} }
@Override @Override
@ -36,19 +37,19 @@ public class CreateLogicalSwitchCommand extends Command {
} }
public String getTransportUuid() { public String getTransportUuid() {
return _transportUuid; return transportUuid;
} }
public String getTransportType() { public String getTransportType() {
return _transportType; return transportType;
} }
public String getName() { public String getName() {
return _name; return name;
} }
public String getOwnerName() { public String getOwnerName() {
return _ownerName; return ownerName;
} }
} }

View File

@ -17,19 +17,19 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class CreateLogicalSwitchPortAnswer extends Answer { public class CreateLogicalSwitchPortAnswer extends Answer {
private String _logicalSwitchPortUuid; private String logicalSwitchPortUuid;
public CreateLogicalSwitchPortAnswer(Command command, boolean success, public CreateLogicalSwitchPortAnswer(final Command command, final boolean success,
String details, String localSwitchPortUuid) { final String details, final String localSwitchPortUuid) {
super(command, success, details); super(command, success, details);
_logicalSwitchPortUuid = localSwitchPortUuid; logicalSwitchPortUuid = localSwitchPortUuid;
} }
public String getLogicalSwitchPortUuid() { public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid; return logicalSwitchPortUuid;
} }
public CreateLogicalSwitchPortAnswer(Command command, Exception e) { public CreateLogicalSwitchPortAnswer(final Command command, final Exception e) {
super(command, e); super(command, e);
} }

View File

@ -17,36 +17,37 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class CreateLogicalSwitchPortCommand extends Command { public class CreateLogicalSwitchPortCommand extends Command {
private String _logicalSwitchUuid; private final String logicalSwitchUuid;
private String _attachmentUuid; private final String attachmentUuid;
private String _ownerName; private final String ownerName;
private String _nicName; private final String nicName;
public CreateLogicalSwitchPortCommand(String logicalSwitchUuid, String attachmentUuid, String ownerName, String nicName) { public CreateLogicalSwitchPortCommand(final String logicalSwitchUuid,
_logicalSwitchUuid = logicalSwitchUuid; final String attachmentUuid, final String ownerName, final String nicName) {
_attachmentUuid = attachmentUuid; this.logicalSwitchUuid = logicalSwitchUuid;
_ownerName = ownerName; this.attachmentUuid = attachmentUuid;
_nicName = nicName; this.ownerName = ownerName;
this.nicName = nicName;
} }
public String getLogicalSwitchUuid() { public String getLogicalSwitchUuid() {
return _logicalSwitchUuid; return logicalSwitchUuid;
} }
public String getAttachmentUuid() { public String getAttachmentUuid() {
return _attachmentUuid; return attachmentUuid;
} }
public String getOwnerName() { public String getOwnerName() {
return _ownerName; return ownerName;
} }
public String getNicName() { public String getNicName() {
return _nicName; return nicName;
} }

View File

@ -21,12 +21,12 @@ package com.cloud.agent.api;
*/ */
public class DeleteLogicalRouterAnswer extends Answer { public class DeleteLogicalRouterAnswer extends Answer {
public DeleteLogicalRouterAnswer(Command command, boolean success, public DeleteLogicalRouterAnswer(final Command command,
String details) { final boolean success, final String details) {
super(command, success, details); super(command, success, details);
} }
public DeleteLogicalRouterAnswer(Command command, Exception e) { public DeleteLogicalRouterAnswer(final Command command, final Exception e) {
super(command, e); super(command, e);
} }
} }

View File

@ -21,14 +21,13 @@ package com.cloud.agent.api;
*/ */
public class DeleteLogicalRouterCommand extends Command { public class DeleteLogicalRouterCommand extends Command {
private String _logicalRouterUuid; private final String logicalRouterUuid;
public DeleteLogicalRouterCommand(String logicalRouterUuid) { public DeleteLogicalRouterCommand(String logicalRouterUuid) {
_logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
} }
/* /* (non-Javadoc)
* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence() * @see com.cloud.agent.api.Command#executeInSequence()
*/ */
@Override @Override
@ -37,6 +36,6 @@ public class DeleteLogicalRouterCommand extends Command {
} }
public String getLogicalRouterUuid() { public String getLogicalRouterUuid() {
return _logicalRouterUuid; return logicalRouterUuid;
} }
} }

View File

@ -18,12 +18,12 @@ package com.cloud.agent.api;
public class DeleteLogicalSwitchAnswer extends Answer { public class DeleteLogicalSwitchAnswer extends Answer {
public DeleteLogicalSwitchAnswer(Command command, boolean success, public DeleteLogicalSwitchAnswer(final Command command,
String details) { final boolean success, final String details) {
super(command, success, details); super(command, success, details);
} }
public DeleteLogicalSwitchAnswer(Command command, Exception e) { public DeleteLogicalSwitchAnswer(final Command command, final Exception e) {
super(command, e); super(command, e);
} }

View File

@ -18,10 +18,10 @@ package com.cloud.agent.api;
public class DeleteLogicalSwitchCommand extends Command { public class DeleteLogicalSwitchCommand extends Command {
private String _logicalSwitchUuid; private final String logicalSwitchUuid;
public DeleteLogicalSwitchCommand(String logicalSwitchUuid) { public DeleteLogicalSwitchCommand(final String logicalSwitchUuid) {
_logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
} }
@Override @Override
@ -30,6 +30,6 @@ public class DeleteLogicalSwitchCommand extends Command {
} }
public String getLogicalSwitchUuid() { public String getLogicalSwitchUuid() {
return _logicalSwitchUuid; return logicalSwitchUuid;
} }
} }

View File

@ -18,12 +18,12 @@ package com.cloud.agent.api;
public class DeleteLogicalSwitchPortAnswer extends Answer { public class DeleteLogicalSwitchPortAnswer extends Answer {
public DeleteLogicalSwitchPortAnswer(Command command, boolean success, public DeleteLogicalSwitchPortAnswer(final Command command,
String details) { final boolean success, final String details) {
super(command, success, details); super(command, success, details);
} }
public DeleteLogicalSwitchPortAnswer(Command command, Exception e) { public DeleteLogicalSwitchPortAnswer(final Command command, final Exception e) {
super(command, e); super(command, e);
} }

View File

@ -17,20 +17,20 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class DeleteLogicalSwitchPortCommand extends Command { public class DeleteLogicalSwitchPortCommand extends Command {
private String _logicalSwitchUuid; private final String logicalSwitchUuid;
private String _logicalSwithPortUuid; private final String logicalSwithPortUuid;
public DeleteLogicalSwitchPortCommand(String logicalSwitchUuid, String logicalSwitchPortUuid) { public DeleteLogicalSwitchPortCommand(final String logicalSwitchUuid, final String logicalSwitchPortUuid) {
_logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
_logicalSwithPortUuid = logicalSwitchPortUuid; logicalSwithPortUuid = logicalSwitchPortUuid;
} }
public String getLogicalSwitchUuid() { public String getLogicalSwitchUuid() {
return _logicalSwitchUuid; return logicalSwitchUuid;
} }
public String getLogicalSwitchPortUuid() { public String getLogicalSwitchPortUuid() {
return _logicalSwithPortUuid; return logicalSwithPortUuid;
} }
@Override @Override

View File

@ -17,19 +17,19 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class FindLogicalSwitchPortAnswer extends Answer { public class FindLogicalSwitchPortAnswer extends Answer {
private String _logicalSwitchPortUuid; private String logicalSwitchPortUuid;
public FindLogicalSwitchPortAnswer(Command command, boolean success, public FindLogicalSwitchPortAnswer(final Command command, final boolean success,
String details, String localSwitchPortUuid) { final String details, final String localSwitchPortUuid) {
super(command, success, details); super(command, success, details);
_logicalSwitchPortUuid = localSwitchPortUuid; logicalSwitchPortUuid = localSwitchPortUuid;
} }
public String getLogicalSwitchPortUuid() { public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid; return logicalSwitchPortUuid;
} }
public FindLogicalSwitchPortAnswer(Command command, Exception e) { public FindLogicalSwitchPortAnswer(final Command command, final Exception e) {
super(command, e); super(command, e);
} }

View File

@ -17,22 +17,22 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class FindLogicalSwitchPortCommand extends Command { public class FindLogicalSwitchPortCommand extends Command {
private String _logicalSwitchUuid; private final String logicalSwitchUuid;
private String _logicalSwitchPortUuid; private final String logicalSwitchPortUuid;
public FindLogicalSwitchPortCommand(String logicalSwitchUuid, String logicalSwitchPortUuid) { public FindLogicalSwitchPortCommand(String logicalSwitchUuid, String logicalSwitchPortUuid) {
_logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
_logicalSwitchPortUuid = logicalSwitchPortUuid; this.logicalSwitchPortUuid = logicalSwitchPortUuid;
} }
public String getLogicalSwitchUuid() { public String getLogicalSwitchUuid() {
return _logicalSwitchUuid; return logicalSwitchUuid;
} }
public String getLogicalSwitchPortUuid() { public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid; return logicalSwitchPortUuid;
} }

View File

@ -17,16 +17,16 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class UpdateLogicalSwitchPortAnswer extends Answer { public class UpdateLogicalSwitchPortAnswer extends Answer {
private String _logicalSwitchPortUuid; private String logicalSwitchPortUuid;
public UpdateLogicalSwitchPortAnswer(Command command, boolean success, public UpdateLogicalSwitchPortAnswer(Command command, boolean success,
String details, String localSwitchPortUuid) { String details, String localSwitchPortUuid) {
super(command, success, details); super(command, success, details);
_logicalSwitchPortUuid = localSwitchPortUuid; logicalSwitchPortUuid = localSwitchPortUuid;
} }
public String getLogicalSwitchPortUuid() { public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid; return logicalSwitchPortUuid;
} }
public UpdateLogicalSwitchPortAnswer(Command command, Exception e) { public UpdateLogicalSwitchPortAnswer(Command command, Exception e) {

View File

@ -17,43 +17,44 @@
package com.cloud.agent.api; package com.cloud.agent.api;
public class UpdateLogicalSwitchPortCommand extends Command { public class UpdateLogicalSwitchPortCommand extends Command {
private String _logicalSwitchUuid; private final String logicalSwitchUuid;
private String _logicalSwitchPortUuid; private final String logicalSwitchPortUuid;
private String _attachmentUuid; private final String attachmentUuid;
private String _ownerName; private final String ownerName;
private String _nicName; private final String nicName;
public UpdateLogicalSwitchPortCommand(String logicalSwitchPortUuid, String logicalSwitchUuid, String attachmentUuid, String ownerName, String nicName) { public UpdateLogicalSwitchPortCommand(final String logicalSwitchPortUuid, final String logicalSwitchUuid,
_logicalSwitchUuid = logicalSwitchUuid; final String attachmentUuid, final String ownerName, final String nicName) {
_logicalSwitchPortUuid = logicalSwitchPortUuid; this.logicalSwitchUuid = logicalSwitchUuid;
_attachmentUuid = attachmentUuid; this.logicalSwitchPortUuid = logicalSwitchPortUuid;
_ownerName = ownerName; this.attachmentUuid = attachmentUuid;
_nicName = nicName; this.ownerName = ownerName;
this.nicName = nicName;
} }
public String getLogicalSwitchUuid() { public String getLogicalSwitchUuid() {
return _logicalSwitchUuid; return logicalSwitchUuid;
} }
public String getLogicalSwitchPortUuid() { public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid; return logicalSwitchPortUuid;
} }
public String getAttachmentUuid() { public String getAttachmentUuid() {
return _attachmentUuid; return attachmentUuid;
} }
public String getOwnerName() { public String getOwnerName() {
return _ownerName; return ownerName;
} }
public String getNicName() { public String getNicName() {
return _nicName; return nicName;
} }

View File

@ -18,8 +18,6 @@ package com.cloud.api.commands;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ApiErrorCode;
@ -42,9 +40,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "addNiciraNvpDevice", responseObject=NiciraNvpDeviceResponse.class, description="Adds a Nicira NVP device") @APICommand(name = "addNiciraNvpDevice", responseObject=NiciraNvpDeviceResponse.class, description="Adds a Nicira NVP device")
public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd { public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(AddNiciraNvpDeviceCmd.class.getName());
private static final String s_name = "addniciranvpdeviceresponse"; private static final String s_name = "addniciranvpdeviceresponse";
@Inject NiciraNvpElementService _niciraNvpElementService; @Inject
protected NiciraNvpElementService niciraNvpElementService;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
//////////////// API parameters ///////////////////// //////////////// API parameters /////////////////////
@ -63,10 +61,12 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to access the Nicira Controller API") @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to access the Nicira Controller API")
private String password; private String password;
@Parameter(name=ApiConstants.NICIRA_NVP_TRANSPORT_ZONE_UUID, type=CommandType.STRING, required = true, description="The Transportzone UUID configured on the Nicira Controller") @Parameter(name=ApiConstants.NICIRA_NVP_TRANSPORT_ZONE_UUID, type=CommandType.STRING, required = true,
description="The Transportzone UUID configured on the Nicira Controller")
private String transportzoneuuid; private String transportzoneuuid;
@Parameter(name=ApiConstants.NICIRA_NVP_GATEWAYSERVICE_UUID, type=CommandType.STRING, required = false, description="The L3 Gateway Service UUID configured on the Nicira Controller") @Parameter(name=ApiConstants.NICIRA_NVP_GATEWAYSERVICE_UUID, type=CommandType.STRING, required = false,
description="The L3 Gateway Service UUID configured on the Nicira Controller")
private String l3gatewayserviceuuid; private String l3gatewayserviceuuid;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@ -104,9 +104,9 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
@Override @Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try { try {
NiciraNvpDeviceVO niciraNvpDeviceVO = _niciraNvpElementService.addNiciraNvpDevice(this); NiciraNvpDeviceVO niciraNvpDeviceVO = niciraNvpElementService.addNiciraNvpDevice(this);
if (niciraNvpDeviceVO != null) { if (niciraNvpDeviceVO != null) {
NiciraNvpDeviceResponse response = _niciraNvpElementService.createNiciraNvpDeviceResponse(niciraNvpDeviceVO); NiciraNvpDeviceResponse response = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraNvpDeviceVO);
response.setObjectName("niciranvpdevice"); response.setObjectName("niciranvpdevice");
response.setResponseName(getCommandName()); response.setResponseName(getCommandName());
setResponseObject(response); setResponseObject(response);

View File

@ -18,18 +18,17 @@ package com.cloud.api.commands;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.log4j.Logger; import com.cloud.api.response.NiciraNvpDeviceResponse;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd; import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse; import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.context.CallContext; import org.apache.cloudstack.context.CallContext;
import com.cloud.api.response.NiciraNvpDeviceResponse;
import com.cloud.event.EventTypes; import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
@ -41,9 +40,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "deleteNiciraNvpDevice", responseObject=SuccessResponse.class, description=" delete a nicira nvp device") @APICommand(name = "deleteNiciraNvpDevice", responseObject=SuccessResponse.class, description=" delete a nicira nvp device")
public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd { public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(DeleteNiciraNvpDeviceCmd.class.getName());
private static final String s_name = "deleteniciranvpdeviceresponse"; private static final String s_name = "deleteniciranvpdeviceresponse";
@Inject NiciraNvpElementService _niciraNvpElementService; @Inject
protected NiciraNvpElementService niciraNvpElementService;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
//////////////// API parameters ///////////////////// //////////////// API parameters /////////////////////
@ -68,7 +67,7 @@ public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
@Override @Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try { try {
boolean result = _niciraNvpElementService.deleteNiciraNvpDevice(this); boolean result = niciraNvpElementService.deleteNiciraNvpDevice(this);
if (result) { if (result) {
SuccessResponse response = new SuccessResponse(getCommandName()); SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName()); response.setResponseName(getCommandName());

View File

@ -21,18 +21,17 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import com.cloud.api.response.NiciraNvpDeviceResponse;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse; import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.NetworkResponse; import org.apache.cloudstack.api.response.NetworkResponse;
import com.cloud.api.response.NiciraNvpDeviceResponse;
import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;
@ -47,7 +46,8 @@ public class ListNiciraNvpDeviceNetworksCmd extends BaseListCmd {
public static final Logger s_logger = Logger.getLogger(ListNiciraNvpDeviceNetworksCmd.class.getName()); public static final Logger s_logger = Logger.getLogger(ListNiciraNvpDeviceNetworksCmd.class.getName());
private static final String s_name = "listniciranvpdevicenetworks"; private static final String s_name = "listniciranvpdevicenetworks";
@Inject NiciraNvpElementService _niciraNvpElementService; @Inject
protected NiciraNvpElementService niciraNvpElementService;
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
//////////////// API parameters ///////////////////// //////////////// API parameters /////////////////////
@ -72,7 +72,7 @@ public class ListNiciraNvpDeviceNetworksCmd extends BaseListCmd {
@Override @Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try { try {
List<? extends Network> networks = _niciraNvpElementService.listNiciraNvpDeviceNetworks(this); List<? extends Network> networks = niciraNvpElementService.listNiciraNvpDeviceNetworks(this);
ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>(); ListResponse<NetworkResponse> response = new ListResponse<NetworkResponse>();
List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>(); List<NetworkResponse> networkResponses = new ArrayList<NetworkResponse>();

View File

@ -21,19 +21,16 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode; import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd; import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException; import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse; import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.response.ListResponse;
import com.cloud.api.response.NiciraNvpDeviceResponse; import com.cloud.api.response.NiciraNvpDeviceResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException; import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.ResourceAllocationException;
@ -44,11 +41,12 @@ import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "listNiciraNvpDevices", responseObject=NiciraNvpDeviceResponse.class, description="Lists Nicira NVP devices") @APICommand(name = "listNiciraNvpDevices", responseObject=NiciraNvpDeviceResponse.class, description="Lists Nicira NVP devices")
public class ListNiciraNvpDevicesCmd extends BaseListCmd { public class ListNiciraNvpDevicesCmd extends BaseListCmd {
private static final Logger s_logger = Logger.getLogger(ListNiciraNvpDevicesCmd.class.getName());
private static final String s_name = "listniciranvpdeviceresponse"; private static final String s_name = "listniciranvpdeviceresponse";
@Inject NiciraNvpElementService _niciraNvpElementService;
///////////////////////////////////////////////////// @Inject
protected NiciraNvpElementService niciraNvpElementService;
/////////////////////////////////////////////////////
//////////////// API parameters ///////////////////// //////////////// API parameters /////////////////////
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@ -77,15 +75,15 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd {
///////////////////////////////////////////////////// /////////////////////////////////////////////////////
@Override @Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
try { try {
List<NiciraNvpDeviceVO> niciraDevices = _niciraNvpElementService.listNiciraNvpDevices(this); List<NiciraNvpDeviceVO> niciraDevices = niciraNvpElementService.listNiciraNvpDevices(this);
ListResponse<NiciraNvpDeviceResponse> response = new ListResponse<NiciraNvpDeviceResponse>(); ListResponse<NiciraNvpDeviceResponse> response = new ListResponse<NiciraNvpDeviceResponse>();
List<NiciraNvpDeviceResponse> niciraDevicesResponse = new ArrayList<NiciraNvpDeviceResponse>(); List<NiciraNvpDeviceResponse> niciraDevicesResponse = new ArrayList<NiciraNvpDeviceResponse>();
if (niciraDevices != null && !niciraDevices.isEmpty()) { if (niciraDevices != null && !niciraDevices.isEmpty()) {
for (NiciraNvpDeviceVO niciraDeviceVO : niciraDevices) { for (NiciraNvpDeviceVO niciraDeviceVO : niciraDevices) {
NiciraNvpDeviceResponse niciraDeviceResponse = _niciraNvpElementService.createNiciraNvpDeviceResponse(niciraDeviceVO); NiciraNvpDeviceResponse niciraDeviceResponse = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraDeviceVO);
niciraDevicesResponse.add(niciraDeviceResponse); niciraDevicesResponse.add(niciraDeviceResponse);
} }
} }

View File

@ -16,15 +16,13 @@
// under the License. // under the License.
package com.cloud.api.response; package com.cloud.api.response;
import com.google.gson.annotations.SerializedName; import com.cloud.network.NiciraNvpDeviceVO;
import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.ApiConstants;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
import org.apache.cloudstack.api.BaseResponse; import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference; import org.apache.cloudstack.api.EntityReference;
import com.cloud.network.NiciraNvpDeviceVO;
import com.cloud.serializer.Param;
@EntityReference(value=NiciraNvpDeviceVO.class) @EntityReference(value=NiciraNvpDeviceVO.class)
public class NiciraNvpDeviceResponse extends BaseResponse { public class NiciraNvpDeviceResponse extends BaseResponse {
@SerializedName(ApiConstants.NICIRA_NVP_DEVICE_ID) @Param(description="device id of the Nicire Nvp") @SerializedName(ApiConstants.NICIRA_NVP_DEVICE_ID) @Param(description="device id of the Nicire Nvp")
@ -49,30 +47,30 @@ public class NiciraNvpDeviceResponse extends BaseResponse {
private String l3GatewayServiceUuid; private String l3GatewayServiceUuid;
public void setId(String nvpDeviceId) { public void setId(String nvpDeviceId) {
id = nvpDeviceId; this.id = nvpDeviceId;
} }
public void setPhysicalNetworkId(String physicalNetworkId) { public void setPhysicalNetworkId(final String physicalNetworkId) {
this.physicalNetworkId = physicalNetworkId; this.physicalNetworkId = physicalNetworkId;
} }
public void setProviderName(String providerName) { public void setProviderName(final String providerName) {
this.providerName = providerName; this.providerName = providerName;
} }
public void setDeviceName(String deviceName) { public void setDeviceName(final String deviceName) {
this.deviceName = deviceName; this.deviceName = deviceName;
} }
public void setHostName(String hostName) { public void setHostName(final String hostName) {
this.hostName = hostName; this.hostName = hostName;
} }
public void setTransportZoneUuid(String transportZoneUuid) { public void setTransportZoneUuid(final String transportZoneUuid) {
this.transportZoneUuid = transportZoneUuid; this.transportZoneUuid = transportZoneUuid;
} }
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) { public void setL3GatewayServiceUuid(final String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid; this.l3GatewayServiceUuid = l3GatewayServiceUuid;
} }

View File

@ -56,8 +56,8 @@ public class NiciraNvpDeviceVO implements InternalIdentity {
uuid = UUID.randomUUID().toString(); uuid = UUID.randomUUID().toString();
} }
public NiciraNvpDeviceVO(long hostId, long physicalNetworkId, public NiciraNvpDeviceVO(final long hostId, final long physicalNetworkId,
String providerName, String deviceName) { final String providerName, final String deviceName) {
super(); super();
this.hostId = hostId; this.hostId = hostId;
this.physicalNetworkId = physicalNetworkId; this.physicalNetworkId = physicalNetworkId;

View File

@ -46,7 +46,7 @@ public class NiciraNvpNicMappingVO implements InternalIdentity {
public NiciraNvpNicMappingVO () { public NiciraNvpNicMappingVO () {
} }
public NiciraNvpNicMappingVO (String logicalSwitchUuid, String logicalSwitchPortUuid, String nicUuid) { public NiciraNvpNicMappingVO (final String logicalSwitchUuid, final String logicalSwitchPortUuid, final String nicUuid) {
this.logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
this.logicalSwitchPortUuid = logicalSwitchPortUuid; this.logicalSwitchPortUuid = logicalSwitchPortUuid;
this.nicUuid = nicUuid; this.nicUuid = nicUuid;
@ -56,7 +56,7 @@ public class NiciraNvpNicMappingVO implements InternalIdentity {
return logicalSwitchUuid; return logicalSwitchUuid;
} }
public void setLogicalSwitchUuid(String logicalSwitchUuid) { public void setLogicalSwitchUuid(final String logicalSwitchUuid) {
this.logicalSwitchUuid = logicalSwitchUuid; this.logicalSwitchUuid = logicalSwitchUuid;
} }
@ -64,7 +64,7 @@ public class NiciraNvpNicMappingVO implements InternalIdentity {
return logicalSwitchPortUuid; return logicalSwitchPortUuid;
} }
public void setLogicalSwitchPortUuid(String logicalSwitchPortUuid) { public void setLogicalSwitchPortUuid(final String logicalSwitchPortUuid) {
this.logicalSwitchPortUuid = logicalSwitchPortUuid; this.logicalSwitchPortUuid = logicalSwitchPortUuid;
} }

View File

@ -28,6 +28,7 @@ import org.apache.cloudstack.api.InternalIdentity;
@Entity @Entity
@Table(name="nicira_nvp_router_map") @Table(name="nicira_nvp_router_map")
public class NiciraNvpRouterMappingVO implements InternalIdentity { public class NiciraNvpRouterMappingVO implements InternalIdentity {
//FIXME the ddl for this table should be in one of the upgrade scripts
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id") @Column(name="id")
@ -42,12 +43,12 @@ public class NiciraNvpRouterMappingVO implements InternalIdentity {
public NiciraNvpRouterMappingVO() { public NiciraNvpRouterMappingVO() {
} }
public NiciraNvpRouterMappingVO(String logicalRouterUuid, long networkId) { public NiciraNvpRouterMappingVO(final String logicalRouterUuid, final long networkId) {
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
this.networkId = networkId; this.networkId = networkId;
} }
public NiciraNvpRouterMappingVO(long id, String logicalRouterUuid, long networkId) { public NiciraNvpRouterMappingVO(final long id, final String logicalRouterUuid, final long networkId) {
this.id = id; this.id = id;
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
this.networkId = networkId; this.networkId = networkId;
@ -58,7 +59,7 @@ public class NiciraNvpRouterMappingVO implements InternalIdentity {
return id; return id;
} }
public void setId(long id) { public void setId(final long id) {
this.id = id; this.id = id;
} }
@ -66,7 +67,7 @@ public class NiciraNvpRouterMappingVO implements InternalIdentity {
return logicalRouterUuid; return logicalRouterUuid;
} }
public void setLogicalRouterUuid(String logicalRouterUuid) { public void setLogicalRouterUuid(final String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid; this.logicalRouterUuid = logicalRouterUuid;
} }
@ -74,7 +75,7 @@ public class NiciraNvpRouterMappingVO implements InternalIdentity {
return networkId; return networkId;
} }
public void setNetworkId(long networkId) { public void setNetworkId(final long networkId) {
this.networkId = networkId; this.networkId = networkId;
} }

View File

@ -31,7 +31,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
@Component @Component
@Local(value=NiciraNvpDao.class) @Local(value=NiciraNvpDao.class)
public class NiciraNvpDaoImpl extends GenericDaoBase<NiciraNvpDeviceVO, Long> public class NiciraNvpDaoImpl extends GenericDaoBase<NiciraNvpDeviceVO, Long>
implements NiciraNvpDao { implements NiciraNvpDao {
protected final SearchBuilder<NiciraNvpDeviceVO> physicalNetworkIdSearch; protected final SearchBuilder<NiciraNvpDeviceVO> physicalNetworkIdSearch;
@ -42,7 +42,7 @@ implements NiciraNvpDao {
} }
@Override @Override
public List<NiciraNvpDeviceVO> listByPhysicalNetwork(long physicalNetworkId) { public List<NiciraNvpDeviceVO> listByPhysicalNetwork(final long physicalNetworkId) {
SearchCriteria<NiciraNvpDeviceVO> sc = physicalNetworkIdSearch.create(); SearchCriteria<NiciraNvpDeviceVO> sc = physicalNetworkIdSearch.create();
sc.setParameters("physicalNetworkId", physicalNetworkId); sc.setParameters("physicalNetworkId", physicalNetworkId);
return search(sc, null); return search(sc, null);

View File

@ -21,12 +21,9 @@ import com.cloud.utils.db.GenericDao;
public interface NiciraNvpNicMappingDao extends GenericDao<NiciraNvpNicMappingVO, Long> { public interface NiciraNvpNicMappingDao extends GenericDao<NiciraNvpNicMappingVO, Long> {
/** /** find the mapping for a nic
* find the mapping for a nic * @param nicUuid the Uuid of a nic attached to a logical switch port
* @param nicUuid * @return NiciraNvpNicMapping for this nic uuid or null if it does not exist
* the Uuid of a nic attached to a logical switch port
* @return NiciraNvpNicMapping for this nic uuid or null if it does not
* exist
*/ */
public NiciraNvpNicMappingVO findByNicUuid(String nicUuid); public NiciraNvpNicMappingVO findByNicUuid(String nicUuid);
} }

View File

@ -29,7 +29,7 @@ import com.cloud.utils.db.SearchCriteria.Op;
@Component @Component
@Local(value=NiciraNvpNicMappingDao.class) @Local(value=NiciraNvpNicMappingDao.class)
public class NiciraNvpNicMappingDaoImpl extends public class NiciraNvpNicMappingDaoImpl extends
GenericDaoBase<NiciraNvpNicMappingVO, Long> implements NiciraNvpNicMappingDao { GenericDaoBase<NiciraNvpNicMappingVO, Long> implements NiciraNvpNicMappingDao {
protected final SearchBuilder<NiciraNvpNicMappingVO> nicSearch; protected final SearchBuilder<NiciraNvpNicMappingVO> nicSearch;
@ -40,7 +40,7 @@ GenericDaoBase<NiciraNvpNicMappingVO, Long> implements NiciraNvpNicMappingDao {
} }
@Override @Override
public NiciraNvpNicMappingVO findByNicUuid(String nicUuid) { public NiciraNvpNicMappingVO findByNicUuid(final String nicUuid) {
SearchCriteria<NiciraNvpNicMappingVO> sc = nicSearch.create(); SearchCriteria<NiciraNvpNicMappingVO> sc = nicSearch.create();
sc.setParameters("nicUuid", nicUuid); sc.setParameters("nicUuid", nicUuid);
return findOneBy(sc); return findOneBy(sc);

View File

@ -39,10 +39,11 @@ public class NiciraNvpRouterMappingDaoImpl extends GenericDaoBase<NiciraNvpRoute
} }
@Override @Override
public NiciraNvpRouterMappingVO findByNetworkId(long id) { public NiciraNvpRouterMappingVO findByNetworkId(final long id) {
SearchCriteria<NiciraNvpRouterMappingVO> sc = networkSearch.create(); SearchCriteria<NiciraNvpRouterMappingVO> sc = networkSearch.create();
sc.setParameters("network_id", id); sc.setParameters("network_id", id);
return findOneBy(sc); return findOneBy(sc);
} }
} }

View File

@ -129,48 +129,52 @@ import com.cloud.vm.dao.NicDao;
SourceNatServiceProvider.class, StaticNatServiceProvider.class, SourceNatServiceProvider.class, StaticNatServiceProvider.class,
PortForwardingServiceProvider.class, IpDeployer.class} ) PortForwardingServiceProvider.class, IpDeployer.class} )
public class NiciraNvpElement extends AdapterBase implements public class NiciraNvpElement extends AdapterBase implements
ConnectivityProvider, SourceNatServiceProvider, ConnectivityProvider, SourceNatServiceProvider,
PortForwardingServiceProvider, StaticNatServiceProvider, PortForwardingServiceProvider, StaticNatServiceProvider,
NiciraNvpElementService, ResourceStateAdapter, IpDeployer { NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
private static final int MAX_PORT = 65535;
private static final int MIN_PORT = 0;
private static final Logger s_logger = Logger private static final Logger s_logger = Logger
.getLogger(NiciraNvpElement.class); .getLogger(NiciraNvpElement.class);
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities(); private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@Inject @Inject
NicDao _nicDao; protected NicDao nicDao;
@Inject @Inject
ResourceManager _resourceMgr; protected ResourceManager resourceMgr;
@Inject @Inject
PhysicalNetworkDao _physicalNetworkDao; protected PhysicalNetworkDao physicalNetworkDao;
@Inject @Inject
PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao; protected PhysicalNetworkServiceProviderDao physicalNetworkServiceProviderDao;
@Inject @Inject
NiciraNvpDao _niciraNvpDao; protected NiciraNvpDao niciraNvpDao;
@Inject @Inject
HostDetailsDao _hostDetailsDao; protected HostDetailsDao hostDetailsDao;
@Inject @Inject
HostDao _hostDao; protected HostDao hostDao;
@Inject @Inject
AgentManager _agentMgr; protected AgentManager agentMgr;
@Inject @Inject
NiciraNvpNicMappingDao _niciraNvpNicMappingDao; protected NiciraNvpNicMappingDao niciraNvpNicMappingDao;
@Inject @Inject
NiciraNvpRouterMappingDao _niciraNvpRouterMappingDao; protected NiciraNvpRouterMappingDao niciraNvpRouterMappingDao;
@Inject @Inject
NetworkDao _networkDao; protected NetworkDao networkDao;
@Inject @Inject
NetworkOrchestrationService _networkManager; protected NetworkOrchestrationService networkManager;
@Inject @Inject
NetworkModel _networkModel; protected NetworkModel networkModel;
@Inject @Inject
ConfigurationManager _configMgr; protected ConfigurationManager configMgr;
@Inject @Inject
NetworkServiceMapDao _ntwkSrvcDao; protected NetworkServiceMapDao ntwkSrvcDao;
@Inject @Inject
VlanDao _vlanDao; protected VlanDao vlanDao;
@Inject @Inject
IpAddressManager _ipAddrMgr; protected IpAddressManager ipAddrMgr;
@Override @Override
public Map<Service, Map<Capability, String>> getCapabilities() { public Map<Service, Map<Capability, String>> getCapabilities() {
@ -189,14 +193,14 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
if (!_networkModel.isProviderForNetwork(getProvider(), if (!networkModel.isProviderForNetwork(getProvider(),
network.getId())) { network.getId())) {
s_logger.debug("NiciraNvpElement is not a provider for network " s_logger.debug("NiciraNvpElement is not a provider for network "
+ network.getDisplayText()); + network.getDisplayText());
return false; return false;
} }
if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), if (!ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(),
service, Network.Provider.NiciraNvp)) { service, Network.Provider.NiciraNvp)) {
s_logger.debug("NiciraNvpElement can't provide the " s_logger.debug("NiciraNvpElement can't provide the "
+ service.getName() + " service on network " + service.getName() + " service on network "
@ -211,15 +215,15 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
public boolean configure(String name, Map<String, Object> params) public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException { throws ConfigurationException {
super.configure(name, params); super.configure(name, params);
_resourceMgr.registerResourceStateAdapter(name, this); resourceMgr.registerResourceStateAdapter(name, this);
return true; return true;
} }
@Override @Override
public boolean implement(Network network, NetworkOffering offering, public boolean implement(Network network, NetworkOffering offering,
DeployDestination dest, ReservationContext context) DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException, throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException { InsufficientCapacityException {
s_logger.debug("entering NiciraNvpElement implement function for network " s_logger.debug("entering NiciraNvpElement implement function for network "
+ network.getDisplayText() + network.getDisplayText()
+ " (state " + " (state "
@ -235,7 +239,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
List<NiciraNvpDeviceVO> devices = _niciraNvpDao List<NiciraNvpDeviceVO> devices = niciraNvpDao
.listByPhysicalNetwork(network.getPhysicalNetworkId()); .listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " s_logger.error("No NiciraNvp Controller on physical network "
@ -243,17 +247,22 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
_hostDao.loadDetails(niciraNvpHost); hostDao.loadDetails(niciraNvpHost);
Account owner = context.getAccount(); Account owner = context.getAccount();
/*
* TODO Shouldn't we lock the network as we might need to do
* multiple operations that should be done only once.
*/
// Implement SourceNat immediately as we have al the info already // Implement SourceNat immediately as we have al the info already
if (_networkModel.isProviderSupportServiceInNetwork( if (networkModel.isProviderSupportServiceInNetwork(
network.getId(), Service.SourceNat, Provider.NiciraNvp)) { network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
s_logger.debug("Apparently we are supposed to provide SourceNat on this network"); s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
PublicIp sourceNatIp = _ipAddrMgr PublicIp sourceNatIp = ipAddrMgr
.assignSourceNatIpAddressToGuestNetwork(owner, network); .assignSourceNatIpAddressToGuestNetwork(owner, network);
String publicCidr = sourceNatIp.getAddress().addr() + "/" String publicCidr = sourceNatIp.getAddress().addr() + "/"
+ NetUtils.getCidrSize(sourceNatIp.getVlanNetmask()); + NetUtils.getCidrSize(sourceNatIp.getVlanNetmask());
@ -267,10 +276,10 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
BroadcastDomainType.getValue(network.getBroadcastUri()), BroadcastDomainType.getValue(network.getBroadcastUri()),
"router-" + network.getDisplayText(), publicCidr, "router-" + network.getDisplayText(), publicCidr,
sourceNatIp.getGateway(), internalCidr, context sourceNatIp.getGateway(), internalCidr, context
.getDomain().getName() .getDomain().getName()
+ "-" + "-"
+ context.getAccount().getAccountName()); + context.getAccount().getAccountName());
CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)_agentMgr CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)agentMgr
.easySend(niciraNvpHost.getId(), cmd); .easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) { if (answer.getResult() == false) {
s_logger.error("Failed to create Logical Router for network " s_logger.error("Failed to create Logical Router for network "
@ -281,7 +290,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
// Store the uuid so we can easily find it during cleanup // Store the uuid so we can easily find it during cleanup
NiciraNvpRouterMappingVO routermapping = NiciraNvpRouterMappingVO routermapping =
new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId()); new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
_niciraNvpRouterMappingDao.persist(routermapping); niciraNvpRouterMappingDao.persist(routermapping);
} }
return true; return true;
@ -303,9 +312,9 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NicVO nicVO = _nicDao.findById(nic.getId()); NicVO nicVO = nicDao.findById(nic.getId());
List<NiciraNvpDeviceVO> devices = _niciraNvpDao List<NiciraNvpDeviceVO> devices = niciraNvpDao
.listByPhysicalNetwork(network.getPhysicalNetworkId()); .listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " s_logger.error("No NiciraNvp Controller on physical network "
@ -313,15 +322,15 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpNicMappingVO existingNicMap = _niciraNvpNicMappingDao NiciraNvpNicMappingVO existingNicMap = niciraNvpNicMappingDao
.findByNicUuid(nicVO.getUuid()); .findByNicUuid(nicVO.getUuid());
if (existingNicMap != null) { if (existingNicMap != null) {
FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand( FindLogicalSwitchPortCommand findCmd = new FindLogicalSwitchPortCommand(
existingNicMap.getLogicalSwitchUuid(), existingNicMap.getLogicalSwitchUuid(),
existingNicMap.getLogicalSwitchPortUuid()); existingNicMap.getLogicalSwitchPortUuid());
FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer)_agentMgr FindLogicalSwitchPortAnswer answer = (FindLogicalSwitchPortAnswer)agentMgr
.easySend(niciraNvpHost.getId(), findCmd); .easySend(niciraNvpHost.getId(), findCmd);
if (answer.getResult()) { if (answer.getResult()) {
@ -333,14 +342,14 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
BroadcastDomainType.getValue(network.getBroadcastUri()), BroadcastDomainType.getValue(network.getBroadcastUri()),
nicVO.getUuid(), context.getDomain().getName() + "-" nicVO.getUuid(), context.getDomain().getName() + "-"
+ context.getAccount().getAccountName(), + context.getAccount().getAccountName(),
nic.getName()); nic.getName());
_agentMgr.easySend(niciraNvpHost.getId(), cmd); agentMgr.easySend(niciraNvpHost.getId(), cmd);
return true; return true;
} else { } else {
s_logger.error("Stale entry found for nic " + nic.getName() s_logger.error("Stale entry found for nic " + nic.getName()
+ " with logical switchport uuid " + " with logical switchport uuid "
+ existingNicMap.getLogicalSwitchPortUuid()); + existingNicMap.getLogicalSwitchPortUuid());
_niciraNvpNicMappingDao.remove(existingNicMap.getId()); niciraNvpNicMappingDao.remove(existingNicMap.getId());
} }
} }
@ -348,7 +357,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
BroadcastDomainType.getValue(network.getBroadcastUri()), BroadcastDomainType.getValue(network.getBroadcastUri()),
nicVO.getUuid(), context.getDomain().getName() + "-" nicVO.getUuid(), context.getDomain().getName() + "-"
+ context.getAccount().getAccountName(), nic.getName()); + context.getAccount().getAccountName(), nic.getName());
CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer)_agentMgr CreateLogicalSwitchPortAnswer answer = (CreateLogicalSwitchPortAnswer)agentMgr
.easySend(niciraNvpHost.getId(), cmd); .easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) { if (answer == null || !answer.getResult()) {
@ -358,7 +367,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(BroadcastDomainType.getValue(network.getBroadcastUri()), NiciraNvpNicMappingVO nicMap = new NiciraNvpNicMappingVO(BroadcastDomainType.getValue(network.getBroadcastUri()),
answer.getLogicalSwitchPortUuid(), nicVO.getUuid()); answer.getLogicalSwitchPortUuid(), nicVO.getUuid());
_niciraNvpNicMappingDao.persist(nicMap); niciraNvpNicMappingDao.persist(nicMap);
return true; return true;
} }
@ -378,9 +387,9 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NicVO nicVO = _nicDao.findById(nic.getId()); NicVO nicVO = nicDao.findById(nic.getId());
List<NiciraNvpDeviceVO> devices = _niciraNvpDao List<NiciraNvpDeviceVO> devices = niciraNvpDao
.listByPhysicalNetwork(network.getPhysicalNetworkId()); .listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " s_logger.error("No NiciraNvp Controller on physical network "
@ -388,9 +397,9 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpNicMappingVO nicMap = _niciraNvpNicMappingDao NiciraNvpNicMappingVO nicMap = niciraNvpNicMappingDao
.findByNicUuid(nicVO.getUuid()); .findByNicUuid(nicVO.getUuid());
if (nicMap == null) { if (nicMap == null) {
s_logger.error("No mapping for nic " + nic.getName()); s_logger.error("No mapping for nic " + nic.getName());
@ -400,7 +409,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand( DeleteLogicalSwitchPortCommand cmd = new DeleteLogicalSwitchPortCommand(
nicMap.getLogicalSwitchUuid(), nicMap.getLogicalSwitchUuid(),
nicMap.getLogicalSwitchPortUuid()); nicMap.getLogicalSwitchPortUuid());
DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer)_agentMgr DeleteLogicalSwitchPortAnswer answer = (DeleteLogicalSwitchPortAnswer)agentMgr
.easySend(niciraNvpHost.getId(), cmd); .easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) { if (answer == null || !answer.getResult()) {
@ -408,7 +417,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
_niciraNvpNicMappingDao.remove(nicMap.getId()); niciraNvpNicMappingDao.remove(nicMap.getId());
return true; return true;
} }
@ -421,7 +430,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
List<NiciraNvpDeviceVO> devices = _niciraNvpDao List<NiciraNvpDeviceVO> devices = niciraNvpDao
.listByPhysicalNetwork(network.getPhysicalNetworkId()); .listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " s_logger.error("No NiciraNvp Controller on physical network "
@ -429,15 +438,15 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
if (_networkModel.isProviderSupportServiceInNetwork(network.getId(), if (networkModel.isProviderSupportServiceInNetwork(network.getId(),
Service.SourceNat, Provider.NiciraNvp)) { Service.SourceNat, Provider.NiciraNvp)) {
s_logger.debug("Apparently we were providing SourceNat on this network"); s_logger.debug("Apparently we were providing SourceNat on this network");
// Deleting the LogicalRouter will also take care of all provisioned // Deleting the LogicalRouter will also take care of all provisioned
// nat rules. // nat rules.
NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao
.findByNetworkId(network.getId()); .findByNetworkId(network.getId());
if (routermapping == null) { if (routermapping == null) {
s_logger.warn("No logical router uuid found for network " s_logger.warn("No logical router uuid found for network "
@ -448,14 +457,14 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid()); DeleteLogicalRouterCommand cmd = new DeleteLogicalRouterCommand(routermapping.getLogicalRouterUuid());
DeleteLogicalRouterAnswer answer = DeleteLogicalRouterAnswer answer =
(DeleteLogicalRouterAnswer)_agentMgr.easySend(niciraNvpHost.getId(), cmd); (DeleteLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) { if (answer.getResult() == false) {
s_logger.error("Failed to delete LogicalRouter for network " s_logger.error("Failed to delete LogicalRouter for network "
+ network.getDisplayText()); + network.getDisplayText());
return false; return false;
} }
_niciraNvpRouterMappingDao.remove(routermapping.getId()); niciraNvpRouterMappingDao.remove(routermapping.getId());
} }
return true; return true;
@ -479,7 +488,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
@Override @Override
public boolean shutdownProviderInstances( public boolean shutdownProviderInstances(
PhysicalNetworkServiceProvider provider, ReservationContext context) PhysicalNetworkServiceProvider provider, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException { throws ConcurrentOperationException, ResourceUnavailableException {
// Nothing to do here. // Nothing to do here.
return true; return true;
} }
@ -547,7 +556,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
NetworkDevice networkDevice = NetworkDevice NetworkDevice networkDevice = NetworkDevice
.getNetworkDevice(deviceName); .getNetworkDevice(deviceName);
final Long physicalNetworkId = cmd.getPhysicalNetworkId(); final Long physicalNetworkId = cmd.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao PhysicalNetworkVO physicalNetwork = physicalNetworkDao
.findById(physicalNetworkId); .findById(physicalNetworkId);
if (physicalNetwork == null) { if (physicalNetwork == null) {
throw new InvalidParameterValueException( throw new InvalidParameterValueException(
@ -556,7 +565,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
} }
long zoneId = physicalNetwork.getDataCenterId(); long zoneId = physicalNetwork.getDataCenterId();
final PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao final PhysicalNetworkServiceProviderVO ntwkSvcProvider = physicalNetworkServiceProviderDao
.findByServiceProvider(physicalNetwork.getId(), .findByServiceProvider(physicalNetwork.getId(),
networkDevice.getNetworkServiceProvder()); networkDevice.getNetworkServiceProvder());
if (ntwkSvcProvider == null) { if (ntwkSvcProvider == null) {
@ -571,7 +580,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
+ physicalNetworkId + "to add this device"); + physicalNetworkId + "to add this device");
} }
if (_niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) { if (niciraNvpDao.listByPhysicalNetwork(physicalNetworkId).size() != 0) {
throw new CloudRuntimeException( throw new CloudRuntimeException(
"A NiciraNvp device is already configured on this physical network"); "A NiciraNvp device is already configured on this physical network");
} }
@ -598,7 +607,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
try { try {
resource.configure(cmd.getHost(), hostdetails); resource.configure(cmd.getHost(), hostdetails);
final Host host = _resourceMgr.addHost(zoneId, resource, final Host host = resourceMgr.addHost(zoneId, resource,
Host.Type.L2Networking, params); Host.Type.L2Networking, params);
if (host != null) { if (host != null) {
return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() { return Transaction.execute(new TransactionCallback<NiciraNvpDeviceVO>() {
@ -607,12 +616,12 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(), NiciraNvpDeviceVO niciraNvpDevice = new NiciraNvpDeviceVO(host.getId(),
physicalNetworkId, ntwkSvcProvider.getProviderName(), physicalNetworkId, ntwkSvcProvider.getProviderName(),
deviceName); deviceName);
_niciraNvpDao.persist(niciraNvpDevice); niciraNvpDao.persist(niciraNvpDevice);
DetailVO detail = new DetailVO(host.getId(), DetailVO detail = new DetailVO(host.getId(),
"niciranvpdeviceid", String.valueOf(niciraNvpDevice "niciranvpdeviceid", String.valueOf(niciraNvpDevice
.getId())); .getId()));
_hostDetailsDao.persist(detail); hostDetailsDao.persist(detail);
return niciraNvpDevice; return niciraNvpDevice;
} }
@ -629,8 +638,8 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
@Override @Override
public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse( public NiciraNvpDeviceResponse createNiciraNvpDeviceResponse(
NiciraNvpDeviceVO niciraNvpDeviceVO) { NiciraNvpDeviceVO niciraNvpDeviceVO) {
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDeviceVO.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDeviceVO.getHostId());
_hostDao.loadDetails(niciraNvpHost); hostDao.loadDetails(niciraNvpHost);
NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse(); NiciraNvpDeviceResponse response = new NiciraNvpDeviceResponse();
response.setDeviceName(niciraNvpDeviceVO.getDeviceName()); response.setDeviceName(niciraNvpDeviceVO.getDeviceName());
@ -650,7 +659,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
@Override @Override
public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) { public boolean deleteNiciraNvpDevice(DeleteNiciraNvpDeviceCmd cmd) {
Long niciraDeviceId = cmd.getNiciraNvpDeviceId(); Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao
.findById(niciraDeviceId); .findById(niciraDeviceId);
if (niciraNvpDevice == null) { if (niciraNvpDevice == null) {
throw new InvalidParameterValueException( throw new InvalidParameterValueException(
@ -659,12 +668,12 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
// Find the physical network we work for // Find the physical network we work for
Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId(); Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao PhysicalNetworkVO physicalNetwork = physicalNetworkDao
.findById(physicalNetworkId); .findById(physicalNetworkId);
if (physicalNetwork != null) { if (physicalNetwork != null) {
// Lets see if there are networks that use us // Lets see if there are networks that use us
// Find the nicira networks on this physical network // Find the nicira networks on this physical network
List<NetworkVO> networkList = _networkDao List<NetworkVO> networkList = networkDao
.listByPhysicalNetwork(physicalNetworkId); .listByPhysicalNetwork(physicalNetworkId);
// Networks with broadcast type lswitch are ours // Networks with broadcast type lswitch are ours
@ -679,14 +688,14 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
} }
} }
HostVO niciraHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraHost = hostDao.findById(niciraNvpDevice.getHostId());
Long hostId = niciraHost.getId(); Long hostId = niciraHost.getId();
niciraHost.setResourceState(ResourceState.Maintenance); niciraHost.setResourceState(ResourceState.Maintenance);
_hostDao.update(hostId, niciraHost); hostDao.update(hostId, niciraHost);
_resourceMgr.deleteHost(hostId, false, false); resourceMgr.deleteHost(hostId, false, false);
_niciraNvpDao.remove(niciraDeviceId); niciraNvpDao.remove(niciraDeviceId);
return true; return true;
} }
@ -703,7 +712,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
} }
if (niciraNvpDeviceId != null) { if (niciraNvpDeviceId != null) {
NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao
.findById(niciraNvpDeviceId); .findById(niciraNvpDeviceId);
if (niciraNvpDevice == null) { if (niciraNvpDevice == null) {
throw new InvalidParameterValueException( throw new InvalidParameterValueException(
@ -712,14 +721,14 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
} }
responseList.add(niciraNvpDevice); responseList.add(niciraNvpDevice);
} else { } else {
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao PhysicalNetworkVO physicalNetwork = physicalNetworkDao
.findById(physicalNetworkId); .findById(physicalNetworkId);
if (physicalNetwork == null) { if (physicalNetwork == null) {
throw new InvalidParameterValueException( throw new InvalidParameterValueException(
"Could not find a physical network with id: " "Could not find a physical network with id: "
+ physicalNetworkId); + physicalNetworkId);
} }
responseList = _niciraNvpDao responseList = niciraNvpDao
.listByPhysicalNetwork(physicalNetworkId); .listByPhysicalNetwork(physicalNetworkId);
} }
@ -730,7 +739,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
public List<? extends Network> listNiciraNvpDeviceNetworks( public List<? extends Network> listNiciraNvpDeviceNetworks(
ListNiciraNvpDeviceNetworksCmd cmd) { ListNiciraNvpDeviceNetworksCmd cmd) {
Long niciraDeviceId = cmd.getNiciraNvpDeviceId(); Long niciraDeviceId = cmd.getNiciraNvpDeviceId();
NiciraNvpDeviceVO niciraNvpDevice = _niciraNvpDao NiciraNvpDeviceVO niciraNvpDevice = niciraNvpDao
.findById(niciraDeviceId); .findById(niciraDeviceId);
if (niciraNvpDevice == null) { if (niciraNvpDevice == null) {
throw new InvalidParameterValueException( throw new InvalidParameterValueException(
@ -739,7 +748,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
// Find the physical network we work for // Find the physical network we work for
Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId(); Long physicalNetworkId = niciraNvpDevice.getPhysicalNetworkId();
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao PhysicalNetworkVO physicalNetwork = physicalNetworkDao
.findById(physicalNetworkId); .findById(physicalNetworkId);
if (physicalNetwork == null) { if (physicalNetwork == null) {
// No such physical network, so no provisioned networks // No such physical network, so no provisioned networks
@ -747,7 +756,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
} }
// Find the nicira networks on this physical network // Find the nicira networks on this physical network
List<NetworkVO> networkList = _networkDao List<NetworkVO> networkList = networkDao
.listByPhysicalNetwork(physicalNetworkId); .listByPhysicalNetwork(physicalNetworkId);
// Networks with broadcast type lswitch are ours // Networks with broadcast type lswitch are ours
@ -808,11 +817,11 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
@Override @Override
public boolean applyIps(Network network, public boolean applyIps(Network network,
List<? extends PublicIpAddress> ipAddress, Set<Service> services) List<? extends PublicIpAddress> ipAddress, Set<Service> services)
throws ResourceUnavailableException { throws ResourceUnavailableException {
if (services.contains(Service.SourceNat)) { if (services.contains(Service.SourceNat)) {
// Only if we need to provide SourceNat we need to configure the logical router // Only if we need to provide SourceNat we need to configure the logical router
// SourceNat is required for StaticNat and PortForwarding // SourceNat is required for StaticNat and PortForwarding
List<NiciraNvpDeviceVO> devices = _niciraNvpDao List<NiciraNvpDeviceVO> devices = niciraNvpDao
.listByPhysicalNetwork(network.getPhysicalNetworkId()); .listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " s_logger.error("No NiciraNvp Controller on physical network "
@ -820,10 +829,10 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
_hostDao.loadDetails(niciraNvpHost); hostDao.loadDetails(niciraNvpHost);
NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao
.findByNetworkId(network.getId()); .findByNetworkId(network.getId());
if (routermapping == null) { if (routermapping == null) {
s_logger.error("No logical router uuid found for network " s_logger.error("No logical router uuid found for network "
@ -842,11 +851,10 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
} }
ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), ConfigurePublicIpsOnLogicalRouterCommand cmd = new ConfigurePublicIpsOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(),
niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs); niciraNvpHost.getDetail("l3gatewayserviceuuid"), cidrs);
ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer)_agentMgr.easySend(niciraNvpHost.getId(), cmd); ConfigurePublicIpsOnLogicalRouterAnswer answer = (ConfigurePublicIpsOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
//FIXME answer can be null if the host is down //FIXME answer can be null if the host is down
return answer.getResult(); return answer.getResult();
} } else {
else {
s_logger.debug("No need to provision ip addresses as we are not providing L3 services."); s_logger.debug("No need to provision ip addresses as we are not providing L3 services.");
} }
@ -859,12 +867,12 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
@Override @Override
public boolean applyStaticNats(Network network, public boolean applyStaticNats(Network network,
List<? extends StaticNat> rules) List<? extends StaticNat> rules)
throws ResourceUnavailableException { throws ResourceUnavailableException {
if (!canHandle(network, Service.StaticNat)) { if (!canHandle(network, Service.StaticNat)) {
return false; return false;
} }
List<NiciraNvpDeviceVO> devices = _niciraNvpDao List<NiciraNvpDeviceVO> devices = niciraNvpDao
.listByPhysicalNetwork(network.getPhysicalNetworkId()); .listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " s_logger.error("No NiciraNvp Controller on physical network "
@ -872,9 +880,9 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao
.findByNetworkId(network.getId()); .findByNetworkId(network.getId());
if (routermapping == null) { if (routermapping == null) {
s_logger.error("No logical router uuid found for network " s_logger.error("No logical router uuid found for network "
@ -884,20 +892,20 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
List<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>(); List<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>();
for (StaticNat rule : rules) { for (StaticNat rule : rules) {
IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId()); IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
// Force the nat rule into the StaticNatRuleTO, no use making a new TO object // Force the nat rule into the StaticNatRuleTO, no use making a new TO object
// we only need the source and destination ip. Unfortunately no mention if a rule // we only need the source and destination ip. Unfortunately no mention if a rule
// is new. // is new.
StaticNatRuleTO ruleTO = new StaticNatRuleTO(1, StaticNatRuleTO ruleTO = new StaticNatRuleTO(1,
sourceIp.getAddress().addr(), 0, 65535, sourceIp.getAddress().addr(), MIN_PORT, MAX_PORT,
rule.getDestIpAddress(), 0, 65535, rule.getDestIpAddress(), MIN_PORT, MAX_PORT,
"any", rule.isForRevoke(), false); "any", rule.isForRevoke(), false);
staticNatRules.add(ruleTO); staticNatRules.add(ruleTO);
} }
ConfigureStaticNatRulesOnLogicalRouterCommand cmd = ConfigureStaticNatRulesOnLogicalRouterCommand cmd =
new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules); new ConfigureStaticNatRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), staticNatRules);
ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer)_agentMgr.easySend(niciraNvpHost.getId(), cmd); ConfigureStaticNatRulesOnLogicalRouterAnswer answer = (ConfigureStaticNatRulesOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
return answer.getResult(); return answer.getResult();
} }
@ -912,7 +920,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
List<NiciraNvpDeviceVO> devices = _niciraNvpDao List<NiciraNvpDeviceVO> devices = niciraNvpDao
.listByPhysicalNetwork(network.getPhysicalNetworkId()); .listByPhysicalNetwork(network.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " s_logger.error("No NiciraNvp Controller on physical network "
@ -920,9 +928,9 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
return false; return false;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
NiciraNvpRouterMappingVO routermapping = _niciraNvpRouterMappingDao NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao
.findByNetworkId(network.getId()); .findByNetworkId(network.getId());
if (routermapping == null) { if (routermapping == null) {
s_logger.error("No logical router uuid found for network " s_logger.error("No logical router uuid found for network "
@ -932,15 +940,15 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
List<PortForwardingRuleTO> portForwardingRules = new ArrayList<PortForwardingRuleTO>(); List<PortForwardingRuleTO> portForwardingRules = new ArrayList<PortForwardingRuleTO>();
for (PortForwardingRule rule : rules) { for (PortForwardingRule rule : rules) {
IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId()); IpAddress sourceIp = networkModel.getIp(rule.getSourceIpAddressId());
Vlan vlan = _vlanDao.findById(sourceIp.getVlanId()); Vlan vlan = vlanDao.findById(sourceIp.getVlanId());
PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr()); PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
portForwardingRules.add(ruleTO); portForwardingRules.add(ruleTO);
} }
ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = ConfigurePortForwardingRulesOnLogicalRouterCommand cmd =
new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules); new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer)_agentMgr.easySend(niciraNvpHost.getId(), cmd); ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
return answer.getResult(); return answer.getResult();
} }

View File

@ -66,30 +66,32 @@ import com.cloud.vm.VirtualMachineProfile;
@Local(value = NetworkGuru.class) @Local(value = NetworkGuru.class)
public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru { public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
private static final int MAX_NAME_LENGTH = 40;
private static final Logger s_logger = Logger.getLogger(NiciraNvpGuestNetworkGuru.class); private static final Logger s_logger = Logger.getLogger(NiciraNvpGuestNetworkGuru.class);
@Inject @Inject
NetworkModel _networkModel; protected NetworkModel networkModel;
@Inject @Inject
NetworkDao _networkDao; protected NetworkDao networkDao;
@Inject @Inject
DataCenterDao _zoneDao; protected DataCenterDao zoneDao;
@Inject @Inject
PhysicalNetworkDao _physicalNetworkDao; protected PhysicalNetworkDao physicalNetworkDao;
@Inject @Inject
AccountDao _accountDao; protected AccountDao accountDao;
@Inject @Inject
NiciraNvpDao _niciraNvpDao; protected NiciraNvpDao niciraNvpDao;
@Inject @Inject
HostDao _hostDao; protected HostDao hostDao;
@Inject @Inject
ResourceManager _resourceMgr; protected ResourceManager resourceMgr;
@Inject @Inject
AgentManager _agentMgr; protected AgentManager agentMgr;
@Inject @Inject
HostDetailsDao _hostDetailsDao; protected HostDetailsDao hostDetailsDao;
@Inject @Inject
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao; protected NetworkOfferingServiceMapDao ntwkOfferingSrvcDao;
public NiciraNvpGuestNetworkGuru() { public NiciraNvpGuestNetworkGuru() {
super(); super();
@ -97,13 +99,13 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
} }
@Override @Override
protected boolean canHandle(NetworkOffering offering, final NetworkType networkType, final PhysicalNetwork physicalNetwork) { protected boolean canHandle(final NetworkOffering offering, final NetworkType networkType, final PhysicalNetwork physicalNetwork) {
// This guru handles only Guest Isolated network that supports Source nat service // This guru handles only Guest Isolated network that supports Source nat service
if (networkType == NetworkType.Advanced if (networkType == NetworkType.Advanced
&& isMyTrafficType(offering.getTrafficType()) && isMyTrafficType(offering.getTrafficType())
&& offering.getGuestType() == Network.GuestType.Isolated && offering.getGuestType() == Network.GuestType.Isolated
&& isMyIsolationMethod(physicalNetwork) && isMyIsolationMethod(physicalNetwork)
&& _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) { && ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
return true; return true;
} else { } else {
s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced); s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced);
@ -112,17 +114,17 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
} }
@Override @Override
public Network design(NetworkOffering offering, DeploymentPlan plan, public Network design(final NetworkOffering offering, final DeploymentPlan plan,
Network userSpecified, Account owner) { final Network userSpecified, final Account owner) {
// Check of the isolation type of the related physical network is STT // Check of the isolation type of the related physical network is STT
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId()); PhysicalNetworkVO physnet = physicalNetworkDao.findById(plan.getPhysicalNetworkId());
DataCenter dc = _dcDao.findById(plan.getDataCenterId()); DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc.getNetworkType(), physnet)) { if (!canHandle(offering, dc.getNetworkType(), physnet)) {
s_logger.debug("Refusing to design this network"); s_logger.debug("Refusing to design this network");
return null; return null;
} }
List<NiciraNvpDeviceVO> devices = _niciraNvpDao.listByPhysicalNetwork(physnet.getId()); List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physnet.getId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + physnet.getName()); s_logger.error("No NiciraNvp Controller on physical network " + physnet.getName());
return null; return null;
@ -141,8 +143,8 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
} }
@Override @Override
public Network implement(Network network, NetworkOffering offering, public Network implement(final Network network, final NetworkOffering offering,
DeployDestination dest, ReservationContext context) final DeployDestination dest, final ReservationContext context)
throws InsufficientVirtualNetworkCapcityException { throws InsufficientVirtualNetworkCapcityException {
assert (network.getState() == State.Implementing) : "Why are we implementing " + network; assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
@ -153,7 +155,7 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
// physical network id can be null in Guest Network in Basic zone, so locate the physical network // physical network id can be null in Guest Network in Basic zone, so locate the physical network
if (physicalNetworkId == null) { if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType()); physicalNetworkId = networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
} }
NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated, NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
@ -172,24 +174,24 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
if (name == null || name.isEmpty()) { if (name == null || name.isEmpty()) {
name = ((NetworkVO)network).getUuid(); name = ((NetworkVO)network).getUuid();
} }
if (name.length() > 40) { if (name.length() > MAX_NAME_LENGTH) {
name = name.substring(0, 39); // max length 40 name = name.substring(0, MAX_NAME_LENGTH - 1); // max length 40
} }
List<NiciraNvpDeviceVO> devices = _niciraNvpDao.listByPhysicalNetwork(physicalNetworkId); List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physicalNetworkId);
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId); s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId);
return null; return null;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
_hostDao.loadDetails(niciraNvpHost); hostDao.loadDetails(niciraNvpHost);
String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid"); String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype"); String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name,
context.getDomain().getName() + "-" + context.getAccount().getAccountName()); context.getDomain().getName() + "-" + context.getAccount().getAccountName());
CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer)_agentMgr.easySend(niciraNvpHost.getId(), cmd); CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) { if (answer == null || !answer.getResult()) {
s_logger.error("CreateLogicalSwitchCommand failed"); s_logger.error("CreateLogicalSwitchCommand failed");
@ -209,9 +211,8 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
} }
@Override @Override
public void reserve(NicProfile nic, Network network, public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm,
VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException, throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException { InsufficientAddressCapacityException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -219,32 +220,30 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
} }
@Override @Override
public boolean release(NicProfile nic, public boolean release(final NicProfile nic, final VirtualMachineProfile vm, final String reservationId) {
VirtualMachineProfile vm,
String reservationId) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return super.release(nic, vm, reservationId); return super.release(nic, vm, reservationId);
} }
@Override @Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) { public void shutdown(final NetworkProfile profile, final NetworkOffering offering) {
NetworkVO networkObject = _networkDao.findById(profile.getId()); NetworkVO networkObject = networkDao.findById(profile.getId());
if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Lswitch || if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Lswitch ||
networkObject.getBroadcastUri() == null) { networkObject.getBroadcastUri() == null) {
s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText()); s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText());
return; return;
} }
List<NiciraNvpDeviceVO> devices = _niciraNvpDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId()); List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId());
if (devices.isEmpty()) { if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + networkObject.getPhysicalNetworkId()); s_logger.error("No NiciraNvp Controller on physical network " + networkObject.getPhysicalNetworkId());
return; return;
} }
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0); NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId()); HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
DeleteLogicalSwitchCommand cmd = new DeleteLogicalSwitchCommand(BroadcastDomainType.getValue(networkObject.getBroadcastUri())); DeleteLogicalSwitchCommand cmd = new DeleteLogicalSwitchCommand(BroadcastDomainType.getValue(networkObject.getBroadcastUri()));
DeleteLogicalSwitchAnswer answer = (DeleteLogicalSwitchAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd); DeleteLogicalSwitchAnswer answer = (DeleteLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) { if (answer == null || !answer.getResult()) {
s_logger.error("DeleteLogicalSwitchCommand failed"); s_logger.error("DeleteLogicalSwitchCommand failed");
@ -254,7 +253,7 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
} }
@Override @Override
public boolean trash(Network network, NetworkOffering offering) { public boolean trash(final Network network, final NetworkOffering offering) {
return super.trash(network, offering); return super.trash(network, offering);
} }

View File

@ -17,67 +17,65 @@
package com.cloud.network.nicira; package com.cloud.network.nicira;
public class ControlClusterStatus { public class ControlClusterStatus {
private String cluster_status; private String clusterStatus;
private Stats node_stats; private Stats nodeStats;
private Stats lqueue_stats; private Stats queueStats;
private Stats lport_stats; private Stats portStats;
private Stats lrouterport_stats; private Stats routerportStats;
private Stats lswitch_stats; private Stats switchStats;
private Stats zone_stats; private Stats zoneStats;
private Stats lrouter_stats; private Stats routerStats;
private Stats security_profile_stats; private Stats securityProfileStats;
public String getClusterStatus() { public String getClusterStatus() {
return cluster_status; return clusterStatus;
} }
public Stats getNodeStats() { public Stats getNodeStats() {
return node_stats; return nodeStats;
} }
public Stats getLqueueStats() { public Stats getLqueueStats() {
return lqueue_stats; return queueStats;
} }
public Stats getLportStats() { public Stats getLportStats() {
return lport_stats; return portStats;
} }
public Stats getLrouterportStats() { public Stats getLrouterportStats() {
return lrouterport_stats; return routerportStats;
} }
public Stats getLswitchStats() { public Stats getLswitchStats() {
return lswitch_stats; return switchStats;
} }
public Stats getZoneStats() { public Stats getZoneStats() {
return zone_stats; return zoneStats;
} }
public Stats getLrouterStats() { public Stats getLrouterStats() {
return lrouter_stats; return routerStats;
} }
public Stats getSecurityProfileStats() { public Stats getSecurityProfileStats() {
return security_profile_stats; return securityProfileStats;
} }
public class Stats { public class Stats {
private int error_state_count; private int errorStateCount;
private int registered_count; private int registeredCount;
private int active_count; private int activeCount;
public int getErrorStateCount() { public int getErrorStateCount() {
return error_state_count; return errorStateCount;
} }
public int getRegisteredCount() { public int getRegisteredCount() {
return registered_count; return registeredCount;
} }
public int getActiveCount() { public int getActiveCount() {
return active_count; return activeCount;
} }
} }

View File

@ -28,15 +28,18 @@ public class DestinationNatRule extends NatRule {
return toDestinationIpAddress; return toDestinationIpAddress;
} }
public void setToDestinationIpAddress(String toDestinationIpAddress) {
public void setToDestinationIpAddress(final String toDestinationIpAddress) {
this.toDestinationIpAddress = toDestinationIpAddress; this.toDestinationIpAddress = toDestinationIpAddress;
} }
public Integer getToDestinationPort() { public Integer getToDestinationPort() {
return toDestinationPort; return toDestinationPort;
} }
public void setToDestinationPort(Integer toDestinationPort) {
public void setToDestinationPort(final Integer toDestinationPort) {
this.toDestinationPort = toDestinationPort; this.toDestinationPort = toDestinationPort;
} }
@ -57,45 +60,59 @@ public class DestinationNatRule extends NatRule {
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (!super.equals(obj)) }
if (!super.equals(obj)) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
DestinationNatRule other = (DestinationNatRule) obj; DestinationNatRule other = (DestinationNatRule) obj;
if (toDestinationIpAddress == null) { if (toDestinationIpAddress == null) {
if (other.toDestinationIpAddress != null) if (other.toDestinationIpAddress != null) {
return false; return false;
} else if (!toDestinationIpAddress.equals(other.toDestinationIpAddress)) }
} else if (!toDestinationIpAddress.equals(other.toDestinationIpAddress)) {
return false; return false;
}
if (toDestinationPort == null) { if (toDestinationPort == null) {
if (other.toDestinationPort != null) if (other.toDestinationPort != null) {
return false; return false;
} else if (!toDestinationPort.equals(other.toDestinationPort)) }
} else if (!toDestinationPort.equals(other.toDestinationPort)) {
return false; return false;
}
return true; return true;
} }
@Override @Override
public boolean equalsIgnoreUuid(Object obj) { public boolean equalsIgnoreUuid(Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (!super.equalsIgnoreUuid(obj)) }
if (!super.equalsIgnoreUuid(obj)) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
DestinationNatRule other = (DestinationNatRule) obj; DestinationNatRule other = (DestinationNatRule) obj;
if (toDestinationIpAddress == null) { if (toDestinationIpAddress == null) {
if (other.toDestinationIpAddress != null) if (other.toDestinationIpAddress != null) {
return false; return false;
} else if (!toDestinationIpAddress.equals(other.toDestinationIpAddress)) }
} else if (!toDestinationIpAddress.equals(other.toDestinationIpAddress)) {
return false; return false;
}
if (toDestinationPort == null) { if (toDestinationPort == null) {
if (other.toDestinationPort != null) if (other.toDestinationPort != null) {
return false; return false;
} else if (!toDestinationPort.equals(other.toDestinationPort)) }
} else if (!toDestinationPort.equals(other.toDestinationPort)) {
return false; return false;
}
return true; return true;
} }

View File

@ -20,33 +20,33 @@ package com.cloud.network.nicira;
* *
*/ */
public class L3GatewayAttachment extends Attachment { public class L3GatewayAttachment extends Attachment {
private String l3_gateway_service_uuid; private String l3GatewayServiceUuid;
private String type = "L3GatewayAttachment"; private final String type = "L3GatewayAttachment";
private Long vlan_id; private Long vlanId;
public L3GatewayAttachment(String l3_gateway_service_uuid) { public L3GatewayAttachment(String l3GatewayServiceUuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid; this.l3GatewayServiceUuid = l3GatewayServiceUuid;
} }
public L3GatewayAttachment(String l3_gateway_service_uuid, long vlan_id) { public L3GatewayAttachment(final String l3GatewayServiceUuid, final long vlanId) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid; this.l3GatewayServiceUuid = l3GatewayServiceUuid;
this.vlan_id = vlan_id; this.vlanId = vlanId;
} }
public String getL3GatewayServiceUuid() { public String getL3GatewayServiceUuid() {
return l3_gateway_service_uuid; return l3GatewayServiceUuid;
} }
public void setL3GatewayServiceUuid(String l3_gateway_service_uuid) { public void setL3GatewayServiceUuid(final String l3GatewayServiceUuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid; this.l3GatewayServiceUuid = l3GatewayServiceUuid;
} }
public long getVlanId() { public long getVlanId() {
return vlan_id; return vlanId;
} }
public void setVlanId(long vlan_id) { public void setVlanId(long vlanId) {
this.vlan_id = vlan_id; this.vlanId = vlanId;
} }
} }

View File

@ -22,26 +22,26 @@ import java.util.List;
* *
*/ */
public class LogicalRouterConfig { public class LogicalRouterConfig {
private String display_name; private String displayName;
private RoutingConfig routing_config; private RoutingConfig routingConfig;
private String type = "LogicalRouterConfig"; private final String type = "LogicalRouterConfig";
private String uuid; private String uuid;
private List<NiciraNvpTag> tags; private List<NiciraNvpTag> tags;
public RoutingConfig getRoutingConfig() { public RoutingConfig getRoutingConfig() {
return routing_config; return routingConfig;
} }
public void setRoutingConfig(RoutingConfig routing_config) { public void setRoutingConfig(RoutingConfig routingConfig) {
this.routing_config = routing_config; this.routingConfig = routingConfig;
} }
public String getDisplayName() { public String getDisplayName() {
return display_name; return displayName;
} }
public void setDisplayName(String display_name) { public void setDisplayName(String displayName) {
this.display_name = display_name; this.displayName = displayName;
} }
public String getUuid() { public String getUuid() {
@ -59,5 +59,4 @@ public class LogicalRouterConfig {
public void setTags(List<NiciraNvpTag> tags) { public void setTags(List<NiciraNvpTag> tags) {
this.tags = tags; this.tags = tags;
} }
} }

View File

@ -22,13 +22,13 @@ import java.util.List;
* *
*/ */
public class LogicalRouterPort { public class LogicalRouterPort {
private String display_name; private String displayName;
private List<NiciraNvpTag> tags; private List<NiciraNvpTag> tags;
private Integer portno; private Integer portno;
private boolean admin_status_enabled; private boolean adminStatusEnabled;
private List<String> ip_addresses; private List<String> ipAddresses;
private String mac_address; private String macAddress;
private String type = "LogicalRouterPortConfig"; private final String type = "LogicalRouterPortConfig";
private String uuid; private String uuid;
public int getPortno() { public int getPortno() {
@ -40,35 +40,35 @@ public class LogicalRouterPort {
} }
public boolean isAdminStatusEnabled() { public boolean isAdminStatusEnabled() {
return admin_status_enabled; return adminStatusEnabled;
} }
public void setAdminStatusEnabled(boolean admin_status_enabled) { public void setAdminStatusEnabled(boolean adminStatusEnabled) {
this.admin_status_enabled = admin_status_enabled; this.adminStatusEnabled = adminStatusEnabled;
} }
public List<String> getIpAddresses() { public List<String> getIpAddresses() {
return ip_addresses; return ipAddresses;
} }
public void setIpAddresses(List<String> ip_addresses) { public void setIpAddresses(List<String> ipAddresses) {
this.ip_addresses = ip_addresses; this.ipAddresses = ipAddresses;
} }
public String getMacAddress() { public String getMacAddress() {
return mac_address; return macAddress;
} }
public void setMacAddress(String mac_address) { public void setMacAddress(String macAddress) {
this.mac_address = mac_address; this.macAddress = macAddress;
} }
public String getDisplayName() { public String getDisplayName() {
return display_name; return displayName;
} }
public void setDisplayName(String display_name) { public void setDisplayName(String displayName) {
this.display_name = display_name; this.displayName = displayName;
} }
public List<NiciraNvpTag> getTags() { public List<NiciraNvpTag> getTags() {

View File

@ -19,31 +19,29 @@ package com.cloud.network.nicira;
import java.util.List; import java.util.List;
public class LogicalSwitch { public class LogicalSwitch {
private String display_name; private String displayName;
private boolean port_isolation_enabled; private boolean portIsolationEnabled;
private List<NiciraNvpTag> tags; private List<NiciraNvpTag> tags;
private List<TransportZoneBinding> transport_zones; private List<TransportZoneBinding> transportZones;
private String type; private String type;
private String uuid; private String uuid;
private String _href; private String href;
//private RequestQueryParameters _query; private String schema;
//private LogicalSwitchRelations _relations;
private String _schema;
public String getDisplay_name() { public String getDisplayName() {
return display_name; return displayName;
} }
public void setDisplay_name(String display_name) { public void setDisplayName(String displayName) {
this.display_name = display_name; this.displayName = displayName;
} }
public boolean isPort_isolation_enabled() { public boolean isPortIsolationEnabled() {
return port_isolation_enabled; return portIsolationEnabled;
} }
public void setPort_isolation_enabled(boolean port_isolation_enabled) { public void setPortIsolationEnabled(boolean portIsolationEnabled) {
this.port_isolation_enabled = port_isolation_enabled; this.portIsolationEnabled = portIsolationEnabled;
} }
public String getType() { public String getType() {
@ -62,20 +60,20 @@ public class LogicalSwitch {
this.uuid = uuid; this.uuid = uuid;
} }
public String get_href() { public String getHref() {
return _href; return href;
} }
public void set_href(String _href) { public void setHref(String href) {
this._href = _href; this.href = href;
} }
public String get_schema() { public String getSchema() {
return _schema; return schema;
} }
public void set_schema(String _schema) { public void setSchema(String schema) {
this._schema = _schema; this.schema = schema;
} }
public List<NiciraNvpTag> getTags() { public List<NiciraNvpTag> getTags() {
@ -86,13 +84,12 @@ public class LogicalSwitch {
this.tags = tags; this.tags = tags;
} }
public List<TransportZoneBinding> getTransport_zones() { public List<TransportZoneBinding> getTransportZones() {
return transport_zones; return transportZones;
} }
public void setTransport_zones(List<TransportZoneBinding> transport_zones) { public void setTransportZones(List<TransportZoneBinding> transportZones) {
this.transport_zones = transport_zones; this.transportZones = transportZones;
} }
} }

View File

@ -19,14 +19,13 @@ package com.cloud.network.nicira;
import java.util.List; import java.util.List;
public class LogicalSwitchPort { public class LogicalSwitchPort {
private String display_name; private String displayName;
private List<NiciraNvpTag> tags; private List<NiciraNvpTag> tags;
private Integer portno; private Integer portno;
private boolean admin_status_enabled; private boolean adminStatusEnabled;
//private List<AddressPairs> allowed_address_pairs; private String queueUuid;
private String queue_uuid; private List<String> securityProfiles;
private List<String> security_profiles; private List<String> mirrorTargets;
private List<String> mirror_targets;
private String type; private String type;
private String uuid; private String uuid;
@ -34,20 +33,20 @@ public class LogicalSwitchPort {
super(); super();
} }
public LogicalSwitchPort(String display_name, List<NiciraNvpTag> tags, public LogicalSwitchPort(final String displayName, final List<NiciraNvpTag> tags,
boolean admin_status_enabled) { final boolean adminStatusEnabled) {
super(); super();
this.display_name = display_name; this.displayName = displayName;
this.tags = tags; this.tags = tags;
this.admin_status_enabled = admin_status_enabled; this.adminStatusEnabled = adminStatusEnabled;
} }
public String getDisplay_name() { public String getDisplayName() {
return display_name; return displayName;
} }
public void setDisplay_name(String display_name) { public void setDisplayName(String displayName) {
this.display_name = display_name; this.displayName = displayName;
} }
public List<NiciraNvpTag> getTags() { public List<NiciraNvpTag> getTags() {
@ -66,36 +65,36 @@ public class LogicalSwitchPort {
this.portno = portno; this.portno = portno;
} }
public boolean isAdmin_status_enabled() { public boolean isAdminStatusEnabled() {
return admin_status_enabled; return adminStatusEnabled;
} }
public void setAdmin_status_enabled(boolean admin_status_enabled) { public void setAdminStatusEnabled(boolean adminStatusEnabled) {
this.admin_status_enabled = admin_status_enabled; this.adminStatusEnabled = adminStatusEnabled;
} }
public String getQueue_uuid() { public String getQueueUuid() {
return queue_uuid; return queueUuid;
} }
public void setQueue_uuid(String queue_uuid) { public void setQueueUuid(String queueUuid) {
this.queue_uuid = queue_uuid; this.queueUuid = queueUuid;
} }
public List<String> getSecurity_profiles() { public List<String> getSecurityProfiles() {
return security_profiles; return securityProfiles;
} }
public void setSecurity_profiles(List<String> security_profiles) { public void setSecurityProfiles(List<String> securityProfiles) {
this.security_profiles = security_profiles; this.securityProfiles = securityProfiles;
} }
public List<String> getMirror_targets() { public List<String> getMirrorTargets() {
return mirror_targets; return mirrorTargets;
} }
public void setMirror_targets(List<String> mirror_targets) { public void setMirrorTargets(List<String> mirrorTargets) {
this.mirror_targets = mirror_targets; this.mirrorTargets = mirrorTargets;
} }
public String getType() { public String getType() {

View File

@ -21,112 +21,134 @@ package com.cloud.network.nicira;
*/ */
public class Match { public class Match {
private Integer protocol; private Integer protocol;
private String source_ip_addresses; private String sourceIpAddresses;
private String destination_ip_addresses; private String destinationIpAddresses;
private Integer source_port; private Integer sourcePort;
private Integer destination_port; private Integer destinationPort;
private String ethertype = "IPv4"; private String ethertype = "IPv4";
public Integer getProtocol() { public Integer getProtocol() {
return protocol; return protocol;
} }
public void setProtocol(Integer protocol) { public void setProtocol(final Integer protocol) {
this.protocol = protocol; this.protocol = protocol;
} }
public Integer getSourcePort() { public Integer getSourcePort() {
return source_port; return sourcePort;
} }
public void setSourcePort(Integer source_port) { public void setSourcePort(final Integer sourcePort) {
this.source_port = source_port; this.sourcePort = sourcePort;
} }
public Integer getDestinationPort() { public Integer getDestinationPort() {
return destination_port; return destinationPort;
} }
public void setDestinationPort(Integer destination_port) { public void setDestinationPort(final Integer destinationPort) {
this.destination_port = destination_port; this.destinationPort = destinationPort;
} }
public String getEthertype() { public String getEthertype() {
return ethertype; return ethertype;
} }
public void setEthertype(String ethertype) { public void setEthertype(final String ethertype) {
this.ethertype = ethertype; this.ethertype = ethertype;
} }
public String getSourceIpAddresses() { public String getSourceIpAddresses() {
return source_ip_addresses; return sourceIpAddresses;
} }
public void setSourceIpAddresses(String source_ip_addresses) { public void setSourceIpAddresses(final String sourceIpAddresses) {
this.source_ip_addresses = source_ip_addresses; this.sourceIpAddresses = sourceIpAddresses;
} }
public String getDestinationIpAddresses() { public String getDestinationIpAddresses() {
return destination_ip_addresses; return destinationIpAddresses;
} }
public void setDestinationIpAddresses(String destination_ip_addresses) { public void setDestinationIpAddresses(final String destinationIpAddresses) {
this.destination_ip_addresses = destination_ip_addresses; this.destinationIpAddresses = destinationIpAddresses;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((destination_ip_addresses == null) ? 0 : destination_ip_addresses.hashCode()); result = prime
result = prime * result + ((destination_port == null) ? 0 : destination_port.hashCode()); * result
result = prime * result + ((ethertype == null) ? 0 : ethertype.hashCode()); + ((destinationIpAddresses == null) ? 0
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode()); : destinationIpAddresses.hashCode());
result = prime * result + ((source_ip_addresses == null) ? 0 : source_ip_addresses.hashCode()); result = prime
result = prime * result + ((source_port == null) ? 0 : source_port.hashCode()); * result
+ ((destinationPort == null) ? 0 : destinationPort
.hashCode());
result = prime * result
+ ((ethertype == null) ? 0 : ethertype.hashCode());
result = prime * result
+ ((protocol == null) ? 0 : protocol.hashCode());
result = prime
* result
+ ((sourceIpAddresses == null) ? 0 : sourceIpAddresses
.hashCode());
result = prime * result
+ ((sourcePort == null) ? 0 : sourcePort.hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
if (this == obj) if (this == obj) {
return true; return true;
if (obj == null) }
if (obj == null) {
return false; return false;
if (getClass() != obj.getClass()) }
if (getClass() != obj.getClass()) {
return false; return false;
}
Match other = (Match) obj; Match other = (Match) obj;
if (destination_ip_addresses == null) { if (destinationIpAddresses == null) {
if (other.destination_ip_addresses != null) if (other.destinationIpAddresses != null)
return false; return false;
} else if (!destination_ip_addresses.equals(other.destination_ip_addresses)) } else if (!destinationIpAddresses.equals(other.destinationIpAddresses)) {
return false; return false;
if (destination_port == null) { }
if (other.destination_port != null) if (destinationPort == null) {
if (other.destinationPort != null) {
return false; return false;
} else if (!destination_port.equals(other.destination_port)) }
} else if (!destinationPort.equals(other.destinationPort)) {
return false; return false;
}
if (ethertype == null) { if (ethertype == null) {
if (other.ethertype != null) if (other.ethertype != null)
return false; return false;
} else if (!ethertype.equals(other.ethertype)) } else if (!ethertype.equals(other.ethertype)) {
return false; return false;
}
if (protocol == null) { if (protocol == null) {
if (other.protocol != null) if (other.protocol != null)
return false; return false;
} else if (!protocol.equals(other.protocol)) } else if (!protocol.equals(other.protocol)) {
return false; return false;
if (source_ip_addresses == null) { }
if (other.source_ip_addresses != null) if (sourceIpAddresses == null) {
if (other.sourceIpAddresses != null)
return false; return false;
} else if (!source_ip_addresses.equals(other.source_ip_addresses)) } else if (!sourceIpAddresses.equals(other.sourceIpAddresses)) {
return false; return false;
if (source_port == null) { }
if (other.source_port != null) if (sourcePort == null) {
if (other.sourcePort != null)
return false; return false;
} else if (!source_port.equals(other.source_port)) } else if (!sourcePort.equals(other.sourcePort)) {
return false; return false;
}
return true; return true;
} }

View File

@ -34,7 +34,7 @@ public abstract class NatRule {
return match; return match;
} }
public void setMatch(Match match) { public void setMatch(final Match match) {
this.match = match; this.match = match;
} }
@ -42,7 +42,7 @@ public abstract class NatRule {
return uuid; return uuid;
} }
public void setUuid(UUID uuid) { public void setUuid(final UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
@ -50,7 +50,7 @@ public abstract class NatRule {
return type; return type;
} }
public void setType(String type) { public void setType(final String type) {
this.type = type; this.type = type;
} }
@ -58,7 +58,7 @@ public abstract class NatRule {
return order; return order;
} }
public void setOrder(int order) { public void setOrder(final int order) {
this.order = order; this.order = order;
} }
@ -74,7 +74,7 @@ public abstract class NatRule {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
@ -102,7 +102,7 @@ public abstract class NatRule {
return true; return true;
} }
public boolean equalsIgnoreUuid(Object obj) { public boolean equalsIgnoreUuid(final Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (obj == null) if (obj == null)
@ -124,6 +124,4 @@ public abstract class NatRule {
return false; return false;
return true; return true;
} }
} }

View File

@ -72,19 +72,26 @@ import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
public class NiciraNvpApi { public class NiciraNvpApi {
private static final String TEXT_HTML_CONTENT_TYPE = "text/html";
private static final String JSON_CONTENT_TYPE = "application/json";
private static final String CONTENT_TYPE = "Content-Type";
private static final int BODY_RESP_MAX_LEN = 1024;
private static final String SWITCH_URI_PREFIX = "/ws.v1/lswitch";
private static final String ROUTER_URI_PREFIX = "/ws.v1/lrouter";
private static final int HTTPS_PORT = 443;
private static final Logger s_logger = Logger.getLogger(NiciraNvpApi.class); private static final Logger s_logger = Logger.getLogger(NiciraNvpApi.class);
private final static String _protocol = "https"; private final static String protocol = "https";
private static final MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager(); private final static MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager();
private String _name; private String name;
private String _host; private String host;
private String _adminuser; private String adminuser;
private String _adminpass; private String adminpass;
private HttpClient _client; private final HttpClient client;
private String _nvpversion; private String nvpVersion;
private Gson _gson; private final Gson gson;
/* This factory method is protected so we can extend this /* This factory method is protected so we can extend this
* in the unittests. * in the unittests.
@ -93,10 +100,10 @@ public class NiciraNvpApi {
return new HttpClient(s_httpClientManager); return new HttpClient(s_httpClientManager);
} }
protected HttpMethod createMethod(String type, String uri) throws NiciraNvpApiException { protected HttpMethod createMethod(final String type, final String uri) throws NiciraNvpApiException {
String url; String url;
try { try {
url = new URL(_protocol, _host, uri).toString(); url = new URL(protocol, host, uri).toString();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e); s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Unable to build Nicira API URL", e); throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
@ -104,76 +111,71 @@ public class NiciraNvpApi {
if ("post".equalsIgnoreCase(type)) { if ("post".equalsIgnoreCase(type)) {
return new PostMethod(url); return new PostMethod(url);
} } else if ("get".equalsIgnoreCase(type)) {
else if ("get".equalsIgnoreCase(type)) {
return new GetMethod(url); return new GetMethod(url);
} } else if ("delete".equalsIgnoreCase(type)) {
else if ("delete".equalsIgnoreCase(type)) {
return new DeleteMethod(url); return new DeleteMethod(url);
} } else if ("put".equalsIgnoreCase(type)) {
else if ("put".equalsIgnoreCase(type)) {
return new PutMethod(url); return new PutMethod(url);
} } else {
else {
throw new NiciraNvpApiException("Requesting unknown method type"); throw new NiciraNvpApiException("Requesting unknown method type");
} }
} }
public NiciraNvpApi() { public NiciraNvpApi() {
_client = createHttpClient(); client = createHttpClient();
_client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY); client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
try { try {
// Cast to ProtocolSocketFactory to avoid the deprecated constructor with the SecureProtocolSocketFactory parameter // Cast to ProtocolSocketFactory to avoid the deprecated constructor with the SecureProtocolSocketFactory parameter
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), 443)); Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), HTTPS_PORT));
} catch (IOException e) { } catch (IOException e) {
s_logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e); s_logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
} }
_gson = new GsonBuilder() gson = new GsonBuilder()
.registerTypeAdapter(NatRule.class, new NatRuleAdapter()) .registerTypeAdapter(NatRule.class, new NatRuleAdapter())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create(); .create();
} }
public void setControllerAddress(String address) { public void setControllerAddress(final String address) {
_host = address; host = address;
} }
public void setAdminCredentials(String username, String password) { public void setAdminCredentials(final String username, final String password) {
_adminuser = username; adminuser = username;
_adminpass = password; adminpass = password;
} }
/** /**
* Logs into the Nicira API. The cookie is stored in the * Logs into the Nicira API. The cookie is stored in the <code>_authcookie<code> variable.
* <code>_authcookie<code> variable.
* <p> * <p>
* The method returns false if the login failed or the connection could not be made. * The method returns false if the login failed or the connection could not be made.
*
*/ */
protected void login() throws NiciraNvpApiException { protected void login() throws NiciraNvpApiException {
String url; String url;
if (_host == null || _host.isEmpty() || if (host == null || host.isEmpty() ||
_adminuser == null || _adminuser.isEmpty() || adminuser == null || adminuser.isEmpty() ||
_adminpass == null || _adminpass.isEmpty()) { adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty"); throw new NiciraNvpApiException("Hostname/credentials are null or empty");
} }
try { try {
url = new URL(_protocol, _host, "/ws.v1/login").toString(); url = new URL(protocol, host, "/ws.v1/login").toString();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e); s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Unable to build Nicira API URL", e); throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
} }
PostMethod pm = new PostMethod(url); PostMethod pm = new PostMethod(url);
pm.addParameter("username", _adminuser); pm.addParameter("username", adminuser);
pm.addParameter("password", _adminpass); pm.addParameter("password", adminpass);
try { try {
_client.executeMethod(pm); client.executeMethod(pm);
} catch (HttpException e) { } catch (HttpException e) {
throw new NiciraNvpApiException("Nicira NVP API login failed ", e); throw new NiciraNvpApiException("Nicira NVP API login failed ", e);
} catch (IOException e) { } catch (IOException e) {
@ -189,44 +191,47 @@ public class NiciraNvpApi {
// Extract the version for later use // Extract the version for later use
if (pm.getResponseHeader("Server") != null) { if (pm.getResponseHeader("Server") != null) {
_nvpversion = pm.getResponseHeader("Server").getValue(); nvpVersion = pm.getResponseHeader("Server").getValue();
s_logger.debug("NVP Controller reports version " + _nvpversion); s_logger.debug("NVP Controller reports version " + nvpVersion);
} }
// Success; the cookie required for login is kept in _client // Success; the cookie required for login is kept in _client
} }
public LogicalSwitch createLogicalSwitch(LogicalSwitch logicalSwitch) throws NiciraNvpApiException { public LogicalSwitch createLogicalSwitch(final LogicalSwitch logicalSwitch) throws NiciraNvpApiException {
String uri = "/ws.v1/lswitch"; String uri = SWITCH_URI_PREFIX;
LogicalSwitch createdLogicalSwitch = executeCreateObject(logicalSwitch, new TypeToken<LogicalSwitch>(){}.getType(), uri, Collections.<String,String>emptyMap()); LogicalSwitch createdLogicalSwitch = executeCreateObject(logicalSwitch, new TypeToken<LogicalSwitch>(){}.getType(), uri, Collections.<String,String>emptyMap());
return createdLogicalSwitch; return createdLogicalSwitch;
} }
public void deleteLogicalSwitch(String uuid) throws NiciraNvpApiException { public void deleteLogicalSwitch(final String uuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lswitch/" + uuid; String uri = SWITCH_URI_PREFIX + uuid;
executeDeleteObject(uri); executeDeleteObject(uri);
} }
public LogicalSwitchPort createLogicalSwitchPort(String logicalSwitchUuid, LogicalSwitchPort logicalSwitchPort) throws NiciraNvpApiException { public LogicalSwitchPort createLogicalSwitchPort(final String logicalSwitchUuid, final LogicalSwitchPort logicalSwitchPort)
String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport"; throws NiciraNvpApiException {
LogicalSwitchPort createdLogicalSwitchPort = executeCreateObject(logicalSwitchPort, new TypeToken<LogicalSwitchPort>(){}.getType(), uri, Collections.<String,String>emptyMap());; String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport";
LogicalSwitchPort createdLogicalSwitchPort = executeCreateObject(logicalSwitchPort,
new TypeToken<LogicalSwitchPort>(){}.getType(), uri, Collections.<String,String>emptyMap());
return createdLogicalSwitchPort; return createdLogicalSwitchPort;
} }
public void modifyLogicalSwitchPortAttachment(String logicalSwitchUuid, String logicalSwitchPortUuid, Attachment attachment) throws NiciraNvpApiException { public void modifyLogicalSwitchPortAttachment(final String logicalSwitchUuid, final String logicalSwitchPortUuid,
String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid + "/attachment"; Attachment attachment) throws NiciraNvpApiException {
String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid + "/attachment";
executeUpdateObject(attachment, uri, Collections.<String,String>emptyMap()); executeUpdateObject(attachment, uri, Collections.<String,String>emptyMap());
} }
public void deleteLogicalSwitchPort(String logicalSwitchUuid, String logicalSwitchPortUuid) throws NiciraNvpApiException { public void deleteLogicalSwitchPort(final String logicalSwitchUuid, final String logicalSwitchPortUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid; String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport/" + logicalSwitchPortUuid;
executeDeleteObject(uri); executeDeleteObject(uri);
} }
public String findLogicalSwitchPortUuidByVifAttachmentUuid(String logicalSwitchUuid, String vifAttachmentUuid) throws NiciraNvpApiException { public String findLogicalSwitchPortUuidByVifAttachmentUuid(final String logicalSwitchUuid, final String vifAttachmentUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport"; String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport";
Map<String,String> params = new HashMap<String,String>(); Map<String,String> params = new HashMap<String,String>();
params.put("attachment_vif_uuid", vifAttachmentUuid); params.put("attachment_vif_uuid", vifAttachmentUuid);
params.put("fields", "uuid"); params.put("fields", "uuid");
@ -248,8 +253,9 @@ public class NiciraNvpApi {
return ccs; return ccs;
} }
public NiciraNvpList<LogicalSwitchPort> findLogicalSwitchPortsByUuid(String logicalSwitchUuid, String logicalSwitchPortUuid) throws NiciraNvpApiException { public NiciraNvpList<LogicalSwitchPort> findLogicalSwitchPortsByUuid(final String logicalSwitchUuid,
String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport"; final String logicalSwitchPortUuid) throws NiciraNvpApiException {
String uri = SWITCH_URI_PREFIX + logicalSwitchUuid + "/lport";
Map<String,String> params = new HashMap<String,String>(); Map<String,String> params = new HashMap<String,String>();
params.put("uuid", logicalSwitchPortUuid); params.put("uuid", logicalSwitchPortUuid);
params.put("fields", "uuid"); params.put("fields", "uuid");
@ -263,64 +269,66 @@ public class NiciraNvpApi {
return lspl; return lspl;
} }
public LogicalRouterConfig createLogicalRouter(LogicalRouterConfig logicalRouterConfig) throws NiciraNvpApiException { public LogicalRouterConfig createLogicalRouter(final LogicalRouterConfig logicalRouterConfig) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter"; String uri = ROUTER_URI_PREFIX;
LogicalRouterConfig lrc = executeCreateObject(logicalRouterConfig, new TypeToken<LogicalRouterConfig>(){}.getType(), uri, Collections.<String,String>emptyMap()); LogicalRouterConfig lrc = executeCreateObject(logicalRouterConfig, new TypeToken<LogicalRouterConfig>(){}.getType(), uri, Collections.<String,String>emptyMap());
return lrc; return lrc;
} }
public void deleteLogicalRouter(String logicalRouterUuid) throws NiciraNvpApiException { public void deleteLogicalRouter(final String logicalRouterUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid; String uri = ROUTER_URI_PREFIX + logicalRouterUuid;
executeDeleteObject(uri); executeDeleteObject(uri);
} }
public LogicalRouterPort createLogicalRouterPort(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException { public LogicalRouterPort createLogicalRouterPort(final String logicalRouterUuid, final LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport"; String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport";
LogicalRouterPort lrp = executeCreateObject(logicalRouterPort, new TypeToken<LogicalRouterPort>(){}.getType(), uri, Collections.<String,String>emptyMap()); LogicalRouterPort lrp = executeCreateObject(logicalRouterPort, new TypeToken<LogicalRouterPort>(){}.getType(), uri, Collections.<String,String>emptyMap());
return lrp; return lrp;
} }
public void deleteLogicalRouterPort(String logicalRouterUuid, String logicalRouterPortUuid) throws NiciraNvpApiException { public void deleteLogicalRouterPort(final String logicalRouterUuid, final String logicalRouterPortUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPortUuid; String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport/" + logicalRouterPortUuid;
executeDeleteObject(uri); executeDeleteObject(uri);
} }
public void modifyLogicalRouterPort(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException { public void modifyLogicalRouterPort(final String logicalRouterUuid, final LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPort.getUuid(); String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport/" + logicalRouterPort.getUuid();
executeUpdateObject(logicalRouterPort, uri, Collections.<String,String>emptyMap()); executeUpdateObject(logicalRouterPort, uri, Collections.<String,String>emptyMap());
} }
public void modifyLogicalRouterPortAttachment(String logicalRouterUuid, String logicalRouterPortUuid, Attachment attachment) throws NiciraNvpApiException { public void modifyLogicalRouterPortAttachment(final String logicalRouterUuid, final String logicalRouterPortUuid,
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPortUuid + "/attachment"; final Attachment attachment) throws NiciraNvpApiException {
String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport/" + logicalRouterPortUuid + "/attachment";
executeUpdateObject(attachment, uri, Collections.<String,String>emptyMap()); executeUpdateObject(attachment, uri, Collections.<String,String>emptyMap());
} }
public NatRule createLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException { public NatRule createLogicalRouterNatRule(final String logicalRouterUuid, final NatRule natRule) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat"; String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat";
return executeCreateObject(natRule, new TypeToken<NatRule>(){}.getType(), uri, Collections.<String,String>emptyMap()); return executeCreateObject(natRule, new TypeToken<NatRule>(){}.getType(), uri, Collections.<String,String>emptyMap());
} }
public void modifyLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException { public void modifyLogicalRouterNatRule(final String logicalRouterUuid, final NatRule natRule) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat/" + natRule.getUuid(); String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat/" + natRule.getUuid();
executeUpdateObject(natRule, uri, Collections.<String,String>emptyMap()); executeUpdateObject(natRule, uri, Collections.<String,String>emptyMap());
} }
public void deleteLogicalRouterNatRule(String logicalRouterUuid, UUID natRuleUuid) throws NiciraNvpApiException { public void deleteLogicalRouterNatRule(final String logicalRouterUuid, final UUID natRuleUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat/" + natRuleUuid.toString(); String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat/" + natRuleUuid.toString();
executeDeleteObject(uri); executeDeleteObject(uri);
} }
public NiciraNvpList<LogicalRouterPort> findLogicalRouterPortByGatewayServiceAndVlanId(String logicalRouterUuid, String gatewayServiceUuid, long vlanId) throws NiciraNvpApiException { public NiciraNvpList<LogicalRouterPort> findLogicalRouterPortByGatewayServiceAndVlanId(
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport"; final String logicalRouterUuid, final String gatewayServiceUuid, final long vlanId) throws NiciraNvpApiException {
String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport";
Map<String,String> params = new HashMap<String,String>(); Map<String,String> params = new HashMap<String,String>();
params.put("attachment_gwsvc_uuid", gatewayServiceUuid); params.put("attachment_gwsvc_uuid", gatewayServiceUuid);
params.put("attachment_vlan", "0"); params.put("attachment_vlan", "0");
@ -329,28 +337,29 @@ public class NiciraNvpApi {
return executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalRouterPort>>(){}.getType(), uri, params); return executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalRouterPort>>(){}.getType(), uri, params);
} }
public LogicalRouterConfig findOneLogicalRouterByUuid(String logicalRouterUuid) throws NiciraNvpApiException { public LogicalRouterConfig findOneLogicalRouterByUuid(final String logicalRouterUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid; String uri = ROUTER_URI_PREFIX + logicalRouterUuid;
return executeRetrieveObject(new TypeToken<LogicalRouterConfig>(){}.getType(), uri, Collections.<String,String>emptyMap()); return executeRetrieveObject(new TypeToken<LogicalRouterConfig>(){}.getType(), uri, Collections.<String,String>emptyMap());
} }
public void updateLogicalRouterPortConfig(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException { public void updateLogicalRouterPortConfig(final String logicalRouterUuid, final LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport" + logicalRouterPort.getUuid(); String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport" + logicalRouterPort.getUuid();
executeUpdateObject(logicalRouterPort, uri, Collections.<String,String>emptyMap()); executeUpdateObject(logicalRouterPort, uri, Collections.<String,String>emptyMap());
} }
public NiciraNvpList<NatRule> findNatRulesByLogicalRouterUuid(String logicalRouterUuid) throws NiciraNvpApiException { public NiciraNvpList<NatRule> findNatRulesByLogicalRouterUuid(final String logicalRouterUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat"; String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/nat";
Map<String,String> params = new HashMap<String,String>(); Map<String,String> params = new HashMap<String,String>();
params.put("fields","*"); params.put("fields","*");
return executeRetrieveObject(new TypeToken<NiciraNvpList<NatRule>>(){}.getType(), uri, params); return executeRetrieveObject(new TypeToken<NiciraNvpList<NatRule>>(){}.getType(), uri, params);
} }
public NiciraNvpList<LogicalRouterPort> findLogicalRouterPortByGatewayServiceUuid(String logicalRouterUuid, String l3GatewayServiceUuid) throws NiciraNvpApiException { public NiciraNvpList<LogicalRouterPort> findLogicalRouterPortByGatewayServiceUuid(final String logicalRouterUuid,
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport"; final String l3GatewayServiceUuid) throws NiciraNvpApiException {
String uri = ROUTER_URI_PREFIX + logicalRouterUuid + "/lport";
Map<String,String> params = new HashMap<String,String>(); Map<String,String> params = new HashMap<String,String>();
params.put("fields", "*"); params.put("fields", "*");
params.put("attachment_gwsvc_uuid", l3GatewayServiceUuid); params.put("attachment_gwsvc_uuid", l3GatewayServiceUuid);
@ -358,18 +367,18 @@ public class NiciraNvpApi {
return executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalRouterPort>>(){}.getType(), uri, params); return executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalRouterPort>>(){}.getType(), uri, params);
} }
protected <T> void executeUpdateObject(T newObject, String uri, Map<String,String> parameters) throws NiciraNvpApiException { protected <T> void executeUpdateObject(final T newObject, final String uri, final Map<String,String> parameters) throws NiciraNvpApiException {
if (_host == null || _host.isEmpty() || if (host == null || host.isEmpty() ||
_adminuser == null || _adminuser.isEmpty() || adminuser == null || adminuser.isEmpty() ||
_adminpass == null || _adminpass.isEmpty()) { adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty"); throw new NiciraNvpApiException("Hostname/credentials are null or empty");
} }
PutMethod pm = (PutMethod) createMethod("put", uri); PutMethod pm = (PutMethod) createMethod("put", uri);
pm.setRequestHeader("Content-Type", "application/json"); pm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
try { try {
pm.setRequestEntity(new StringRequestEntity( pm.setRequestEntity(new StringRequestEntity(
_gson.toJson(newObject),"application/json", null)); gson.toJson(newObject),JSON_CONTENT_TYPE, null));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new NiciraNvpApiException("Failed to encode json request body", e); throw new NiciraNvpApiException("Failed to encode json request body", e);
} }
@ -385,18 +394,19 @@ public class NiciraNvpApi {
pm.releaseConnection(); pm.releaseConnection();
} }
protected <T> T executeCreateObject(T newObject, Type returnObjectType, String uri, Map<String,String> parameters) throws NiciraNvpApiException { protected <T> T executeCreateObject(final T newObject, final Type returnObjectType, final String uri,
if (_host == null || _host.isEmpty() || final Map<String,String> parameters) throws NiciraNvpApiException {
_adminuser == null || _adminuser.isEmpty() || if (host == null || host.isEmpty() ||
_adminpass == null || _adminpass.isEmpty()) { adminuser == null || adminuser.isEmpty() ||
adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty"); throw new NiciraNvpApiException("Hostname/credentials are null or empty");
} }
PostMethod pm = (PostMethod) createMethod("post", uri); PostMethod pm = (PostMethod) createMethod("post", uri);
pm.setRequestHeader("Content-Type", "application/json"); pm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
try { try {
pm.setRequestEntity(new StringRequestEntity( pm.setRequestEntity(new StringRequestEntity(
_gson.toJson(newObject),"application/json", null)); gson.toJson(newObject),JSON_CONTENT_TYPE, null));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new NiciraNvpApiException("Failed to encode json request body", e); throw new NiciraNvpApiException("Failed to encode json request body", e);
} }
@ -412,7 +422,7 @@ public class NiciraNvpApi {
T result; T result;
try { 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) { } catch (IOException e) {
throw new NiciraNvpApiException("Failed to decode json response body", e); throw new NiciraNvpApiException("Failed to decode json response body", e);
} finally { } finally {
@ -422,15 +432,15 @@ public class NiciraNvpApi {
return result; return result;
} }
protected void executeDeleteObject(String uri) throws NiciraNvpApiException { protected void executeDeleteObject(final String uri) throws NiciraNvpApiException {
if (_host == null || _host.isEmpty() || if (host == null || host.isEmpty() ||
_adminuser == null || _adminuser.isEmpty() || adminuser == null || adminuser.isEmpty() ||
_adminpass == null || _adminpass.isEmpty()) { adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty"); throw new NiciraNvpApiException("Hostname/credentials are null or empty");
} }
DeleteMethod dm = (DeleteMethod) createMethod("delete", uri); DeleteMethod dm = (DeleteMethod) createMethod("delete", uri);
dm.setRequestHeader("Content-Type", "application/json"); dm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
executeMethod(dm); executeMethod(dm);
@ -443,15 +453,16 @@ public class NiciraNvpApi {
dm.releaseConnection(); dm.releaseConnection();
} }
protected <T> T executeRetrieveObject(Type returnObjectType, String uri, Map<String,String> parameters) throws NiciraNvpApiException { protected <T> T executeRetrieveObject(final Type returnObjectType, final String uri,
if (_host == null || _host.isEmpty() || final Map<String,String> parameters) throws NiciraNvpApiException {
_adminuser == null || _adminuser.isEmpty() || if (host == null || host.isEmpty() ||
_adminpass == null || _adminpass.isEmpty()) { adminuser == null || adminuser.isEmpty() ||
adminpass == null || adminpass.isEmpty()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty"); throw new NiciraNvpApiException("Hostname/credentials are null or empty");
} }
GetMethod gm = (GetMethod) createMethod("get", uri); GetMethod gm = (GetMethod) createMethod("get", uri);
gm.setRequestHeader("Content-Type", "application/json"); gm.setRequestHeader(CONTENT_TYPE, JSON_CONTENT_TYPE);
if (parameters != null && !parameters.isEmpty()) { if (parameters != null && !parameters.isEmpty()) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size()); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
for (Entry<String,String> e : parameters.entrySet()) { for (Entry<String,String> e : parameters.entrySet()) {
@ -471,7 +482,7 @@ public class NiciraNvpApi {
T returnValue; T returnValue;
try { try {
returnValue = (T)_gson.fromJson(gm.getResponseBodyAsString(), returnObjectType); returnValue = (T)gson.fromJson(gm.getResponseBodyAsString(), returnObjectType);
} catch (IOException e) { } catch (IOException e) {
s_logger.error("IOException while retrieving response body",e); s_logger.error("IOException while retrieving response body",e);
throw new NiciraNvpApiException(e); throw new NiciraNvpApiException(e);
@ -481,14 +492,14 @@ public class NiciraNvpApi {
return returnValue; return returnValue;
} }
protected void executeMethod(HttpMethodBase method) throws NiciraNvpApiException { protected void executeMethod(final HttpMethodBase method) throws NiciraNvpApiException {
try { try {
_client.executeMethod(method); client.executeMethod(method);
if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { if (method.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
method.releaseConnection(); method.releaseConnection();
// login and try again // login and try again
login(); login();
_client.executeMethod(method); client.executeMethod(method);
} }
} catch (HttpException e) { } catch (HttpException e) {
s_logger.error("HttpException caught while trying to connect to the Nicira NVP Controller", 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"; 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 // The error message is the response content
// Safety margin of 1024 characters, anything longer is probably useless // Safety margin of 1024 characters, anything longer is probably useless
// and will clutter the logs // and will clutter the logs
try { try {
return method.getResponseBodyAsString(1024); return method.getResponseBodyAsString(BODY_RESP_MAX_LEN);
} catch (IOException e) { } catch (IOException e) {
s_logger.debug("Error while loading response body", e); s_logger.debug("Error while loading response body", e);
} }
@ -531,22 +542,22 @@ public class NiciraNvpApi {
public TrustingProtocolSocketFactory() throws IOException { public TrustingProtocolSocketFactory() throws IOException {
// Create a trust manager that does not validate certificate chains // Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] { TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() { new X509TrustManager() {
@Override @Override
public X509Certificate[] getAcceptedIssuers() { public X509Certificate[] getAcceptedIssuers() {
return null; return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
// Trust always
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
// Trust always
}
} }
@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 { try {
@ -562,26 +573,25 @@ public class NiciraNvpApi {
} }
@Override @Override
public Socket createSocket(String host, int port) throws IOException, public Socket createSocket(final String host, final int port) throws IOException {
UnknownHostException {
return ssf.createSocket(host, port); return ssf.createSocket(host, port);
} }
@Override @Override
public Socket createSocket(String address, int port, InetAddress localAddress, public Socket createSocket(final String address, final int port, final InetAddress localAddress,
int localPort) throws IOException, UnknownHostException { final int localPort) throws IOException, UnknownHostException {
return ssf.createSocket(address, port, localAddress, localPort); return ssf.createSocket(address, port, localAddress, localPort);
} }
@Override @Override
public Socket createSocket(Socket socket, String host, int port, public Socket createSocket(final Socket socket, final String host, final int port,
boolean autoClose) throws IOException, UnknownHostException { final boolean autoClose) throws IOException, UnknownHostException {
return ssf.createSocket(socket, host, port, autoClose); return ssf.createSocket(socket, host, port, autoClose);
} }
@Override @Override
public Socket createSocket(String host, int port, InetAddress localAddress, public Socket createSocket(final String host, final int port, final InetAddress localAddress,
int localPort, HttpConnectionParams params) throws IOException, final int localPort, final HttpConnectionParams params) throws IOException,
UnknownHostException, ConnectTimeoutException { UnknownHostException, ConnectTimeoutException {
int timeout = params.getConnectionTimeout(); int timeout = params.getConnectionTimeout();
if (timeout == 0) { if (timeout == 0) {
@ -594,16 +604,15 @@ public class NiciraNvpApi {
return s; return s;
} }
} }
} }
public static class NatRuleAdapter implements JsonDeserializer<NatRule> { public static class NatRuleAdapter implements JsonDeserializer<NatRule> {
@Override @Override
public NatRule deserialize(JsonElement jsonElement, Type type, public NatRule deserialize(final JsonElement jsonElement, final Type type,
JsonDeserializationContext context) throws JsonParseException { final JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonObject jsonObject = jsonElement.getAsJsonObject();
if (!jsonObject.has("type")) { if (!jsonObject.has("type")) {
throw new JsonParseException("Deserializing as a NatRule, but no type present in the json object"); 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(); String natRuleType = jsonObject.get("type").getAsString();
if ("SourceNatRule".equals(natRuleType)) { if ("SourceNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, SourceNatRule.class); return context.deserialize(jsonElement, SourceNatRule.class);
} } else if ("DestinationNatRule".equals(natRuleType)) {
else if ("DestinationNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, DestinationNatRule.class); return context.deserialize(jsonElement, DestinationNatRule.class);
} }

View File

@ -21,15 +21,15 @@ public class NiciraNvpApiException extends Exception {
public NiciraNvpApiException() { public NiciraNvpApiException() {
} }
public NiciraNvpApiException(String message) { public NiciraNvpApiException(final String message) {
super(message); super(message);
} }
public NiciraNvpApiException(Throwable cause) { public NiciraNvpApiException(final Throwable cause) {
super(cause); super(cause);
} }
public NiciraNvpApiException(String message, Throwable cause) { public NiciraNvpApiException(final String message, final Throwable cause) {
super(message, cause); super(message, cause);
} }

View File

@ -20,10 +20,10 @@ import java.util.List;
public class NiciraNvpList<T> { public class NiciraNvpList<T> {
private List<T> results; private List<T> results;
private int result_count; private int resultCount;
public List<T> getResults() { public List<T> getResults() {
return results; return this.results;
} }
public void setResults(List<T> results) { public void setResults(List<T> results) {
@ -31,15 +31,15 @@ public class NiciraNvpList<T> {
} }
public int getResultCount() { public int getResultCount() {
return result_count; return resultCount;
} }
public void setResultCount(int result_count) { public void setResultCount(int resultCount) {
this.result_count = result_count; this.resultCount = resultCount;
} }
public boolean isEmpty() { public boolean isEmpty() {
return result_count == 0; return this.resultCount == 0;
} }
} }

View File

@ -19,6 +19,7 @@ package com.cloud.network.nicira;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
public class NiciraNvpTag { public class NiciraNvpTag {
private static final int TAG_MAX_LEN = 40;
private static final Logger s_logger = Logger.getLogger(NiciraNvpTag.class); private static final Logger s_logger = Logger.getLogger(NiciraNvpTag.class);
private String scope; private String scope;
private String tag; private String tag;
@ -29,7 +30,7 @@ public class NiciraNvpTag {
this.scope = scope; this.scope = scope;
if (tag.length() > 40) { if (tag.length() > 40) {
s_logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters"); 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 { } else {
this.tag = tag; this.tag = tag;
} }

View File

@ -21,18 +21,19 @@ package com.cloud.network.nicira;
*/ */
public class PatchAttachment extends Attachment { public class PatchAttachment extends Attachment {
private final String type = "PatchAttachment"; private final String type = "PatchAttachment";
private String peer_port_uuid; private String peerPortUuid;
public PatchAttachment(String peerPortUuid) { public PatchAttachment(String peerPortUuid) {
peer_port_uuid = peerPortUuid; this.peerPortUuid = peerPortUuid;
} }
public String getPeerPortUuid() { public String getPeerPortUuid() {
return peer_port_uuid; return peerPortUuid;
} }
public void setPeerPortUuid(String peerPortUuid) { public void setPeerPortUuid(String peerPortUuid) {
peer_port_uuid = peerPortUuid; this.peerPortUuid = peerPortUuid;
} }
} }

View File

@ -20,19 +20,18 @@ package com.cloud.network.nicira;
* *
*/ */
public class RouterNextHop { public class RouterNextHop {
private String gateway_ip_address; private String gatewayIpAddress;
private String type = "RouterNextHop"; private final String type = "RouterNextHop";
public RouterNextHop(String gatewayIpAddress) { public RouterNextHop(String gatewayIpAddress) {
gateway_ip_address = gatewayIpAddress; this.gatewayIpAddress = gatewayIpAddress;
} }
public String getGatewayIpAddress() { public String getGatewayIpAddress() {
return gateway_ip_address; return gatewayIpAddress;
} }
public void setGatewayIpAddress(String gateway_ip_address) { public void setGatewayIpAddress(String gatewayIpAddress) {
this.gateway_ip_address = gateway_ip_address; this.gatewayIpAddress = gatewayIpAddress;
} }
} }

View File

@ -20,19 +20,18 @@ package com.cloud.network.nicira;
* *
*/ */
public class SingleDefaultRouteImplictRoutingConfig extends RoutingConfig { public class SingleDefaultRouteImplictRoutingConfig extends RoutingConfig {
public RouterNextHop default_route_next_hop; public RouterNextHop defaultRouteNextHop;
public String type = "SingleDefaultRouteImplicitRoutingConfig"; public String type = "SingleDefaultRouteImplicitRoutingConfig";
public SingleDefaultRouteImplictRoutingConfig(RouterNextHop routerNextHop) { public SingleDefaultRouteImplictRoutingConfig(RouterNextHop routerNextHop) {
default_route_next_hop = routerNextHop; defaultRouteNextHop = routerNextHop;
} }
public RouterNextHop getDefaultRouteNextHop() { public RouterNextHop getDefaultRouteNextHop() {
return default_route_next_hop; return defaultRouteNextHop;
} }
public void setDefaultRouteNextHop(RouterNextHop default_route_next_hop) { public void setDefaultRouteNextHop(RouterNextHop defaultRouteNextHop) {
this.default_route_next_hop = default_route_next_hop; this.defaultRouteNextHop = defaultRouteNextHop;
} }
} }

View File

@ -29,7 +29,7 @@ public class SourceNatRule extends NatRule {
return toSourceIpAddressMax; return toSourceIpAddressMax;
} }
public void setToSourceIpAddressMax(String toSourceIpAddressMax) { public void setToSourceIpAddressMax(final String toSourceIpAddressMax) {
this.toSourceIpAddressMax = toSourceIpAddressMax; this.toSourceIpAddressMax = toSourceIpAddressMax;
} }
@ -37,7 +37,7 @@ public class SourceNatRule extends NatRule {
return toSourceIpAddressMin; return toSourceIpAddressMin;
} }
public void setToSourceIpAddressMin(String toSourceIpAddressMin) { public void setToSourceIpAddressMin(final String toSourceIpAddressMin) {
this.toSourceIpAddressMin = toSourceIpAddressMin; this.toSourceIpAddressMin = toSourceIpAddressMin;
} }
@ -45,7 +45,7 @@ public class SourceNatRule extends NatRule {
return toSourcePort; return toSourcePort;
} }
public void setToSourcePort(Integer toSourcePort) { public void setToSourcePort(final Integer toSourcePort) {
this.toSourcePort = toSourcePort; this.toSourcePort = toSourcePort;
} }
@ -67,7 +67,7 @@ public class SourceNatRule extends NatRule {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(final Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (!super.equals(obj)) if (!super.equals(obj))
@ -94,7 +94,7 @@ public class SourceNatRule extends NatRule {
} }
@Override @Override
public boolean equalsIgnoreUuid(Object obj) { public boolean equalsIgnoreUuid(final Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (!super.equalsIgnoreUuid(obj)) if (!super.equalsIgnoreUuid(obj))

View File

@ -17,30 +17,30 @@
package com.cloud.network.nicira; package com.cloud.network.nicira;
public class TransportZoneBinding { public class TransportZoneBinding {
private String zone_uuid; private String zoneUuid;
private String transport_type; private String transportType;
public TransportZoneBinding() {} public TransportZoneBinding() {}
public TransportZoneBinding(String zone_uuid, String transport_type) { public TransportZoneBinding(String zoneUuid, String transportType) {
this.zone_uuid = zone_uuid; this.zoneUuid = zoneUuid;
this.transport_type = transport_type; this.transportType = transportType;
} }
public String getZone_uuid() { public String getZoneUuid() {
return zone_uuid; return zoneUuid;
} }
public void setZone_uuid(String zone_uuid) { public void setZoneUuid(String zoneUuid) {
this.zone_uuid = zone_uuid; this.zoneUuid = zoneUuid;
} }
public String getTransport_type() { public String getTransportType() {
return transport_type; return transportType;
} }
public void setTransport_type(String transport_type) { public void setTransportType(String transportType) {
this.transport_type = transport_type; this.transportType = transportType;
} }
} }

View File

@ -18,21 +18,21 @@ package com.cloud.network.nicira;
public class VifAttachment extends Attachment { public class VifAttachment extends Attachment {
private final String type = "VifAttachment"; private final String type = "VifAttachment";
private String vif_uuid; private String vifUuid;
public VifAttachment() { public VifAttachment() {
} }
public VifAttachment(String vifUuid) { public VifAttachment(final String vifUuid) {
vif_uuid = vifUuid; this.vifUuid = vifUuid;
} }
public String getVif_uuid() { public String getVifUuid() {
return vif_uuid; return vifUuid;
} }
public void setVif_uuid(String vif_uuid) { public void setVifUuid(String vifUuid) {
this.vif_uuid = vif_uuid; this.vifUuid = vifUuid;
} }
public String getType() { public String getType() {

View File

@ -82,39 +82,41 @@ import com.cloud.network.nicira.VifAttachment;
import com.cloud.resource.ServerResource; import com.cloud.resource.ServerResource;
public class NiciraNvpResource implements 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 static final Logger s_logger = Logger.getLogger(NiciraNvpResource.class);
private String _name; private String name;
private String _guid; private String guid;
private String _zoneId; private String zoneId;
private int _numRetries; private int numRetries;
private NiciraNvpApi _niciraNvpApi; private NiciraNvpApi niciraNvpApi;
protected NiciraNvpApi createNiciraNvpApi() { protected NiciraNvpApi createNiciraNvpApi() {
return new NiciraNvpApi(); return new NiciraNvpApi();
} }
@Override @Override
public boolean configure(String name, Map<String, Object> params) public boolean configure(String ignoredName, final Map<String, Object> params)
throws ConfigurationException { throws ConfigurationException {
_name = (String) params.get("name"); name = (String) params.get("name");
if (_name == null) { if (name == null) {
throw new ConfigurationException("Unable to find name"); throw new ConfigurationException("Unable to find name");
} }
_guid = (String)params.get("guid"); guid = (String)params.get("guid");
if (_guid == null) { if (guid == null) {
throw new ConfigurationException("Unable to find the guid"); throw new ConfigurationException("Unable to find the guid");
} }
_zoneId = (String) params.get("zoneId"); zoneId = (String) params.get("zoneId");
if (_zoneId == null) { if (zoneId == null) {
throw new ConfigurationException("Unable to find zone"); throw new ConfigurationException("Unable to find zone");
} }
_numRetries = 2; numRetries = 2;
String ip = (String) params.get("ip"); String ip = (String) params.get("ip");
if (ip == null) { if (ip == null) {
@ -131,9 +133,9 @@ public class NiciraNvpResource implements ServerResource {
throw new ConfigurationException("Unable to find admin password"); throw new ConfigurationException("Unable to find admin password");
} }
_niciraNvpApi = createNiciraNvpApi(); niciraNvpApi = createNiciraNvpApi();
_niciraNvpApi.setControllerAddress(ip); niciraNvpApi.setControllerAddress(ip);
_niciraNvpApi.setAdminCredentials(adminuser,adminpass); niciraNvpApi.setAdminCredentials(adminuser,adminpass);
return true; return true;
} }
@ -150,7 +152,7 @@ public class NiciraNvpResource implements ServerResource {
@Override @Override
public String getName() { public String getName() {
return _name; return name;
} }
@Override @Override
@ -162,9 +164,9 @@ public class NiciraNvpResource implements ServerResource {
@Override @Override
public StartupCommand[] initialize() { public StartupCommand[] initialize() {
StartupNiciraNvpCommand sc = new StartupNiciraNvpCommand(); StartupNiciraNvpCommand sc = new StartupNiciraNvpCommand();
sc.setGuid(_guid); sc.setGuid(guid);
sc.setName(_name); sc.setName(name);
sc.setDataCenter(_zoneId); sc.setDataCenter(zoneId);
sc.setPod(""); sc.setPod("");
sc.setPrivateIpAddress(""); sc.setPrivateIpAddress("");
sc.setStorageIpAddress(""); sc.setStorageIpAddress("");
@ -173,9 +175,9 @@ public class NiciraNvpResource implements ServerResource {
} }
@Override @Override
public PingCommand getCurrentStatus(long id) { public PingCommand getCurrentStatus(final long id) {
try { try {
ControlClusterStatus ccs = _niciraNvpApi.getControlClusterStatus(); ControlClusterStatus ccs = niciraNvpApi.getControlClusterStatus();
if (!"stable".equals(ccs.getClusterStatus())) { if (!"stable".equals(ccs.getClusterStatus())) {
s_logger.error("ControlCluster state is not stable: " s_logger.error("ControlCluster state is not stable: "
+ ccs.getClusterStatus()); + ccs.getClusterStatus());
@ -189,11 +191,11 @@ public class NiciraNvpResource implements ServerResource {
} }
@Override @Override
public Answer executeRequest(Command cmd) { public Answer executeRequest(final Command cmd) {
return executeRequest(cmd, _numRetries); return executeRequest(cmd, numRetries);
} }
public Answer executeRequest(Command cmd, int numRetries) { public Answer executeRequest(final Command cmd, final int numRetries) {
if (cmd instanceof ReadyCommand) { if (cmd instanceof ReadyCommand) {
return executeRequest((ReadyCommand) cmd); return executeRequest((ReadyCommand) cmd);
} }
@ -247,18 +249,18 @@ public class NiciraNvpResource implements ServerResource {
} }
@Override @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 logicalSwitch = new LogicalSwitch();
logicalSwitch.setDisplay_name(truncate("lswitch-" + cmd.getName(), 40)); logicalSwitch.setDisplayName(truncate("lswitch-" + cmd.getName(), NAME_MAX_LEN));
logicalSwitch.setPort_isolation_enabled(false); logicalSwitch.setPortIsolationEnabled(false);
// Set transport binding // Set transport binding
List<TransportZoneBinding> ltzb = new ArrayList<TransportZoneBinding>(); List<TransportZoneBinding> ltzb = new ArrayList<TransportZoneBinding>();
ltzb.add(new TransportZoneBinding(cmd.getTransportUuid(), cmd.getTransportType())); ltzb.add(new TransportZoneBinding(cmd.getTransportUuid(), cmd.getTransportType()));
logicalSwitch.setTransport_zones(ltzb); logicalSwitch.setTransportZones(ltzb);
// Tags set to scope cs_account and account name // Tags set to scope cs_account and account name
List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>(); List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
@ -266,7 +268,7 @@ public class NiciraNvpResource implements ServerResource {
logicalSwitch.setTags(tags); logicalSwitch.setTags(tags);
try { try {
logicalSwitch = _niciraNvpApi.createLogicalSwitch(logicalSwitch); logicalSwitch = niciraNvpApi.createLogicalSwitch(logicalSwitch);
return new CreateLogicalSwitchAnswer(cmd, true, "Logicalswitch " + logicalSwitch.getUuid() + " created", logicalSwitch.getUuid()); return new CreateLogicalSwitchAnswer(cmd, true, "Logicalswitch " + logicalSwitch.getUuid() + " created", logicalSwitch.getUuid());
} catch (NiciraNvpApiException e) { } catch (NiciraNvpApiException e) {
if (numRetries > 0) { 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 { try {
_niciraNvpApi.deleteLogicalSwitch(cmd.getLogicalSwitchUuid()); niciraNvpApi.deleteLogicalSwitch(cmd.getLogicalSwitchUuid());
return new DeleteLogicalSwitchAnswer(cmd, true, "Logicalswitch " + cmd.getLogicalSwitchUuid() + " deleted"); return new DeleteLogicalSwitchAnswer(cmd, true, "Logicalswitch " + cmd.getLogicalSwitchUuid() + " deleted");
} catch (NiciraNvpApiException e) { } catch (NiciraNvpApiException e) {
if (numRetries > 0) { 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 logicalSwitchUuid = cmd.getLogicalSwitchUuid();
String attachmentUuid = cmd.getAttachmentUuid(); String attachmentUuid = cmd.getAttachmentUuid();
@ -303,12 +305,12 @@ public class NiciraNvpResource implements ServerResource {
tags.add(new NiciraNvpTag("cs_account",cmd.getOwnerName())); tags.add(new NiciraNvpTag("cs_account",cmd.getOwnerName()));
LogicalSwitchPort logicalSwitchPort = new LogicalSwitchPort(attachmentUuid, tags, true); LogicalSwitchPort logicalSwitchPort = new LogicalSwitchPort(attachmentUuid, tags, true);
LogicalSwitchPort newPort = _niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort); LogicalSwitchPort newPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, logicalSwitchPort);
try { try {
_niciraNvpApi.modifyLogicalSwitchPortAttachment(cmd.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid)); niciraNvpApi.modifyLogicalSwitchPortAttachment(cmd.getLogicalSwitchUuid(), newPort.getUuid(), new VifAttachment(attachmentUuid));
} catch (NiciraNvpApiException ex) { } catch (NiciraNvpApiException ex) {
s_logger.warn("modifyLogicalSwitchPort failed after switchport was created, removing switchport"); 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 throw (ex); // Rethrow the original exception
} }
return new CreateLogicalSwitchPortAnswer(cmd, true, "Logical switch port " + newPort.getUuid() + " created", newPort.getUuid()); 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 { try {
_niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), cmd.getLogicalSwitchPortUuid()); niciraNvpApi.deleteLogicalSwitchPort(cmd.getLogicalSwitchUuid(), cmd.getLogicalSwitchPortUuid());
return new DeleteLogicalSwitchPortAnswer(cmd, true, "Logical switch port " + cmd.getLogicalSwitchPortUuid() + " deleted"); return new DeleteLogicalSwitchPortAnswer(cmd, true, "Logical switch port " + cmd.getLogicalSwitchPortUuid() + " deleted");
} catch (NiciraNvpApiException e) { } catch (NiciraNvpApiException e) {
if (numRetries > 0) { 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 logicalSwitchUuid = cmd.getLogicalSwitchUuid();
String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid(); String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid();
String attachmentUuid = cmd.getAttachmentUuid(); String attachmentUuid = cmd.getAttachmentUuid();
@ -347,7 +349,7 @@ public class NiciraNvpResource implements ServerResource {
List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>(); List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
tags.add(new NiciraNvpTag("cs_account",cmd.getOwnerName())); 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); return new UpdateLogicalSwitchPortAnswer(cmd, true, "Attachment for " + logicalSwitchPortUuid + " updated", logicalSwitchPortUuid);
} catch (NiciraNvpApiException e) { } catch (NiciraNvpApiException e) {
if (numRetries > 0) { 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 logicalSwitchUuid = cmd.getLogicalSwitchUuid();
String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid(); String logicalSwitchPortUuid = cmd.getLogicalSwitchPortUuid();
try { try {
NiciraNvpList<LogicalSwitchPort> ports = _niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid); NiciraNvpList<LogicalSwitchPort> ports = niciraNvpApi.findLogicalSwitchPortsByUuid(logicalSwitchUuid, logicalSwitchPortUuid);
if (ports.getResultCount() == 0) { if (ports.getResultCount() == 0) {
return new FindLogicalSwitchPortAnswer(cmd, false, "Logical switchport " + logicalSwitchPortUuid + " not found", null); 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 routerName = cmd.getName();
String gatewayServiceUuid = cmd.getGatewayServiceUuid(); String gatewayServiceUuid = cmd.getGatewayServiceUuid();
String logicalSwitchUuid = cmd.getLogicalSwitchUuid(); String logicalSwitchUuid = cmd.getLogicalSwitchUuid();
@ -401,11 +403,11 @@ public class NiciraNvpResource implements ServerResource {
try { try {
// Create the Router // Create the Router
LogicalRouterConfig lrc = new LogicalRouterConfig(); LogicalRouterConfig lrc = new LogicalRouterConfig();
lrc.setDisplayName(truncate(routerName, 40)); lrc.setDisplayName(truncate(routerName, NAME_MAX_LEN));
lrc.setTags(tags); lrc.setTags(tags);
lrc.setRoutingConfig(new SingleDefaultRouteImplictRoutingConfig( lrc.setRoutingConfig(new SingleDefaultRouteImplictRoutingConfig(
new RouterNextHop(publicNetworkNextHopIp))); new RouterNextHop(publicNetworkNextHopIp)));
lrc = _niciraNvpApi.createLogicalRouter(lrc); lrc = niciraNvpApi.createLogicalRouter(lrc);
// store the switchport for rollback // store the switchport for rollback
LogicalSwitchPort lsp = null; LogicalSwitchPort lsp = null;
@ -414,40 +416,40 @@ public class NiciraNvpResource implements ServerResource {
// Create the outside port for the router // Create the outside port for the router
LogicalRouterPort lrpo = new LogicalRouterPort(); LogicalRouterPort lrpo = new LogicalRouterPort();
lrpo.setAdminStatusEnabled(true); lrpo.setAdminStatusEnabled(true);
lrpo.setDisplayName(truncate(routerName + "-outside-port", 40)); lrpo.setDisplayName(truncate(routerName + "-outside-port", NAME_MAX_LEN));
lrpo.setTags(tags); lrpo.setTags(tags);
List<String> outsideIpAddresses = new ArrayList<String>(); List<String> outsideIpAddresses = new ArrayList<String>();
outsideIpAddresses.add(publicNetworkIpAddress); outsideIpAddresses.add(publicNetworkIpAddress);
lrpo.setIpAddresses(outsideIpAddresses); 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 // Attach the outside port to the gateway service on the correct VLAN
L3GatewayAttachment attachment = new L3GatewayAttachment(gatewayServiceUuid); L3GatewayAttachment attachment = new L3GatewayAttachment(gatewayServiceUuid);
if (cmd.getVlanId() != 0) { if (cmd.getVlanId() != 0) {
attachment.setVlanId(cmd.getVlanId()); 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 // Create the inside port for the router
LogicalRouterPort lrpi = new LogicalRouterPort(); LogicalRouterPort lrpi = new LogicalRouterPort();
lrpi.setAdminStatusEnabled(true); lrpi.setAdminStatusEnabled(true);
lrpi.setDisplayName(truncate(routerName + "-inside-port", 40)); lrpi.setDisplayName(truncate(routerName + "-inside-port", NAME_MAX_LEN));
lrpi.setTags(tags); lrpi.setTags(tags);
List<String> insideIpAddresses = new ArrayList<String>(); List<String> insideIpAddresses = new ArrayList<String>();
insideIpAddresses.add(internalNetworkAddress); insideIpAddresses.add(internalNetworkAddress);
lrpi.setIpAddresses(insideIpAddresses); lrpi.setIpAddresses(insideIpAddresses);
lrpi = _niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpi); lrpi = niciraNvpApi.createLogicalRouterPort(lrc.getUuid(),lrpi);
// Create the inside port on the lswitch // Create the inside port on the lswitch
lsp = new LogicalSwitchPort(truncate(routerName + "-inside-port", 40), tags, true); lsp = new LogicalSwitchPort(truncate(routerName + "-inside-port", NAME_MAX_LEN), tags, true);
lsp = _niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lsp); lsp = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lsp);
// Attach the inside router port to the lswitch port with a PatchAttachment // 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())); new PatchAttachment(lsp.getUuid()));
// Attach the inside lswitch port to the router with a PatchAttachment // 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())); new PatchAttachment(lrpi.getUuid()));
// Setup the source nat rule // Setup the source nat rule
@ -458,14 +460,14 @@ public class NiciraNvpResource implements ServerResource {
match.setSourceIpAddresses(internalNetworkAddress); match.setSourceIpAddresses(internalNetworkAddress);
snr.setMatch(match); snr.setMatch(match);
snr.setOrder(200); snr.setOrder(200);
_niciraNvpApi.createLogicalRouterNatRule(lrc.getUuid(), snr); niciraNvpApi.createLogicalRouterNatRule(lrc.getUuid(), snr);
} catch (NiciraNvpApiException e) { } catch (NiciraNvpApiException e) {
// We need to destroy the router if we already created it // We need to destroy the router if we already created it
// this will also take care of any router ports and rules // this will also take care of any router ports and rules
try { try {
_niciraNvpApi.deleteLogicalRouter(lrc.getUuid()); niciraNvpApi.deleteLogicalRouter(lrc.getUuid());
if (lsp != null) { if (lsp != null) {
_niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lsp.getUuid()); niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lsp.getUuid());
} }
} catch (NiciraNvpApiException ex) {} } 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 { try {
_niciraNvpApi.deleteLogicalRouter(cmd.getLogicalRouterUuid()); niciraNvpApi.deleteLogicalRouter(cmd.getLogicalRouterUuid());
return new DeleteLogicalRouterAnswer(cmd, true, "Logical Router deleted (uuid " + cmd.getLogicalRouterUuid() + ")"); return new DeleteLogicalRouterAnswer(cmd, true, "Logical Router deleted (uuid " + cmd.getLogicalRouterUuid() + ")");
} catch (NiciraNvpApiException e) { } catch (NiciraNvpApiException e) {
if (numRetries > 0) { 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 { try {
NiciraNvpList<LogicalRouterPort> ports = _niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(cmd.getLogicalRouterUuid(), cmd.getL3GatewayServiceUuid()); NiciraNvpList<LogicalRouterPort> ports = niciraNvpApi.findLogicalRouterPortByGatewayServiceUuid(cmd.getLogicalRouterUuid(), cmd.getL3GatewayServiceUuid());
if (ports.getResultCount() != 1) { if (ports.getResultCount() != 1) {
return new ConfigurePublicIpsOnLogicalRouterAnswer(cmd, false, "No logical router ports found, unable to set ip addresses"); return new ConfigurePublicIpsOnLogicalRouterAnswer(cmd, false, "No logical router ports found, unable to set ip addresses");
} }
LogicalRouterPort lrp = ports.getResults().get(0); LogicalRouterPort lrp = ports.getResults().get(0);
lrp.setIpAddresses(cmd.getPublicCidrs()); lrp.setIpAddresses(cmd.getPublicCidrs());
_niciraNvpApi.modifyLogicalRouterPort(cmd.getLogicalRouterUuid(), lrp); niciraNvpApi.modifyLogicalRouterPort(cmd.getLogicalRouterUuid(), lrp);
return new ConfigurePublicIpsOnLogicalRouterAnswer(cmd, true, "Configured " + cmd.getPublicCidrs().size() + return new ConfigurePublicIpsOnLogicalRouterAnswer(cmd, true, "Configured " + cmd.getPublicCidrs().size() +
" ip addresses on logical router uuid " + cmd.getLogicalRouterUuid()); " 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 { try {
NiciraNvpList<NatRule> existingRules = _niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid()); NiciraNvpList<NatRule> existingRules = niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid());
// Rules of the game (also known as assumptions-that-will-make-stuff-break-later-on) // 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 // 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 // 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 (incoming != null && outgoing != null) {
if (rule.revoked()) { if (rule.revoked()) {
s_logger.debug("Deleting incoming rule " + incoming.getUuid()); 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()); s_logger.debug("Deleting outgoing rule " + outgoing.getUuid());
_niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid()); niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
} }
} }
else { else {
@ -568,15 +570,15 @@ public class NiciraNvpResource implements ServerResource {
break; break;
} }
rulepair[0] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]); rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
s_logger.debug("Created " + natRuleToString(rulepair[0])); s_logger.debug("Created " + natRuleToString(rulepair[0]));
try { try {
rulepair[1] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]); rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
s_logger.debug("Created " + natRuleToString(rulepair[1])); s_logger.debug("Created " + natRuleToString(rulepair[1]));
} catch (NiciraNvpApiException ex) { } catch (NiciraNvpApiException ex) {
s_logger.debug("Failed to create SourceNatRule, rolling back DestinationNatRule"); 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 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 { try {
NiciraNvpList<NatRule> existingRules = _niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid()); NiciraNvpList<NatRule> existingRules = niciraNvpApi.findNatRulesByLogicalRouterUuid(cmd.getLogicalRouterUuid());
// Rules of the game (also known as assumptions-that-will-make-stuff-break-later-on) // 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 // 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 // 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 (incoming != null && outgoing != null) {
if (rule.revoked()) { if (rule.revoked()) {
s_logger.debug("Deleting incoming rule " + incoming.getUuid()); 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()); s_logger.debug("Deleting outgoing rule " + outgoing.getUuid());
_niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid()); niciraNvpApi.deleteLogicalRouterNatRule(cmd.getLogicalRouterUuid(), outgoing.getUuid());
} }
} }
else { else {
@ -650,15 +652,15 @@ public class NiciraNvpResource implements ServerResource {
break; break;
} }
rulepair[0] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]); rulepair[0] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[0]);
s_logger.debug("Created " + natRuleToString(rulepair[0])); s_logger.debug("Created " + natRuleToString(rulepair[0]));
try { try {
rulepair[1] = _niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]); rulepair[1] = niciraNvpApi.createLogicalRouterNatRule(cmd.getLogicalRouterUuid(), rulepair[1]);
s_logger.debug("Created " + natRuleToString(rulepair[1])); s_logger.debug("Created " + natRuleToString(rulepair[1]));
} catch (NiciraNvpApiException ex) { } catch (NiciraNvpApiException ex) {
s_logger.warn("NiciraNvpApiException during create call, rolling back previous create"); 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 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); return new ReadyAnswer(cmd);
} }
private Answer executeRequest(MaintainCommand cmd) { private Answer executeRequest(final MaintainCommand cmd) {
return new MaintainAnswer(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); s_logger.warn("Retrying " + cmd.getClass().getSimpleName() + ". Number of retries remaining: " + numRetries);
return executeRequest(cmd, numRetries); return executeRequest(cmd, numRetries);
} }
private String natRuleToString(NatRule rule) { private String natRuleToString(final NatRule rule) {
StringBuilder natRuleStr = new StringBuilder(); StringBuilder natRuleStr = new StringBuilder();
natRuleStr.append("Rule "); natRuleStr.append("Rule ");
@ -726,7 +728,7 @@ public class NiciraNvpResource implements ServerResource {
return natRuleStr.toString(); return natRuleStr.toString();
} }
private String truncate(String string, int length) { private String truncate(final String string, final int length) {
if (string.length() <= length) { if (string.length() <= length) {
return string; 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]; NatRule[] rulepair = new NatRule[2];
rulepair[0] = new DestinationNatRule(); rulepair[0] = new DestinationNatRule();
rulepair[0].setType("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) { protected NatRule[] generatePortForwardingRulePair(final String insideIp, final int[] insidePorts,
// Start with a basic static nat rule, then add port and protocol details 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); NatRule[] rulepair = generateStaticNatRulePair(insideIp, outsideIp);
((DestinationNatRule)rulepair[0]).setToDestinationPort(insidePorts[0]); ((DestinationNatRule)rulepair[0]).setToDestinationPort(insidePorts[0]);
@ -791,15 +794,13 @@ public class NiciraNvpResource implements ServerResource {
} }
@Override @Override
public void setName(String name) { public void setName(final String name) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void setConfigParams(Map<String, Object> params) { public void setConfigParams(final Map<String, Object> params) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
@ -815,9 +816,8 @@ public class NiciraNvpResource implements ServerResource {
} }
@Override @Override
public void setRunLevel(int level) { public void setRunLevel(final int level) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }

View File

@ -72,59 +72,60 @@ import com.cloud.vm.ReservationContext;
public class NiciraNvpElementTest { public class NiciraNvpElementTest {
NiciraNvpElement _element = new NiciraNvpElement(); private static final long NETWORK_ID = 42L;
NetworkOrchestrationService _networkManager = mock(NetworkOrchestrationService.class); NiciraNvpElement element = new NiciraNvpElement();
NetworkModel _networkModel = mock(NetworkModel.class); NetworkOrchestrationService networkManager = mock(NetworkOrchestrationService.class);
NetworkServiceMapDao _ntwkSrvcDao = mock(NetworkServiceMapDao.class); NetworkModel networkModel = mock(NetworkModel.class);
AgentManager _agentManager = mock(AgentManager.class); NetworkServiceMapDao ntwkSrvcDao = mock(NetworkServiceMapDao.class);
HostDao _hostDao = mock(HostDao.class); AgentManager agentManager = mock(AgentManager.class);
NiciraNvpDao _niciraNvpDao = mock(NiciraNvpDao.class); HostDao hostDao = mock(HostDao.class);
NiciraNvpRouterMappingDao _niciraNvpRouterMappingDao = mock(NiciraNvpRouterMappingDao.class); NiciraNvpDao niciraNvpDao = mock(NiciraNvpDao.class);
NiciraNvpRouterMappingDao niciraNvpRouterMappingDao = mock(NiciraNvpRouterMappingDao.class);
@Before @Before
public void setUp() throws ConfigurationException { public void setUp() throws ConfigurationException {
_element._resourceMgr = mock(ResourceManager.class); element.resourceMgr = mock(ResourceManager.class);
_element._networkManager = _networkManager; element.networkManager = networkManager;
_element._ntwkSrvcDao = _ntwkSrvcDao; element.ntwkSrvcDao = ntwkSrvcDao;
_element._networkModel = _networkModel; element.networkModel = networkModel;
_element._agentMgr = _agentManager; element.agentMgr = agentManager;
_element._hostDao = _hostDao; element.hostDao = hostDao;
_element._niciraNvpDao = _niciraNvpDao; element.niciraNvpDao = niciraNvpDao;
_element._niciraNvpRouterMappingDao = _niciraNvpRouterMappingDao; element.niciraNvpRouterMappingDao = niciraNvpRouterMappingDao;
// Standard responses // Standard responses
when(_networkModel.isProviderForNetwork(Provider.NiciraNvp, 42L)).thenReturn(true); when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
_element.configure("NiciraNvpTestElement", Collections.<String, Object> emptyMap()); element.configure("NiciraNvpTestElement", Collections.<String, Object> emptyMap());
} }
@Test @Test
public void canHandleTest() { public void canHandleTest() {
Network net = mock(Network.class); Network net = mock(Network.class);
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); 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 // Golden path
assertTrue(_element.canHandle(net, Service.Connectivity)); assertTrue(element.canHandle(net, Service.Connectivity));
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan); when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vlan);
// Only broadcastdomaintype lswitch is supported // Only broadcastdomaintype lswitch is supported
assertFalse(_element.canHandle(net, Service.Connectivity)); assertFalse(element.canHandle(net, Service.Connectivity));
when(net.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); 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 // 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(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(false);
when(_ntwkSrvcDao.canProviderSupportServiceInNetwork(42L, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true); when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
// NVP provider does not provide Connectivity for this network // 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 // 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 { public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
Network network = mock(Network.class); Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getId()).thenReturn(42L); when(network.getId()).thenReturn(NETWORK_ID);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@ -148,19 +149,17 @@ public class NiciraNvpElementTest {
ReservationContext context = mock(ReservationContext.class); ReservationContext context = mock(ReservationContext.class);
when(context.getDomain()).thenReturn(dom); when(context.getDomain()).thenReturn(dom);
when(context.getAccount()).thenReturn(acc); when(context.getAccount()).thenReturn(acc);
// assertTrue(_element.implement(network, offering, dest, context));
} }
@Test @Test
public void applyIpTest() throws ResourceUnavailableException { public void applyIpTest() throws ResourceUnavailableException {
Network network = mock(Network.class); Network network = mock(Network.class);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getId()).thenReturn(42L); when(network.getId()).thenReturn(NETWORK_ID);
when(network.getPhysicalNetworkId()).thenReturn(42L); when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@ -186,23 +185,23 @@ public class NiciraNvpElementTest {
List<NiciraNvpDeviceVO> deviceList = new ArrayList<NiciraNvpDeviceVO>(); List<NiciraNvpDeviceVO> deviceList = new ArrayList<NiciraNvpDeviceVO>();
NiciraNvpDeviceVO nndVO = mock(NiciraNvpDeviceVO.class); NiciraNvpDeviceVO nndVO = mock(NiciraNvpDeviceVO.class);
NiciraNvpRouterMappingVO nnrmVO = mock(NiciraNvpRouterMappingVO.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(nnrmVO.getLogicalRouterUuid()).thenReturn("abcde");
when(nndVO.getHostId()).thenReturn(42L); when(nndVO.getHostId()).thenReturn(NETWORK_ID);
HostVO hvo = mock(HostVO.class); HostVO hvo = mock(HostVO.class);
when(hvo.getId()).thenReturn(42L); when(hvo.getId()).thenReturn(NETWORK_ID);
when(hvo.getDetail("l3gatewayserviceuuid")).thenReturn("abcde"); when(hvo.getDetail("l3gatewayserviceuuid")).thenReturn("abcde");
when(_hostDao.findById(42L)).thenReturn(hvo); when(hostDao.findById(NETWORK_ID)).thenReturn(hvo);
deviceList.add(nndVO); deviceList.add(nndVO);
when(_niciraNvpDao.listByPhysicalNetwork(42L)).thenReturn(deviceList); when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(deviceList);
ConfigurePublicIpsOnLogicalRouterAnswer answer = mock(ConfigurePublicIpsOnLogicalRouterAnswer.class); ConfigurePublicIpsOnLogicalRouterAnswer answer = mock(ConfigurePublicIpsOnLogicalRouterAnswer.class);
when(answer.getResult()).thenReturn(true); 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<ConfigurePublicIpsOnLogicalRouterCommand>() { argThat(new ArgumentMatcher<ConfigurePublicIpsOnLogicalRouterCommand>() {
@Override @Override
public boolean matches(Object argument) { public boolean matches(Object argument) {

View File

@ -70,6 +70,7 @@ import com.cloud.user.Account;
import com.cloud.vm.ReservationContext; import com.cloud.vm.ReservationContext;
public class NiciraNvpGuestNetworkGuruTest { public class NiciraNvpGuestNetworkGuruTest {
private static final long NETWORK_ID = 42L;
PhysicalNetworkDao physnetdao = mock(PhysicalNetworkDao.class); PhysicalNetworkDao physnetdao = mock(PhysicalNetworkDao.class);
NiciraNvpDao nvpdao = mock(NiciraNvpDao.class); NiciraNvpDao nvpdao = mock(NiciraNvpDao.class);
DataCenterDao dcdao = mock(DataCenterDao.class); DataCenterDao dcdao = mock(DataCenterDao.class);
@ -87,14 +88,14 @@ public class NiciraNvpGuestNetworkGuruTest {
public void setUp() { public void setUp() {
guru = new NiciraNvpGuestNetworkGuru(); guru = new NiciraNvpGuestNetworkGuru();
((GuestNetworkGuru) guru)._physicalNetworkDao = physnetdao; ((GuestNetworkGuru) guru)._physicalNetworkDao = physnetdao;
guru._physicalNetworkDao = physnetdao; guru.physicalNetworkDao = physnetdao;
guru._niciraNvpDao = nvpdao; guru.niciraNvpDao = nvpdao;
guru._dcDao = dcdao; guru._dcDao = dcdao;
guru._ntwkOfferingSrvcDao = nosd; guru.ntwkOfferingSrvcDao = nosd;
guru._networkModel = netmodel; guru.networkModel = netmodel;
guru._hostDao = hostdao; guru.hostDao = hostdao;
guru._agentMgr = agentmgr; guru.agentMgr = agentmgr;
guru._networkDao = netdao; guru.networkDao = netdao;
DataCenterVO dc = mock(DataCenterVO.class); DataCenterVO dc = mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced); when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
@ -106,15 +107,15 @@ public class NiciraNvpGuestNetworkGuruTest {
@Test @Test
public void testCanHandle() { public void testCanHandle() {
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); when(offering.getGuestType()).thenReturn(GuestType.Isolated);
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); 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); assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
@ -142,18 +143,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); 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); 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); when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); 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); DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class); Network network = mock(Network.class);
@ -169,13 +170,13 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" }));
when(physnet.getId()).thenReturn(42L); when(physnet.getId()).thenReturn(NETWORK_ID);
mock(NiciraNvpDeviceVO.class); mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList()); when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList());
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@ -192,13 +193,13 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" })); when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" }));
when(physnet.getId()).thenReturn(42L); when(physnet.getId()).thenReturn(NETWORK_ID);
mock(NiciraNvpDeviceVO.class); mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList()); when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList());
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); when(offering.getGuestType()).thenReturn(GuestType.Isolated);
@ -215,18 +216,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); 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); 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); when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); 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); DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class); Network network = mock(Network.class);
@ -241,25 +242,25 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); 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); 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); when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); 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); mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class); NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork"); when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing); when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(42L); when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
DeployDestination dest = mock(DeployDestination.class); DeployDestination dest = mock(DeployDestination.class);
@ -270,9 +271,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost); when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa"); when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt"); 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); Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain"); when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class); Account acc = mock(Account.class);
@ -284,11 +285,11 @@ public class NiciraNvpGuestNetworkGuruTest {
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class); CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true); when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa"); 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); Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null); assertTrue(implementednetwork != null);
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any()); verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
} }
@Test @Test
@ -296,18 +297,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); 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); 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); when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); 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); mock(DeploymentPlan.class);
@ -316,7 +317,7 @@ public class NiciraNvpGuestNetworkGuruTest {
when(network.getState()).thenReturn(State.Implementing); when(network.getState()).thenReturn(State.Implementing);
when(network.getGateway()).thenReturn("10.1.1.1"); when(network.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24"); 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); DeployDestination dest = mock(DeployDestination.class);
@ -327,9 +328,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost); when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa"); when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt"); 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); Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain"); when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class); Account acc = mock(Account.class);
@ -341,13 +342,13 @@ public class NiciraNvpGuestNetworkGuruTest {
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class); CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true); when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa"); 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); Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null); assertTrue(implementednetwork != null);
assertTrue(implementednetwork.getCidr().equals("10.1.1.0/24")); assertTrue(implementednetwork.getCidr().equals("10.1.1.0/24"));
assertTrue(implementednetwork.getGateway().equals("10.1.1.1")); 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 @Test
@ -355,25 +356,25 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); 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); 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); when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); 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); mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class); NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork"); when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing); when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(42L); when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
DeployDestination dest = mock(DeployDestination.class); DeployDestination dest = mock(DeployDestination.class);
@ -384,9 +385,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost); when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa"); when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt"); 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); Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain"); when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class); Account acc = mock(Account.class);
@ -398,11 +399,11 @@ public class NiciraNvpGuestNetworkGuruTest {
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class); CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true); when(answer.getResult()).thenReturn(true);
//when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa"); //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); Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork == null); assertTrue(implementednetwork == null);
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any()); verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
} }
@Test @Test
@ -410,18 +411,18 @@ public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class); PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
when(physnetdao.findById((Long) any())).thenReturn(physnet); when(physnetdao.findById((Long) any())).thenReturn(physnet);
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT" })); 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); 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); when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class); NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L); when(offering.getId()).thenReturn(NETWORK_ID);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest); when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated); 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); mock(DeploymentPlan.class);
@ -430,8 +431,8 @@ public class NiciraNvpGuestNetworkGuruTest {
when(network.getState()).thenReturn(State.Implementing); when(network.getState()).thenReturn(State.Implementing);
when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch); when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa")); when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
when(network.getPhysicalNetworkId()).thenReturn(42L); when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
when(netdao.findById(42L)).thenReturn(network); when(netdao.findById(NETWORK_ID)).thenReturn(network);
DeployDestination dest = mock(DeployDestination.class); DeployDestination dest = mock(DeployDestination.class);
@ -442,9 +443,9 @@ public class NiciraNvpGuestNetworkGuruTest {
when(hostdao.findById(anyLong())).thenReturn(niciraHost); when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa"); when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt"); 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); Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain"); when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class); Account acc = mock(Account.class);
@ -455,15 +456,15 @@ public class NiciraNvpGuestNetworkGuruTest {
DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class); DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true); 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); 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(implementednetwork.getBroadcastUri()).thenReturn(new URI("lswitch:aaaa"));
when(offering.getSpecifyVlan()).thenReturn(false); when(offering.getSpecifyVlan()).thenReturn(false);
guru.shutdown(implementednetwork, offering); 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); verify(implementednetwork, times(1)).setBroadcastUri(null);
} }
} }

View File

@ -40,87 +40,87 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class NiciraNvpApiTest { public class NiciraNvpApiTest {
NiciraNvpApi _api; NiciraNvpApi api;
HttpClient _client = mock(HttpClient.class); HttpClient client = mock(HttpClient.class);
HttpMethod _method; HttpMethod method;
@Before @Before
public void setUp() { public void setUp() {
HttpClientParams hmp = mock(HttpClientParams.class); HttpClientParams hmp = mock(HttpClientParams.class);
when (_client.getParams()).thenReturn(hmp); when (client.getParams()).thenReturn(hmp);
_api = new NiciraNvpApi() { api = new NiciraNvpApi() {
@Override @Override
protected HttpClient createHttpClient() { protected HttpClient createHttpClient() {
return _client; return client;
} }
@Override @Override
protected HttpMethod createMethod(String type, String uri) { protected HttpMethod createMethod(String type, String uri) {
return _method; return method;
} }
}; };
_api.setAdminCredentials("admin", "adminpass"); api.setAdminCredentials("admin", "adminpass");
_api.setControllerAddress("localhost"); api.setControllerAddress("localhost");
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutHostname() throws NiciraNvpApiException { public void testExecuteLoginWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null); api.setControllerAddress(null);
_api.login(); api.login();
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutCredentials() throws NiciraNvpApiException { public void testExecuteLoginWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null); api.setAdminCredentials(null, null);
_api.login(); api.login();
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutHostname() throws NiciraNvpApiException { public void testExecuteUpdateObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null); api.setControllerAddress(null);
_api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap()); api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap());
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutCredentials() throws NiciraNvpApiException { public void testExecuteUpdateObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null); api.setAdminCredentials(null, null);
_api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap()); api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap());
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectWithoutHostname() throws NiciraNvpApiException { public void testExecuteCreateObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null); api.setControllerAddress(null);
_api.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap()); api.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap());
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectWithoutCredentials() throws NiciraNvpApiException { public void testExecuteCreateObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null); api.setAdminCredentials(null, null);
_api.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap()); api.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap());
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutHostname() throws NiciraNvpApiException { public void testExecuteDeleteObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null); api.setControllerAddress(null);
_api.executeDeleteObject("/"); api.executeDeleteObject("/");
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutCredentials() throws NiciraNvpApiException { public void testExecuteDeleteObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null); api.setAdminCredentials(null, null);
_api.executeDeleteObject("/"); api.executeDeleteObject("/");
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutHostname() throws NiciraNvpApiException { public void testExecuteRetrieveObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null); api.setControllerAddress(null);
_api.executeRetrieveObject(String.class, "/", Collections.<String, String> emptyMap()); api.executeRetrieveObject(String.class, "/", Collections.<String, String> emptyMap());
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutCredentials() throws NiciraNvpApiException { public void testExecuteRetrieveObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null); api.setAdminCredentials(null, null);
_api.executeDeleteObject("/"); api.executeDeleteObject("/");
} }
@Test @Test
@ -128,7 +128,7 @@ public class NiciraNvpApiTest {
GetMethod gm = mock(GetMethod.class); GetMethod gm = mock(GetMethod.class);
when(gm.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(gm.getStatusCode()).thenReturn(HttpStatus.SC_OK);
_api.executeMethod(gm); api.executeMethod(gm);
verify(gm, times(1)).getStatusCode(); verify(gm, times(1)).getStatusCode();
} }
@ -138,172 +138,172 @@ public class NiciraNvpApiTest {
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void executeMethodTestWithLogin() throws NiciraNvpApiException, HttpException, IOException { public void executeMethodTestWithLogin() throws NiciraNvpApiException, HttpException, IOException {
GetMethod gm = mock(GetMethod.class); 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); when(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED);
_api.executeMethod(gm); api.executeMethod(gm);
verify(gm, times(1)).getStatusCode(); verify(gm, times(1)).getStatusCode();
} }
@Test @Test
public void testExecuteCreateObject() throws NiciraNvpApiException, IOException { public void testExecuteCreateObject() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch(); LogicalSwitch ls = new LogicalSwitch();
_method = mock(PostMethod.class); method = mock(PostMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_CREATED); when(method.getStatusCode()).thenReturn(HttpStatus.SC_CREATED);
when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }"); when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap()); ls = api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
assertTrue("aaaa".equals(ls.getUuid())); assertTrue("aaaa".equals(ls.getUuid()));
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectFailure() throws NiciraNvpApiException, IOException { public void testExecuteCreateObjectFailure() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch(); LogicalSwitch ls = new LogicalSwitch();
_method = mock(PostMethod.class); method = mock(PostMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class); Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html"); when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-Type")).thenReturn(header); when(method.getResponseHeader("Content-Type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
when(_method.isRequestSent()).thenReturn(true); when(method.isRequestSent()).thenReturn(true);
try { try {
ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap()); ls = api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectException() throws NiciraNvpApiException, IOException { public void testExecuteCreateObjectException() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch(); LogicalSwitch ls = new LogicalSwitch();
when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException()); when(client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
_method = mock(PostMethod.class); method = mock(PostMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class); Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html"); when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-Type")).thenReturn(header); when(method.getResponseHeader("Content-Type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
try { try {
ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap()); ls = api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }
@Test @Test
public void testExecuteUpdateObject() throws NiciraNvpApiException, IOException { public void testExecuteUpdateObject() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch(); LogicalSwitch ls = new LogicalSwitch();
_method = mock(PutMethod.class); method = mock(PutMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
_api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap()); api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap());
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
verify(_client, times(1)).executeMethod(_method); verify(client, times(1)).executeMethod(method);
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectFailure() throws NiciraNvpApiException, IOException { public void testExecuteUpdateObjectFailure() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch(); LogicalSwitch ls = new LogicalSwitch();
_method = mock(PutMethod.class); method = mock(PutMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class); Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html"); when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-Type")).thenReturn(header); when(method.getResponseHeader("Content-Type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
when(_method.isRequestSent()).thenReturn(true); when(method.isRequestSent()).thenReturn(true);
try { try {
_api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap()); api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap());
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectException() throws NiciraNvpApiException, IOException { public void testExecuteUpdateObjectException() throws NiciraNvpApiException, IOException {
LogicalSwitch ls = new LogicalSwitch(); LogicalSwitch ls = new LogicalSwitch();
_method = mock(PutMethod.class); method = mock(PutMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
when(_client.executeMethod((HttpMethod) any())).thenThrow(new IOException()); when(client.executeMethod((HttpMethod) any())).thenThrow(new IOException());
try { try {
_api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap()); api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap());
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }
@Test @Test
public void testExecuteDeleteObject() throws NiciraNvpApiException, IOException { public void testExecuteDeleteObject() throws NiciraNvpApiException, IOException {
_method = mock(DeleteMethod.class); method = mock(DeleteMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT); when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
_api.executeDeleteObject("/"); api.executeDeleteObject("/");
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
verify(_client, times(1)).executeMethod(_method); verify(client, times(1)).executeMethod(method);
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectFailure() throws NiciraNvpApiException, IOException { public void testExecuteDeleteObjectFailure() throws NiciraNvpApiException, IOException {
_method = mock(DeleteMethod.class); method = mock(DeleteMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
Header header = mock(Header.class); Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html"); when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-Type")).thenReturn(header); when(method.getResponseHeader("Content-Type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
when(_method.isRequestSent()).thenReturn(true); when(method.isRequestSent()).thenReturn(true);
try { try {
_api.executeDeleteObject("/"); api.executeDeleteObject("/");
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectException() throws NiciraNvpApiException, IOException { public void testExecuteDeleteObjectException() throws NiciraNvpApiException, IOException {
_method = mock(DeleteMethod.class); method = mock(DeleteMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT); when(method.getStatusCode()).thenReturn(HttpStatus.SC_NO_CONTENT);
when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException()); when(client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
try { try {
_api.executeDeleteObject("/"); api.executeDeleteObject("/");
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }
@Test @Test
public void testExecuteRetrieveObject() throws NiciraNvpApiException, IOException { public void testExecuteRetrieveObject() throws NiciraNvpApiException, IOException {
_method = mock(GetMethod.class); method = mock(GetMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }"); when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
_api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap()); api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
verify(_client, times(1)).executeMethod(_method); verify(client, times(1)).executeMethod(method);
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectFailure() throws NiciraNvpApiException, IOException { public void testExecuteRetrieveObjectFailure() throws NiciraNvpApiException, IOException {
_method = mock(GetMethod.class); method = mock(GetMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR); when(method.getStatusCode()).thenReturn(HttpStatus.SC_INTERNAL_SERVER_ERROR);
when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }"); when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
Header header = mock(Header.class); Header header = mock(Header.class);
when(header.getValue()).thenReturn("text/html"); when(header.getValue()).thenReturn("text/html");
when(_method.getResponseHeader("Content-Type")).thenReturn(header); when(method.getResponseHeader("Content-Type")).thenReturn(header);
when(_method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later."); when(method.getResponseBodyAsString()).thenReturn("Off to timbuktu, won't be back later.");
when(_method.isRequestSent()).thenReturn(true); when(method.isRequestSent()).thenReturn(true);
try { try {
_api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap()); api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }
@Test (expected=NiciraNvpApiException.class) @Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectException() throws NiciraNvpApiException, IOException { public void testExecuteRetrieveObjectException() throws NiciraNvpApiException, IOException {
_method = mock(GetMethod.class); method = mock(GetMethod.class);
when(_method.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(method.getStatusCode()).thenReturn(HttpStatus.SC_OK);
when(_method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }"); when(method.getResponseBodyAsString()).thenReturn("{ \"uuid\" : \"aaaa\" }");
when(_client.executeMethod((HttpMethod) any())).thenThrow(new HttpException()); when(client.executeMethod((HttpMethod) any())).thenThrow(new HttpException());
try { try {
_api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap()); api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally { } finally {
verify(_method, times(1)).releaseConnection(); verify(method, times(1)).releaseConnection();
} }
} }

View File

@ -17,7 +17,7 @@
package com.cloud.network.nicira; package com.cloud.network.nicira;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.assertEquals;
public class NiciraTagTest { public class NiciraTagTest {
@Test @Test

View File

@ -84,68 +84,67 @@ import com.cloud.network.nicira.NiciraNvpList;
import com.cloud.network.nicira.SourceNatRule; import com.cloud.network.nicira.SourceNatRule;
public class NiciraNvpResourceTest { public class NiciraNvpResourceTest {
NiciraNvpApi _nvpApi = mock(NiciraNvpApi.class); NiciraNvpApi nvpApi = mock(NiciraNvpApi.class);
NiciraNvpResource _resource; NiciraNvpResource resource;
Map<String,Object> _parameters; Map<String,Object> parameters;
@Before @Before
public void setUp() throws ConfigurationException { public void setUp() throws ConfigurationException {
_resource = new NiciraNvpResource() { resource = new NiciraNvpResource() {
@Override @Override
protected NiciraNvpApi createNiciraNvpApi() { protected NiciraNvpApi createNiciraNvpApi() {
return _nvpApi; return nvpApi;
} }
}; };
_parameters = new HashMap<String,Object>(); parameters = new HashMap<String,Object>();
_parameters.put("name","nvptestdevice"); parameters.put("name","nvptestdevice");
_parameters.put("ip","127.0.0.1"); parameters.put("ip","127.0.0.1");
_parameters.put("adminuser","adminuser"); parameters.put("adminuser","adminuser");
_parameters.put("guid", "aaaaa-bbbbb-ccccc"); parameters.put("guid", "aaaaa-bbbbb-ccccc");
_parameters.put("zoneId", "blublub"); parameters.put("zoneId", "blublub");
_parameters.put("adminpass","adminpass"); parameters.put("adminpass","adminpass");
} }
@Test (expected=ConfigurationException.class) @Test (expected=ConfigurationException.class)
public void resourceConfigureFailure() throws ConfigurationException { public void resourceConfigureFailure() throws ConfigurationException {
_resource.configure("NiciraNvpResource", Collections.<String,Object>emptyMap()); resource.configure("NiciraNvpResource", Collections.<String,Object>emptyMap());
} }
@Test @Test
public void resourceConfigure() throws ConfigurationException { public void resourceConfigure() throws ConfigurationException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
verify(_nvpApi).setAdminCredentials("adminuser", "adminpass"); verify(nvpApi).setAdminCredentials("adminuser", "adminpass");
verify(_nvpApi).setControllerAddress("127.0.0.1"); verify(nvpApi).setControllerAddress("127.0.0.1");
assertTrue("Incorrect resource name", "nvptestdevice".equals(resource.getName()));
assertTrue("nvptestdevice".equals(_resource.getName()));
/* Pretty lame test, but here to assure this plugin fails /* Pretty lame test, but here to assure this plugin fails
* if the type name ever changes from L2Networking * if the type name ever changes from L2Networking
*/ */
assertTrue(_resource.getType() == Host.Type.L2Networking); assertTrue("Incorrect resource type", resource.getType() == Host.Type.L2Networking);
} }
@Test @Test
public void testInitialization() throws ConfigurationException { 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(sc.length ==1);
assertTrue("aaaaa-bbbbb-ccccc".equals(sc[0].getGuid())); assertTrue("Incorrect startup command GUID", "aaaaa-bbbbb-ccccc".equals(sc[0].getGuid()));
assertTrue("nvptestdevice".equals(sc[0].getName())); assertTrue("Incorrect NVP device name", "nvptestdevice".equals(sc[0].getName()));
assertTrue("blublub".equals(sc[0].getDataCenter())); assertTrue("Incorrect Data Center", "blublub".equals(sc[0].getDataCenter()));
} }
@Test @Test
public void testPingCommandStatusOk() throws ConfigurationException, NiciraNvpApiException { public void testPingCommandStatusOk() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
ControlClusterStatus ccs = mock(ControlClusterStatus.class); ControlClusterStatus ccs = mock(ControlClusterStatus.class);
when(ccs.getClusterStatus()).thenReturn("stable"); 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 != null);
assertTrue(ping.getHostId() == 42); assertTrue(ping.getHostId() == 42);
assertTrue(ping.getHostType() == Host.Type.L2Networking); assertTrue(ping.getHostType() == Host.Type.L2Networking);
@ -153,98 +152,98 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testPingCommandStatusFail() throws ConfigurationException, NiciraNvpApiException { public void testPingCommandStatusFail() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
ControlClusterStatus ccs = mock(ControlClusterStatus.class); ControlClusterStatus ccs = mock(ControlClusterStatus.class);
when(ccs.getClusterStatus()).thenReturn("unstable"); 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); assertTrue(ping == null);
} }
@Test @Test
public void testPingCommandStatusApiException() throws ConfigurationException, NiciraNvpApiException { public void testPingCommandStatusApiException() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
ControlClusterStatus ccs = mock(ControlClusterStatus.class); ControlClusterStatus ccs = mock(ControlClusterStatus.class);
when(ccs.getClusterStatus()).thenReturn("unstable"); 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); assertTrue(ping == null);
} }
@Test @Test
public void testRetries() throws ConfigurationException, NiciraNvpApiException { public void testRetries() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalSwitch ls = mock(LogicalSwitch.class); LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc"); 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"); CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)parameters.get("guid"), "stt", "loigicalswitch","owner");
CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) _resource.executeRequest(clsc); CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertTrue(clsa.getResult()); assertTrue(clsa.getResult());
} }
@Test @Test
public void testCreateLogicalSwitch() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalSwitch() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalSwitch ls = mock(LogicalSwitch.class); LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc"); 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"); CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)parameters.get("guid"), "stt", "loigicalswitch","owner");
CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) _resource.executeRequest(clsc); CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertTrue(clsa.getResult()); assertTrue(clsa.getResult());
assertTrue("cccc".equals(clsa.getLogicalSwitchUuid())); assertTrue("cccc".equals(clsa.getLogicalSwitchUuid()));
} }
@Test @Test
public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalSwitch ls = mock(LogicalSwitch.class); LogicalSwitch ls = mock(LogicalSwitch.class);
when(ls.getUuid()).thenReturn("cccc").thenReturn("cccc"); 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"); CreateLogicalSwitchCommand clsc = new CreateLogicalSwitchCommand((String)parameters.get("guid"), "stt", "loigicalswitch","owner");
CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) _resource.executeRequest(clsc); CreateLogicalSwitchAnswer clsa = (CreateLogicalSwitchAnswer) resource.executeRequest(clsc);
assertFalse(clsa.getResult()); assertFalse(clsa.getResult());
} }
@Test @Test
public void testDeleteLogicalSwitch() throws ConfigurationException, NiciraNvpApiException { public void testDeleteLogicalSwitch() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc"); DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc");
DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) _resource.executeRequest(dlsc); DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) resource.executeRequest(dlsc);
assertTrue(dlsa.getResult()); assertTrue(dlsa.getResult());
} }
@Test @Test
public void testDeleteLogicalSwitchApiException() throws ConfigurationException, NiciraNvpApiException { 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"); DeleteLogicalSwitchCommand dlsc = new DeleteLogicalSwitchCommand("cccc");
DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) _resource.executeRequest(dlsc); DeleteLogicalSwitchAnswer dlsa = (DeleteLogicalSwitchAnswer) resource.executeRequest(dlsc);
assertFalse(dlsa.getResult()); assertFalse(dlsa.getResult());
} }
@Test @Test
public void testCreateLogicalSwitchPort() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalSwitchPort() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalSwitchPort lsp = mock(LogicalSwitchPort.class); LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lsp.getUuid()).thenReturn("eeee"); 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"); CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) _resource.executeRequest(clspc); CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
assertTrue(clspa.getResult()); assertTrue(clspa.getResult());
assertTrue("eeee".equals(clspa.getLogicalSwitchPortUuid())); assertTrue("eeee".equals(clspa.getLogicalSwitchPortUuid()));
@ -252,91 +251,91 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testCreateLogicalSwitchPortApiExceptionInCreate() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalSwitchPortApiExceptionInCreate() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalSwitchPort lsp = mock(LogicalSwitchPort.class); LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lsp.getUuid()).thenReturn("eeee"); 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"); CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) _resource.executeRequest(clspc); CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
assertFalse(clspa.getResult()); assertFalse(clspa.getResult());
} }
@Test @Test
public void testCreateLogicalSwitchPortApiExceptionInModify() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalSwitchPortApiExceptionInModify() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalSwitchPort lsp = mock(LogicalSwitchPort.class); LogicalSwitchPort lsp = mock(LogicalSwitchPort.class);
when(lsp.getUuid()).thenReturn("eeee"); when(lsp.getUuid()).thenReturn("eeee");
when(_nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenReturn(lsp); when(nvpApi.createLogicalSwitchPort(eq("cccc"), (LogicalSwitchPort) any())).thenReturn(lsp);
doThrow(new NiciraNvpApiException()).when(_nvpApi).modifyLogicalSwitchPortAttachment((String)any(), (String)any(), (Attachment)any()); doThrow(new NiciraNvpApiException()).when(nvpApi).modifyLogicalSwitchPortAttachment((String)any(), (String)any(), (Attachment)any());
CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname"); CreateLogicalSwitchPortCommand clspc = new CreateLogicalSwitchPortCommand("cccc", "dddd", "owner", "nicname");
CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) _resource.executeRequest(clspc); CreateLogicalSwitchPortAnswer clspa = (CreateLogicalSwitchPortAnswer) resource.executeRequest(clspc);
assertFalse(clspa.getResult()); assertFalse(clspa.getResult());
verify(_nvpApi, atLeastOnce()).deleteLogicalSwitchPort((String) any(), (String) any()); verify(nvpApi, atLeastOnce()).deleteLogicalSwitchPort((String) any(), (String) any());
} }
@Test @Test
public void testDeleteLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException { public void testDeleteLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
doThrow(new NiciraNvpApiException()).when(_nvpApi).deleteLogicalSwitchPort((String) any(), (String) any()); doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalSwitchPort((String) any(), (String) any());
DeleteLogicalSwitchPortAnswer dlspa = (DeleteLogicalSwitchPortAnswer) _resource.executeRequest(new DeleteLogicalSwitchPortCommand("aaaa","bbbb")); DeleteLogicalSwitchPortAnswer dlspa = (DeleteLogicalSwitchPortAnswer) resource.executeRequest(new DeleteLogicalSwitchPortCommand("aaaa","bbbb"));
assertFalse(dlspa.getResult()); assertFalse(dlspa.getResult());
} }
@Test @Test
public void testUpdateLogicalSwitchPortException() throws ConfigurationException, NiciraNvpApiException { 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()); doThrow(new NiciraNvpApiException()).when(nvpApi).modifyLogicalSwitchPortAttachment((String) any(), (String) any(), (Attachment) any());
UpdateLogicalSwitchPortAnswer dlspa = (UpdateLogicalSwitchPortAnswer) _resource.executeRequest( UpdateLogicalSwitchPortAnswer dlspa = (UpdateLogicalSwitchPortAnswer) resource.executeRequest(
new UpdateLogicalSwitchPortCommand("aaaa","bbbb","cccc","owner","nicname")); new UpdateLogicalSwitchPortCommand("aaaa","bbbb","cccc","owner","nicname"));
assertFalse(dlspa.getResult()); assertFalse(dlspa.getResult());
} }
@Test @Test
public void testFindLogicalSwitchPort() throws ConfigurationException, NiciraNvpApiException { public void testFindLogicalSwitchPort() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<LogicalSwitchPort> lspl = mock(NiciraNvpList.class); NiciraNvpList<LogicalSwitchPort> lspl = mock(NiciraNvpList.class);
when(lspl.getResultCount()).thenReturn(1); 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()); assertTrue(flspa.getResult());
} }
@Test @Test
public void testFindLogicalSwitchPortNotFound() throws ConfigurationException, NiciraNvpApiException { public void testFindLogicalSwitchPortNotFound() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<LogicalSwitchPort> lspl = mock(NiciraNvpList.class); NiciraNvpList<LogicalSwitchPort> lspl = mock(NiciraNvpList.class);
when(lspl.getResultCount()).thenReturn(0); 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()); assertFalse(flspa.getResult());
} }
@Test @Test
public void testFindLogicalSwitchPortApiException() throws ConfigurationException, NiciraNvpApiException { 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()); assertFalse(flspa.getResult());
} }
@Test @Test
public void testCreateLogicalRouter() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalRouterConfig lrc = mock(LogicalRouterConfig.class); LogicalRouterConfig lrc = mock(LogicalRouterConfig.class);
LogicalRouterPort lrp = mock(LogicalRouterPort.class); LogicalRouterPort lrp = mock(LogicalRouterPort.class);
@ -344,46 +343,46 @@ public class NiciraNvpResourceTest {
when(lrc.getUuid()).thenReturn("ccccc"); when(lrc.getUuid()).thenReturn("ccccc");
when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee"); when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
when(lsp.getUuid()).thenReturn("fffff"); when(lsp.getUuid()).thenReturn("fffff");
when(_nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc); when(nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
when(_nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp); when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp);
when(_nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp); when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp);
CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner"); 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(clra.getResult());
assertTrue("ccccc".equals(clra.getLogicalRouterUuid())); assertTrue("ccccc".equals(clra.getLogicalRouterUuid()));
verify(_nvpApi, atLeast(1)).createLogicalRouterNatRule((String) any(), (NatRule) any()); verify(nvpApi, atLeast(1)).createLogicalRouterNatRule((String) any(), (NatRule) any());
} }
@Test @Test
public void testCreateLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException { 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"); 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()); assertFalse(clra.getResult());
} }
@Test @Test
public void testCreateLogicalRouterApiExceptionRollbackRouter() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalRouterApiExceptionRollbackRouter() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalRouterConfig lrc = mock(LogicalRouterConfig.class); LogicalRouterConfig lrc = mock(LogicalRouterConfig.class);
when(lrc.getUuid()).thenReturn("ccccc"); when(lrc.getUuid()).thenReturn("ccccc");
when(_nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc); when(nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
when(_nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenThrow(new NiciraNvpApiException()); when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenThrow(new NiciraNvpApiException());
CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner"); 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()); assertFalse(clra.getResult());
verify(_nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc")); verify(nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
} }
@Test @Test
public void testCreateLogicalRouterApiExceptionRollbackRouterAndSwitchPort() throws ConfigurationException, NiciraNvpApiException { public void testCreateLogicalRouterApiExceptionRollbackRouterAndSwitchPort() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
LogicalRouterConfig lrc = mock(LogicalRouterConfig.class); LogicalRouterConfig lrc = mock(LogicalRouterConfig.class);
LogicalRouterPort lrp = mock(LogicalRouterPort.class); LogicalRouterPort lrp = mock(LogicalRouterPort.class);
@ -391,30 +390,30 @@ public class NiciraNvpResourceTest {
when(lrc.getUuid()).thenReturn("ccccc"); when(lrc.getUuid()).thenReturn("ccccc");
when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee"); when(lrp.getUuid()).thenReturn("ddddd").thenReturn("eeeee");
when(lsp.getUuid()).thenReturn("fffff"); when(lsp.getUuid()).thenReturn("fffff");
when(_nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc); when(nvpApi.createLogicalRouter((LogicalRouterConfig)any())).thenReturn(lrc);
when(_nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp); when(nvpApi.createLogicalRouterPort(eq("ccccc"), (LogicalRouterPort)any())).thenReturn(lrp);
when(_nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp); when(nvpApi.createLogicalSwitchPort(eq("bbbbb"), (LogicalSwitchPort)any())).thenReturn(lsp);
when(_nvpApi.createLogicalRouterNatRule((String) any(), (NatRule)any())).thenThrow(new NiciraNvpApiException()); when(nvpApi.createLogicalRouterNatRule((String) any(), (NatRule)any())).thenThrow(new NiciraNvpApiException());
CreateLogicalRouterCommand clrc = new CreateLogicalRouterCommand("aaaaa", 50, "bbbbb", "lrouter", "publiccidr", "nexthop", "internalcidr", "owner"); 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()); assertFalse(clra.getResult());
verify(_nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc")); verify(nvpApi, atLeast(1)).deleteLogicalRouter(eq("ccccc"));
verify(_nvpApi, atLeast(1)).deleteLogicalSwitchPort(eq("bbbbb"), eq("fffff")); verify(nvpApi, atLeast(1)).deleteLogicalSwitchPort(eq("bbbbb"), eq("fffff"));
} }
@Test @Test
public void testDeleteLogicalRouterApiException() throws ConfigurationException,NiciraNvpApiException { public void testDeleteLogicalRouterApiException() throws ConfigurationException,NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
doThrow(new NiciraNvpApiException()).when(_nvpApi).deleteLogicalRouter(eq("aaaaa")); doThrow(new NiciraNvpApiException()).when(nvpApi).deleteLogicalRouter(eq("aaaaa"));
DeleteLogicalRouterAnswer dlspa = (DeleteLogicalRouterAnswer) _resource.executeRequest(new DeleteLogicalRouterCommand("aaaaa")); DeleteLogicalRouterAnswer dlspa = (DeleteLogicalRouterAnswer) resource.executeRequest(new DeleteLogicalRouterCommand("aaaaa"));
assertFalse(dlspa.getResult()); assertFalse(dlspa.getResult());
} }
@Test @Test
public void testConfigurePublicIpsOnLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException { public void testConfigurePublicIpsOnLogicalRouterApiException() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
ConfigurePublicIpsOnLogicalRouterCommand cmd = mock(ConfigurePublicIpsOnLogicalRouterCommand.class); ConfigurePublicIpsOnLogicalRouterCommand cmd = mock(ConfigurePublicIpsOnLogicalRouterCommand.class);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -422,18 +421,18 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa"); when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
when(cmd.getL3GatewayServiceUuid()).thenReturn("bbbbb"); when(cmd.getL3GatewayServiceUuid()).thenReturn("bbbbb");
doThrow(new NiciraNvpApiException()).when(_nvpApi).modifyLogicalRouterPort((String) any(), (LogicalRouterPort) any()); doThrow(new NiciraNvpApiException()).when(nvpApi).modifyLogicalRouterPort((String) any(), (LogicalRouterPort) any());
when(_nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa","bbbbb")).thenReturn(list); when(nvpApi.findLogicalRouterPortByGatewayServiceUuid("aaaaa","bbbbb")).thenReturn(list);
ConfigurePublicIpsOnLogicalRouterAnswer answer = ConfigurePublicIpsOnLogicalRouterAnswer answer =
(ConfigurePublicIpsOnLogicalRouterAnswer) _resource.executeRequest(cmd); (ConfigurePublicIpsOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertFalse(answer.getResult()); assertFalse(answer.getResult());
} }
@Test @Test
public void testConfigureStaticNatRulesOnLogicalRouter() throws ConfigurationException, NiciraNvpApiException { public void testConfigureStaticNatRulesOnLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -450,18 +449,18 @@ public class NiciraNvpResourceTest {
// Mock the api find call // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules); when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
// Mock the api create calls // 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[0].setUuid(UUID.randomUUID());
rulepair[1].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()); assertTrue(a.getResult());
verify(_nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() { verify(nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
@Override @Override
public boolean matches(Object argument) { public boolean matches(Object argument) {
NatRule rule = (NatRule) argument; NatRule rule = (NatRule) argument;
@ -479,7 +478,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testConfigureStaticNatRulesOnLogicalRouterExistingRules() throws ConfigurationException, NiciraNvpApiException { public void testConfigureStaticNatRulesOnLogicalRouterExistingRules() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -494,22 +493,22 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa"); when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls // 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[0].setUuid(UUID.randomUUID());
rulepair[1].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 // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2); when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair)); 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()); assertTrue(a.getResult());
verify(_nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() { verify(nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
@Override @Override
public boolean matches(Object argument) { public boolean matches(Object argument) {
NatRule rule = (NatRule) argument; NatRule rule = (NatRule) argument;
@ -527,7 +526,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testConfigureStaticNatRulesOnLogicalRouterRemoveRules() throws ConfigurationException, NiciraNvpApiException { public void testConfigureStaticNatRulesOnLogicalRouterRemoveRules() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -542,24 +541,24 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa"); when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls // 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 rule0Uuid = UUID.randomUUID();
final UUID rule1Uuid = UUID.randomUUID(); final UUID rule1Uuid = UUID.randomUUID();
rulepair[0].setUuid(rule0Uuid); rulepair[0].setUuid(rule0Uuid);
rulepair[1].setUuid(rule1Uuid); 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 // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2); when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair)); 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()); assertTrue(a.getResult());
verify(_nvpApi, atLeast(2)).deleteLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<UUID>() { verify(nvpApi, atLeast(2)).deleteLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<UUID>() {
@Override @Override
public boolean matches(Object argument) { public boolean matches(Object argument) {
UUID uuid = (UUID) argument; UUID uuid = (UUID) argument;
@ -572,7 +571,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testConfigureStaticNatRulesOnLogicalRouterRollback() throws ConfigurationException, NiciraNvpApiException { public void testConfigureStaticNatRulesOnLogicalRouterRollback() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -587,26 +586,26 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa"); when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls // 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[0].setUuid(UUID.randomUUID());
rulepair[1].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 // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(0); 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()); assertFalse(a.getResult());
verify(_nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq(rulepair[0].getUuid())); verify(nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq(rulepair[0].getUuid()));
} }
@Test @Test
public void testConfigurePortForwardingRulesOnLogicalRouter() throws ConfigurationException, NiciraNvpApiException { public void testConfigurePortForwardingRulesOnLogicalRouter() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -623,18 +622,18 @@ public class NiciraNvpResourceTest {
// Mock the api find call // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules); when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
// Mock the api create calls // 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[0].setUuid(UUID.randomUUID());
rulepair[1].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()); assertTrue(a.getResult());
verify(_nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() { verify(nvpApi, atLeast(2)).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
@Override @Override
public boolean matches(Object argument) { public boolean matches(Object argument) {
NatRule rule = (NatRule) argument; NatRule rule = (NatRule) argument;
@ -652,7 +651,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testConfigurePortForwardingRulesOnLogicalRouterExistingRules() throws ConfigurationException, NiciraNvpApiException { public void testConfigurePortForwardingRulesOnLogicalRouterExistingRules() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -667,22 +666,22 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa"); when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls // 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[0].setUuid(UUID.randomUUID());
rulepair[1].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 // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2); when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair)); 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()); assertTrue(a.getResult());
verify(_nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() { verify(nvpApi, never()).createLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<NatRule>() {
@Override @Override
public boolean matches(Object argument) { public boolean matches(Object argument) {
NatRule rule = (NatRule) argument; NatRule rule = (NatRule) argument;
@ -700,7 +699,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testConfigurePortForwardingRulesOnLogicalRouterRemoveRules() throws ConfigurationException, NiciraNvpApiException { public void testConfigurePortForwardingRulesOnLogicalRouterRemoveRules() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -715,24 +714,24 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa"); when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls // 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");
final UUID rule0Uuid = UUID.randomUUID(); final UUID rule0Uuid = UUID.randomUUID();
final UUID rule1Uuid = UUID.randomUUID(); final UUID rule1Uuid = UUID.randomUUID();
rulepair[0].setUuid(rule0Uuid); rulepair[0].setUuid(rule0Uuid);
rulepair[1].setUuid(rule1Uuid); 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 // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(2); when(storedRules.getResultCount()).thenReturn(2);
when(storedRules.getResults()).thenReturn(Arrays.asList(rulepair)); 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()); assertTrue(a.getResult());
verify(_nvpApi, atLeast(2)).deleteLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<UUID>() { verify(nvpApi, atLeast(2)).deleteLogicalRouterNatRule(eq("aaaaa"), argThat(new ArgumentMatcher<UUID>() {
@Override @Override
public boolean matches(Object argument) { public boolean matches(Object argument) {
UUID uuid = (UUID) argument; UUID uuid = (UUID) argument;
@ -745,7 +744,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testConfigurePortForwardingRulesOnLogicalRouterRollback() throws ConfigurationException, NiciraNvpApiException { public void testConfigurePortForwardingRulesOnLogicalRouterRollback() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -760,26 +759,26 @@ public class NiciraNvpResourceTest {
when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa"); when(cmd.getLogicalRouterUuid()).thenReturn("aaaaa");
// Mock the api create calls // 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[0].setUuid(UUID.randomUUID());
rulepair[1].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 // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(storedRules.getResultCount()).thenReturn(0); when(storedRules.getResultCount()).thenReturn(0);
when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules); when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) _resource.executeRequest(cmd); ConfigurePortForwardingRulesOnLogicalRouterAnswer a = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) resource.executeRequest(cmd);
assertFalse(a.getResult()); assertFalse(a.getResult());
verify(_nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq(rulepair[0].getUuid())); verify(nvpApi, atLeastOnce()).deleteLogicalRouterNatRule(eq("aaaaa"), eq(rulepair[0].getUuid()));
} }
@Test @Test
public void testConfigurePortForwardingRulesOnLogicalRouterPortRange() throws ConfigurationException, NiciraNvpApiException { public void testConfigurePortForwardingRulesOnLogicalRouterPortRange() throws ConfigurationException, NiciraNvpApiException {
_resource.configure("NiciraNvpResource", _parameters); resource.configure("NiciraNvpResource", parameters);
/* StaticNat /* StaticNat
* Outside IP: 11.11.11.11 * Outside IP: 11.11.11.11
* Inside IP: 10.10.10.10 * Inside IP: 10.10.10.10
@ -796,15 +795,15 @@ public class NiciraNvpResourceTest {
// Mock the api find call // Mock the api find call
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class); NiciraNvpList<NatRule> storedRules = mock(NiciraNvpList.class);
when(_nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules); when(nvpApi.findNatRulesByLogicalRouterUuid("aaaaa")).thenReturn(storedRules);
// Mock the api create calls // Mock the api create calls
NatRule[] rulepair = _resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 80, 85 }, "11.11.11.11", new int[] { 80, 85}, "tcp"); NatRule[] rulepair = resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 80, 85 }, "11.11.11.11", new int[] { 80, 85}, "tcp");
rulepair[0].setUuid(UUID.randomUUID()); rulepair[0].setUuid(UUID.randomUUID());
rulepair[1].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);
// The expected result is false, Nicira does not support port ranges in DNAT // The expected result is false, Nicira does not support port ranges in DNAT
assertFalse(a.getResult()); assertFalse(a.getResult());
@ -813,7 +812,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testGenerateStaticNatRulePair() { public void testGenerateStaticNatRulePair() {
NatRule[] rules = _resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11"); NatRule[] rules = resource.generateStaticNatRulePair("10.10.10.10", "11.11.11.11");
assertTrue("DestinationNatRule".equals(rules[0].getType())); assertTrue("DestinationNatRule".equals(rules[0].getType()));
assertTrue("SourceNatRule".equals(rules[1].getType())); assertTrue("SourceNatRule".equals(rules[1].getType()));
@ -830,7 +829,7 @@ public class NiciraNvpResourceTest {
@Test @Test
public void testGeneratePortForwardingRulePair() { public void testGeneratePortForwardingRulePair() {
NatRule[] rules = _resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 8080, 8080 }, "11.11.11.11", new int[] { 80, 80 }, "tcp" ); NatRule[] rules = resource.generatePortForwardingRulePair("10.10.10.10", new int[] { 8080, 8080 }, "11.11.11.11", new int[] { 80, 80 }, "tcp" );
assertTrue("DestinationNatRule".equals(rules[0].getType())); assertTrue("DestinationNatRule".equals(rules[0].getType()));
assertTrue("SourceNatRule".equals(rules[1].getType())); assertTrue("SourceNatRule".equals(rules[1].getType()));