Search in sources :

Example 6 with NetworkDetailVO

use of com.cloud.network.dao.NetworkDetailVO in project cloudstack by apache.

the class VirtualRouterElementTest method mockDAOs.

/**
     * @param network
     */
private void mockDAOs(final NetworkVO network, final NetworkOfferingVO offering) {
    when(_networkDao.acquireInLockTable(network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value())).thenReturn(network);
    when(_networksDao.acquireInLockTable(network.getId(), NetworkOrchestrationService.NetworkLockTimeout.value())).thenReturn(network);
    when(_physicalProviderDao.findByServiceProvider(0L, "VirtualRouter")).thenReturn(new PhysicalNetworkServiceProviderVO());
    when(_vrProviderDao.findByNspIdAndType(0L, Type.VirtualRouter)).thenReturn(new VirtualRouterProviderVO());
    when(_networkOfferingDao.findById(0L)).thenReturn(offering);
    // watchit: (in this test) there can be only one
    when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(0L);
    final ServiceOfferingVO svcoff = new ServiceOfferingVO("name", /* cpu */
    1, /* ramsize */
    1024 * 1024, /* (clock?)speed */
    1024 * 1024 * 1024, /* rateMbps */
    1, /* multicastRateMbps */
    0, /* offerHA */
    false, "displayText", ProvisioningType.THIN, /* useLocalStorage */
    false, /* recreatable */
    false, "tags", /* systemUse */
    false, VirtualMachine.Type.DomainRouter, /* defaultUse */
    false);
    when(_serviceOfferingDao.findById(0L)).thenReturn(svcoff);
    when(_serviceOfferingDao.findByName(Matchers.anyString())).thenReturn(svcoff);
    final DomainRouterVO router = new DomainRouterVO(/* id */
    1L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.UNKNOWN, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    final DomainRouterVO routerNeedUpdateBackup = new DomainRouterVO(/* id */
    2L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.BACKUP, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerNeedUpdateBackup.setUpdateState(VirtualRouter.UpdateState.UPDATE_NEEDED);
    final DomainRouterVO routerNeedUpdateMaster = new DomainRouterVO(/* id */
    3L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.MASTER, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerNeedUpdateMaster.setUpdateState(VirtualRouter.UpdateState.UPDATE_NEEDED);
    final DomainRouterVO routerUpdateComplete = new DomainRouterVO(/* id */
    4L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.UNKNOWN, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerUpdateComplete.setUpdateState(VirtualRouter.UpdateState.UPDATE_COMPLETE);
    final DomainRouterVO routerUpdateInProgress = new DomainRouterVO(/* id */
    5L, /* serviceOfferingId */
    1L, /* elementId */
    0L, "name", /* templateId */
    0L, HypervisorType.XenServer, /* guestOSId */
    0L, /* domainId */
    0L, /* accountId */
    1L, /* userId */
    1L, /* isRedundantRouter */
    false, RedundantState.UNKNOWN, /* haEnabled */
    false, /* stopPending */
    false, /* vpcId */
    null);
    routerUpdateInProgress.setUpdateState(VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
    List<DomainRouterVO> routerList1 = new ArrayList<>();
    routerList1.add(routerUpdateComplete);
    routerList1.add(routerNeedUpdateBackup);
    routerList1.add(routerNeedUpdateMaster);
    routerList1.add(routerUpdateInProgress);
    List<DomainRouterVO> routerList2 = new ArrayList<>();
    routerList2.add(routerUpdateComplete);
    routerList2.add(routerNeedUpdateBackup);
    routerList2.add(routerNeedUpdateMaster);
    List<DomainRouterVO> routerList3 = new ArrayList<>();
    routerList3.add(routerUpdateComplete);
    routerList3.add(routerUpdateInProgress);
    when(_routerDao.getNextInSequence(Long.class, "id")).thenReturn(1L);
    when(_templateDao.findRoutingTemplate(HypervisorType.XenServer, "SystemVM Template (XenServer)")).thenReturn(new VMTemplateVO());
    when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router);
    when(_routerDao.findById(router.getId())).thenReturn(router);
    when(_routerDao.listByNetworkAndRole(1l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList1);
    when(_routerDao.listByNetworkAndRole(2l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList2);
    when(_routerDao.listByNetworkAndRole(3l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList1);
    when(_routerDao.listByNetworkAndRole(6l, VirtualRouter.Role.VIRTUAL_ROUTER)).thenReturn(routerList3);
    when(_networkDetailsDao.findDetail(1l, Network.updatingInSequence)).thenReturn(new NetworkDetailVO(1l, Network.updatingInSequence, "true", true));
    when(_networkDetailsDao.findDetail(2l, Network.updatingInSequence)).thenReturn(new NetworkDetailVO(2l, Network.updatingInSequence, "true", true));
    when(_networkDetailsDao.findDetail(6l, Network.updatingInSequence)).thenReturn(new NetworkDetailVO(2l, Network.updatingInSequence, "true", true));
    when(_routerDao.persist(any(DomainRouterVO.class))).thenReturn(router);
}
Also used : PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) ArrayList(java.util.ArrayList) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) NetworkDetailVO(com.cloud.network.dao.NetworkDetailVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 7 with NetworkDetailVO

use of com.cloud.network.dao.NetworkDetailVO in project cloudstack by apache.

the class NuageVspGuestNetworkGuru method implement.

@Override
public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
    long networkId = network.getId();
    network = _networkDao.acquireInLockTable(network.getId(), 1200);
    if (network == null) {
        throw new ConcurrentOperationException("Unable to acquire lock on network " + networkId);
    }
    NetworkVO implemented = null;
    try {
        if (offering.getGuestType() == GuestType.Isolated && network.getState() != State.Implementing) {
            throw new IllegalStateException("Network " + networkId + " is not in expected state Implementing, but is in state " + network.getState());
        }
        //Get the Account details and find the type
        AccountVO networksAccount = _accountDao.findById(network.getAccountId());
        if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
            String errorMessage = "Networks created by account " + networksAccount.getAccountName() + " of type Project (" + Account.ACCOUNT_TYPE_PROJECT + ") " + "are not yet supported by NuageVsp provider";
            s_logger.error(errorMessage);
            throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
        }
        //We don't support a shared network with UserData and multiple IP ranges at the same time.
        checkMultipleSubnetsCombinedWithUseData(network);
        long dcId = dest.getDataCenter().getId();
        //Get physical network id
        Long physicalNetworkId = network.getPhysicalNetworkId();
        //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
        if (physicalNetworkId == null) {
            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
        }
        implemented = new NetworkVO(network.getId(), network, network.getNetworkOfferingId(), network.getGuruName(), network.getDomainId(), network.getAccountId(), network.getRelated(), network.getName(), network.getDisplayText(), network.getNetworkDomain(), network.getGuestType(), network.getDataCenterId(), physicalNetworkId, network.getAclType(), network.getSpecifyIpRanges(), network.getVpcId(), offering.getRedundantRouter());
        implemented.setUuid(network.getUuid());
        implemented.setState(State.Allocated);
        if (network.getGateway() != null) {
            implemented.setGateway(network.getGateway());
        }
        if (network.getCidr() != null) {
            implemented.setCidr(network.getCidr());
        }
        VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(implemented);
        String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
        String broadcastUriStr = implemented.getUuid() + "/" + vspNetwork.getVirtualRouterIp();
        implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
        implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
        if (!implement(physicalNetworkId, vspNetwork, _nuageVspEntityBuilder.buildNetworkDhcpOption(network, offering))) {
            return null;
        }
        if (StringUtils.isNotBlank(vspNetwork.getDomainTemplateName())) {
            if (network.getVpcId() != null) {
                VpcDetailVO vpcDetail = new VpcDetailVO(network.getVpcId(), NuageVspManager.nuageDomainTemplateDetailName, vspNetwork.getDomainTemplateName(), false);
                _vpcDetailsDao.persist(vpcDetail);
            } else {
                NetworkDetailVO networkDetail = new NetworkDetailVO(implemented.getId(), NuageVspManager.nuageDomainTemplateDetailName, vspNetwork.getDomainTemplateName(), false);
                _networkDetailsDao.persist(networkDetail);
            }
        }
        s_logger.info("Implemented OK, network " + implemented.getUuid() + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri());
    } finally {
        _networkDao.releaseFromLockTable(network.getId());
    }
    return implemented;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) VspNetwork(net.nuage.vsp.acs.client.api.model.VspNetwork) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) AccountVO(com.cloud.user.AccountVO) NetworkDetailVO(com.cloud.network.dao.NetworkDetailVO) VpcDetailVO(org.apache.cloudstack.resourcedetail.VpcDetailVO)

Example 8 with NetworkDetailVO

use of com.cloud.network.dao.NetworkDetailVO in project cloudstack by apache.

the class RouterDeploymentDefinition method deployAllVirtualRouters.

protected void deployAllVirtualRouters() throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    final int routersToDeploy = getNumberOfRoutersToDeploy();
    for (int i = 0; i < routersToDeploy; i++) {
        // Don't start the router as we are holding the network lock that
        // needs to be released at the end of router allocation
        final DomainRouterVO router = nwHelper.deployRouter(this, false);
        //check if the network update is in progress.
        //if update is in progress add the update_pending flag to DomainRouterVO.
        NetworkDetailVO detail = networkDetailsDao.findDetail(guestNetwork.getId(), Network.updatingInSequence);
        if ("true".equalsIgnoreCase(detail != null ? detail.getValue() : null)) {
            router.setUpdateState(VirtualRouter.UpdateState.UPDATE_IN_PROGRESS);
            routerDao.persist(router);
        }
        if (router != null) {
            routerDao.addRouterToGuestNetwork(router, guestNetwork);
            //Fix according to changes by Sheng Yang in commit ID cb4513379996b262ae378daf00c6388c6b7313cf
            routers.add(router);
        }
    }
}
Also used : NetworkDetailVO(com.cloud.network.dao.NetworkDetailVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

NetworkDetailVO (com.cloud.network.dao.NetworkDetailVO)8 DomainRouterVO (com.cloud.vm.DomainRouterVO)5 ArrayList (java.util.ArrayList)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 DataCenter (com.cloud.dc.DataCenter)1 DeployDestination (com.cloud.deploy.DeployDestination)1 ActionEvent (com.cloud.event.ActionEvent)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)1 InsufficientVirtualNetworkCapacityException (com.cloud.exception.InsufficientVirtualNetworkCapacityException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)1 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)1 UnsupportedServiceException (com.cloud.exception.UnsupportedServiceException)1 Capability (com.cloud.network.Network.Capability)1 PhysicalNetworkServiceProviderVO (com.cloud.network.dao.PhysicalNetworkServiceProviderVO)1