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"/>
</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">
<!-- \s matches whitespace character, $ matches end of line. -->
<!-- \s matches whitespace character, $ matches end of line.-->
<property name="format" value="\s+$"/>
<property name="message" value="Line has trailing spaces."/>
</module>
<module name="TreeWalker">
<module name="RedundantImport"/>
<module name="UnusedImports"/>
</module>
<!-- some modules that we should soon add
<module name="MagicNumber"/> -->
<!-- some modules that we should soon add -->
</module>

View File

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

View File

@ -21,11 +21,16 @@ package com.cloud.agent.api;
*/
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);
}
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(Command command, Exception e) {
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(
final Command command,
final Exception e) {
super(command, e);
}

View File

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

View File

@ -18,11 +18,13 @@ package com.cloud.agent.api;
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);
}
public ConfigurePublicIpsOnLogicalRouterAnswer(Command command, Exception e) {
public ConfigurePublicIpsOnLogicalRouterAnswer(final Command command,
final Exception e) {
super(command, e);
}

View File

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

View File

@ -26,7 +26,8 @@ public class ConfigureStaticNatRulesOnLogicalRouterAnswer extends Answer {
* @param success
* @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);
}
@ -34,7 +35,8 @@ public class ConfigureStaticNatRulesOnLogicalRouterAnswer extends Answer {
* @param command
* @param e
*/
public ConfigureStaticNatRulesOnLogicalRouterAnswer(Command command, Exception e) {
public ConfigureStaticNatRulesOnLogicalRouterAnswer(final Command command,
final Exception e) {
super(command, e);
}

View File

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

View File

@ -21,20 +21,20 @@ package com.cloud.agent.api;
*/
public class CreateLogicalRouterAnswer extends Answer {
private String _logicalRouterUuid;
private String logicalRouterUuid;
public CreateLogicalRouterAnswer(Command command, boolean success,
String details, String logicalRouterUuid) {
public CreateLogicalRouterAnswer(final Command command, final boolean success,
final String details, final String logicalRouterUuid) {
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);
}
public String getLogicalRouterUuid() {
return _logicalRouterUuid;
return logicalRouterUuid;
}
}

View File

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

View File

@ -17,20 +17,20 @@
package com.cloud.agent.api;
public class CreateLogicalSwitchAnswer extends Answer {
private String _logicalSwitchUuid;
private String logicalSwitchUuid;
public CreateLogicalSwitchAnswer(Command command, boolean success,
String details, String logicalSwitchUuid) {
public CreateLogicalSwitchAnswer(final Command command, final boolean success,
final String details, final String logicalSwitchUuid) {
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);
}
public String getLogicalSwitchUuid() {
return _logicalSwitchUuid;
return logicalSwitchUuid;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -18,8 +18,6 @@ package com.cloud.api.commands;
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.ApiErrorCode;
@ -42,9 +40,9 @@ import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "addNiciraNvpDevice", responseObject=NiciraNvpDeviceResponse.class, description="Adds a Nicira NVP device")
public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(AddNiciraNvpDeviceCmd.class.getName());
private static final String s_name = "addniciranvpdeviceresponse";
@Inject NiciraNvpElementService _niciraNvpElementService;
@Inject
protected NiciraNvpElementService niciraNvpElementService;
/////////////////////////////////////////////////////
//////////////// 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")
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;
@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;
/////////////////////////////////////////////////////
@ -104,9 +104,9 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
NiciraNvpDeviceVO niciraNvpDeviceVO = _niciraNvpElementService.addNiciraNvpDevice(this);
NiciraNvpDeviceVO niciraNvpDeviceVO = niciraNvpElementService.addNiciraNvpDevice(this);
if (niciraNvpDeviceVO != null) {
NiciraNvpDeviceResponse response = _niciraNvpElementService.createNiciraNvpDeviceResponse(niciraNvpDeviceVO);
NiciraNvpDeviceResponse response = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraNvpDeviceVO);
response.setObjectName("niciranvpdevice");
response.setResponseName(getCommandName());
setResponseObject(response);

View File

@ -18,18 +18,17 @@ package com.cloud.api.commands;
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.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.context.CallContext;
import com.cloud.api.response.NiciraNvpDeviceResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
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")
public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(DeleteNiciraNvpDeviceCmd.class.getName());
private static final String s_name = "deleteniciranvpdeviceresponse";
@Inject NiciraNvpElementService _niciraNvpElementService;
@Inject
protected NiciraNvpElementService niciraNvpElementService;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
@ -68,7 +67,7 @@ public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
try {
boolean result = _niciraNvpElementService.deleteNiciraNvpDevice(this);
boolean result = niciraNvpElementService.deleteNiciraNvpDevice(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());

View File

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

View File

@ -21,19 +21,16 @@ import java.util.List;
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.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
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.APICommand;
import org.apache.cloudstack.api.response.ListResponse;
import com.cloud.api.response.NiciraNvpDeviceResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
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")
public class ListNiciraNvpDevicesCmd extends BaseListCmd {
private static final Logger s_logger = Logger.getLogger(ListNiciraNvpDevicesCmd.class.getName());
private static final String s_name = "listniciranvpdeviceresponse";
@Inject NiciraNvpElementService _niciraNvpElementService;
/////////////////////////////////////////////////////
@Inject
protected NiciraNvpElementService niciraNvpElementService;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ -77,15 +75,15 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd {
/////////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ResourceAllocationException {
try {
List<NiciraNvpDeviceVO> niciraDevices = _niciraNvpElementService.listNiciraNvpDevices(this);
List<NiciraNvpDeviceVO> niciraDevices = niciraNvpElementService.listNiciraNvpDevices(this);
ListResponse<NiciraNvpDeviceResponse> response = new ListResponse<NiciraNvpDeviceResponse>();
List<NiciraNvpDeviceResponse> niciraDevicesResponse = new ArrayList<NiciraNvpDeviceResponse>();
if (niciraDevices != null && !niciraDevices.isEmpty()) {
for (NiciraNvpDeviceVO niciraDeviceVO : niciraDevices) {
NiciraNvpDeviceResponse niciraDeviceResponse = _niciraNvpElementService.createNiciraNvpDeviceResponse(niciraDeviceVO);
NiciraNvpDeviceResponse niciraDeviceResponse = niciraNvpElementService.createNiciraNvpDeviceResponse(niciraDeviceVO);
niciraDevicesResponse.add(niciraDeviceResponse);
}
}

View File

@ -16,15 +16,13 @@
// under the License.
package com.cloud.api.response;
import com.google.gson.annotations.SerializedName;
import com.cloud.network.NiciraNvpDeviceVO;
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.EntityReference;
import com.cloud.network.NiciraNvpDeviceVO;
import com.cloud.serializer.Param;
@EntityReference(value=NiciraNvpDeviceVO.class)
public class NiciraNvpDeviceResponse extends BaseResponse {
@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;
public void setId(String nvpDeviceId) {
id = nvpDeviceId;
this.id = nvpDeviceId;
}
public void setPhysicalNetworkId(String physicalNetworkId) {
public void setPhysicalNetworkId(final String physicalNetworkId) {
this.physicalNetworkId = physicalNetworkId;
}
public void setProviderName(String providerName) {
public void setProviderName(final String providerName) {
this.providerName = providerName;
}
public void setDeviceName(String deviceName) {
public void setDeviceName(final String deviceName) {
this.deviceName = deviceName;
}
public void setHostName(String hostName) {
public void setHostName(final String hostName) {
this.hostName = hostName;
}
public void setTransportZoneUuid(String transportZoneUuid) {
public void setTransportZoneUuid(final String transportZoneUuid) {
this.transportZoneUuid = transportZoneUuid;
}
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) {
public void setL3GatewayServiceUuid(final String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -66,30 +66,32 @@ import com.cloud.vm.VirtualMachineProfile;
@Local(value = NetworkGuru.class)
public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
private static final int MAX_NAME_LENGTH = 40;
private static final Logger s_logger = Logger.getLogger(NiciraNvpGuestNetworkGuru.class);
@Inject
NetworkModel _networkModel;
protected NetworkModel networkModel;
@Inject
NetworkDao _networkDao;
protected NetworkDao networkDao;
@Inject
DataCenterDao _zoneDao;
protected DataCenterDao zoneDao;
@Inject
PhysicalNetworkDao _physicalNetworkDao;
protected PhysicalNetworkDao physicalNetworkDao;
@Inject
AccountDao _accountDao;
protected AccountDao accountDao;
@Inject
NiciraNvpDao _niciraNvpDao;
protected NiciraNvpDao niciraNvpDao;
@Inject
HostDao _hostDao;
protected HostDao hostDao;
@Inject
ResourceManager _resourceMgr;
protected ResourceManager resourceMgr;
@Inject
AgentManager _agentMgr;
protected AgentManager agentMgr;
@Inject
HostDetailsDao _hostDetailsDao;
protected HostDetailsDao hostDetailsDao;
@Inject
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
protected NetworkOfferingServiceMapDao ntwkOfferingSrvcDao;
public NiciraNvpGuestNetworkGuru() {
super();
@ -97,13 +99,13 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
}
@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
if (networkType == NetworkType.Advanced
&& isMyTrafficType(offering.getTrafficType())
&& offering.getGuestType() == Network.GuestType.Isolated
&& isMyIsolationMethod(physicalNetwork)
&& _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
&& ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
return true;
} else {
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
public Network design(NetworkOffering offering, DeploymentPlan plan,
Network userSpecified, Account owner) {
public Network design(final NetworkOffering offering, final DeploymentPlan plan,
final Network userSpecified, final Account owner) {
// 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());
if (!canHandle(offering, dc.getNetworkType(), physnet)) {
s_logger.debug("Refusing to design this network");
return null;
}
List<NiciraNvpDeviceVO> devices = _niciraNvpDao.listByPhysicalNetwork(physnet.getId());
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(physnet.getId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + physnet.getName());
return null;
@ -141,8 +143,8 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
}
@Override
public Network implement(Network network, NetworkOffering offering,
DeployDestination dest, ReservationContext context)
public Network implement(final Network network, final NetworkOffering offering,
final DeployDestination dest, final ReservationContext context)
throws InsufficientVirtualNetworkCapcityException {
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
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,
@ -172,24 +174,24 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
if (name == null || name.isEmpty()) {
name = ((NetworkVO)network).getUuid();
}
if (name.length() > 40) {
name = name.substring(0, 39); // max length 40
if (name.length() > MAX_NAME_LENGTH) {
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()) {
s_logger.error("No NiciraNvp Controller on physical network " + physicalNetworkId);
return null;
}
NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
HostVO niciraNvpHost = _hostDao.findById(niciraNvpDevice.getHostId());
_hostDao.loadDetails(niciraNvpHost);
HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
hostDao.loadDetails(niciraNvpHost);
String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name,
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()) {
s_logger.error("CreateLogicalSwitchCommand failed");
@ -209,9 +211,8 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
}
@Override
public void reserve(NicProfile nic, Network network,
VirtualMachineProfile vm,
DeployDestination dest, ReservationContext context)
public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm,
final DeployDestination dest, final ReservationContext context)
throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
// TODO Auto-generated method stub
@ -219,32 +220,30 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
}
@Override
public boolean release(NicProfile nic,
VirtualMachineProfile vm,
String reservationId) {
public boolean release(final NicProfile nic, final VirtualMachineProfile vm, final String reservationId) {
// TODO Auto-generated method stub
return super.release(nic, vm, reservationId);
}
@Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
NetworkVO networkObject = _networkDao.findById(profile.getId());
public void shutdown(final NetworkProfile profile, final NetworkOffering offering) {
NetworkVO networkObject = networkDao.findById(profile.getId());
if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Lswitch ||
networkObject.getBroadcastUri() == null) {
s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork " + networkObject.getDisplayText());
return;
}
List<NiciraNvpDeviceVO> devices = _niciraNvpDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId());
List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(networkObject.getPhysicalNetworkId());
if (devices.isEmpty()) {
s_logger.error("No NiciraNvp Controller on physical network " + networkObject.getPhysicalNetworkId());
return;
}
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()));
DeleteLogicalSwitchAnswer answer = (DeleteLogicalSwitchAnswer) _agentMgr.easySend(niciraNvpHost.getId(), cmd);
DeleteLogicalSwitchAnswer answer = (DeleteLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
if (answer == null || !answer.getResult()) {
s_logger.error("DeleteLogicalSwitchCommand failed");
@ -254,7 +253,7 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
}
@Override
public boolean trash(Network network, NetworkOffering offering) {
public boolean trash(final Network network, final NetworkOffering offering) {
return super.trash(network, offering);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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