bug 3120: incremental checkin

This commit is contained in:
abhishek 2010-09-15 11:17:20 -07:00
parent 0dc2a7c47e
commit a05dc480a7
8 changed files with 25 additions and 15 deletions

View File

@ -29,6 +29,7 @@ public class IPAssocCommand extends RoutingCommand {
private String publicIp;
private boolean sourceNat;
private boolean add;
private boolean oneToOneNat;
private boolean firstIP;
private String vlanId;
private String vlanGateway;
@ -38,7 +39,7 @@ public class IPAssocCommand extends RoutingCommand {
protected IPAssocCommand() {
}
public IPAssocCommand(String routerName, String privateIpAddress, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress) {
public IPAssocCommand(String routerName, String privateIpAddress, String ipAddress, boolean add, boolean firstIP, boolean sourceNat, String vlanId, String vlanGateway, String vlanNetmask, String vifMacAddress, boolean oneToOneNat) {
this.setRouterName(routerName);
this.routerIp = privateIpAddress;
this.publicIp = ipAddress;
@ -49,6 +50,7 @@ public class IPAssocCommand extends RoutingCommand {
this.vlanGateway = vlanGateway;
this.vlanNetmask = vlanNetmask;
this.vifMacAddress = vifMacAddress;
this.oneToOneNat = oneToOneNat;
}
public String getRouterIp() {
@ -63,6 +65,10 @@ public class IPAssocCommand extends RoutingCommand {
return add;
}
public boolean isOneToOneNat(){
return this.oneToOneNat;
}
public boolean isFirstIP() {
return firstIP;
}

View File

@ -1288,7 +1288,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
}
protected void assignPublicIpAddress(final String vmName, final String privateIpAddress, final String publicIpAddress, final boolean add, final boolean firstIP,
final boolean sourceNat, final String vlanId, final String vlanGateway, final String vlanNetmask, final String vifMacAddress) throws InternalErrorException {
final boolean sourceNat, final String vlanId, final String vlanGateway, final String vlanNetmask, final String vifMacAddress, final boolean oneToOneNat) throws InternalErrorException {
try {
Connection conn = getConnection();
@ -1405,7 +1405,7 @@ public abstract class CitrixResourceBase implements StoragePoolResource, ServerR
protected Answer execute(final IPAssocCommand cmd) {
try {
assignPublicIpAddress(cmd.getRouterName(), cmd.getRouterIp(), cmd.getPublicIp(), cmd.isAdd(), cmd.isFirstIP(), cmd.isSourceNat(), cmd.getVlanId(),
cmd.getVlanGateway(), cmd.getVlanNetmask(), cmd.getVifMacAddress());
cmd.getVlanGateway(), cmd.getVlanNetmask(), cmd.getVifMacAddress(), cmd.isOneToOneNat());
} catch (InternalErrorException e) {
return new Answer(cmd, false, e.getMessage());
}

View File

@ -409,12 +409,13 @@ public interface ManagementServer {
* @param accountId
* @param domainId
* @param zoneId
* @param oneToOneNat whether we want one to one mapping for this public ip to a private ip
* @return allocated IP address in the zone specified
* @throws InsufficientAddressCapacityException if no more addresses are available
* @throws InvalidParameterValueException if no router for that user exists in the zone specified
* @throws InternalErrorException if the new address could not be sent down to the router
*/
String associateIpAddress(long userId, long accountId, long domainId, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException, InvalidParameterValueException, InternalErrorException;
String associateIpAddress(long userId, long accountId, long domainId, long zoneId, boolean oneToOneNat) throws ResourceAllocationException, InsufficientAddressCapacityException, InvalidParameterValueException, InternalErrorException;
long associateIpAddressAsync(long userId, long accountId, long domainId, long zoneId);

View File

@ -70,7 +70,9 @@ public class AssociateIPAddrCmd extends BaseCmd {
Account account = (Account)params.get(BaseCmd.Properties.ACCOUNT_OBJ.getName());
Long userId = (Long)params.get(BaseCmd.Properties.USER_ID.getName());
String accountName = (String)params.get(BaseCmd.Properties.ACCOUNT.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
Long domainId = (Long)params.get(BaseCmd.Properties.DOMAIN_ID.getName());
boolean oneToOneNat = false;
oneToOneNat = (Boolean)params.get(BaseCmd.Properties.ONE_TO_ONE_NAT.getName());
String newIpAddr = null;
String errorDesc = null;
Long accountId = null;
@ -107,7 +109,7 @@ public class AssociateIPAddrCmd extends BaseCmd {
}
try {
newIpAddr = getManagementServer().associateIpAddress(userId.longValue(), accountId.longValue(), domainId.longValue(), zoneId.longValue());
newIpAddr = getManagementServer().associateIpAddress(userId.longValue(), accountId.longValue(), domainId.longValue(), zoneId.longValue(), oneToOneNat);
} catch (ResourceAllocationException rae) {
if (rae.getResourceType().equals("vm")) throw new ServerApiException (BaseCmd.VM_ALLOCATION_ERROR, rae.getMessage());
else if (rae.getResourceType().equals("ip")) throw new ServerApiException (BaseCmd.IP_ALLOCATION_ERROR, rae.getMessage());

View File

@ -62,7 +62,7 @@ public class AssociateIpAddressExecutor extends BaseAsyncJobExecutor {
} else {
try {
String ipAddress = managementServer.associateIpAddress(param.getUserId(), param.getAccountId(),
param.getDomainId(), param.getZoneId());
param.getDomainId(), param.getZoneId(), false);
asyncMgr.completeAsyncJob(getJob().getId(), AsyncJobResult.STATUS_SUCCEEDED, 0,
composeResultObject(managementServer, param, ipAddress));
} catch (ResourceAllocationException e) {

View File

@ -170,9 +170,10 @@ public interface NetworkManager extends Manager {
* @param router router object to send the association to
* @param ipAddrList list of public IP addresses
* @param add true if associate, false if disassociate
* @param whether one to one nat mapping or not
* @return
*/
boolean associateIP(DomainRouterVO router, List<String> ipAddrList, boolean add) throws ResourceAllocationException;
boolean associateIP(DomainRouterVO router, List<String> ipAddrList, boolean add, boolean oneToOneNat) throws ResourceAllocationException;
boolean updateFirewallRule(FirewallRuleVO fwRule, String oldPrivateIP, String oldPrivatePort);
boolean executeAssignToLoadBalancer(AssignToLoadBalancerExecutor executor, LoadBalancerParam param);

View File

@ -1109,7 +1109,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
ipAddrList.add(ipVO.getAddress());
}
if (!ipAddrList.isEmpty()) {
final boolean success = associateIP(router, ipAddrList, true);
final boolean success = associateIP(router, ipAddrList, true, false);
if (!success) {
return false;
}
@ -1344,7 +1344,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
}
@Override
public boolean associateIP(final DomainRouterVO router, final List<String> ipAddrList, final boolean add) {
public boolean associateIP(final DomainRouterVO router, final List<String> ipAddrList, final boolean add, final boolean oneToOneNat) {
final Command [] cmds = new Command[ipAddrList.size()];
int i=0;
boolean sourceNat = false;
@ -1365,7 +1365,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
vifMacAddress = macAddresses[1];
}
cmds[i++] = new IPAssocCommand(router.getInstanceName(), router.getPrivateIpAddress(), ipAddress, add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress);
cmds[i++] = new IPAssocCommand(router.getInstanceName(), router.getPrivateIpAddress(), ipAddress, add, firstIP, sourceNat, vlanId, vlanGateway, vlanNetmask, vifMacAddress, oneToOneNat);
sourceNat = false;
}
@ -1708,7 +1708,7 @@ public class NetworkManagerImpl implements NetworkManager, VirtualMachineManager
s_logger.debug("Disassociate ip " + router.getName());
}
if (associateIP(router, ipAddrs, false)) {
if (associateIP(router, ipAddrs, false, false)) {
_ipAddressDao.unassignIpAddress(ipAddress);
} else {
if (s_logger.isDebugEnabled()) {

View File

@ -1478,7 +1478,7 @@ public class ManagementServerImpl implements ManagementServer {
boolean success = true;
String params = "\nsourceNat=" + false + "\ndcId=" + zoneId;
ArrayList<String> dummyipAddrList = new ArrayList<String>();
success = _networkMgr.associateIP(router,ipAddrsList, true);
success = _networkMgr.associateIP(router,ipAddrsList, true, false);
String errorMsg = "Unable to assign public IP address pool";
if (!success) {
s_logger.debug(errorMsg);
@ -1509,7 +1509,7 @@ public class ManagementServerImpl implements ManagementServer {
@Override
@DB
public String associateIpAddress(long userId, long accountId, long domainId, long zoneId) throws ResourceAllocationException, InsufficientAddressCapacityException,
public String associateIpAddress(long userId, long accountId, long domainId, long zoneId, boolean oneToOneNat) throws ResourceAllocationException, InsufficientAddressCapacityException,
InvalidParameterValueException, InternalErrorException {
Transaction txn = Transaction.currentTxn();
AccountVO account = null;
@ -1561,7 +1561,7 @@ public class ManagementServerImpl implements ManagementServer {
ipAddrs.add(ipAddress);
if (router.getState() == State.Running) {
success = _networkMgr.associateIP(router, ipAddrs, true);
success = _networkMgr.associateIP(router, ipAddrs, true, oneToOneNat);
if (!success) {
errorMsg = "Unable to assign public IP address.";
}