Fixes/improvements for VPC feature:

1) Added comments to VPC/VPCService/VPCManager interfaces
2) Moved VPC offering related methods from VpcService to the new interface - VpcProvisioningService
3) Fixed static nat creation in the VPC - used to result in NPE due to invalid method referencing while obtaining VPC VR information
This commit is contained in:
Alena Prokharchyk 2013-03-29 16:24:24 -07:00
parent f8471e545f
commit cf72aa3274
28 changed files with 398 additions and 310 deletions

View File

@ -261,4 +261,6 @@ public interface NetworkModel {
String getStartIpv6Address(long id);
Nic getPlaceholderNic(Network network, Long podId);
boolean isProviderEnabledInZone(long zoneId, String provider);
}

View File

@ -20,32 +20,63 @@ import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
import com.cloud.network.Network;
public interface Vpc extends ControlledEntity, Identity, InternalIdentity {
public enum State {
Enabled,
Inactive
}
public static final String _supportedProviders = Network.Provider.VPCVirtualRouter.getName();
boolean readyToUse();
/**
*
* @return VPC name
*/
String getName();
/**
* @return the id of the zone the VPC belongs to
*/
long getZoneId();
/**
* @return super CIDR of the VPC. All the networks participating in VPC, should have CIDRs that are the part of the super cidr
*/
String getCidr();
/**
*
* @return VPC state
*/
State getState();
/**
*
* @return VPC offering id - the offering that VPC is created from
*/
long getVpcOfferingId();
/**
*
* @return VPC display text
*/
String getDisplayText();
/**
*
* @return VPC network domain. All networks participating in the VPC, become the part of the same network domain
*/
String getNetworkDomain();
/**
*
* @return true if restart is required for the VPC; false otherwise
*/
boolean isRestartRequired();
}

View File

@ -27,18 +27,33 @@ public interface VpcOffering extends InternalIdentity, Identity {
public static final String defaultVPCOfferingName = "Default VPC offering";
/**
*
* @return VPC offering name
*/
String getName();
String getUniqueName();
/**
* @return VPC offering display text
*/
String getDisplayText();
/**
*
* @return VPC offering state
*/
State getState();
/**
*
* @return true if offering is default - came with the cloudStack fresh install; false otherwise
*/
boolean isDefault();
/**
* @return
* @return service offering id used by VPC virutal router
*/
Long getServiceOfferingId();

View File

@ -0,0 +1,46 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// 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,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.vpc;
import java.util.List;
import java.util.Map;
public interface VpcProvisioningService {
public VpcOffering getVpcOffering(long vpcOfferingId);
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices, Map<String, List<String>> serviceProviders);
List<? extends VpcOffering> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr,
Boolean isDefault, String keyword, String state, Long startIndex, Long pageSizeVal);
/**
* @param offId
* @return
*/
public boolean deleteVpcOffering(long offId);
/**
* @param vpcOffId
* @param vpcOfferingName
* @param displayText
* @param state
* @return
*/
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state);
}

View File

@ -18,7 +18,6 @@ package com.cloud.network.vpc;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
@ -31,45 +30,29 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.Pair;
public interface VpcService {
public VpcOffering getVpcOffering(long vpcOfferingId);
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices, Map<String, List<String>> serviceProviders);
/**Returns existing VPC found by id
*
* @param vpcId
* @return
*/
public Vpc getVpc(long vpcId);
public Vpc getActiveVpc(long vpcId);
/**
* Returns all the Guest networks that are part of VPC
*
* @param vpcId
* @return
*/
public List<? extends Network> getVpcNetworks(long vpcId);
Map<Service, Set<Provider>> getVpcOffSvcProvidersMap(long vpcOffId);
List<? extends VpcOffering> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr,
Boolean isDefault, String keyword, String state, Long startIndex, Long pageSizeVal);
/**
* @param offId
* @return
*/
public boolean deleteVpcOffering(long offId);
/**
* @param vpcOffId
* @param vpcOfferingName
* @param displayText
* @param state
* @return
*/
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state);
/**
* Persists VPC record in the database
*
* @param zoneId
* @param vpcOffId
* @param vpcOwnerId
@ -83,7 +66,10 @@ public interface VpcService {
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr,
String networkDomain) throws ResourceAllocationException;
/**
* Deletes a VPC
*
* @param vpcId
* @return
* @throws InsufficientCapacityException
@ -92,7 +78,10 @@ public interface VpcService {
*/
public boolean deleteVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* Updates VPC with new name/displayText
*
* @param vpcId
* @param vpcName
* @param displayText
@ -100,7 +89,10 @@ public interface VpcService {
*/
public Vpc updateVpc(long vpcId, String vpcName, String displayText);
/**
* Lists VPC(s) based on the parameters passed to the method call
*
* @param id
* @param vpcName
* @param displayText
@ -127,6 +119,8 @@ public interface VpcService {
Boolean restartRequired, Map<String, String> tags, Long projectId);
/**
* Starts VPC which includes starting VPC provider and applying all the neworking rules on the backend
*
* @param vpcId
* @param destroyOnFailure TODO
* @return
@ -138,6 +132,8 @@ public interface VpcService {
ResourceUnavailableException, InsufficientCapacityException;
/**
* Shuts down the VPC which includes shutting down all VPC provider and rules cleanup on the backend
*
* @param vpcId
* @return
* @throws ConcurrentOperationException
@ -145,16 +141,28 @@ public interface VpcService {
*/
boolean shutdownVpc(long vpcId) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* Restarts the VPC. VPC gets shutdown and started as a part of it
*
* @param id
* @return
* @throws InsufficientCapacityException
*/
boolean restartVpc(long id) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
/**
* Returns a Private gateway found in the VPC by id
*
* @param id
* @return
*/
PrivateGateway getVpcPrivateGateway(long id);
/**
* Persists VPC private gateway in the Database.
*
* @param vpcId TODO
* @param physicalNetworkId
* @param vlan
@ -172,6 +180,8 @@ public interface VpcService {
ConcurrentOperationException, InsufficientCapacityException;
/**
* Applies VPC private gateway on the backend, so it becomes functional
*
* @param gatewayId
* @param destroyOnFailure TODO
* @return
@ -180,7 +190,10 @@ public interface VpcService {
*/
public PrivateGateway applyVpcPrivateGateway(long gatewayId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* Deletes VPC private gateway
*
* @param id
* @return
* @throws ResourceUnavailableException
@ -188,52 +201,76 @@ public interface VpcService {
*/
boolean deleteVpcPrivateGateway(long gatewayId) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* Returns the list of Private gateways existing in the VPC
*
* @param listPrivateGatewaysCmd
* @return
*/
public Pair<List<PrivateGateway>, Integer> listPrivateGateway(ListPrivateGatewaysCmd listPrivateGatewaysCmd);
/**
* Returns Static Route found by Id
*
* @param routeId
* @return
*/
StaticRoute getStaticRoute(long routeId);
/**
* Applies existing Static Routes to the VPC elements
*
* @param vpcId
* @return
* @throws ResourceUnavailableException
*/
public boolean applyStaticRoutes(long vpcId) throws ResourceUnavailableException;
/**
* Deletes static route from the backend and the database
*
* @param routeId
* @return TODO
* @throws ResourceUnavailableException
*/
public boolean revokeStaticRoute(long routeId) throws ResourceUnavailableException;
/**
* Persists static route entry in the Database
*
* @param gatewayId
* @param cidr
* @return
*/
public StaticRoute createStaticRoute(long gatewayId, String cidr) throws NetworkRuleConflictException;
/**
* Lists static routes based on parameters passed to the call
*
* @param listStaticRoutesCmd
* @return
*/
public Pair<List<? extends StaticRoute>, Integer> listStaticRoutes(ListStaticRoutesCmd cmd);
/**
* Returns gateway (VPN or Public) existign in the VPC
*
* @param id
* @return
*/
VpcGateway getVpcGateway(long id);
/**
* Associates IP address from the Public network, to the VPC
*
* @param ipId
* @param vpcId
* @return
@ -245,6 +282,4 @@ public interface VpcService {
IpAddress associateIPToVpc(long ipId, long vpcId) throws ResourceAllocationException, ResourceUnavailableException,
InsufficientAddressCapacityException, ConcurrentOperationException;
public Network updateVpcGuestNetwork(long networkId, String name, String displayText, Account callerAccount,
User callerUser, String domainSuffix, Long ntwkOffId, Boolean changeCidr, String guestVmCidr);
}

View File

@ -52,6 +52,7 @@ import com.cloud.network.firewall.NetworkACLService;
import com.cloud.network.lb.LoadBalancingRulesService;
import com.cloud.network.rules.RulesService;
import com.cloud.network.security.SecurityGroupService;
import com.cloud.network.vpc.VpcProvisioningService;
import com.cloud.network.vpc.VpcService;
import com.cloud.network.vpn.RemoteAccessVpnService;
import com.cloud.network.vpn.Site2SiteVpnService;
@ -132,6 +133,7 @@ public abstract class BaseCmd {
@Inject public NetworkUsageService _networkUsageService;
@Inject public VMSnapshotService _vmSnapshotService;
@Inject public DataStoreProviderApiService dataStoreProviderApiService;
@Inject public VpcProvisioningService _vpcProvSvc;
public abstract void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException;

View File

@ -98,7 +98,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
@Override
public void create() throws ResourceAllocationException {
VpcOffering vpcOff = _vpcService.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices(), getServiceProviders());
VpcOffering vpcOff = _vpcProvSvc.createVpcOffering(getVpcOfferingName(), getDisplayText(), getSupportedServices(), getServiceProviders());
if (vpcOff != null) {
this.setEntityId(vpcOff.getId());
this.setEntityUuid(vpcOff.getUuid());
@ -109,7 +109,7 @@ public class CreateVPCOfferingCmd extends BaseAsyncCreateCmd{
@Override
public void execute() {
VpcOffering vpc = _vpcService.getVpcOffering(this.getEntityId());
VpcOffering vpc = _vpcProvSvc.getVpcOffering(this.getEntityId());
if (vpc != null) {
VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(vpc);
response.setResponseName(getCommandName());

View File

@ -66,7 +66,7 @@ public class DeleteVPCOfferingCmd extends BaseAsyncCmd{
@Override
public void execute(){
boolean result = _vpcService.deleteVpcOffering(getId());
boolean result = _vpcProvSvc.deleteVpcOffering(getId());
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
this.setResponseObject(response);

View File

@ -88,7 +88,7 @@ public class UpdateVPCOfferingCmd extends BaseAsyncCmd{
@Override
public void execute(){
VpcOffering result = _vpcService.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
VpcOffering result = _vpcProvSvc.updateVpcOffering(getId(), getVpcOfferingName(), getDisplayText(), getState());
if (result != null) {
VpcOfferingResponse response = _responseGenerator.createVpcOfferingResponse(result);
response.setResponseName(getCommandName());

View File

@ -129,14 +129,9 @@ public class UpdateNetworkCmd extends BaseAsyncCmd {
throw new InvalidParameterValueException("Couldn't find network by id");
}
Network result = null;
if (network.getVpcId() != null) {
result = _vpcService.updateVpcGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
Network result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr(), getGuestVmCidr());
} else {
result = _networkService.updateGuestNetwork(getId(), getNetworkName(), getDisplayText(), callerAccount,
callerUser, getNetworkDomain(), getNetworkOfferingId(), getChangeCidr(), getGuestVmCidr());
}
if (result != null) {
NetworkResponse response = _responseGenerator.createNetworkResponse(result);

View File

@ -92,7 +92,7 @@ public class ListVPCOfferingsCmd extends BaseListCmd{
@Override
public void execute(){
List<? extends VpcOffering> offerings = _vpcService.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(),
List<? extends VpcOffering> offerings = _vpcProvSvc.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(),
getSupportedServices(), isDefault, this.getKeyword(), getState(), this.getStartIndex(), this.getPageSizeVal());
ListResponse<VpcOfferingResponse> response = new ListResponse<VpcOfferingResponse>();
List<VpcOfferingResponse> offeringResponses = new ArrayList<VpcOfferingResponse>();

View File

@ -95,8 +95,20 @@ import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationService;
import com.cloud.configuration.Resource.ResourceType;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.dc.*;
import com.cloud.dc.dao.*;
import com.cloud.dc.AccountVlanMapVO;
import com.cloud.dc.ClusterDetailsDao;
import com.cloud.dc.ClusterDetailsVO;
import com.cloud.dc.ClusterVO;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan;
import com.cloud.dc.VlanVO;
import com.cloud.dc.dao.AccountVlanMapDao;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.HostPodDao;
import com.cloud.dc.dao.VlanDao;
import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.Event;
@ -162,7 +174,12 @@ import com.cloud.network.security.SecurityGroup;
import com.cloud.network.security.SecurityGroupManager;
import com.cloud.network.security.SecurityGroupVO;
import com.cloud.network.security.dao.SecurityGroupDao;
import com.cloud.network.vpc.*;
import com.cloud.network.vpc.StaticRouteVO;
import com.cloud.network.vpc.VpcGatewayVO;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.VpcOffering;
import com.cloud.network.vpc.VpcProvisioningService;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.dao.StaticRouteDao;
import com.cloud.network.vpc.dao.VpcDao;
import com.cloud.network.vpc.dao.VpcGatewayDao;
@ -177,19 +194,57 @@ import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectInvitation;
import com.cloud.projects.ProjectService;
import com.cloud.resource.ResourceManager;
import com.cloud.server.*;
import com.cloud.server.Criteria;
import com.cloud.server.ManagementServer;
import com.cloud.server.ResourceTag;
import com.cloud.server.ResourceTag.TaggedResourceType;
import com.cloud.server.StatsCollector;
import com.cloud.server.TaggedResourceService;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.*;
import com.cloud.storage.DiskOfferingVO;
import com.cloud.storage.GuestOS;
import com.cloud.storage.GuestOSCategoryVO;
import com.cloud.storage.Snapshot;
import com.cloud.storage.SnapshotVO;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.StorageManager;
import com.cloud.storage.StoragePool;
import com.cloud.storage.StorageStats;
import com.cloud.storage.UploadVO;
import com.cloud.storage.VMTemplateHostVO;
import com.cloud.storage.VMTemplateS3VO;
import com.cloud.storage.VMTemplateSwiftVO;
import com.cloud.storage.VMTemplateVO;
import com.cloud.storage.Volume;
import com.cloud.storage.Volume.Type;
import com.cloud.storage.dao.*;
import com.cloud.storage.VolumeHostVO;
import com.cloud.storage.VolumeManager;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.GuestOSCategoryDao;
import com.cloud.storage.dao.GuestOSDao;
import com.cloud.storage.dao.SnapshotDao;
import com.cloud.storage.dao.SnapshotPolicyDao;
import com.cloud.storage.dao.UploadDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VMTemplateDetailsDao;
import com.cloud.storage.dao.VMTemplateHostDao;
import com.cloud.storage.dao.VMTemplateS3Dao;
import com.cloud.storage.dao.VMTemplateSwiftDao;
import com.cloud.storage.dao.VolumeDao;
import com.cloud.storage.dao.VolumeHostDao;
import com.cloud.storage.snapshot.SnapshotPolicy;
import com.cloud.template.TemplateManager;
import com.cloud.user.*;
import com.cloud.user.Account;
import com.cloud.user.AccountDetailsDao;
import com.cloud.user.AccountVO;
import com.cloud.user.ResourceLimitService;
import com.cloud.user.SSHKeyPairVO;
import com.cloud.user.User;
import com.cloud.user.UserAccount;
import com.cloud.user.UserStatisticsVO;
import com.cloud.user.UserVO;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.SSHKeyPairDao;
import com.cloud.user.dao.UserDao;
@ -202,7 +257,6 @@ import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.InstanceGroup;
import com.cloud.vm.InstanceGroupVO;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicSecondaryIp;
import com.cloud.vm.UserVmDetailVO;
import com.cloud.vm.UserVmManager;
import com.cloud.vm.UserVmVO;
@ -324,6 +378,7 @@ public class ApiDBUtils {
static VMSnapshotDao _vmSnapshotDao;
static ClusterDetailsDao _clusterDetailsDao;
static NicSecondaryIpDao _nicSecondaryIpDao;
static VpcProvisioningService _vpcProvSvc;
@Inject private ManagementServer ms;
@Inject public AsyncJobManager asyncMgr;
@ -427,6 +482,7 @@ public class ApiDBUtils {
@Inject private ClusterDetailsDao clusterDetailsDao;
@Inject private VMSnapshotDao vmSnapshotDao;
@Inject private NicSecondaryIpDao nicSecondaryIpDao;
@Inject private VpcProvisioningService vpcProvSvc;
@PostConstruct
void init() {
_ms = ms;
@ -528,6 +584,7 @@ public class ApiDBUtils {
_clusterDetailsDao = clusterDetailsDao;
_vmSnapshotDao = vmSnapshotDao;
_nicSecondaryIpDao = nicSecondaryIpDao;
_vpcProvSvc = vpcProvSvc;
// Note: stats collector should already have been initialized by this time, otherwise a null instance is returned
_statsCollector = StatsCollector.getInstance();
}

View File

@ -20,8 +20,8 @@ import java.util.List;
import java.util.Map;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.Pod;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.deploy.DataCenterDeployment;
@ -51,13 +51,11 @@ import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.NicSecondaryIp;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
/**
* NetworkManager manages the network for the different end users.

View File

@ -1528,7 +1528,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
// associate a source NAT IP (if one isn't already associated with the network)
boolean sharedSourceNat = offering.getSharedSourceNat();
DataCenter zone = _dcDao.findById(network.getDataCenterId());
if (network.getGuestType() == Network.GuestType.Isolated
&& _networkModel.areServicesSupportedInNetwork(network.getId(), Service.SourceNat)
&& !sharedSourceNat) {

View File

@ -1212,6 +1212,19 @@ public class NetworkModelImpl extends ManagerBase implements NetworkModel {
}
return isProviderEnabled(ntwkSvcProvider);
}
@Override
public boolean isProviderEnabledInZone(long zoneId, String provider)
{
//the provider has to be enabled at least in one network in the zone
for (PhysicalNetwork pNtwk : _physicalNetworkDao.listByZone(zoneId)) {
if (isProviderEnabledInPhysicalNetwork(pNtwk.getId(), provider)) {
return true;
}
}
return false;
}
@Override
public String getNetworkTag(HypervisorType hType, Network network) {

View File

@ -94,6 +94,7 @@ import com.cloud.network.rules.FirewallRuleVO;
import com.cloud.network.rules.PortForwardingRuleVO;
import com.cloud.network.rules.RulesManager;
import com.cloud.network.vpc.PrivateIpVO;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.dao.PrivateIpDao;
import com.cloud.offering.NetworkOffering;
@ -1715,6 +1716,12 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
ex.addProxyObject("networks", networkId, "networkId");
throw ex;
}
//perform below validation if the network is vpc network
if (network.getVpcId() != null && networkOfferingId != null) {
Vpc vpc = _vpcMgr.getVpc(network.getVpcId());
_vpcMgr.validateNtwkOffForNtwkInVpc(networkId, networkOfferingId, null, null, vpc, null, _accountMgr.getAccount(network.getAccountId()));
}
// don't allow to update network in Destroy state
if (network.getState() == Network.State.Destroy) {

View File

@ -37,6 +37,7 @@ import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.Site2SiteVpnConnection;
import com.cloud.network.Site2SiteVpnGateway;
@ -76,6 +77,8 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
Site2SiteVpnGatewayDao _vpnGatewayDao;
@Inject
IPAddressDao _ipAddressDao;
@Inject
NetworkModel _ntwkModel;
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@ -322,7 +325,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
return false;
}
List<DomainRouterVO> routers = _vpcMgr.getVpcRouters(gateway.getVpcId());
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
if (routers == null || routers.isEmpty()) {
s_logger.debug(this.getName() + " element doesn't need to create Private gateway on the backend; VPC virtual " +
"router doesn't exist in the vpc id=" + gateway.getVpcId());
@ -345,7 +348,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
return false;
}
List<DomainRouterVO> routers = _vpcMgr.getVpcRouters(gateway.getVpcId());
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(gateway.getVpcId());
if (routers == null || routers.isEmpty()) {
s_logger.debug(this.getName() + " element doesn't need to delete Private gateway on the backend; VPC virtual " +
"router doesn't exist in the vpc id=" + gateway.getVpcId());
@ -361,10 +364,6 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
return _vpcRouterMgr.destroyPrivateGateway(gateway, router);
}
@Override
protected List<DomainRouterVO> getRouters(Network network, DeployDestination dest) {
return _vpcMgr.getVpcRouters(network.getVpcId());
}
@Override
public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> services)
@ -377,7 +376,7 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
}
}
if (canHandle) {
List<DomainRouterVO> routers = getRouters(network, null);
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
if (routers == null || routers.isEmpty()) {
s_logger.debug(this.getName() + " element doesn't need to associate ip addresses on the backend; VPC virtual " +
"router doesn't exist in the network " + network.getId());
@ -446,12 +445,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
Long vpcId = ip.getVpcId();
Vpc vpc = _vpcMgr.getVpc(vpcId);
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
DataCenter.class, vpc.getZoneId());
}
List<DomainRouterVO> routers = _vpcMgr.getVpcRouters(ip.getVpcId());
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
if (routers == null || routers.size() != 1) {
throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(),
DataCenter.class, vpc.getZoneId());
@ -474,12 +473,12 @@ public class VpcVirtualRouterElement extends VirtualRouterElement implements Vpc
Long vpcId = ip.getVpcId();
Vpc vpc = _vpcMgr.getVpc(vpcId);
if (!_vpcMgr.vpcProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) {
throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(),
DataCenter.class, vpc.getZoneId());
}
List<DomainRouterVO> routers = _vpcMgr.getVpcRouters(ip.getVpcId());
List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId());
if (routers == null || routers.size() != 1) {
throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(),
DataCenter.class, vpc.getZoneId());

View File

@ -101,4 +101,10 @@ public interface VpcVirtualNetworkApplianceManager extends VirtualNetworkApplian
* @throws ResourceUnavailableException
*/
boolean stopSite2SiteVpn(Site2SiteVpnConnection conn, VirtualRouter router) throws ResourceUnavailableException;
/**
* @param vpcId
* @return
*/
List<DomainRouterVO> getVpcRouters(long vpcId);
}

View File

@ -234,7 +234,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
long dcId = dest.getDataCenter().getId();
DeploymentPlan plan = new DataCenterDeployment(dcId);
List<DomainRouterVO> routers = _routerDao.listByVpcId(vpcId);
List<DomainRouterVO> routers = getVpcRouters(vpcId);
return new Pair<DeploymentPlan, List<DomainRouterVO>>(plan, routers);
}
@ -1212,7 +1212,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
networks = super.createRouterNetworks(owner, isRedundant, plan, null, sourceNatIp);
//2) allocate nic for private gateway if needed
VpcGateway privateGateway = _vpcMgr.getPrivateGatewayForVpc(vpcId);
PrivateGateway privateGateway = _vpcMgr.getVpcPrivateGateway(vpcId);
if (privateGateway != null) {
NicProfile privateNic = createPrivateNicProfileForGateway(privateGateway);
Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
@ -1233,7 +1233,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
for (IPAddressVO ip : ips) {
PublicIp publicIp = PublicIp.createFromAddrAndVlan(ip, _vlanDao.findById(ip.getVlanId()));
if ((ip.getState() == IpAddress.State.Allocated || ip.getState() == IpAddress.State.Allocating)
&& _vpcMgr.ipUsedInVpc(ip)&& !publicVlans.contains(publicIp.getVlanTag())) {
&& _vpcMgr.isIpAllocatedToVpc(ip)&& !publicVlans.contains(publicIp.getVlanTag())) {
s_logger.debug("Allocating nic for router in vlan " + publicIp.getVlanTag());
NicProfile publicNic = new NicProfile();
publicNic.setDefaultNic(false);
@ -1314,7 +1314,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
long publicNtwkId = ip.getNetworkId();
//if ip is not associated to any network, and there are no firewall rules, release it on the backend
if (!_vpcMgr.ipUsedInVpc(ip)) {
if (!_vpcMgr.isIpAllocatedToVpc(ip)) {
ip.setState(IpAddress.State.Releasing);
}
@ -1334,7 +1334,7 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
long publicNtwkId = ip.getNetworkId();
//if ip is not associated to any network, and there are no firewall rules, release it on the backend
if (!_vpcMgr.ipUsedInVpc(ip)) {
if (!_vpcMgr.isIpAllocatedToVpc(ip)) {
ip.setState(IpAddress.State.Releasing);
}
@ -1376,4 +1376,9 @@ public class VpcVirtualNetworkApplianceManagerImpl extends VirtualNetworkApplian
}
}
@Override
public List<DomainRouterVO> getVpcRouters(long vpcId) {
return _routerDao.listByVpcId(vpcId);
}
}

View File

@ -17,8 +17,11 @@
package com.cloud.network.vpc;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
@ -27,33 +30,27 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.IpAddress;
import com.cloud.network.Network;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.addr.PublicIp;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.vm.DomainRouterVO;
public interface VpcManager extends VpcService{
/**
* @param ntwkOffId
* @param cidr
* @param networkDomain
* @param networkOwner
* @param vpc TODO
* @param networkId TODO
* @param gateway TODO
* Returns all existing VPCs for a given account
* @param accountId
* @return
*/
void validateNtkwOffForVpc(long ntwkOffId, String cidr, String networkDomain, Account networkOwner,
Vpc vpc, Long networkId, String gateway);
List<? extends Vpc> getVpcsForAccount(long accountId);
/**
* Destroys the VPC
*
* @param vpc
* @param caller TODO
* @param callerUserId TODO
@ -63,34 +60,19 @@ public interface VpcManager extends VpcService{
*/
boolean destroyVpc(Vpc vpc, Account caller, Long callerUserId) throws ConcurrentOperationException, ResourceUnavailableException;
/**
* @param vpcId
* @return
*/
List<DomainRouterVO> getVpcRouters(long vpcId);
/**
* @param zoneId
* @param provider
* @return
*/
boolean vpcProviderEnabledInZone(long zoneId, String provider);
/**
* @param vpcId
* @return
*/
VpcGateway getPrivateGatewayForVpc(long vpcId);
/**
* Returns true if the IP is allocated to the VPC; false otherwise
*
* @param ip
* @return
*/
boolean ipUsedInVpc(IpAddress ip);
boolean isIpAllocatedToVpc(IpAddress ip);
/**
* Disassociates the public IP address from VPC
*
* @param ipId
* @param networkId
*/
@ -98,6 +80,8 @@ public interface VpcManager extends VpcService{
/**
* Creates guest network in the VPC
*
* @param ntwkOffId
* @param name
* @param displayText
@ -125,9 +109,11 @@ public interface VpcManager extends VpcService{
/**
* Assigns source nat public IP address to VPC
*
* @param owner
* @param vpc
* @return
* @return public IP address object
* @throws InsufficientAddressCapacityException
* @throws ConcurrentOperationException
*/
@ -135,6 +121,8 @@ public interface VpcManager extends VpcService{
/**
* Validates network offering to find if it can be used for network creation in VPC
*
* @param guestNtwkOff
* @param supportedSvcs TODO
*/
@ -142,8 +130,36 @@ public interface VpcManager extends VpcService{
/**
* @return
* @return list of hypervisors that are supported by VPC
*/
List<HypervisorType> getSupportedVpcHypervisors();
/**
* Lists all the services and providers that the current VPC suppots
* @param vpcOffId
* @return map of Service to Provider(s) map
*/
Map<Service, Set<Provider>> getVpcOffSvcProvidersMap(long vpcOffId);
/**
* Returns VPC that is ready to be used
* @param vpcId
* @return VPC object
*/
public Vpc getActiveVpc(long vpcId);
/**
* Performs network offering validation to determine if it can be used for network upgrade inside the VPC
* @param networkId
* @param newNtwkOffId
* @param newCidr
* @param newNetworkDomain
* @param vpc
* @param gateway
* @param networkOwner TODO
*/
void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner);
}

View File

@ -31,13 +31,12 @@ import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.network.element.StaticNatServiceProvider;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
import org.apache.cloudstack.api.command.user.vpc.ListStaticRoutesCmd;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.api.command.user.vpc.ListPrivateGatewaysCmd;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.Resource.ResourceType;
@ -77,6 +76,7 @@ import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkDao;
import com.cloud.network.dao.Site2SiteVpnGatewayDao;
import com.cloud.network.element.StaticNatServiceProvider;
import com.cloud.network.element.VpcProvider;
import com.cloud.network.vpc.VpcOffering.State;
import com.cloud.network.vpc.dao.PrivateIpDao;
@ -103,8 +103,6 @@ import com.cloud.user.UserContext;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.utils.Ternary;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.ManagerBase;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
@ -124,8 +122,8 @@ import com.cloud.vm.dao.DomainRouterDao;
@Component
@Local(value = { VpcManager.class, VpcService.class })
public class VpcManagerImpl extends ManagerBase implements VpcManager{
@Local(value = { VpcManager.class, VpcService.class, VpcProvisioningService.class })
public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvisioningService{
private static final Logger s_logger = Logger.getLogger(VpcManagerImpl.class);
@Inject
VpcOfferingDao _vpcOffDao;
@ -584,19 +582,6 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
return createVpc(zoneId, vpcOffId, owner, vpcName, displayText, cidr, networkDomain);
}
@Override
public boolean vpcProviderEnabledInZone(long zoneId, String provider)
{
//the provider has to be enabled at least in one network in the zone
for (PhysicalNetwork pNtwk : _pNtwkDao.listByZone(zoneId)) {
if (_ntwkModel.isProviderEnabledInPhysicalNetwork(pNtwk.getId(), provider)) {
return true;
}
}
return false;
}
@DB
@ -656,7 +641,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
}
if (!vpcProviderEnabledInZone(zoneId, provider)) {
if (!_ntwkModel.isProviderEnabledInZone(zoneId, provider)) {
throw new InvalidParameterValueException("Provider " + provider +
" should be enabled in at least one physical network of the zone specified");
}
@ -1015,20 +1000,20 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
return success;
}
@Override
@DB
public void validateNtkwOffForVpc(long ntwkOffId, String cidr, String networkDomain,
Account networkOwner, Vpc vpc, Long networkId, String gateway) {
@Override
public void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr,
String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner) {
NetworkOffering guestNtwkOff = _configMgr.getNetworkOffering(ntwkOffId);
NetworkOffering guestNtwkOff = _configMgr.getNetworkOffering(newNtwkOffId);
if (guestNtwkOff == null) {
throw new InvalidParameterValueException("Can't find network offering by id specified");
}
if (networkId == null) {
//1) Validate attributes that has to be passed in when create new guest network
validateNewVpcGuestNetwork(cidr, gateway, networkOwner, vpc, networkDomain);
validateNewVpcGuestNetwork(newCidr, gateway, networkOwner, vpc, newNetworkDomain);
}
//2) validate network offering attributes
@ -1213,7 +1198,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
}
//4) Delete private gateway
VpcGateway gateway = getPrivateGatewayForVpc(vpcId);
PrivateGateway gateway = getVpcPrivateGateway(vpcId);
if (gateway != null) {
s_logger.debug("Deleting private gateway " + gateway + " as a part of vpc " + vpcId + " resources cleanup");
if (!deleteVpcPrivateGateway(gateway.getId())) {
@ -1270,11 +1255,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
}
}
@Override
public List<DomainRouterVO> getVpcRouters(long vpcId) {
return _routerDao.listByVpcId(vpcId);
}
@Override
public PrivateGateway getVpcPrivateGateway(long id) {
VpcGateway gateway = _vpcGatewayDao.findById(id);
@ -1835,11 +1816,6 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
}
}
}
@Override
public VpcGateway getPrivateGatewayForVpc(long vpcId) {
return _vpcGatewayDao.getPrivateGatewayForVpc(vpcId);
}
@DB
@ -1895,7 +1871,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
@Override
public void unassignIPFromVpcNetwork(long ipId, long networkId) {
IPAddressVO ip = _ipAddressDao.findById(ipId);
if (ipUsedInVpc(ip)) {
if (isIpAllocatedToVpc(ip)) {
return;
}
@ -1927,7 +1903,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
}
@Override
public boolean ipUsedInVpc(IpAddress ip) {
public boolean isIpAllocatedToVpc(IpAddress ip) {
return (ip != null && ip.getVpcId() != null &&
(ip.isOneToOneNat() || !_firewallDao.listByIp(ip.getId()).isEmpty()));
}
@ -1957,7 +1933,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
}
//1) Validate if network can be created for VPC
validateNtkwOffForVpc(ntwkOffId, cidr, networkDomain, owner, vpc, null, gateway);
validateNtwkOffForNtwkInVpc(null, ntwkOffId, cidr, networkDomain, vpc, gateway, owner);
//2) Create network
Network guestNetwork = _ntwkMgr.createGuestNetwork(ntwkOffId, name, displayText, gateway, cidr, vlanId,
@ -2020,24 +1996,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager{
return ipToReturn;
}
@Override
public Network updateVpcGuestNetwork(long networkId, String name, String displayText, Account callerAccount,
User callerUser, String domainSuffix, Long ntwkOffId, Boolean changeCidr, String guestVmCidr) {
NetworkVO network = _ntwkDao.findById(networkId);
if (network == null) {
throw new InvalidParameterValueException("Couldn't find network by id");
}
//perform below validation if the network is vpc network
if (network.getVpcId() != null && ntwkOffId != null) {
Vpc vpc = getVpc(network.getVpcId());
validateNtkwOffForVpc(ntwkOffId, null, null, null, vpc, networkId, null);
}
return _ntwkSvc.updateGuestNetwork(networkId, name, displayText, callerAccount, callerUser, domainSuffix,
ntwkOffId, changeCidr, guestVmCidr);
}
@Override
public List<HypervisorType> getSupportedVpcHypervisors() {

View File

@ -102,7 +102,6 @@ public class VpcOfferingVO implements VpcOffering {
return name;
}
@Override
public String getUniqueName() {
return uniqueName;
}

View File

@ -26,9 +26,7 @@ import javax.persistence.Enumerated;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.api.Identity;
import com.cloud.utils.db.GenericDao;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="vpc")
@ -94,11 +92,6 @@ public class VpcVO implements Vpc {
this.networkDomain = networkDomain;
this.vpcOfferingId = vpcOffId;
}
@Override
public boolean readyToUse() {
return state == State.Enabled;
}
@Override
public long getId() {

View File

@ -844,4 +844,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean isProviderEnabledInZone(long zoneId, String provider) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -857,4 +857,10 @@ public class MockNetworkModelImpl extends ManagerBase implements NetworkModel {
return null;
}
@Override
public boolean isProviderEnabledInZone(long zoneId, String provider) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -47,15 +47,11 @@ import com.cloud.network.vpc.StaticRoute;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcGateway;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.VpcOffering;
import com.cloud.network.vpc.VpcService;
import com.cloud.offering.NetworkOffering;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Manager;
import com.cloud.utils.component.ManagerBase;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vpc.dao.MockVpcDaoImpl;
@Component
@ -63,19 +59,6 @@ import com.cloud.vpc.dao.MockVpcDaoImpl;
public class MockVpcManagerImpl extends ManagerBase implements VpcManager {
@Inject MockVpcDaoImpl _vpcDao;
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#getVpcOffering(long)
*/
@Override
public VpcOffering getVpcOffering(long vpcOfferingId) {
// TODO Auto-generated method stub
return null;
}
@Override
public VpcOffering createVpcOffering(String name, String displayText, List<String> supportedServices, Map<String, List<String>> serviceProviders) {
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#getVpc(long)
@ -104,42 +87,6 @@ public class MockVpcManagerImpl extends ManagerBase implements VpcManager {
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#getVpcOffSvcProvidersMap(long)
*/
@Override
public Map<Service, Set<Provider>> getVpcOffSvcProvidersMap(long vpcOffId) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#listVpcOfferings(java.lang.Long, java.lang.String, java.lang.String, java.util.List, java.lang.Boolean, java.lang.String, java.lang.String, java.lang.Long, java.lang.Long)
*/
@Override
public List<? extends VpcOffering> listVpcOfferings(Long id, String name, String displayText, List<String> supportedServicesStr, Boolean isDefault, String keyword, String state, Long startIndex, Long pageSizeVal) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#deleteVpcOffering(long)
*/
@Override
public boolean deleteVpcOffering(long offId) {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#updateVpcOffering(long, java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public VpcOffering updateVpcOffering(long vpcOffId, String vpcOfferingName, String displayText, String state) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#createVpc(long, long, long, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@ -313,19 +260,6 @@ public class MockVpcManagerImpl extends ManagerBase implements VpcManager {
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcService#updateVpcGuestNetwork(long, java.lang.String, java.lang.String, com.cloud.user.Account, com.cloud.user.User, java.lang.String, java.lang.Long, java.lang.Boolean)
*/
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcManager#validateNtkwOffForVpc(long, java.lang.String, java.lang.String, com.cloud.user.Account, com.cloud.network.vpc.Vpc, java.lang.Long, java.lang.String)
*/
@Override
public void validateNtkwOffForVpc(long ntwkOffId, String cidr, String networkDomain, Account networkOwner, Vpc vpc, Long networkId, String gateway) {
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcManager#getVpcsForAccount(long)
*/
@ -344,34 +278,13 @@ public class MockVpcManagerImpl extends ManagerBase implements VpcManager {
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcManager#getVpcRouters(long)
*/
@Override
public List<DomainRouterVO> getVpcRouters(long vpcId) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean vpcProviderEnabledInZone(long zoneId, String provider) {
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcManager#getPrivateGatewayForVpc(long)
*/
@Override
public VpcGateway getPrivateGatewayForVpc(long vpcId) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.VpcManager#ipUsedInVpc(com.cloud.network.IpAddress)
*/
@Override
public boolean ipUsedInVpc(IpAddress ip) {
public boolean isIpAllocatedToVpc(IpAddress ip) {
// TODO Auto-generated method stub
return false;
}
@ -458,11 +371,16 @@ public class MockVpcManagerImpl extends ManagerBase implements VpcManager {
return null;
}
@Override
public Network updateVpcGuestNetwork(long networkId, String name, String displayText, Account callerAccount, User callerUser,
String domainSuffix, Long ntwkOffId, Boolean changeCidr, String guestVmCidr) {
// TODO Auto-generated method stub
return null;
}
@Override
public Map<Service, Set<Provider>> getVpcOffSvcProvidersMap(long vpcOffId) {
// TODO Auto-generated method stub
return null;
}
@Override
public void validateNtwkOffForNtwkInVpc(Long networkId, long newNtwkOffId, String newCidr, String newNetworkDomain, Vpc vpc, String gateway, Account networkOwner) {
// TODO Auto-generated method stub
}
}

View File

@ -396,4 +396,10 @@ VpcVirtualNetworkApplianceService {
return false;
}
@Override
public List<DomainRouterVO> getVpcRouters(long vpcId) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -30,38 +30,13 @@ import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.cloud.configuration.dao.ConfigurationDaoImpl;
import com.cloud.configuration.dao.ResourceCountDaoImpl;
import com.cloud.dc.dao.VlanDaoImpl;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.network.Network.Service;
import com.cloud.network.dao.FirewallRulesDaoImpl;
import com.cloud.network.dao.IPAddressDaoImpl;
import com.cloud.network.dao.PhysicalNetworkDaoImpl;
import com.cloud.network.dao.Site2SiteVpnGatewayDaoImpl;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.VpcManager;
import com.cloud.network.vpc.VpcManagerImpl;
import com.cloud.network.vpc.dao.PrivateIpDaoImpl;
import com.cloud.network.vpc.dao.StaticRouteDaoImpl;
import com.cloud.network.vpc.dao.VpcGatewayDaoImpl;
import com.cloud.network.vpc.dao.VpcOfferingDaoImpl;
import com.cloud.server.ManagementService;
import com.cloud.tags.dao.ResourceTagsDaoImpl;
import com.cloud.user.AccountVO;
import com.cloud.user.MockAccountManagerImpl;
import com.cloud.user.dao.AccountDaoImpl;
import com.cloud.utils.component.ComponentContext;
import com.cloud.vm.dao.DomainRouterDaoImpl;
import com.cloud.vpc.dao.MockNetworkDaoImpl;
import com.cloud.vpc.dao.MockNetworkOfferingDaoImpl;
import com.cloud.vpc.dao.MockNetworkOfferingServiceMapDaoImpl;
import com.cloud.vpc.dao.MockNetworkServiceMapDaoImpl;
import com.cloud.vpc.dao.MockVpcDaoImpl;
import com.cloud.vpc.dao.MockVpcOfferingDaoImpl;
import com.cloud.vpc.dao.MockVpcOfferingServiceMapDaoImpl;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/VpcTestContext.xml")
public class VpcApiUnitTest extends TestCase{
@ -180,7 +155,7 @@ public class VpcApiUnitTest extends TestCase{
//1) correct network offering
boolean result = false;
try {
_vpcService.validateNtkwOffForVpc(1, "0.0.0.0", "111-", new AccountVO(), _vpcService.getVpc(1), 2L, "10.1.1.1");
_vpcService.validateNtwkOffForNtwkInVpc(2L, 1, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
result = true;
s_logger.debug("Validate network offering: Test passed: the offering is valid for vpc creation");
} catch (Exception ex) {
@ -191,7 +166,7 @@ public class VpcApiUnitTest extends TestCase{
result = false;
String msg = null;
try {
_vpcService.validateNtkwOffForVpc(2, "0.0.0.0", "111-", new AccountVO(), _vpcService.getVpc(1), 2L, "10.1.1.1");
_vpcService.validateNtwkOffForNtwkInVpc(2L, 2, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
result = true;
} catch (InvalidParameterValueException ex) {
msg = ex.getMessage();
@ -207,7 +182,7 @@ public class VpcApiUnitTest extends TestCase{
result = false;
msg = null;
try {
_vpcService.validateNtkwOffForVpc(3, "0.0.0.0", "111-", new AccountVO(), _vpcService.getVpc(1), 2L, "10.1.1.1");
_vpcService.validateNtwkOffForNtwkInVpc(2L, 3, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
result = true;
} catch (InvalidParameterValueException ex) {
msg = ex.getMessage();
@ -222,7 +197,7 @@ public class VpcApiUnitTest extends TestCase{
//4) invalid offering - guest type shared
result = false;
try {
_vpcService.validateNtkwOffForVpc(4, "0.0.0.0", "111-", new AccountVO(), _vpcService.getVpc(1), 2L, "10.1.1.1");
_vpcService.validateNtwkOffForNtwkInVpc(2L, 4, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
result = true;
} catch (InvalidParameterValueException ex) {
msg = ex.getMessage();
@ -237,7 +212,7 @@ public class VpcApiUnitTest extends TestCase{
//5) Invalid offering - no redundant router support
result = false;
try {
_vpcService.validateNtkwOffForVpc(5, "0.0.0.0", "111-", new AccountVO(), _vpcService.getVpc(1), 2L, "10.1.1.1");
_vpcService.validateNtwkOffForNtwkInVpc(2L, 5, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
result = true;
} catch (InvalidParameterValueException ex) {
msg = ex.getMessage();
@ -252,7 +227,7 @@ public class VpcApiUnitTest extends TestCase{
//6) Only one network in the VPC can support LB service - negative scenario
result = false;
try {
_vpcService.validateNtkwOffForVpc(6, "0.0.0.0", "111-", new AccountVO(), _vpcService.getVpc(1), 2L, "10.1.1.1");
_vpcService.validateNtwkOffForNtwkInVpc(2L, 6, "0.0.0.0", "111-", _vpcService.getVpc(1), "10.1.1.1", new AccountVO());
result = true;
s_logger.debug("Validate network offering: Test passed: the offering is valid for vpc creation");
} catch (InvalidParameterValueException ex) {