Static route can be created for generic VpcGateway now, not just Private gateway

This commit is contained in:
Alena Prokharchyk 2012-06-28 13:09:10 -07:00
parent 4944652933
commit 90b96642a7
12 changed files with 87 additions and 41 deletions

View File

@ -129,7 +129,7 @@ public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException,
ResourceAllocationException, ResourceUnavailableException {
PrivateGateway result = _vpcService.applyVpcGateway(getEntityId());
PrivateGateway result = _vpcService.applyVpcPrivateGateway(getEntityId());
if (result != null) {
PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponse(result);
response.setResponseName(getCommandName());

View File

@ -31,6 +31,7 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.VpcGateway;
import com.cloud.user.UserContext;
/**
@ -122,7 +123,7 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
@Override
public long getEntityOwnerId() {
PrivateGateway gateway = _vpcService.getVpcPrivateGateway(gatewayId);
VpcGateway gateway = _vpcService.getVpcGateway(gatewayId);
if (gateway == null) {
throw new InvalidParameterValueException("Invalid gateway id is specified");
}
@ -136,11 +137,11 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{
@Override
public Long getSyncObjId() {
PrivateGateway privateGateway = _vpcService.getVpcPrivateGateway(gatewayId);
if (privateGateway == null) {
VpcGateway gateway = _vpcService.getVpcGateway(gatewayId);
if (gateway == null) {
throw new InvalidParameterValueException("Invalid id is specified for the gateway");
}
return privateGateway.getVpcId();
return gateway.getVpcId();
}
@Override

View File

@ -93,7 +93,7 @@ public class DeletePrivateGatewayCmd extends BaseAsyncCmd {
@Override
public String getSyncObjType() {
return BaseAsyncCmd.networkSyncObject;
return BaseAsyncCmd.vpcSyncObject;
}
@Override

View File

@ -16,8 +16,5 @@ package com.cloud.network.vpc;
* @author Alena Prokharchyk
*/
public interface PrivateGateway extends VpcGateway{
String getVlanTag();
String getGateway();
String getNetmask();
long getPhysicalNetworkId();
}

View File

@ -17,7 +17,7 @@ package com.cloud.network.vpc;
*/
public class StaticRouteProfile implements StaticRoute{
private long id;
private String cidr;
private String targetCidr;
private long accountId;
private long domainId;
private long gatewayId;
@ -29,9 +29,9 @@ public class StaticRouteProfile implements StaticRoute{
String ipAddress;
public StaticRouteProfile(StaticRoute staticRoute, PrivateGateway gateway) {
public StaticRouteProfile(StaticRoute staticRoute, VpcGateway gateway) {
this.id = staticRoute.getId();
this.cidr = staticRoute.getCidr();
this.targetCidr = staticRoute.getCidr();
this.accountId = staticRoute.getAccountId();
this.domainId = staticRoute.getDomainId();
this.gatewayId = staticRoute.getVpcGatewayId();
@ -60,7 +60,7 @@ public class StaticRouteProfile implements StaticRoute{
@Override
public String getCidr() {
return cidr;
return targetCidr;
}
@Override

View File

@ -50,4 +50,19 @@ public interface VpcGateway extends Identity {
* @return
*/
Long getNetworkId();
/**
* @return
*/
String getGateway();
/**
* @return
*/
String getNetmask();
/**
* @return
*/
String getVlanTag();
}

View File

@ -164,7 +164,7 @@ public interface VpcService {
* @throws ResourceUnavailableException
* @throws ConcurrentOperationException
*/
public PrivateGateway applyVpcGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException;
public PrivateGateway applyVpcPrivateGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* @param id
@ -213,4 +213,10 @@ public interface VpcService {
*/
public List<? extends StaticRoute> listStaticRoutes(ListStaticRoutesCmd cmd);
/**
* @param id
* @return
*/
VpcGateway getVpcGateway(long id);
}

View File

@ -83,6 +83,7 @@ import com.cloud.network.vpc.PrivateGateway;
import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.StaticRouteProfile;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcGateway;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.Dao.StaticRouteDao;
import com.cloud.network.vpc.Dao.VpcDao;
@ -819,11 +820,11 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
//3) RE-APPLY ALL STATIC ROUTE RULES
List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(router.getVpcId());
List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
Map<Long, PrivateGateway> gatewayMap = new HashMap<Long, PrivateGateway>();
Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
for (StaticRoute route : routes) {
PrivateGateway gateway = gatewayMap.get(route.getVpcGatewayId());
VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId());
if (gateway == null) {
gateway = _vpcMgr.getVpcPrivateGateway(route.getVpcGatewayId());
gateway = _vpcMgr.getVpcGateway(route.getVpcGatewayId());
gatewayMap.put(gateway.getId(), gateway);
}
staticRouteProfiles.add(new StaticRouteProfile(route, gateway));

View File

@ -17,24 +17,15 @@ package com.cloud.network.vpc;
*/
public class PrivateGatewayProfile implements PrivateGateway{
VpcGateway vpcGateway;
String vlanTag;
String gateway;
String netmask;
long physicalNetworkId;
/**
* @param vpcGateway
* @param vlanTag
* @param gateway
* @param netmask
* @param physicalNetworkId TODO
*/
public PrivateGatewayProfile(VpcGateway vpcGateway, String vlanTag, String gateway, String netmask, long physicalNetworkId) {
public PrivateGatewayProfile(VpcGateway vpcGateway, long physicalNetworkId) {
super();
this.vpcGateway = vpcGateway;
this.vlanTag = vlanTag;
this.gateway = gateway;
this.netmask = netmask;
this.physicalNetworkId = physicalNetworkId;
}
@ -75,17 +66,17 @@ public class PrivateGatewayProfile implements PrivateGateway{
@Override
public String getVlanTag() {
return vlanTag;
return vpcGateway.getVlanTag();
}
@Override
public String getGateway() {
return gateway;
return vpcGateway.getGateway();
}
@Override
public String getNetmask() {
return netmask;
return vpcGateway.getNetmask();
}
@Override

View File

@ -42,6 +42,15 @@ public class VpcGatewayVO implements VpcGateway{
@Column(name = "ip4_address")
String ip4Address;
@Column(name="gateway")
String gateway;
@Column(name="netmask")
String netmask;
@Column(name="vlan_tag")
String vlanTag;
@Column(name = "type")
@Enumerated(value = EnumType.STRING)
VpcGateway.Type type;
@ -74,15 +83,20 @@ public class VpcGatewayVO implements VpcGateway{
* @param vpcId
* @param zoneId
* @param networkId
* @param vlanTag TODO
* @param gateway TODO
* @param netmask TODO
* @param account_id
*/
public VpcGatewayVO(String ip4Address, Type type, Long vpcId, long zoneId, Long networkId) {
super();
public VpcGatewayVO(String ip4Address, Type type, Long vpcId, long zoneId, Long networkId, String vlanTag, String gateway, String netmask) {
this.ip4Address = ip4Address;
this.type = type;
this.vpcId = vpcId;
this.zoneId = zoneId;
this.networkId = networkId;
this.vlanTag = vlanTag;
this.gateway = gateway;
this.netmask = netmask;
this.uuid = UUID.randomUUID().toString();
}
@ -127,4 +141,19 @@ public class VpcGatewayVO implements VpcGateway{
buf.append(id).append("|").append(ip4Address.toString()).append("|").append(vpcId).append("]");
return buf.toString();
}
@Override
public String getGateway() {
return gateway;
}
@Override
public String getNetmask() {
return netmask;
}
@Override
public String getVlanTag() {
return vlanTag;
}
}

View File

@ -994,12 +994,15 @@ public class VpcManagerImpl implements VpcManager, Manager{
}
return getPrivateGatewayProfile(gateway);
}
@Override
public VpcGateway getVpcGateway(long id) {
return _vpcGatewayDao.findById(id);
}
protected PrivateGateway getPrivateGatewayProfile(VpcGateway gateway) {
Network network = _ntwkMgr.getNetwork(gateway.getNetworkId());
String vlanTag = network.getBroadcastUri().getHost();
String netmask = NetUtils.getCidrNetmask(network.getCidr());
return new PrivateGatewayProfile(gateway, vlanTag, network.getGateway(),netmask, network.getPhysicalNetworkId());
return new PrivateGatewayProfile(gateway, network.getPhysicalNetworkId());
}
@Override
@ -1042,7 +1045,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
//2) create gateway entry
gatewayVO = new VpcGatewayVO(ipAddress, VpcGateway.Type.Private, vpcId, privateNtwk.getDataCenterId(),
privateNtwk.getId());
privateNtwk.getId(), vlan, gateway, netmask);
_vpcGatewayDao.persist(gatewayVO);
s_logger.debug("Created vpc gateway entry " + gatewayVO);
@ -1054,7 +1057,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
@Override
public PrivateGateway applyVpcGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException {
public PrivateGateway applyVpcPrivateGateway(Long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException {
PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
if (getVpcElement().createPrivateGateway(gateway)) {
s_logger.debug("Private gateway " + gateway + " was applied succesfully on the backend");
@ -1183,11 +1186,11 @@ public class VpcManagerImpl implements VpcManager, Manager{
protected boolean applyStaticRoutes(List<? extends StaticRoute> routes, Account caller, boolean updateRoutesInDB) throws ResourceUnavailableException {
boolean success = true;
List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
Map<Long, PrivateGateway> gatewayMap = new HashMap<Long, PrivateGateway>();
Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
for (StaticRoute route : routes) {
PrivateGateway gateway = gatewayMap.get(route.getVpcGatewayId());
VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId());
if (gateway == null) {
gateway = getVpcPrivateGateway(route.getVpcGatewayId());
gateway = _vpcGatewayDao.findById(route.getVpcGatewayId());
gatewayMap.put(gateway.getId(), gateway);
}
staticRouteProfiles.add(new StaticRouteProfile(route, gateway));
@ -1275,7 +1278,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
Account caller = UserContext.current().getCaller();
//parameters validation
PrivateGateway gateway = getVpcPrivateGateway(gatewayId);
VpcGateway gateway = _vpcGatewayDao.findById(gatewayId);
if (gateway == null) {
throw new InvalidParameterValueException("Invalid gateway id is given");
}

View File

@ -2255,6 +2255,9 @@ CREATE TABLE `cloud`.`vpc_gateways` (
`id` bigint unsigned NOT NULL UNIQUE AUTO_INCREMENT COMMENT 'id',
`uuid` varchar(40),
`ip4_address` char(40) COMMENT 'ip4 address of the gateway',
`netmask` varchar(15) COMMENT 'netmask of the gateway',
`gateway` varchar(15) COMMENT 'gateway',
`vlan_tag` varchar(255),
`type` varchar(32) COMMENT 'type of gateway; can be Public/Private/Vpn',
`network_id` bigint unsigned NOT NULL COMMENT 'network id vpc gateway belongs to',
`vpc_id` bigint unsigned NOT NULL COMMENT 'id of the vpc the gateway belongs to',