Fix checkstyle errors in Nicira NVP plugin

This commit is contained in:
Hugo Trippaers 2013-11-04 15:23:02 +01:00
parent f39b6b2c56
commit 256763cf65
60 changed files with 2894 additions and 2898 deletions

View File

@ -36,5 +36,5 @@
<bean id="NiciraNvp" class="com.cloud.network.element.NiciraNvpElement">
<property name="name" value="NiciraNvp" />
</bean>
</beans>

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,18 +17,16 @@
package com.cloud.agent.api;
/**
*
*
*/
public class ConfigurePortForwardingRulesOnLogicalRouterAnswer extends Answer {
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(Command command,
boolean success, String details) {
super(command, success, details);
}
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(Command command, boolean success, String details) {
super(command, success, details);
}
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(Command command,
Exception e) {
super(command, e);
}
public ConfigurePortForwardingRulesOnLogicalRouterAnswer(Command command, Exception e) {
super(command, e);
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -21,40 +21,41 @@ import java.util.List;
import com.cloud.agent.api.to.PortForwardingRuleTO;
/**
*
*
*/
public class ConfigurePortForwardingRulesOnLogicalRouterCommand extends Command {
private String logicalRouterUuid;
private List<PortForwardingRuleTO> rules;
public ConfigurePortForwardingRulesOnLogicalRouterCommand(String logicalRouterUuid, List<PortForwardingRuleTO> rules) {
this.logicalRouterUuid = logicalRouterUuid;
this.rules = rules;
}
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
private String logicalRouterUuid;
private List<PortForwardingRuleTO> rules;
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
public ConfigurePortForwardingRulesOnLogicalRouterCommand(String logicalRouterUuid, List<PortForwardingRuleTO> rules) {
this.logicalRouterUuid = logicalRouterUuid;
this.rules = rules;
}
public List<PortForwardingRuleTO> getRules() {
return rules;
}
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
public void setRules(List<PortForwardingRuleTO> rules) {
this.rules = rules;
}
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
/* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence()
*/
@Override
public boolean executeInSequence() {
return false;
}
public List<PortForwardingRuleTO> getRules() {
return rules;
}
public void setRules(List<PortForwardingRuleTO> rules) {
this.rules = rules;
}
/*
* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence()
*/
@Override
public boolean executeInSequence() {
return false;
}
}

View File

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

View File

@ -19,47 +19,45 @@ package com.cloud.agent.api;
import java.util.List;
public class ConfigurePublicIpsOnLogicalRouterCommand extends Command {
private String logicalRouterUuid;
private String l3GatewayServiceUuid;
private List<String> publicCidrs;
public ConfigurePublicIpsOnLogicalRouterCommand(String logicalRouterUuid,
String l3GatewayServiceUuid,
List<String> publicCidrs) {
super();
this.logicalRouterUuid = logicalRouterUuid;
this.publicCidrs = publicCidrs;
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
private String logicalRouterUuid;
private String l3GatewayServiceUuid;
private List<String> publicCidrs;
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
public String getL3GatewayServiceUuid() {
return l3GatewayServiceUuid;
}
public ConfigurePublicIpsOnLogicalRouterCommand(String logicalRouterUuid, String l3GatewayServiceUuid, List<String> publicCidrs) {
super();
this.logicalRouterUuid = logicalRouterUuid;
this.publicCidrs = publicCidrs;
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
public List<String> getPublicCidrs() {
return publicCidrs;
}
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
public void setPublicCidrs(List<String> publicCidrs) {
this.publicCidrs = publicCidrs;
}
public String getL3GatewayServiceUuid() {
return l3GatewayServiceUuid;
}
@Override
public boolean executeInSequence() {
return false;
}
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}
public List<String> getPublicCidrs() {
return publicCidrs;
}
public void setPublicCidrs(List<String> publicCidrs) {
this.publicCidrs = publicCidrs;
}
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,27 +17,25 @@
package com.cloud.agent.api;
/**
*
*
*/
public class ConfigureStaticNatRulesOnLogicalRouterAnswer extends Answer {
/**
* @param command
* @param success
* @param details
*/
public ConfigureStaticNatRulesOnLogicalRouterAnswer(Command command,
boolean success, String details) {
super(command, success, details);
}
/**
* @param command
* @param success
* @param details
*/
public ConfigureStaticNatRulesOnLogicalRouterAnswer(Command command, boolean success, String details) {
super(command, success, details);
}
/**
* @param command
* @param e
*/
public ConfigureStaticNatRulesOnLogicalRouterAnswer(Command command,
Exception e) {
super(command, e);
}
/**
* @param command
* @param e
*/
public ConfigureStaticNatRulesOnLogicalRouterAnswer(Command command, Exception e) {
super(command, e);
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -21,43 +21,43 @@ import java.util.List;
import com.cloud.agent.api.to.StaticNatRuleTO;
/**
*
*
*/
public class ConfigureStaticNatRulesOnLogicalRouterCommand extends Command {
private String logicalRouterUuid;
private List<StaticNatRuleTO> rules;
public ConfigureStaticNatRulesOnLogicalRouterCommand(
String logicalRouterUuid, List<StaticNatRuleTO> rules) {
super();
this.logicalRouterUuid = logicalRouterUuid;
this.rules = rules;
private String logicalRouterUuid;
private List<StaticNatRuleTO> rules;
}
public ConfigureStaticNatRulesOnLogicalRouterCommand(String logicalRouterUuid, List<StaticNatRuleTO> rules) {
super();
this.logicalRouterUuid = logicalRouterUuid;
this.rules = rules;
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
}
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
public List<StaticNatRuleTO> getRules() {
return rules;
}
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
public void setRules(List<StaticNatRuleTO> rules) {
this.rules = rules;
}
public List<StaticNatRuleTO> getRules() {
return rules;
}
/* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence()
*/
@Override
public boolean executeInSequence() {
return false;
}
public void setRules(List<StaticNatRuleTO> rules) {
this.rules = rules;
}
/*
* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence()
*/
@Override
public boolean executeInSequence() {
return false;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,7 +17,7 @@
package com.cloud.agent.api;
/**
*
*
*/
public class CreateLogicalRouterAnswer extends Answer {
@ -26,9 +26,9 @@ public class CreateLogicalRouterAnswer extends Answer {
public CreateLogicalRouterAnswer(Command command, boolean success,
String details, String logicalRouterUuid) {
super(command, success, details);
this._logicalRouterUuid = logicalRouterUuid;
_logicalRouterUuid = logicalRouterUuid;
}
public CreateLogicalRouterAnswer(Command command, Exception e) {
super(command, e);
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,99 +17,99 @@
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;
public CreateLogicalRouterCommand(String gatewayServiceUuid, long vlanId,
String logicalSwitchUuid, String name,
String publicIpCidr, String publicNextHop,
String internalIpCidr, String ownerName) {
super();
this._gatewayServiceUuid = gatewayServiceUuid;
this._logicalSwitchUuid = logicalSwitchUuid;
this._vlanId = vlanId;
this._name = name;
this._ownerName = ownerName;
this._publicIpCidr = publicIpCidr;
this._publicNextHop = publicNextHop;
this._internalIpCidr = 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) {
super();
_gatewayServiceUuid = gatewayServiceUuid;
_logicalSwitchUuid = logicalSwitchUuid;
_vlanId = vlanId;
_name = name;
_ownerName = ownerName;
_publicIpCidr = publicIpCidr;
_publicNextHop = publicNextHop;
_internalIpCidr = internalIpCidr;
}
@Override
public boolean executeInSequence() {
return false;
}
public String getGatewayServiceUuid() {
return _gatewayServiceUuid;
}
public String getGatewayServiceUuid() {
return _gatewayServiceUuid;
}
public void setGatewayServiceUuid(String gatewayServiceUuid) {
this._gatewayServiceUuid = gatewayServiceUuid;
}
public String getLogicalSwitchUuid() {
return _logicalSwitchUuid;
}
public void setLogicalSwitchUuid(String logicalSwitchUuid) {
_logicalSwitchUuid = logicalSwitchUuid;
}
public void setGatewayServiceUuid(String gatewayServiceUuid) {
_gatewayServiceUuid = gatewayServiceUuid;
}
public long getVlanId() {
return _vlanId;
}
public String getLogicalSwitchUuid() {
return _logicalSwitchUuid;
}
public void setVlanId(long vlanId) {
this._vlanId = vlanId;
}
public void setLogicalSwitchUuid(String logicalSwitchUuid) {
_logicalSwitchUuid = logicalSwitchUuid;
}
public String getName() {
return _name;
}
public long getVlanId() {
return _vlanId;
}
public void setName(String name) {
this._name = name;
}
public void setVlanId(long vlanId) {
_vlanId = vlanId;
}
public String getOwnerName() {
return _ownerName;
}
public String getName() {
return _name;
}
public void setOwnerName(String ownerName) {
this._ownerName = ownerName;
}
public void setName(String name) {
_name = name;
}
public String getPublicIpCidr() {
return _publicIpCidr;
}
public String getOwnerName() {
return _ownerName;
}
public void setPublicIpCidr(String publicIpCidr) {
this._publicIpCidr = publicIpCidr;
}
public void setOwnerName(String ownerName) {
_ownerName = ownerName;
}
public String getInternalIpCidr() {
return _internalIpCidr;
}
public String getPublicIpCidr() {
return _publicIpCidr;
}
public void setInternalIpCidr(String internalIpCidr) {
this._internalIpCidr = internalIpCidr;
}
public String getPublicNextHop() {
return _publicNextHop;
}
public void setPublicNextHop(String publicNextHop) {
this._publicNextHop = publicNextHop;
}
public void setPublicIpCidr(String publicIpCidr) {
_publicIpCidr = publicIpCidr;
}
public String getInternalIpCidr() {
return _internalIpCidr;
}
public void setInternalIpCidr(String internalIpCidr) {
_internalIpCidr = internalIpCidr;
}
public String getPublicNextHop() {
return _publicNextHop;
}
public void setPublicNextHop(String publicNextHop) {
_publicNextHop = publicNextHop;
}
}

View File

@ -22,9 +22,9 @@ public class CreateLogicalSwitchAnswer extends Answer {
public CreateLogicalSwitchAnswer(Command command, boolean success,
String details, String logicalSwitchUuid) {
super(command, success, details);
this._logicalSwitchUuid = logicalSwitchUuid;
_logicalSwitchUuid = logicalSwitchUuid;
}
public CreateLogicalSwitchAnswer(Command command, Exception e) {
super(command, e);
}

View File

@ -17,17 +17,17 @@
package com.cloud.agent.api;
public class CreateLogicalSwitchCommand extends Command {
private String _transportUuid;
private String _transportType;
private String _name;
private String _ownerName;
public CreateLogicalSwitchCommand(String transportUuid, String transportType, String name, String ownerName) {
this._transportUuid = transportUuid;
this._transportType = transportType;
this._name = name;
this._ownerName = ownerName;
_transportUuid = transportUuid;
_transportType = transportType;
_name = name;
_ownerName = ownerName;
}
@Override

View File

@ -22,9 +22,9 @@ public class CreateLogicalSwitchPortAnswer extends Answer {
public CreateLogicalSwitchPortAnswer(Command command, boolean success,
String details, String localSwitchPortUuid) {
super(command, success, details);
this._logicalSwitchPortUuid = localSwitchPortUuid;
_logicalSwitchPortUuid = localSwitchPortUuid;
}
public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid;
}
@ -32,5 +32,5 @@ public class CreateLogicalSwitchPortAnswer extends Answer {
public CreateLogicalSwitchPortAnswer(Command command, Exception e) {
super(command, e);
}
}

View File

@ -21,15 +21,15 @@ public class CreateLogicalSwitchPortCommand extends Command {
private String _attachmentUuid;
private String _ownerName;
private String _nicName;
public CreateLogicalSwitchPortCommand(String logicalSwitchUuid, String attachmentUuid, String ownerName, String nicName) {
this._logicalSwitchUuid = logicalSwitchUuid;
this._attachmentUuid = attachmentUuid;
this._ownerName = ownerName;
this._nicName = nicName;
_logicalSwitchUuid = logicalSwitchUuid;
_attachmentUuid = attachmentUuid;
_ownerName = ownerName;
_nicName = nicName;
}
public String getLogicalSwitchUuid() {
return _logicalSwitchUuid;
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,10 +17,10 @@
package com.cloud.agent.api;
/**
*
*
*/
public class DeleteLogicalRouterAnswer extends Answer {
public DeleteLogicalRouterAnswer(Command command, boolean success,
String details) {
super(command, success, details);

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,25 +17,26 @@
package com.cloud.agent.api;
/**
*
*
*/
public class DeleteLogicalRouterCommand extends Command {
private String _logicalRouterUuid;
public DeleteLogicalRouterCommand(String logicalRouterUuid) {
this._logicalRouterUuid = logicalRouterUuid;
}
/* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence()
*/
@Override
public boolean executeInSequence() {
return false;
}
private String _logicalRouterUuid;
public String getLogicalRouterUuid() {
return _logicalRouterUuid;
}
public DeleteLogicalRouterCommand(String logicalRouterUuid) {
_logicalRouterUuid = logicalRouterUuid;
}
/*
* (non-Javadoc)
* @see com.cloud.agent.api.Command#executeInSequence()
*/
@Override
public boolean executeInSequence() {
return false;
}
public String getLogicalRouterUuid() {
return _logicalRouterUuid;
}
}

View File

@ -17,11 +17,11 @@
package com.cloud.agent.api;
public class DeleteLogicalSwitchCommand extends Command {
private String _logicalSwitchUuid;
public DeleteLogicalSwitchCommand(String logicalSwitchUuid) {
this._logicalSwitchUuid = logicalSwitchUuid;
_logicalSwitchUuid = logicalSwitchUuid;
}
@Override

View File

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

View File

@ -22,9 +22,9 @@ public class FindLogicalSwitchPortAnswer extends Answer {
public FindLogicalSwitchPortAnswer(Command command, boolean success,
String details, String localSwitchPortUuid) {
super(command, success, details);
this._logicalSwitchPortUuid = localSwitchPortUuid;
_logicalSwitchPortUuid = localSwitchPortUuid;
}
public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid;
}
@ -32,5 +32,5 @@ public class FindLogicalSwitchPortAnswer extends Answer {
public FindLogicalSwitchPortAnswer(Command command, Exception e) {
super(command, e);
}
}

View File

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

View File

@ -22,9 +22,9 @@ public class UpdateLogicalSwitchPortAnswer extends Answer {
public UpdateLogicalSwitchPortAnswer(Command command, boolean success,
String details, String localSwitchPortUuid) {
super(command, success, details);
this._logicalSwitchPortUuid = localSwitchPortUuid;
_logicalSwitchPortUuid = localSwitchPortUuid;
}
public String getLogicalSwitchPortUuid() {
return _logicalSwitchPortUuid;
}
@ -32,5 +32,5 @@ public class UpdateLogicalSwitchPortAnswer extends Answer {
public UpdateLogicalSwitchPortAnswer(Command command, Exception e) {
super(command, e);
}
}

View File

@ -22,16 +22,16 @@ public class UpdateLogicalSwitchPortCommand extends Command {
private String _attachmentUuid;
private String _ownerName;
private String _nicName;
public UpdateLogicalSwitchPortCommand(String logicalSwitchPortUuid, String logicalSwitchUuid, String attachmentUuid, String ownerName, String nicName) {
this._logicalSwitchUuid = logicalSwitchUuid;
this._logicalSwitchPortUuid = logicalSwitchPortUuid;
this._attachmentUuid = attachmentUuid;
this._ownerName = ownerName;
this._nicName = nicName;
_logicalSwitchUuid = logicalSwitchUuid;
_logicalSwitchPortUuid = logicalSwitchPortUuid;
_attachmentUuid = attachmentUuid;
_ownerName = ownerName;
_nicName = nicName;
}
public String getLogicalSwitchUuid() {
return _logicalSwitchUuid;
}

View File

@ -18,12 +18,15 @@ package com.cloud.api.commands;
import javax.inject.Inject;
import org.apache.cloudstack.api.*;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
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.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import org.apache.cloudstack.context.CallContext;
import com.cloud.api.response.NiciraNvpDeviceResponse;
@ -42,7 +45,7 @@ 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;
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ -56,16 +59,16 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to access the Nicira Controller API")
private String username;
@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")
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")
private String l3gatewayserviceuuid;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@ -85,13 +88,13 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
public String getPassword() {
return password;
}
public String getTransportzoneUuid() {
return transportzoneuuid;
}
public String getL3GatewayServiceUuid() {
return l3gatewayserviceuuid;
return l3gatewayserviceuuid;
}
/////////////////////////////////////////////////////
@ -106,7 +109,7 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
NiciraNvpDeviceResponse response = _niciraNvpElementService.createNiciraNvpDeviceResponse(niciraNvpDeviceVO);
response.setObjectName("niciranvpdevice");
response.setResponseName(getCommandName());
this.setResponseObject(response);
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nicira NVP device due to internal error.");
}
@ -116,7 +119,7 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
@Override
public String getCommandName() {
return s_name;
@ -127,13 +130,13 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
return CallContext.current().getCallingAccount().getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_NVP_CONTROLLER_ADD;
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_NVP_CONTROLLER_ADD;
}
@Override
public String getEventDescription() {
return "Adding a Nicira Nvp Controller";
}
@Override
public String getEventDescription() {
return "Adding a Nicira Nvp Controller";
}
}

View File

@ -18,20 +18,18 @@ package com.cloud.api.commands;
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.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
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;
@ -74,7 +72,7 @@ public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
this.setResponseObject(response);
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Nicira device.");
}
@ -95,14 +93,14 @@ public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
return CallContext.current().getCallingAccount().getId();
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_NVP_CONTROLLER_DELETE;
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_NVP_CONTROLLER_DELETE;
}
@Override
public String getEventDescription() {
return "Deleting Nicira Nvp Controller";
}
@Override
public String getEventDescription() {
return "Deleting Nicira Nvp Controller";
}
}

View File

@ -21,18 +21,18 @@ 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.BaseCmd;
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;
@ -85,7 +85,7 @@ public class ListNiciraNvpDeviceNetworksCmd extends BaseListCmd {
response.setResponses(networkResponses);
response.setResponseName(getCommandName());
this.setResponseObject(response);
setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {

View File

@ -21,17 +21,17 @@ import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
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 com.cloud.api.response.NiciraNvpDeviceResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@ -48,7 +48,7 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd {
private static final String s_name = "listniciranvpdeviceresponse";
@Inject NiciraNvpElementService _niciraNvpElementService;
/////////////////////////////////////////////////////
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@ -92,7 +92,7 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd {
response.setResponses(niciraDevicesResponse);
response.setResponseName(getCommandName());
this.setResponseObject(response);
setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
@ -104,5 +104,5 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd {
public String getCommandName() {
return s_name;
}
}

View File

@ -16,13 +16,15 @@
// under the License.
package com.cloud.api.response;
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.ApiConstants;
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")
@ -47,7 +49,7 @@ public class NiciraNvpDeviceResponse extends BaseResponse {
private String l3GatewayServiceUuid;
public void setId(String nvpDeviceId) {
this.id = nvpDeviceId;
id = nvpDeviceId;
}
public void setPhysicalNetworkId(String physicalNetworkId) {
@ -62,18 +64,16 @@ public class NiciraNvpDeviceResponse extends BaseResponse {
this.deviceName = deviceName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public void setTransportZoneUuid(String transportZoneUuid) {
this.transportZoneUuid = transportZoneUuid;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
public void setTransportZoneUuid(String transportZoneUuid) {
this.transportZoneUuid = transportZoneUuid;
}
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}
public void setL3GatewayServiceUuid(String l3GatewayServiceUuid) {
this.l3GatewayServiceUuid = l3GatewayServiceUuid;
}
}

View File

@ -16,8 +16,6 @@
// under the License.
package com.cloud.network;
import org.apache.cloudstack.api.InternalIdentity;
import java.util.UUID;
import javax.persistence.Column;
@ -27,6 +25,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="external_nicira_nvp_devices")
public class NiciraNvpDeviceVO implements InternalIdentity {
@ -35,25 +35,25 @@ public class NiciraNvpDeviceVO implements InternalIdentity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private long id;
@Column(name="uuid")
private String uuid;
@Column(name="host_id")
private long hostId;
@Column(name="physical_network_id")
private long physicalNetworkId;
@Column(name="provider_name")
private String providerName;
@Column(name="device_name")
private String deviceName;
public NiciraNvpDeviceVO() {
this.uuid = UUID.randomUUID().toString();
uuid = UUID.randomUUID().toString();
}
public NiciraNvpDeviceVO(long hostId, long physicalNetworkId,
@ -63,13 +63,14 @@ public class NiciraNvpDeviceVO implements InternalIdentity {
this.physicalNetworkId = physicalNetworkId;
this.providerName = providerName;
this.deviceName = deviceName;
this.uuid = UUID.randomUUID().toString();
uuid = UUID.randomUUID().toString();
}
@Override
public long getId() {
return id;
}
public String getUuid() {
return uuid;
}
@ -93,5 +94,5 @@ public class NiciraNvpDeviceVO implements InternalIdentity {
public String getDeviceName() {
return deviceName;
}
}

View File

@ -16,8 +16,6 @@
// under the License.
package com.cloud.network;
import org.apache.cloudstack.api.InternalIdentity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@ -25,6 +23,8 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="nicira_nvp_nic_map")
public class NiciraNvpNicMappingVO implements InternalIdentity {
@ -36,16 +36,16 @@ public class NiciraNvpNicMappingVO implements InternalIdentity {
@Column(name="logicalswitch")
private String logicalSwitchUuid;
@Column(name="logicalswitchport")
private String logicalSwitchPortUuid;
@Column(name="nic")
private String nicUuid;
public NiciraNvpNicMappingVO () {
public NiciraNvpNicMappingVO () {
}
public NiciraNvpNicMappingVO (String logicalSwitchUuid, String logicalSwitchPortUuid, String nicUuid) {
this.logicalSwitchUuid = logicalSwitchUuid;
this.logicalSwitchPortUuid = logicalSwitchPortUuid;
@ -76,8 +76,9 @@ public class NiciraNvpNicMappingVO implements InternalIdentity {
this.nicUuid = nicUuid;
}
@Override
public long getId() {
return id;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -16,8 +16,6 @@
// under the License.
package com.cloud.network;
import org.apache.cloudstack.api.InternalIdentity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
@ -25,57 +23,59 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
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")
private long id;
@Column(name="logicalrouter_uuid")
private String logicalRouterUuid;
@Column(name="network_id")
private long networkId;
public NiciraNvpRouterMappingVO() {
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private long id;
public NiciraNvpRouterMappingVO(String logicalRouterUuid, long networkId) {
this.logicalRouterUuid = logicalRouterUuid;
this.networkId = networkId;
}
public NiciraNvpRouterMappingVO(long id, String logicalRouterUuid, long networkId) {
this.id = id;
this.logicalRouterUuid = logicalRouterUuid;
this.networkId = networkId;
}
@Column(name="logicalrouter_uuid")
private String logicalRouterUuid;
public long getId() {
return id;
}
@Column(name="network_id")
private long networkId;
public void setId(long id) {
this.id = id;
}
public NiciraNvpRouterMappingVO() {
}
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
public NiciraNvpRouterMappingVO(String logicalRouterUuid, long networkId) {
this.logicalRouterUuid = logicalRouterUuid;
this.networkId = networkId;
}
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
public NiciraNvpRouterMappingVO(long id, String logicalRouterUuid, long networkId) {
this.id = id;
this.logicalRouterUuid = logicalRouterUuid;
this.networkId = networkId;
}
public long getNetworkId() {
return networkId;
}
@Override
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getLogicalRouterUuid() {
return logicalRouterUuid;
}
public void setLogicalRouterUuid(String logicalRouterUuid) {
this.logicalRouterUuid = logicalRouterUuid;
}
public long getNetworkId() {
return networkId;
}
public void setNetworkId(long networkId) {
this.networkId = networkId;
}
public void setNetworkId(long networkId) {
this.networkId = networkId;
}
}

View File

@ -31,10 +31,10 @@ 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;
public NiciraNvpDaoImpl() {
physicalNetworkIdSearch = createSearchBuilder();
physicalNetworkIdSearch.and("physicalNetworkId", physicalNetworkIdSearch.entity().getPhysicalNetworkId(), Op.EQ);

View File

@ -21,9 +21,12 @@ 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,16 +29,16 @@ 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;
public NiciraNvpNicMappingDaoImpl() {
nicSearch = createSearchBuilder();
nicSearch.and("nicUuid", nicSearch.entity().getNicUuid(), Op.EQ);
nicSearch.done();
}
@Override
public NiciraNvpNicMappingVO findByNicUuid(String nicUuid) {
SearchCriteria<NiciraNvpNicMappingVO> sc = nicSearch.create();

View File

@ -21,5 +21,5 @@ import com.cloud.utils.db.GenericDao;
public interface NiciraNvpRouterMappingDao extends GenericDao<NiciraNvpRouterMappingVO, Long> {
public NiciraNvpRouterMappingVO findByNetworkId(long id);
public NiciraNvpRouterMappingVO findByNetworkId(long id);
}

View File

@ -30,20 +30,19 @@ import com.cloud.utils.db.SearchCriteria.Op;
@Local(value=NiciraNvpRouterMappingDao.class)
public class NiciraNvpRouterMappingDaoImpl extends GenericDaoBase<NiciraNvpRouterMappingVO, Long> implements NiciraNvpRouterMappingDao {
protected final SearchBuilder<NiciraNvpRouterMappingVO> networkSearch;
public NiciraNvpRouterMappingDaoImpl() {
networkSearch = createSearchBuilder();
networkSearch.and("network_id", networkSearch.entity().getNetworkId(), Op.EQ);
networkSearch.done();
}
@Override
public NiciraNvpRouterMappingVO findByNetworkId(long id) {
SearchCriteria<NiciraNvpRouterMappingVO> sc = networkSearch.create();
sc.setParameters("network_id", id);
return findOneBy(sc);
}
protected final SearchBuilder<NiciraNvpRouterMappingVO> networkSearch;
public NiciraNvpRouterMappingDaoImpl() {
networkSearch = createSearchBuilder();
networkSearch.and("network_id", networkSearch.entity().getNetworkId(), Op.EQ);
networkSearch.done();
}
@Override
public NiciraNvpRouterMappingVO findByNetworkId(long id) {
SearchCriteria<NiciraNvpRouterMappingVO> sc = networkSearch.create();
sc.setParameters("network_id", id);
return findOneBy(sc);
}
}

View File

@ -30,6 +30,7 @@ import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
@ -128,9 +129,9 @@ 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 Logger s_logger = Logger
.getLogger(NiciraNvpElement.class);
@ -217,8 +218,8 @@ public class NiciraNvpElement extends AdapterBase implements
@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 "
@ -247,17 +248,6 @@ public class NiciraNvpElement extends AdapterBase implements
Account owner = context.getAccount();
/**
* Lock the network as we might need to do multiple operations that
* should be done only once.
*/
// Network lock = _networkDao.acquireInLockTable(network.getId(),
// _networkModel.getNetworkLockTimeout());
// if (lock == null) {
// throw new ConcurrentOperationException("Unable to lock network "
// + network.getId());
// }
// Implement SourceNat immediately as we have al the info already
if (_networkModel.isProviderSupportServiceInNetwork(
network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
@ -277,9 +267,9 @@ public class NiciraNvpElement extends AdapterBase implements
BroadcastDomainType.getValue(network.getBroadcastUri()),
"router-" + network.getDisplayText(), publicCidr,
sourceNatIp.getGateway(), internalCidr, context
.getDomain().getName()
+ "-"
+ context.getAccount().getAccountName());
.getDomain().getName()
+ "-"
+ context.getAccount().getAccountName());
CreateLogicalRouterAnswer answer = (CreateLogicalRouterAnswer)_agentMgr
.easySend(niciraNvpHost.getId(), cmd);
if (answer.getResult() == false) {
@ -343,7 +333,7 @@ public class NiciraNvpElement extends AdapterBase implements
BroadcastDomainType.getValue(network.getBroadcastUri()),
nicVO.getUuid(), context.getDomain().getName() + "-"
+ context.getAccount().getAccountName(),
nic.getName());
nic.getName());
_agentMgr.easySend(niciraNvpHost.getId(), cmd);
return true;
} else {
@ -489,7 +479,7 @@ public class NiciraNvpElement extends AdapterBase implements
@Override
public boolean shutdownProviderInstances(
PhysicalNetworkServiceProvider provider, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException {
throws ConcurrentOperationException, ResourceUnavailableException {
// Nothing to do here.
return true;
}
@ -618,7 +608,7 @@ public class NiciraNvpElement extends AdapterBase implements
physicalNetworkId, ntwkSvcProvider.getProviderName(),
deviceName);
_niciraNvpDao.persist(niciraNvpDevice);
DetailVO detail = new DetailVO(host.getId(),
"niciranvpdeviceid", String.valueOf(niciraNvpDevice
.getId()));
@ -818,7 +808,7 @@ public class NiciraNvpElement extends AdapterBase implements
@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
@ -869,7 +859,7 @@ public class NiciraNvpElement extends AdapterBase implements
@Override
public boolean applyStaticNats(Network network,
List<? extends StaticNat> rules)
throws ResourceUnavailableException {
throws ResourceUnavailableException {
if (!canHandle(network, Service.StaticNat)) {
return false;
}

View File

@ -62,7 +62,6 @@ import com.cloud.user.Account;
import com.cloud.user.dao.AccountDao;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Local(value = NetworkGuru.class)

View File

@ -17,66 +17,68 @@
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;
public String getClusterStatus() {
return cluster_status;
}
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;
public Stats getNodeStats() {
return node_stats;
}
public String getClusterStatus() {
return cluster_status;
}
public Stats getLqueueStats() {
return lqueue_stats;
}
public Stats getNodeStats() {
return node_stats;
}
public Stats getLportStats() {
return lport_stats;
}
public Stats getLqueueStats() {
return lqueue_stats;
}
public Stats getLrouterportStats() {
return lrouterport_stats;
}
public Stats getLportStats() {
return lport_stats;
}
public Stats getLswitchStats() {
return lswitch_stats;
}
public Stats getLrouterportStats() {
return lrouterport_stats;
}
public Stats getZoneStats() {
return zone_stats;
}
public Stats getLswitchStats() {
return lswitch_stats;
}
public Stats getLrouterStats() {
return lrouter_stats;
}
public Stats getZoneStats() {
return zone_stats;
}
public Stats getSecurityProfileStats() {
return security_profile_stats;
}
public Stats getLrouterStats() {
return lrouter_stats;
}
public class Stats {
private int error_state_count;
private int registered_count;
private int active_count;
public int getErrorStateCount() {
return error_state_count;
}
public int getRegisteredCount() {
return registered_count;
}
public int getActiveCount() {
return active_count;
}
}
public Stats getSecurityProfileStats() {
return security_profile_stats;
}
public class Stats {
private int error_state_count;
private int registered_count;
private int active_count;
public int getErrorStateCount() {
return error_state_count;
}
public int getRegisteredCount() {
return registered_count;
}
public int getActiveCount() {
return active_count;
}
}
}

View File

@ -19,7 +19,7 @@ package com.cloud.network.nicira;
public class DestinationNatRule extends NatRule {
private String toDestinationIpAddress;
private Integer toDestinationPort;
public DestinationNatRule() {
setType("DestinationNatRule");
}
@ -28,17 +28,14 @@ public class DestinationNatRule extends NatRule {
return toDestinationIpAddress;
}
public void setToDestinationIpAddress(String toDestinationIpAddress) {
this.toDestinationIpAddress = toDestinationIpAddress;
}
public Integer getToDestinationPort() {
return toDestinationPort;
}
public void setToDestinationPort(Integer toDestinationPort) {
this.toDestinationPort = toDestinationPort;
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,36 +17,36 @@
package com.cloud.network.nicira;
/**
*
*
*/
public class L3GatewayAttachment extends Attachment {
private String l3_gateway_service_uuid;
private String type = "L3GatewayAttachment";
private Long vlan_id;
public L3GatewayAttachment(String l3_gateway_service_uuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid;
}
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 String getL3GatewayServiceUuid() {
return l3_gateway_service_uuid;
}
public void setL3GatewayServiceUuid(String l3_gateway_service_uuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid;
}
public long getVlanId() {
return vlan_id;
}
public void setVlanId(long vlan_id) {
this.vlan_id = vlan_id;
}
private String l3_gateway_service_uuid;
private String type = "L3GatewayAttachment";
private Long vlan_id;
public L3GatewayAttachment(String l3_gateway_service_uuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid;
}
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 String getL3GatewayServiceUuid() {
return l3_gateway_service_uuid;
}
public void setL3GatewayServiceUuid(String l3_gateway_service_uuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid;
}
public long getVlanId() {
return vlan_id;
}
public void setVlanId(long vlan_id) {
this.vlan_id = vlan_id;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -19,39 +19,39 @@ package com.cloud.network.nicira;
import java.util.List;
/**
*
*
*/
public class LogicalRouterConfig {
private String display_name;
private RoutingConfig routing_config;
private String type = "LogicalRouterConfig";
private String uuid;
private String display_name;
private RoutingConfig routing_config;
private String type = "LogicalRouterConfig";
private String uuid;
private List<NiciraNvpTag> tags;
public RoutingConfig getRoutingConfig() {
return routing_config;
}
public void setRoutingConfig(RoutingConfig routing_config) {
this.routing_config = routing_config;
}
public String getDisplayName() {
return display_name;
}
public void setDisplayName(String display_name) {
this.display_name = display_name;
}
public RoutingConfig getRoutingConfig() {
return routing_config;
}
public void setRoutingConfig(RoutingConfig routing_config) {
this.routing_config = routing_config;
}
public String getDisplayName() {
return display_name;
}
public void setDisplayName(String display_name) {
this.display_name = display_name;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public List<NiciraNvpTag> getTags() {
return tags;
}
@ -59,6 +59,5 @@ public class LogicalRouterConfig {
public void setTags(List<NiciraNvpTag> tags) {
this.tags = tags;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -19,72 +19,72 @@ package com.cloud.network.nicira;
import java.util.List;
/**
*
*
*/
public class LogicalRouterPort {
private String display_name;
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 String uuid;
public int getPortno() {
return portno;
}
public void setPortno(int portno) {
this.portno = portno;
}
public boolean isAdminStatusEnabled() {
return admin_status_enabled;
}
public void setAdminStatusEnabled(boolean admin_status_enabled) {
this.admin_status_enabled = admin_status_enabled;
}
public List<String> getIpAddresses() {
return ip_addresses;
}
public void setIpAddresses(List<String> ip_addresses) {
this.ip_addresses = ip_addresses;
}
public String getMacAddress() {
return mac_address;
}
public void setMacAddress(String mac_address) {
this.mac_address = mac_address;
}
public String getDisplayName() {
return display_name;
}
private String display_name;
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 String uuid;
public void setDisplayName(String display_name) {
this.display_name = display_name;
}
public int getPortno() {
return portno;
}
public List<NiciraNvpTag> getTags() {
return tags;
}
public void setPortno(int portno) {
this.portno = portno;
}
public void setTags(List<NiciraNvpTag> tags) {
this.tags = tags;
}
public boolean isAdminStatusEnabled() {
return admin_status_enabled;
}
public String getUuid() {
return uuid;
}
public void setAdminStatusEnabled(boolean admin_status_enabled) {
this.admin_status_enabled = admin_status_enabled;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public List<String> getIpAddresses() {
return ip_addresses;
}
public void setIpAddresses(List<String> ip_addresses) {
this.ip_addresses = ip_addresses;
}
public String getMacAddress() {
return mac_address;
}
public void setMacAddress(String mac_address) {
this.mac_address = mac_address;
}
public String getDisplayName() {
return display_name;
}
public void setDisplayName(String display_name) {
this.display_name = display_name;
}
public List<NiciraNvpTag> getTags() {
return tags;
}
public void setTags(List<NiciraNvpTag> tags) {
this.tags = tags;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -29,51 +29,51 @@ public class LogicalSwitch {
//private RequestQueryParameters _query;
//private LogicalSwitchRelations _relations;
private String _schema;
public String getDisplay_name() {
return display_name;
}
public void setDisplay_name(String display_name) {
this.display_name = display_name;
}
public boolean isPort_isolation_enabled() {
return port_isolation_enabled;
}
public void setPort_isolation_enabled(boolean port_isolation_enabled) {
this.port_isolation_enabled = port_isolation_enabled;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public String get_href() {
return _href;
}
public void set_href(String _href) {
this._href = _href;
}
public String get_schema() {
return _schema;
}
public void set_schema(String _schema) {
this._schema = _schema;
}
@ -93,6 +93,6 @@ public class LogicalSwitch {
public void setTransport_zones(List<TransportZoneBinding> transport_zones) {
this.transport_zones = transport_zones;
}
}

View File

@ -29,7 +29,7 @@ public class LogicalSwitchPort {
private List<String> mirror_targets;
private String type;
private String uuid;
public LogicalSwitchPort() {
super();
}
@ -113,5 +113,5 @@ public class LogicalSwitchPort {
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,131 +17,117 @@
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 ethertype = "IPv4";
public Integer getProtocol() {
return protocol;
}
public void setProtocol(Integer protocol) {
this.protocol = protocol;
}
public Integer getSourcePort() {
return source_port;
}
public void setSourcePort(Integer source_port) {
this.source_port = source_port;
}
public Integer getDestinationPort() {
return destination_port;
}
public void setDestinationPort(Integer destination_port) {
this.destination_port = destination_port;
}
public String getEthertype() {
return ethertype;
}
public void setEthertype(String ethertype) {
this.ethertype = ethertype;
}
private Integer protocol;
private String source_ip_addresses;
private String destination_ip_addresses;
private Integer source_port;
private Integer destination_port;
private String ethertype = "IPv4";
public String getSourceIpAddresses() {
return source_ip_addresses;
}
public Integer getProtocol() {
return protocol;
}
public void setSourceIpAddresses(String source_ip_addresses) {
this.source_ip_addresses = source_ip_addresses;
}
public void setProtocol(Integer protocol) {
this.protocol = protocol;
}
public String getDestinationIpAddresses() {
return destination_ip_addresses;
}
public Integer getSourcePort() {
return source_port;
}
public void setDestinationIpAddresses(String destination_ip_addresses) {
this.destination_ip_addresses = destination_ip_addresses;
}
public void setSourcePort(Integer source_port) {
this.source_port = source_port;
}
@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());
return result;
}
public Integer getDestinationPort() {
return destination_port;
}
public void setDestinationPort(Integer destination_port) {
this.destination_port = destination_port;
}
public String getEthertype() {
return ethertype;
}
public void setEthertype(String ethertype) {
this.ethertype = ethertype;
}
public String getSourceIpAddresses() {
return source_ip_addresses;
}
public void setSourceIpAddresses(String source_ip_addresses) {
this.source_ip_addresses = source_ip_addresses;
}
public String getDestinationIpAddresses() {
return destination_ip_addresses;
}
public void setDestinationIpAddresses(String destination_ip_addresses) {
this.destination_ip_addresses = destination_ip_addresses;
}
@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());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Match other = (Match) obj;
if (destination_ip_addresses == null) {
if (other.destination_ip_addresses != null)
return false;
} else if (!destination_ip_addresses.equals(other.destination_ip_addresses))
return false;
if (destination_port == null) {
if (other.destination_port != null)
return false;
} else if (!destination_port.equals(other.destination_port))
return false;
if (ethertype == null) {
if (other.ethertype != null)
return false;
} else if (!ethertype.equals(other.ethertype))
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
if (source_ip_addresses == null) {
if (other.source_ip_addresses != null)
return false;
} else if (!source_ip_addresses.equals(other.source_ip_addresses))
return false;
if (source_port == null) {
if (other.source_port != null)
return false;
} else if (!source_port.equals(other.source_port))
return false;
return true;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Match other = (Match) obj;
if (destination_ip_addresses == null) {
if (other.destination_ip_addresses != null)
return false;
} else if (!destination_ip_addresses
.equals(other.destination_ip_addresses))
return false;
if (destination_port == null) {
if (other.destination_port != null)
return false;
} else if (!destination_port.equals(other.destination_port))
return false;
if (ethertype == null) {
if (other.ethertype != null)
return false;
} else if (!ethertype.equals(other.ethertype))
return false;
if (protocol == null) {
if (other.protocol != null)
return false;
} else if (!protocol.equals(other.protocol))
return false;
if (source_ip_addresses == null) {
if (other.source_ip_addresses != null)
return false;
} else if (!source_ip_addresses.equals(other.source_ip_addresses))
return false;
if (source_port == null) {
if (other.source_port != null)
return false;
} else if (!source_port.equals(other.source_port))
return false;
return true;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -19,7 +19,7 @@ package com.cloud.network.nicira;
import java.util.UUID;
/**
*
*
*/
public abstract class NatRule {
protected Match match;
@ -53,15 +53,15 @@ public abstract class NatRule {
public void setType(String type) {
this.type = type;
}
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
@Override
public int hashCode() {
final int prime = 31;
@ -101,7 +101,7 @@ public abstract class NatRule {
return false;
return true;
}
public boolean equalsIgnoreUuid(Object obj) {
if (this == obj)
return true;
@ -124,6 +124,6 @@ public abstract class NatRule {
return false;
return true;
}
}

View File

@ -75,103 +75,103 @@ public class NiciraNvpApi {
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 String _name;
private String _host;
private String _adminuser;
private String _adminpass;
private HttpClient _client;
private String _nvpversion;
private Gson _gson;
/* This factory method is protected so we can extend this
* in the unittests.
*/
protected HttpClient createHttpClient() {
return new HttpClient(s_httpClientManager);
return new HttpClient(s_httpClientManager);
}
protected HttpMethod createMethod(String type, String uri) throws NiciraNvpApiException {
String url;
String url;
try {
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);
}
if ("post".equalsIgnoreCase(type)) {
return new PostMethod(url);
return new PostMethod(url);
}
else if ("get".equalsIgnoreCase(type)) {
return new GetMethod(url);
return new GetMethod(url);
}
else if ("delete".equalsIgnoreCase(type)) {
return new DeleteMethod(url);
return new DeleteMethod(url);
}
else if ("put".equalsIgnoreCase(type)) {
return new PutMethod(url);
return new PutMethod(url);
}
else {
throw new NiciraNvpApiException("Requesting unknown method type");
throw new NiciraNvpApiException("Requesting unknown method type");
}
}
public NiciraNvpApi() {
_client = createHttpClient();
_client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
try {
try {
// Cast to ProtocolSocketFactory to avoid the deprecated constructor with the SecureProtocolSocketFactory parameter
Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), 443));
} 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();
.registerTypeAdapter(NatRule.class, new NatRuleAdapter())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
}
public void setControllerAddress(String address) {
this._host = address;
_host = address;
}
public void setAdminCredentials(String username, String password) {
this._adminuser = username;
this._adminpass = 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()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
_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();
} 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);
try {
_client.executeMethod(pm);
} catch (HttpException e) {
@ -181,25 +181,25 @@ public class NiciraNvpApi {
} finally {
pm.releaseConnection();
}
if (pm.getStatusCode() != HttpStatus.SC_OK) {
s_logger.error("Nicira NVP API login failed : " + pm.getStatusText());
throw new NiciraNvpApiException("Nicira NVP API login failed " + pm.getStatusText());
}
// Extract the version for later use
if (pm.getResponseHeader("Server") != null) {
_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";
LogicalSwitch createdLogicalSwitch = executeCreateObject(logicalSwitch, new TypeToken<LogicalSwitch>(){}.getType(), uri, Collections.<String,String>emptyMap());
return createdLogicalSwitch;
}
@ -207,11 +207,11 @@ public class NiciraNvpApi {
String uri = "/ws.v1/lswitch/" + 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());;
return createdLogicalSwitchPort;
}
@ -219,28 +219,28 @@ public class NiciraNvpApi {
String uri = "/ws.v1/lswitch/" + 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;
executeDeleteObject(uri);
}
public String findLogicalSwitchPortUuidByVifAttachmentUuid(String logicalSwitchUuid, String vifAttachmentUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lswitch/" + logicalSwitchUuid + "/lport";
Map<String,String> params = new HashMap<String,String>();
params.put("attachment_vif_uuid", vifAttachmentUuid);
params.put("fields", "uuid");
NiciraNvpList<LogicalSwitchPort> lspl = executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalSwitchPort>>(){}.getType(), uri, params);
if (lspl == null || lspl.getResultCount() != 1) {
throw new NiciraNvpApiException("Unexpected response from API");
}
LogicalSwitchPort lsp = lspl.getResults().get(0);
return lsp.getUuid();
}
public ControlClusterStatus getControlClusterStatus() throws NiciraNvpApiException {
String uri = "/ws.v1/control-cluster/status";
ControlClusterStatus ccs = executeRetrieveObject(new TypeToken<ControlClusterStatus>(){}.getType(), uri, null);
@ -253,118 +253,118 @@ public class NiciraNvpApi {
Map<String,String> params = new HashMap<String,String>();
params.put("uuid", logicalSwitchPortUuid);
params.put("fields", "uuid");
NiciraNvpList<LogicalSwitchPort> lspl = executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalSwitchPort>>(){}.getType(), uri, params);
if (lspl == null ) {
throw new NiciraNvpApiException("Unexpected response from API");
}
return lspl;
}
public LogicalRouterConfig createLogicalRouter(LogicalRouterConfig logicalRouterConfig) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter";
LogicalRouterConfig lrc = executeCreateObject(logicalRouterConfig, new TypeToken<LogicalRouterConfig>(){}.getType(), uri, Collections.<String,String>emptyMap());
return lrc;
String uri = "/ws.v1/lrouter";
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;
executeDeleteObject(uri);
String uri = "/ws.v1/lrouter/" + logicalRouterUuid;
executeDeleteObject(uri);
}
public LogicalRouterPort createLogicalRouterPort(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
LogicalRouterPort lrp = executeCreateObject(logicalRouterPort, new TypeToken<LogicalRouterPort>(){}.getType(), uri, Collections.<String,String>emptyMap());
return lrp;
String uri = "/ws.v1/lrouter/" + 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;
executeDeleteObject(uri);
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPortUuid;
executeDeleteObject(uri);
}
public void modifyLogicalRouterPort(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPort.getUuid();
executeUpdateObject(logicalRouterPort, uri, Collections.<String,String>emptyMap());
String uri = "/ws.v1/lrouter/" + 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";
executeUpdateObject(attachment, uri, Collections.<String,String>emptyMap());
}
public NatRule createLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat";
return executeCreateObject(natRule, new TypeToken<NatRule>(){}.getType(), uri, Collections.<String,String>emptyMap());
String uri = "/ws.v1/lrouter/" + 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();
executeUpdateObject(natRule, uri, Collections.<String,String>emptyMap());
String uri = "/ws.v1/lrouter/" + 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();
executeDeleteObject(uri);
String uri = "/ws.v1/lrouter/" + 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";
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
Map<String,String> params = new HashMap<String,String>();
params.put("attachment_gwsvc_uuid", gatewayServiceUuid);
params.put("attachment_vlan", "0");
params.put("fields","*");
return executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalRouterPort>>(){}.getType(), uri, params);
}
public LogicalRouterConfig findOneLogicalRouterByUuid(String logicalRouterUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid;
return executeRetrieveObject(new TypeToken<LogicalRouterConfig>(){}.getType(), uri, Collections.<String,String>emptyMap());
String uri = "/ws.v1/lrouter/" + 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();
executeUpdateObject(logicalRouterPort, uri, Collections.<String,String>emptyMap());
String uri = "/ws.v1/lrouter/" + 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";
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat";
Map<String,String> params = new HashMap<String,String>();
params.put("fields","*");
return executeRetrieveObject(new TypeToken<NiciraNvpList<NatRule>>(){}.getType(), uri, params);
return executeRetrieveObject(new TypeToken<NiciraNvpList<NatRule>>(){}.getType(), uri, params);
}
public NiciraNvpList<LogicalRouterPort> findLogicalRouterPortByGatewayServiceUuid(String logicalRouterUuid, String l3GatewayServiceUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
Map<String,String> params = new HashMap<String,String>();
params.put("fields", "*");
params.put("attachment_gwsvc_uuid", l3GatewayServiceUuid);
return executeRetrieveObject(new TypeToken<NiciraNvpList<LogicalRouterPort>>(){}.getType(), uri, params);
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
Map<String,String> params = new HashMap<String,String>();
params.put("fields", "*");
params.put("attachment_gwsvc_uuid", l3GatewayServiceUuid);
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()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
_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");
try {
@ -373,9 +373,9 @@ public class NiciraNvpApi {
} catch (UnsupportedEncodingException e) {
throw new NiciraNvpApiException("Failed to encode json request body", e);
}
executeMethod(pm);
if (pm.getStatusCode() != HttpStatus.SC_OK) {
String errorMessage = responseToErrorMessage(pm);
pm.releaseConnection();
@ -384,14 +384,14 @@ 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()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
_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");
try {
@ -400,16 +400,16 @@ public class NiciraNvpApi {
} catch (UnsupportedEncodingException e) {
throw new NiciraNvpApiException("Failed to encode json request body", e);
}
executeMethod(pm);
if (pm.getStatusCode() != HttpStatus.SC_CREATED) {
String errorMessage = responseToErrorMessage(pm);
pm.releaseConnection();
s_logger.error("Failed to create object : " + errorMessage);
throw new NiciraNvpApiException("Failed to create object : " + errorMessage);
}
T result;
try {
result = (T)_gson.fromJson(pm.getResponseBodyAsString(), TypeToken.get(newObject.getClass()).getType());
@ -418,22 +418,22 @@ public class NiciraNvpApi {
} finally {
pm.releaseConnection();
}
return result;
return result;
}
protected void executeDeleteObject(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");
_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");
executeMethod(dm);
if (dm.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
String errorMessage = responseToErrorMessage(dm);
dm.releaseConnection();
@ -442,33 +442,33 @@ 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()) {
throw new NiciraNvpApiException("Hostname/credentials are null or empty");
_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");
if (parameters != null && !parameters.isEmpty()) {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
for (Entry<String,String> e : parameters.entrySet()) {
nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));
}
gm.setQueryString(nameValuePairs.toArray(new NameValuePair[0]));
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(parameters.size());
for (Entry<String,String> e : parameters.entrySet()) {
nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue()));
}
gm.setQueryString(nameValuePairs.toArray(new NameValuePair[0]));
}
executeMethod(gm);
if (gm.getStatusCode() != HttpStatus.SC_OK) {
String errorMessage = responseToErrorMessage(gm);
gm.releaseConnection();
s_logger.error("Failed to retrieve object : " + errorMessage);
throw new NiciraNvpApiException("Failed to retrieve object : " + errorMessage);
}
T returnValue;
try {
returnValue = (T)_gson.fromJson(gm.getResponseBodyAsString(), returnObjectType);
@ -480,7 +480,7 @@ public class NiciraNvpApi {
}
return returnValue;
}
protected void executeMethod(HttpMethodBase method) throws NiciraNvpApiException {
try {
_client.executeMethod(method);
@ -497,13 +497,13 @@ public class NiciraNvpApi {
} catch (IOException e) {
s_logger.error("IOException caught while trying to connect to the Nicira NVP Controller", e);
method.releaseConnection();
throw new NiciraNvpApiException("API call to Nicira NVP Controller Failed", e);
throw new NiciraNvpApiException("API call to Nicira NVP Controller Failed", e);
}
}
private String responseToErrorMessage(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())) {
// The error message is the response content
// Safety margin of 1024 characters, anything longer is probably useless
@ -514,38 +514,41 @@ public class NiciraNvpApi {
s_logger.debug("Error while loading response body", e);
}
}
// The default
return method.getStatusText();
}
/* The Nicira controller uses a self-signed certificate. The
/* The Nicira controller uses a self-signed certificate. The
* TrustingProtocolSocketFactory will accept any provided
* certificate when making an SSL connection to the SDN
* certificate when making an SSL connection to the SDN
* Manager
*/
private class TrustingProtocolSocketFactory implements SecureProtocolSocketFactory {
private SSLSocketFactory ssf;
public TrustingProtocolSocketFactory() throws IOException {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
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
}
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
// Trust always
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
// Trust always
}
}
};
try {
// Install the all-trusting trust manager
SSLContext sc = SSLContext.getInstance("SSL");
@ -557,10 +560,10 @@ public class NiciraNvpApi {
throw new IOException(e);
}
}
@Override
public Socket createSocket(String host, int port) throws IOException,
UnknownHostException {
UnknownHostException {
return ssf.createSocket(host, port);
}
@ -592,21 +595,19 @@ public class NiciraNvpApi {
}
}
}
public static class NatRuleAdapter implements JsonDeserializer<NatRule> {
@Override
public NatRule deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = jsonElement.getAsJsonObject();
NatRule natRule = null;
if (!jsonObject.has("type")) {
throw new JsonParseException("Deserializing as a NatRule, but no type present in the json object");
}
String natRuleType = jsonObject.get("type").getAsString();
if ("SourceNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, SourceNatRule.class);
@ -614,7 +615,7 @@ public class NiciraNvpApi {
else if ("DestinationNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, DestinationNatRule.class);
}
throw new JsonParseException("Failed to deserialize type \"" + natRuleType + "\"");
}

View File

@ -37,9 +37,9 @@ public class NiciraNvpList<T> {
public void setResultCount(int result_count) {
this.result_count = result_count;
}
public boolean isEmpty() {
return result_count == 0;
return result_count == 0;
}
}

View File

@ -22,9 +22,9 @@ public class NiciraNvpTag {
private static final Logger s_logger = Logger.getLogger(NiciraNvpTag.class);
private String scope;
private String tag;
public NiciraNvpTag() {}
public NiciraNvpTag(String scope, String tag) {
this.scope = scope;
if (tag.length() > 40) {
@ -34,19 +34,19 @@ public class NiciraNvpTag {
this.tag = tag;
}
}
public String getScope() {
return scope;
}
public void setScope(String scope) {
this.scope = scope;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
if (tag.length() > 40) {
s_logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters");
@ -55,5 +55,5 @@ public class NiciraNvpTag {
this.tag = tag;
}
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,23 +17,22 @@
package com.cloud.network.nicira;
/**
*
*
*/
public class PatchAttachment extends Attachment {
private final String type = "PatchAttachment";
private String peer_port_uuid;
public PatchAttachment(String peerPortUuid) {
this.peer_port_uuid = peerPortUuid;
}
private final String type = "PatchAttachment";
private String peer_port_uuid;
public String getPeerPortUuid() {
return peer_port_uuid;
}
public PatchAttachment(String peerPortUuid) {
peer_port_uuid = peerPortUuid;
}
public String getPeerPortUuid() {
return peer_port_uuid;
}
public void setPeerPortUuid(String peerPortUuid) {
peer_port_uuid = peerPortUuid;
}
public void setPeerPortUuid(String peerPortUuid) {
this.peer_port_uuid = peerPortUuid;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,22 +17,22 @@
package com.cloud.network.nicira;
/**
*
*
*/
public class RouterNextHop {
private String gateway_ip_address;
private String type = "RouterNextHop";
public RouterNextHop(String gatewayIpAddress) {
this.gateway_ip_address = gatewayIpAddress;
}
public String getGatewayIpAddress() {
return gateway_ip_address;
}
public void setGatewayIpAddress(String gateway_ip_address) {
this.gateway_ip_address = gateway_ip_address;
}
private String gateway_ip_address;
private String type = "RouterNextHop";
public RouterNextHop(String gatewayIpAddress) {
gateway_ip_address = gatewayIpAddress;
}
public String getGatewayIpAddress() {
return gateway_ip_address;
}
public void setGatewayIpAddress(String gateway_ip_address) {
this.gateway_ip_address = gateway_ip_address;
}
}

View File

@ -5,7 +5,7 @@
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
@ -17,22 +17,22 @@
package com.cloud.network.nicira;
/**
*
*
*/
public class SingleDefaultRouteImplictRoutingConfig extends RoutingConfig {
public RouterNextHop default_route_next_hop;
public String type = "SingleDefaultRouteImplicitRoutingConfig";
public SingleDefaultRouteImplictRoutingConfig(RouterNextHop routerNextHop) {
default_route_next_hop = routerNextHop;
}
public RouterNextHop getDefaultRouteNextHop() {
return default_route_next_hop;
}
public void setDefaultRouteNextHop(RouterNextHop default_route_next_hop) {
this.default_route_next_hop = default_route_next_hop;
}
public RouterNextHop default_route_next_hop;
public String type = "SingleDefaultRouteImplicitRoutingConfig";
public SingleDefaultRouteImplictRoutingConfig(RouterNextHop routerNextHop) {
default_route_next_hop = routerNextHop;
}
public RouterNextHop getDefaultRouteNextHop() {
return default_route_next_hop;
}
public void setDefaultRouteNextHop(RouterNextHop default_route_next_hop) {
this.default_route_next_hop = default_route_next_hop;
}
}

View File

@ -20,7 +20,7 @@ public class SourceNatRule extends NatRule {
private String toSourceIpAddressMax;
private String toSourceIpAddressMin;
private Integer toSourcePort;
public SourceNatRule() {
setType("SourceNatRule");
}
@ -119,5 +119,5 @@ public class SourceNatRule extends NatRule {
return false;
return true;
}
}

View File

@ -19,9 +19,9 @@ package com.cloud.network.nicira;
public class TransportZoneBinding {
private String zone_uuid;
private String transport_type;
public TransportZoneBinding() {}
public TransportZoneBinding(String zone_uuid, String transport_type) {
this.zone_uuid = zone_uuid;
this.transport_type = transport_type;
@ -42,5 +42,5 @@ public class TransportZoneBinding {
public void setTransport_type(String transport_type) {
this.transport_type = transport_type;
}
}

View File

@ -19,12 +19,12 @@ package com.cloud.network.nicira;
public class VifAttachment extends Attachment {
private final String type = "VifAttachment";
private String vif_uuid;
public VifAttachment() {
}
public VifAttachment(String vifUuid) {
this.vif_uuid = vifUuid;
vif_uuid = vifUuid;
}
public String getVif_uuid() {
@ -38,5 +38,5 @@ public class VifAttachment extends Attachment {
public String getType() {
return type;
}
}

View File

@ -16,6 +16,16 @@
// under the License.
package com.cloud.network.element;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@ -31,7 +41,6 @@ import org.mockito.ArgumentMatcher;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer;
import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand;
import com.cloud.deploy.DeployDestination;
@ -41,11 +50,11 @@ import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.IpAddress;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.TrafficType;
@ -55,18 +64,12 @@ import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.dao.NiciraNvpDao;
import com.cloud.network.dao.NiciraNvpRouterMappingDao;
import com.cloud.network.nicira.NatRule;
import com.cloud.offering.NetworkOffering;
import com.cloud.resource.ResourceManager;
import com.cloud.user.Account;
import com.cloud.utils.net.Ip;
import com.cloud.vm.ReservationContext;
import static org.junit.Assert.*;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
public class NiciraNvpElementTest {
NiciraNvpElement _element = new NiciraNvpElement();
@ -136,7 +139,7 @@ public class NiciraNvpElementTest {
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
DeployDestination dest = mock(DeployDestination.class);
mock(DeployDestination.class);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");

View File

@ -16,8 +16,19 @@
// under the License.
package com.cloud.network.guru;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Before;
@ -25,16 +36,13 @@ import org.junit.Test;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.CreateLogicalSwitchAnswer;
import com.cloud.agent.api.DeleteLogicalSwitchAnswer;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.DataCenter.NetworkType;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.deploy.DeployDestination;
import com.cloud.deploy.DeploymentPlan;
@ -61,404 +69,401 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.user.Account;
import com.cloud.vm.ReservationContext;
import java.util.Arrays;
public class NiciraNvpGuestNetworkGuruTest {
PhysicalNetworkDao physnetdao = mock (PhysicalNetworkDao.class);
NiciraNvpDao nvpdao = mock(NiciraNvpDao.class);
DataCenterDao dcdao = mock(DataCenterDao.class);
NetworkOfferingServiceMapDao nosd = mock(NetworkOfferingServiceMapDao.class);
AgentManager agentmgr = mock (AgentManager.class);
NetworkOrchestrationService netmgr = mock (NetworkOrchestrationService.class);
NetworkModel netmodel = mock (NetworkModel.class);
PhysicalNetworkDao physnetdao = mock(PhysicalNetworkDao.class);
NiciraNvpDao nvpdao = mock(NiciraNvpDao.class);
DataCenterDao dcdao = mock(DataCenterDao.class);
NetworkOfferingServiceMapDao nosd = mock(NetworkOfferingServiceMapDao.class);
AgentManager agentmgr = mock (AgentManager.class);
NetworkOrchestrationService netmgr = mock (NetworkOrchestrationService.class);
NetworkModel netmodel = mock (NetworkModel.class);
HostDao hostdao = mock (HostDao.class);
NetworkDao netdao = mock(NetworkDao.class);
NiciraNvpGuestNetworkGuru guru;
@Before
public void setUp() {
guru = new NiciraNvpGuestNetworkGuru();
((GuestNetworkGuru) guru)._physicalNetworkDao = physnetdao;
guru._physicalNetworkDao = physnetdao;
guru._niciraNvpDao = nvpdao;
guru._dcDao = dcdao;
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);
when(dc.getGuestNetworkCidr()).thenReturn("10.1.1.1/24");
when(dcdao.findById((Long) any())).thenReturn((DataCenterVO) dc);
}
@Test
public void testCanHandle() {
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
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(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(true);
assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported TrafficType != Guest
when(offering.getTrafficType()).thenReturn(TrafficType.Management);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: GuestType Shared
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Shared);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: Basic networking
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
assertFalse(guru.canHandle(offering, NetworkType.Basic, physnet) == true);
// Not supported: IsolationMethod != STT
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" }));
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
}
@Test
public void testDesign() {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(true);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork != null);
assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Lswitch);
}
@Test
public void testDesignNoElementOnPhysicalNetwork() {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList());
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@Test
public void testDesignNoIsolationMethodSTT() {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList());
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@Test
public void testDesignNoConnectivityInOffering() {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@Test
public void testImplement() throws InsufficientVirtualNetworkCapcityException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
DeploymentPlan plan = mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(42L);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
HostDao hostdao = mock (HostDao.class);
NetworkDao netdao = mock(NetworkDao.class);
NiciraNvpGuestNetworkGuru guru;
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null);
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
}
@Test
public void testImplementWithCidr() throws InsufficientVirtualNetworkCapcityException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
DeploymentPlan plan = mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
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);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
@Before
public void setUp() {
guru = new NiciraNvpGuestNetworkGuru();
((GuestNetworkGuru) guru)._physicalNetworkDao = physnetdao;
guru._physicalNetworkDao = physnetdao;
guru._niciraNvpDao = nvpdao;
guru._dcDao = dcdao;
guru._ntwkOfferingSrvcDao = nosd;
guru._networkModel = netmodel;
guru._hostDao = hostdao;
guru._agentMgr = agentmgr;
guru._networkDao = netdao;
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());
}
@Test
public void testImplementURIException() throws InsufficientVirtualNetworkCapcityException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
DeploymentPlan plan = mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
when(network.getState()).thenReturn(State.Implementing);
when(network.getPhysicalNetworkId()).thenReturn(42L);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
//when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
DataCenterVO dc = mock(DataCenterVO.class);
when(dc.getNetworkType()).thenReturn(NetworkType.Advanced);
when(dc.getGuestNetworkCidr()).thenReturn("10.1.1.1/24");
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork == null);
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
}
@Test
public void testShutdown() throws InsufficientVirtualNetworkCapcityException, URISyntaxException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
DeploymentPlan plan = mock(DeploymentPlan.class);
NetworkVO network = mock(NetworkVO.class);
when(network.getName()).thenReturn("testnetwork");
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);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
when(dcdao.findById((Long) any())).thenReturn(dc);
}
NetworkProfile implementednetwork = mock(NetworkProfile.class);
when(implementednetwork.getId()).thenReturn(42L);
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(implementednetwork, times(1)).setBroadcastUri(null);
}
@Test
public void testCanHandle() {
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
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(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(true);
assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported TrafficType != Guest
when(offering.getTrafficType()).thenReturn(TrafficType.Management);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: GuestType Shared
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Shared);
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
// Not supported: Basic networking
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
assertFalse(guru.canHandle(offering, NetworkType.Basic, physnet) == true);
// Not supported: IsolationMethod != STT
when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" }));
assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
}
@Test
public void testDesign() {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(true);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork != null);
assertTrue(designednetwork.getBroadcastDomainType() == BroadcastDomainType.Lswitch);
}
@Test
public void testDesignNoElementOnPhysicalNetwork() {
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);
mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList());
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@Test
public void testDesignNoIsolationMethodSTT() {
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);
mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Collections.<NiciraNvpDeviceVO> emptyList());
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@Test
public void testDesignNoConnectivityInOffering() {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, Service.Connectivity)).thenReturn(false);
DeploymentPlan plan = mock(DeploymentPlan.class);
Network network = mock(Network.class);
Account account = mock(Account.class);
Network designednetwork = guru.design(offering, plan, network, account);
assertTrue(designednetwork == null);
}
@Test
public void testImplement() throws InsufficientVirtualNetworkCapcityException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, 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);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork != null);
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
}
@Test
public void testImplementWithCidr() throws InsufficientVirtualNetworkCapcityException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, 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.getGateway()).thenReturn("10.1.1.1");
when(network.getCidr()).thenReturn("10.1.1.0/24");
when(network.getPhysicalNetworkId()).thenReturn(42L);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
when(agentmgr.easySend(eq(42L), (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());
}
@Test
public void testImplementURIException() throws InsufficientVirtualNetworkCapcityException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, 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);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
CreateLogicalSwitchAnswer answer = mock(CreateLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
//when(answer.getLogicalSwitchUuid()).thenReturn("aaaaa");
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
Network implementednetwork = guru.implement(network, offering, dest, res);
assertTrue(implementednetwork == null);
verify(agentmgr, times(1)).easySend(eq(42L), (Command)any());
}
@Test
public void testShutdown() throws InsufficientVirtualNetworkCapcityException, URISyntaxException {
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);
NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
when(nvpdao.listByPhysicalNetwork(42L)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
when(device.getId()).thenReturn(1L);
NetworkOffering offering = mock(NetworkOffering.class);
when(offering.getId()).thenReturn(42L);
when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
when(offering.getGuestType()).thenReturn(GuestType.Isolated);
when(nosd.areServicesSupportedByNetworkOffering(42L, 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.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
when(network.getPhysicalNetworkId()).thenReturn(42L);
when(netdao.findById(42L)).thenReturn(network);
DeployDestination dest = mock(DeployDestination.class);
DataCenter dc = mock(DataCenter.class);
when(dest.getDataCenter()).thenReturn(dc);
HostVO niciraHost = mock(HostVO.class);
when(hostdao.findById(anyLong())).thenReturn(niciraHost);
when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
when(niciraHost.getId()).thenReturn(42L);
when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
Domain dom = mock(Domain.class);
when(dom.getName()).thenReturn("domain");
Account acc = mock(Account.class);
when(acc.getAccountName()).thenReturn("accountname");
ReservationContext res = mock(ReservationContext.class);
when(res.getDomain()).thenReturn(dom);
when(res.getAccount()).thenReturn(acc);
DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
when(answer.getResult()).thenReturn(true);
when(agentmgr.easySend(eq(42L), (Command)any())).thenReturn(answer);
NetworkProfile implementednetwork = mock(NetworkProfile.class);
when(implementednetwork.getId()).thenReturn(42L);
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(implementednetwork, times(1)).setBroadcastUri(null);
}
}

View File

@ -16,7 +16,7 @@
// under the License.
package com.cloud.network.nicira;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@ -25,14 +25,14 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
public class NatRuleTest {
@Test
public void testNatRuleEncoding() {
Gson gson = new GsonBuilder()
.registerTypeAdapter(NatRule.class, new com.cloud.network.nicira.NiciraNvpApi.NatRuleAdapter())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
.registerTypeAdapter(NatRule.class, new com.cloud.network.nicira.NiciraNvpApi.NatRuleAdapter())
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
DestinationNatRule rn1 = new DestinationNatRule();
rn1.setToDestinationIpAddress("10.10.10.10");
rn1.setToDestinationPort(80);
@ -41,12 +41,12 @@ public class NatRuleTest {
mr1.setEthertype("IPv4");
mr1.setProtocol(6);
rn1.setMatch(mr1);
String jsonString = gson.toJson(rn1);
NatRule dnr = gson.fromJson(jsonString, NatRule.class);
assertTrue(dnr instanceof DestinationNatRule);
assertTrue(rn1.equals(dnr));
}
}

View File

@ -16,8 +16,12 @@
// under the License.
package com.cloud.network.nicira;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Collections;
@ -36,271 +40,271 @@ import org.junit.Before;
import org.junit.Test;
public class NiciraNvpApiTest {
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() {
@Override
protected HttpClient createHttpClient() {
return _client;
}
@Override
protected HttpMethod createMethod(String type, String uri) {
return _method;
}
};
_api.setAdminCredentials("admin", "adminpass");
_api.setControllerAddress("localhost");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.login();
}
NiciraNvpApi _api;
HttpClient _client = mock(HttpClient.class);
HttpMethod _method;
@Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.login();
}
@Before
public void setUp() {
HttpClientParams hmp = mock(HttpClientParams.class);
when (_client.getParams()).thenReturn(hmp);
_api = new NiciraNvpApi() {
@Override
protected HttpClient createHttpClient() {
return _client;
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap());
}
@Override
protected HttpMethod createMethod(String type, String uri) {
return _method;
}
};
_api.setAdminCredentials("admin", "adminpass");
_api.setControllerAddress("localhost");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.login();
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteLoginWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.login();
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeDeleteObject("/");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteUpdateObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.executeUpdateObject(new String(), "/", Collections.<String, String> emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.executeDeleteObject("/");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteCreateObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeCreateObject(new String(), String.class, "/", Collections.<String, String> emptyMap());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeRetrieveObject(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());
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.executeDeleteObject("/");
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeDeleteObject("/");
}
@Test
public void executeMethodTest() throws NiciraNvpApiException {
GetMethod gm = mock(GetMethod.class);
when(gm.getStatusCode()).thenReturn(HttpStatus.SC_OK);
_api.executeMethod(gm);
verify(gm, times(1)).getStatusCode();
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.executeDeleteObject("/");
}
/* Bit of a roundabout way to ensure that login is called after an un authorized result
* It not possible to properly mock login()
*/
@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(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED);
_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());
assertTrue("aaaa".equals(ls.getUuid()));
verify(_method, times(1)).releaseConnection();
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutHostname() throws NiciraNvpApiException {
_api.setControllerAddress(null);
_api.executeRetrieveObject(String.class, "/", Collections.<String, String> emptyMap());
}
@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);
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);
try {
ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteRetrieveObjectWithoutCredentials() throws NiciraNvpApiException {
_api.setAdminCredentials(null, null);
_api.executeDeleteObject("/");
}
@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);
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.");
try {
ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
@Test
public void executeMethodTest() throws NiciraNvpApiException {
GetMethod gm = mock(GetMethod.class);
@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);
}
when(gm.getStatusCode()).thenReturn(HttpStatus.SC_OK);
_api.executeMethod(gm);
verify(gm, times(1)).getStatusCode();
}
@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);
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);
try {
_api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
/* Bit of a roundabout way to ensure that login is called after an un authorized result
* It not possible to properly mock login()
*/
@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(gm.getStatusCode()).thenReturn(HttpStatus.SC_UNAUTHORIZED).thenReturn(HttpStatus.SC_UNAUTHORIZED);
_api.executeMethod(gm);
verify(gm, times(1)).getStatusCode();
}
@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());
try {
_api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
@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());
assertTrue("aaaa".equals(ls.getUuid()));
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);
}
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectFailure() throws NiciraNvpApiException, IOException {
_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);
try {
_api.executeDeleteObject("/");
} finally {
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);
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);
try {
ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
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());
try {
_api.executeDeleteObject("/");
} finally {
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);
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.");
try {
ls = _api.executeCreateObject(ls, LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
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);
}
@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);
}
@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\" }");
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);
try {
_api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
@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);
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);
try {
_api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap());
} finally {
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());
try {
_api.executeUpdateObject(ls, "/", Collections.<String, String> emptyMap());
} finally {
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);
}
@Test (expected=NiciraNvpApiException.class)
public void testExecuteDeleteObjectFailure() throws NiciraNvpApiException, IOException {
_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);
try {
_api.executeDeleteObject("/");
} finally {
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());
try {
_api.executeDeleteObject("/");
} finally {
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);
}
@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\" }");
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);
try {
_api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
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());
try {
_api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
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());
try {
_api.executeRetrieveObject(LogicalSwitch.class, "/", Collections.<String, String> emptyMap());
} finally {
verify(_method, times(1)).releaseConnection();
}
}
}