use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class VirtualRouterElementTest method completeAggregationCommandTest1.
@Test
public void completeAggregationCommandTest1() throws AgentUnavailableException, ResourceUnavailableException {
virtualRouterElement._routerMgr = Mockito.mock(VpcVirtualNetworkApplianceManagerImpl.class);
virtualRouterElement.routerDeploymentDefinitionBuilder = routerDeploymentDefinitionBuilder;
Network network = new NetworkVO(6l, null, null, null, 1l, 1l, 1l, 1l, "d", "d", "d", null, 1l, 1l, null, true, null, true);
when(virtualRouterElement._routerMgr.completeAggregatedExecution(any(Network.class), anyList())).thenReturn(true);
mockDAOs((NetworkVO) network, testOffering);
when(virtualRouterElement._routerDao.persist(any(DomainRouterVO.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] args = invocationOnMock.getArguments();
DomainRouterVO router = (DomainRouterVO) args[0];
if (router.getUpdateState() != VirtualRouter.UpdateState.UPDATE_COMPLETE) {
throw new CloudRuntimeException("TestFailed: completeAggregationCommandTest1 failed");
} else
return null;
}
});
virtualRouterElement.completeAggregatedExecution(network, testDestination);
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method startInternalLbVm.
@Override
public VirtualRouter startInternalLbVm(final long internalLbVmId, final Account caller, final long callerUserId) throws StorageUnavailableException, InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
final DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId);
if (internalLbVm == null || internalLbVm.getRole() != Role.INTERNAL_LB_VM) {
throw new InvalidParameterValueException("Can't find internal lb vm by id specified");
}
//check permissions
_accountMgr.checkAccess(caller, null, true, internalLbVm);
return startInternalLbVm(internalLbVm, caller, callerUserId, null);
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method findInternalLbVms.
@Override
public List<DomainRouterVO> findInternalLbVms(final long guestNetworkId, final Ip requestedGuestIp) {
final List<DomainRouterVO> internalLbVms = _internalLbVmDao.listByNetworkAndRole(guestNetworkId, Role.INTERNAL_LB_VM);
if (requestedGuestIp != null && !internalLbVms.isEmpty()) {
final Iterator<DomainRouterVO> it = internalLbVms.iterator();
while (it.hasNext()) {
final DomainRouterVO vm = it.next();
final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetworkId, vm.getId());
if (!nic.getIPv4Address().equalsIgnoreCase(requestedGuestIp.addr())) {
it.remove();
}
}
}
return internalLbVms;
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method findOrDeployInternalLbVm.
@DB
protected List<DomainRouterVO> findOrDeployInternalLbVm(final Network guestNetwork, final Ip requestedGuestIp, final DeployDestination dest, final Account owner, final Map<Param, Object> params) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
List<DomainRouterVO> internalLbVms = new ArrayList<DomainRouterVO>();
final Network lock = _networkDao.acquireInLockTable(guestNetwork.getId(), NetworkOrchestrationService.NetworkLockTimeout.value());
if (lock == null) {
throw new ConcurrentOperationException("Unable to lock network " + guestNetwork.getId());
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is acquired for network id " + lock.getId() + " as a part of internal lb startup in " + dest);
}
final long internalLbProviderId = getInternalLbProviderId(guestNetwork);
try {
assert guestNetwork.getState() == Network.State.Implemented || guestNetwork.getState() == Network.State.Setup || guestNetwork.getState() == Network.State.Implementing : "Network is not yet fully implemented: " + guestNetwork;
assert guestNetwork.getTrafficType() == TrafficType.Guest;
//deploy internal lb vm
final Pair<DeploymentPlan, List<DomainRouterVO>> planAndInternalLbVms = getDeploymentPlanAndInternalLbVms(dest, guestNetwork.getId(), requestedGuestIp);
internalLbVms = planAndInternalLbVms.second();
final DeploymentPlan plan = planAndInternalLbVms.first();
if (internalLbVms.size() > 0) {
s_logger.debug("Found " + internalLbVms.size() + " internal lb vms for the requested IP " + requestedGuestIp.addr());
return internalLbVms;
}
final LinkedHashMap<Network, List<? extends NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
long internalLbVmOfferingId = _internalLbVmOfferingId;
if (internalLbVmOfferingId == 0L) {
ServiceOfferingVO serviceOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.internalLbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
internalLbVmOfferingId = serviceOffering.getId();
}
//Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
final DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false);
if (internalLbVm != null) {
_internalLbVmDao.addRouterToGuestNetwork(internalLbVm, guestNetwork);
internalLbVms.add(internalLbVm);
}
} finally {
if (lock != null) {
_networkDao.releaseFromLockTable(lock.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Lock is released for network id " + lock.getId() + " as a part of internal lb vm startup in " + dest);
}
}
}
return internalLbVms;
}
use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.
the class InternalLBVMManagerTest method applyToVmInStartingState.
@Test(expected = ResourceUnavailableException.class)
public void applyToVmInStartingState() throws ResourceUnavailableException {
boolean result = false;
final List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
vm.setState(State.Starting);
vms.add(vm);
final List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
final LoadBalancingRule rule = new LoadBalancingRule(null, null, null, null, null, null, null);
rules.add(rule);
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
} finally {
assertFalse("Rules were applied to vm in Starting state", result);
}
}
Aggregations