VPC: more unittests for VpcService

This commit is contained in:
Alena Prokharchyk 2012-08-06 23:27:39 -07:00
parent b8e3a20ba0
commit 1cf91a8397
16 changed files with 464 additions and 48 deletions

View File

@ -77,7 +77,8 @@ public interface VpcService {
* @return
* @throws ResourceAllocationException TODO
*/
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr, String networkDomain) throws ResourceAllocationException;
public Vpc createVpc(long zoneId, long vpcOffId, long vpcOwnerId, String vpcName, String displayText, String cidr,
String networkDomain) throws ResourceAllocationException;
/**
* @param vpcId

View File

@ -12,13 +12,12 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.user;
import com.cloud.server.ManagementService;
import com.cloud.utils.component.ComponentLocator;
public class UserContext {
private static ThreadLocal<UserContext> s_currentContext = new ThreadLocal<UserContext>();
private static final ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
private static final ComponentLocator locator = ComponentLocator.getCurrentLocator();
private static final AccountService _accountMgr = locator.getManager(AccountService.class);
private long userId;

View File

@ -454,7 +454,7 @@ public class NetworkVO implements Network, Identity {
@Override
public String toString() {
StringBuilder buf = new StringBuilder("Ntwk[");
buf.append(id).append("|").append(trafficType.toString()).append("|").append(networkOfferingId).append("]");
buf.append(id).append("|").append(trafficType).append("|").append(networkOfferingId).append("]");
return buf.toString();
}

View File

@ -633,7 +633,7 @@ public class VpcManagerImpl implements VpcManager, Manager{
@DB
public boolean destroyVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException {
UserContext ctx = UserContext.current();
s_logger.debug("Destroying vpc " + vpc);
//don't allow to delete vpc if it's in use by existing networks
int networksCount = _ntwkDao.getNetworkCountByVpcId(vpc.getId());
if (networksCount > 0) {
@ -671,9 +671,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
//update the instance with removed flag only when the cleanup is executed successfully
if (_vpcDao.remove(vpc.getId())) {
s_logger.debug("Vpc " + vpc + " is removed succesfully");
s_logger.debug("Vpc " + vpc + " is destroyed succesfully");
return true;
} else {
s_logger.warn("Vpc " + vpc + " failed to destroy");
return false;
}
}
@ -927,9 +928,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
_accountMgr.checkAccess(caller, null, false, vpc);
//shutdown provider
s_logger.debug("Shutting down vpc " + vpc);
boolean success = getVpcElement().shutdownVpc(vpc);
//TODO - cleanup all vpc resources here (ACLs, gateways, etc)
//TODO - shutdown all vpc resources here (ACLs, gateways, etc)
if (success) {
s_logger.debug("Vpc " + vpc + " has been shutdown succesfully");
} else {
@ -1088,6 +1090,10 @@ public class VpcManagerImpl implements VpcManager, Manager{
vpcElement = ((VpcProvider)_ntwkMgr.getElementImplementingProvider(Provider.VPCVirtualRouter.getName()));
}
if (vpcElement == null) {
throw new CloudRuntimeException("Failed to initialize vpc element");
}
return vpcElement;
}

View File

@ -39,7 +39,7 @@ import com.cloud.utils.db.SearchCriteria;
@Local(value = { AccountManager.class, AccountService.class })
public class MockAccountManagerImpl implements Manager, AccountManager {
public class MockAccountManagerImpl implements Manager, AccountManager, AccountService {
@Override
@ -98,14 +98,12 @@ public class MockAccountManagerImpl implements Manager, AccountManager {
@Override
public Account getSystemAccount() {
// TODO Auto-generated method stub
return null;
return new AccountVO();
}
@Override
public User getSystemUser() {
// TODO Auto-generated method stub
return null;
return new UserVO();
}
@Override

View File

@ -13,6 +13,7 @@
package com.cloud.vpc;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -20,6 +21,8 @@ import java.util.Set;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.acl.ControlledEntity.ACLType;
import com.cloud.api.commands.CreateNetworkCmd;
import com.cloud.api.commands.ListNetworksCmd;
@ -70,6 +73,7 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.user.Account;
import com.cloud.user.User;
import com.cloud.utils.Pair;
import com.cloud.utils.component.Adapters;
import com.cloud.utils.component.Inject;
import com.cloud.utils.component.Manager;
import com.cloud.vm.Nic;
@ -79,6 +83,7 @@ import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
import com.cloud.vpc.dao.MockVpcVirtualRouterElement;
@Local(value = { NetworkManager.class, NetworkService.class })
public class MockNetworkManagerImpl implements NetworkManager, Manager{
@ -86,6 +91,12 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager{
NetworkServiceMapDao _ntwkSrvcDao;
@Inject
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
@Inject(adapter = NetworkElement.class)
Adapters<NetworkElement> _networkElements;
private static HashMap<String, String> s_providerToNetworkElementMap = new HashMap<String, String>();
private static final Logger s_logger = Logger.getLogger(MockNetworkManagerImpl.class);
/* (non-Javadoc)
* @see com.cloud.network.NetworkService#getIsolatedNetworksOwnedByAccountInZone(long, com.cloud.user.Account)
@ -1267,8 +1278,7 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager{
*/
@Override
public NetworkElement getElementImplementingProvider(String providerName) {
// TODO Auto-generated method stub
return null;
return new MockVpcVirtualRouterElement();
}
/* (non-Javadoc)
@ -1451,7 +1461,17 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager{
*/
@Override
public boolean start() {
// TODO Auto-generated method stub
for (NetworkElement element : _networkElements) {
Provider implementedProvider = element.getProvider();
if (implementedProvider != null) {
if (s_providerToNetworkElementMap.containsKey(implementedProvider.getName())) {
s_logger.error("Cannot start MapNetworkManager: Provider <-> NetworkElement must be a one-to-one map, " +
"multiple NetworkElements found for Provider: " + implementedProvider.getName());
return false;
}
s_providerToNetworkElementMap.put(implementedProvider.getName(), element.getName());
}
}
return true;
}

View File

@ -12,6 +12,9 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.vpc;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.apache.log4j.Logger;
@ -21,28 +24,34 @@ 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.NetworkDaoImpl;
import com.cloud.network.dao.PhysicalNetworkDaoImpl;
import com.cloud.network.element.VpcVirtualRouterElement;
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.network.vpc.Dao.VpcOfferingServiceMapDaoImpl;
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.Adapter;
import com.cloud.utils.component.ComponentLocator;
import com.cloud.utils.component.MockComponentLocator;
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;
public class VpcApiUnitTest extends TestCase{
private static final Logger s_logger = Logger.getLogger(VpcApiUnitTest.class);
@ -52,19 +61,18 @@ public class VpcApiUnitTest extends TestCase{
@Override
@Before
public void setUp() throws Exception {
_locator = new MockComponentLocator("management-server");
_locator = new MockComponentLocator(ManagementService.Name);
_locator.addDao("VpcDao", MockVpcDaoImpl.class);
_locator.addDao("VpcOfferingDao", VpcOfferingDaoImpl.class);
_locator.addDao("VpcOfferingServiceMapDao", VpcOfferingServiceMapDaoImpl.class);
_locator.addDao("ConfigDao", ConfigurationDaoImpl.class);
_locator.addDao("NetworkDao", NetworkDaoImpl.class);
_locator.addDao("ConfigurationDao", ConfigurationDaoImpl.class);
_locator.addDao("NetworkDao", MockNetworkDaoImpl.class);
_locator.addDao("IPAddressDao", IPAddressDaoImpl.class);
_locator.addDao("DomainRouterDao", DomainRouterDaoImpl.class);
_locator.addDao("_vpcGatewayDao", VpcGatewayDaoImpl.class);
_locator.addDao("VpcGatewayDao", VpcGatewayDaoImpl.class);
_locator.addDao("PrivateIpDao", PrivateIpDaoImpl.class);
_locator.addDao("StaticRouteDao", StaticRouteDaoImpl.class);
_locator.addDao("NetworkOfferingServiceMapDao", MockNetworkOfferingServiceMapDaoImpl.class);
_locator.addDao("VpcOfferingServiceMapDao", VpcOfferingServiceMapDaoImpl.class);
_locator.addDao("VpcOfferingServiceMapDao", MockVpcOfferingServiceMapDaoImpl.class);
_locator.addDao("PhysicalNetworkDao", PhysicalNetworkDaoImpl.class);
_locator.addDao("ResourceTagDao", ResourceTagsDaoImpl.class);
_locator.addDao("FirewallRulesDao", FirewallRulesDaoImpl.class);
@ -73,32 +81,132 @@ public class VpcApiUnitTest extends TestCase{
_locator.addDao("ResourceCountDao", ResourceCountDaoImpl.class);
_locator.addDao("NetworkOfferingDao", MockNetworkOfferingDaoImpl.class);
_locator.addDao("NetworkServiceMapDao", MockNetworkServiceMapDaoImpl.class);
_locator.addDao("VpcOfferingDao", MockVpcOfferingDaoImpl.class);
_locator.addManager("ConfigService", MockConfigurationManagerImpl.class);
_locator.addManager("vpc manager", VpcManagerImpl.class);
_locator.addManager("account manager", MockAccountManagerImpl.class);
_locator.addManager("network manager", MockNetworkManagerImpl.class);
_locator.addManager("Site2SiteVpnManager", MockSite2SiteVpnManagerImpl.class);
_locator.addManager("ResourceLimitService", MockResourceLimitManagerImpl.class);
_locator.addManager("ConfigService", MockConfigurationManagerImpl.class);
_locator.makeActive(null);
_vpcService = ComponentLocator.inject(VpcManagerImpl.class);
}
public void test() {
s_logger.debug("Starting test for VpcService interface");
//Vpc service methods
getActiveVpc();
deleteVpc();
//Vpc manager methods
validateNtwkOffForVpc();
//destroyVpc();
}
protected void deleteVpc() {
//delete existing offering
boolean result = false;
String msg = null;
try {
List<String> svcs = new ArrayList<String>();
svcs.add(Service.SourceNat.getName());
result = _vpcService.deleteVpc(1);
} catch (Exception ex) {
msg = ex.getMessage();
} finally {
if (result) {
s_logger.debug("Delete vpc: Test passed, vpc is deleted");
} else {
s_logger.error("Delete vpc: TEST FAILED, vpc failed to delete " + msg);
}
}
//delete non-existing offering
result = false;
msg = null;
try {
List<String> svcs = new ArrayList<String>();
svcs.add(Service.SourceNat.getName());
result = _vpcService.deleteVpc(100);
} catch (Exception ex) {
msg = ex.getMessage();
} finally {
if (!result) {
s_logger.debug("Delete vpc: Test passed, non existing vpc failed to delete ");
} else {
s_logger.error("Delete vpc: TEST FAILED, true is returned when try to delete non existing vpc");
}
}
}
protected void getActiveVpc() {
//test for active vpc
boolean result = false;
String msg = null;
Vpc vpc = null;
try {
List<String> svcs = new ArrayList<String>();
svcs.add(Service.SourceNat.getName());
vpc = _vpcService.getActiveVpc(1);
if (vpc != null) {
result = true;
}
} catch (Exception ex) {
msg = ex.getMessage();
} finally {
if (result) {
s_logger.debug("Get active Vpc: Test passed, active vpc is returned");
} else {
s_logger.error("Get active Vpc: TEST FAILED, active vpc is not returned " + msg);
}
}
//test for inactive vpc
result = false;
msg = null;
vpc = null;
try {
List<String> svcs = new ArrayList<String>();
svcs.add(Service.SourceNat.getName());
vpc = _vpcService.getActiveVpc(2);
if (vpc != null) {
result = true;
}
} catch (Exception ex) {
msg = ex.getMessage();
} finally {
if (!result) {
s_logger.debug("Get active Vpc: Test passed, no vpc is returned");
} else {
s_logger.error("Get active Vpc: TEST FAILED, non active vpc is returned");
}
}
}
protected void destroyVpc() {
try {
_vpcService.destroyVpc(_vpcService.getVpc(1));
} catch (Exception ex) {
s_logger.error("Destroy VPC TEST FAILED due to exc ", ex);
}
}
protected void validateNtwkOffForVpc() {
//validate network offering
//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");
result = true;
s_logger.debug("Test passed: the offering is valid for vpc creation");
s_logger.debug("Validate network offering: Test passed: the offering is valid for vpc creation");
} catch (Exception ex) {
s_logger.warn("TEST FAILED due to exc ", ex);
s_logger.error("Validate network offering: TEST FAILED due to exc ", ex);
}
//2) invalid offering - source nat is not included
result = false;
String msg = null;
@ -109,9 +217,9 @@ public class VpcApiUnitTest extends TestCase{
msg = ex.getMessage();
} finally {
if (!result) {
s_logger.debug("Test passed: " + msg);
s_logger.debug("Validate network offering: Test passed: " + msg);
} else {
s_logger.warn("TEST FAILED, can't use network offering without SourceNat service");
s_logger.error("Validate network offering: TEST FAILED, can't use network offering without SourceNat service");
}
}
@ -125,9 +233,9 @@ public class VpcApiUnitTest extends TestCase{
msg = ex.getMessage();
} finally {
if (!result) {
s_logger.debug("Test passed: " + msg);
s_logger.debug("Validate network offering: Test passed: " + msg);
} else {
s_logger.warn("TEST FAILED, can't use network offering without conserve mode = true");
s_logger.error("Validate network offering: TEST FAILED, can't use network offering without conserve mode = true");
}
}
@ -140,13 +248,14 @@ public class VpcApiUnitTest extends TestCase{
msg = ex.getMessage();
} finally {
if (!result) {
s_logger.debug("Test passed: " + msg);
s_logger.debug("Validate network offering: Test passed: " + msg);
} else {
s_logger.warn("TEST FAILED, can't use network offering with guest type = Shared");
s_logger.error("Validate network offering: TEST FAILED, can't use network offering with guest type = Shared");
}
}
//5) Invalid offering - no redundant router supportresult = false;
//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");
result = true;
@ -154,15 +263,27 @@ public class VpcApiUnitTest extends TestCase{
msg = ex.getMessage();
} finally {
if (!result) {
s_logger.debug("Test passed: " + msg);
s_logger.debug("Validate network offering: Test passed: " + msg);
} else {
s_logger.warn("TEST FAILED, can't use network offering with guest type = Shared");
s_logger.error("TEST FAILED, can't use network offering with guest type = Shared");
}
}
//6) Only one network in the VPC can support LB service - positive scenario
//7) Only one netowrk in the VPC can support LB service - negative scenario
//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");
result = true;
s_logger.debug("Validate network offering: Test passed: the offering is valid for vpc creation");
} catch (InvalidParameterValueException ex) {
msg = ex.getMessage();
} finally {
if (!result) {
s_logger.debug("Test passed: " + msg);
} else {
s_logger.error("Validate network offering: TEST FAILED, can't use network offering with guest type = Shared");
}
}
}
}

View File

@ -0,0 +1,106 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.vpc.dao;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.Local;
import com.cloud.configuration.ConfigurationVO;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.utils.db.GenericDaoBase;
@Local(value={ConfigurationDao.class})
public class MockConfigurationDaoImpl extends GenericDaoBase<ConfigurationVO, String> implements ConfigurationDao{
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#getConfiguration(java.lang.String, java.util.Map)
*/
@Override
public Map<String, String> getConfiguration(String instance, Map<String, ? extends Object> params) {
return new HashMap<String, String>();
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#getConfiguration(java.util.Map)
*/
@Override
public Map<String, String> getConfiguration(Map<String, ? extends Object> params) {
return new HashMap<String, String>();
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#getConfiguration()
*/
@Override
public Map<String, String> getConfiguration() {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#update(java.lang.String, java.lang.String)
*/
@Override
public boolean update(String name, String value) {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#getValue(java.lang.String)
*/
@Override
public String getValue(String name) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#getValueAndInitIfNotExist(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public String getValueAndInitIfNotExist(String name, String category, String initValue) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#isPremium()
*/
@Override
public boolean isPremium() {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#findByName(java.lang.String)
*/
@Override
public ConfigurationVO findByName(String name) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.configuration.dao.ConfigurationDao#update(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public boolean update(String name, String category, String value) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -12,6 +12,7 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.vpc.dao;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -314,8 +315,9 @@ public class MockNetworkDaoImpl extends GenericDaoBase<NetworkVO, Long> implemen
*/
@Override
public List<NetworkVO> listByVpc(long vpcId) {
// TODO Auto-generated method stub
return null;
List<NetworkVO> networks = new ArrayList<NetworkVO>();
networks.add(new NetworkVO());
return networks;
}
/* (non-Javadoc)

View File

@ -35,7 +35,6 @@ import com.cloud.utils.db.GenericDaoBase;
public class MockNetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO, Long> implements NetworkOfferingDao {
private static final Logger s_logger = Logger.getLogger(MockNetworkOfferingDaoImpl.class);
/* (non-Javadoc)
* @see com.cloud.offerings.dao.NetworkOfferingDao#findByUniqueName(java.lang.String)
*/
@ -111,10 +110,14 @@ public class MockNetworkOfferingDaoImpl extends GenericDaoBase<NetworkOfferingVO
vo = new NetworkOfferingVO("non vpc", "non vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Shared, false, false);
} else if (id.longValue() == 5) {
//network offering invalid for vpc (Shared)
//network offering invalid for vpc (has redundant router)
vo = new NetworkOfferingVO("vpc", "vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Isolated, false, false);
vo.setRedundantRouter(true);
} else if (id.longValue() == 6) {
//network offering invalid for vpc (has lb service)
vo = new NetworkOfferingVO("vpc", "vpc", TrafficType.Guest, false, true, null, null, false,
Availability.Optional, null, Network.GuestType.Isolated, false, false);
}
if (vo != null) {

View File

@ -27,7 +27,7 @@ public class MockNetworkOfferingServiceMapDaoImpl extends NetworkOfferingService
public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service... services) {
if (services.length > 0 && services[0] == Service.SourceNat && networkOfferingId != 2) {
return true;
} else if (services.length > 0 && services[0] == Service.Lb && networkOfferingId != 2) {
} else if (services.length > 0 && services[0] == Service.Lb && networkOfferingId == 6) {
return true;
}
return false;

View File

@ -32,7 +32,9 @@ public class MockNetworkServiceMapDaoImpl extends GenericDaoBase<NetworkServiceM
*/
@Override
public boolean areServicesSupportedInNetwork(long networkId, Service... services) {
// TODO Auto-generated method stub
if (services.length > 0 && services[0] == Service.Lb) {
return true;
}
return false;
}

View File

@ -12,11 +12,15 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.vpc.dao;
import java.lang.reflect.Field;
import java.util.List;
import javax.ejb.Local;
import org.apache.log4j.Logger;
import com.cloud.network.vpc.Vpc;
import com.cloud.network.vpc.Vpc.State;
import com.cloud.network.vpc.VpcVO;
import com.cloud.network.vpc.Dao.VpcDao;
import com.cloud.utils.db.DB;
@ -25,6 +29,8 @@ import com.cloud.utils.db.GenericDaoBase;
@Local(value = VpcDao.class)
@DB(txn = false)
public class MockVpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDao{
private static final Logger s_logger = Logger.getLogger(MockNetworkOfferingDaoImpl.class);
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcDao#getVpcCountByOfferingId(long)
@ -39,7 +45,11 @@ public class MockVpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDa
*/
@Override
public Vpc getActiveVpcById(long vpcId) {
// TODO Auto-generated method stub
Vpc vpc = findById(vpcId);
if (vpc != null && vpc.getState() == Vpc.State.Enabled) {
return vpc;
}
return null;
}
@ -77,9 +87,40 @@ public class MockVpcDaoImpl extends GenericDaoBase<VpcVO, Long> implements VpcDa
vo = new VpcVO(1, "new vpc", "new vpc", 1,1 , 1, "0.0.0.0/0", "vpc domain");
} else if (id.longValue() == 2) {
vo = new VpcVO(1, "new vpc", "new vpc", 1,1 , 1, "0.0.0.0/0", "vpc domain");
vo.setState(State.Inactive);
}
vo = setId(vo, id);
return vo;
}
private VpcVO setId(VpcVO vo, long id) {
VpcVO voToReturn = vo;
Class<?> c = voToReturn.getClass();
try {
Field f = c.getDeclaredField("id");
f.setAccessible(true);
f.setLong(voToReturn, id);
} catch (NoSuchFieldException ex) {
s_logger.warn(ex);
return null;
} catch (IllegalAccessException ex) {
s_logger.warn(ex);
return null;
}
return voToReturn;
}
@Override
public boolean remove(Long id) {
return true;
}
@Override
public boolean update(Long id, VpcVO vo) {
return true;
}
}

View File

@ -0,0 +1,39 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.vpc.dao;
import javax.ejb.Local;
import com.cloud.network.vpc.VpcOfferingVO;
import com.cloud.network.vpc.Dao.VpcOfferingDao;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@Local(value = VpcOfferingDao.class)
@DB(txn = false)
public class MockVpcOfferingDaoImpl extends GenericDaoBase<VpcOfferingVO, Long> implements VpcOfferingDao{
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcOfferingDao#findByUniqueName(java.lang.String)
*/
@Override
public VpcOfferingVO findByUniqueName(String uniqueName) {
return new VpcOfferingVO();
}
@Override
public VpcOfferingVO persist(VpcOfferingVO vo) {
return vo;
}
}

View File

@ -0,0 +1,69 @@
// Copyright 2012 Citrix Systems, Inc. Licensed under the
// Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. Citrix Systems, Inc.
// reserves all rights not expressly granted by 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.
//
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.vpc.dao;
import java.util.List;
import javax.ejb.Local;
import com.cloud.network.Network.Service;
import com.cloud.network.vpc.VpcOfferingServiceMapVO;
import com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.GenericDaoBase;
@Local(value = VpcOfferingServiceMapDao.class)
@DB(txn = false)
public class MockVpcOfferingServiceMapDaoImpl extends GenericDaoBase<VpcOfferingServiceMapVO, Long> implements VpcOfferingServiceMapDao{
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao#listByVpcOffId(long)
*/
@Override
public List<VpcOfferingServiceMapVO> listByVpcOffId(long vpcOffId) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao#areServicesSupportedByNetworkOffering(long, com.cloud.network.Network.Service[])
*/
@Override
public boolean areServicesSupportedByNetworkOffering(long networkOfferingId, Service[] services) {
// TODO Auto-generated method stub
return false;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao#listServicesForVpcOffering(long)
*/
@Override
public List<String> listServicesForVpcOffering(long vpcOfferingId) {
// TODO Auto-generated method stub
return null;
}
/* (non-Javadoc)
* @see com.cloud.network.vpc.Dao.VpcOfferingServiceMapDao#findByServiceProviderAndOfferingId(java.lang.String, java.lang.String, long)
*/
@Override
public VpcOfferingServiceMapVO findByServiceProviderAndOfferingId(String service, String provider, long vpcOfferingId) {
return new VpcOfferingServiceMapVO();
}
@Override
public VpcOfferingServiceMapVO persist (VpcOfferingServiceMapVO vo) {
return vo;
}
}

View File

@ -12,6 +12,15 @@
// Automatically generated by addcopyright.py at 04/03/2012
package com.cloud.vpc.dao;
public class MockVpcOfferingServiceMapDao {
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.element.VpcVirtualRouterElement;
import com.cloud.network.vpc.Vpc;
public class MockVpcVirtualRouterElement extends VpcVirtualRouterElement{
@Override
public boolean shutdownVpc(Vpc vpc) throws ConcurrentOperationException, ResourceUnavailableException {
return true;
}
}