Search in sources :

Example 96 with DomainRouterVO

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);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) VpcVirtualNetworkApplianceManagerImpl(com.cloud.network.router.VpcVirtualNetworkApplianceManagerImpl) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 97 with DomainRouterVO

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);
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 98 with DomainRouterVO

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;
}
Also used : Nic(com.cloud.vm.Nic) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 99 with DomainRouterVO

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;
}
Also used : Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) DeploymentPlan(com.cloud.deploy.DeploymentPlan) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) DB(com.cloud.utils.db.DB)

Example 100 with DomainRouterVO

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);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Aggregations

DomainRouterVO (com.cloud.vm.DomainRouterVO)148 ArrayList (java.util.ArrayList)39 DataCenterVO (com.cloud.dc.DataCenterVO)33 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)33 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 Test (org.junit.Test)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)24 Network (com.cloud.network.Network)20 NicProfile (com.cloud.vm.NicProfile)17 Account (com.cloud.user.Account)12 NetworkVO (com.cloud.network.dao.NetworkVO)11 Answer (com.cloud.agent.api.Answer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 UserVmVO (com.cloud.vm.UserVmVO)9 Vpc (com.cloud.network.vpc.Vpc)8 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)8 UserVO (com.cloud.user.UserVO)8 HashMap (java.util.HashMap)8