Search in sources :

Example 91 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class RouterDeploymentDefinition method findDestinations.

protected List<DeployDestination> findDestinations() {
    // dest has pod=null, for Basic Zone findOrDeployVRs for all Pods
    final List<DeployDestination> destinations = new ArrayList<DeployDestination>();
    // restart scenario otherwise it is a vm deployment scenario
    if (isBasic() && dest.getPod() == null) {
        // Find all pods in the data center with running or starting user vms
        final long dcId = dest.getDataCenter().getId();
        final List<HostPodVO> pods = listByDataCenterIdVMTypeAndStates(dcId, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running);
        // Loop through all the pods skip those with running or starting VRs
        for (final HostPodVO pod : pods) {
            // Get list of VRs in starting or running state
            final long podId = pod.getId();
            final List<DomainRouterVO> virtualRouters = routerDao.listByPodIdAndStates(podId, VirtualMachine.State.Starting, VirtualMachine.State.Running);
            if (virtualRouters.size() > 1) {
                // FIXME Find or create a better and more specific exception for this
                throw new CloudRuntimeException("Pod can have utmost one VR in Basic Zone, please check!");
            }
            // Add virtualRouters to the routers, this avoids the situation when
            // all routers are skipped and VirtualRouterElement throws exception
            routers.addAll(virtualRouters);
            // If List size is one, we already have a starting or running VR, skip deployment
            if (virtualRouters.size() == 1) {
                logger.debug("Skipping VR deployment: Found a running or starting VR in Pod " + pod.getName() + " id=" + podId);
                continue;
            }
            // Add new DeployDestination for this pod
            destinations.add(new DeployDestination(dest.getDataCenter(), pod, null, null));
        }
    } else {
        // Else, just add the supplied dest
        destinations.add(dest);
    }
    return destinations;
}
Also used : DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 92 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class RouterControlHelper method getRouterControlIp.

public String getRouterControlIp(final long routerId) {
    String routerControlIpAddress = null;
    final List<NicVO> nics = nicDao.listByVmId(routerId);
    for (final NicVO n : nics) {
        final NetworkVO nc = networkDao.findById(n.getNetworkId());
        if (nc != null && nc.getTrafficType() == TrafficType.Control) {
            routerControlIpAddress = n.getIPv4Address();
            // router will have only one control ip
            break;
        }
    }
    if (routerControlIpAddress == null) {
        logger.warn("Unable to find router's control ip in its attached NICs!. routerId: " + routerId);
        final DomainRouterVO router = routerDao.findById(routerId);
        return router.getPrivateIpAddress();
    }
    return routerControlIpAddress;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 93 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method updateRoutersRedundantState.

protected void updateRoutersRedundantState(final List<DomainRouterVO> routers) {
    boolean updated;
    for (final DomainRouterVO router : routers) {
        updated = false;
        if (!router.getIsRedundantRouter()) {
            continue;
        }
        final RedundantState prevState = router.getRedundantState();
        if (router.getState() != VirtualMachine.State.Running) {
            router.setRedundantState(RedundantState.UNKNOWN);
            updated = true;
        } else {
            final String privateIP = router.getPrivateIpAddress();
            final HostVO host = _hostDao.findById(router.getHostId());
            if (host == null || host.getState() != Status.Up) {
                router.setRedundantState(RedundantState.UNKNOWN);
                updated = true;
            } else if (privateIP != null) {
                final CheckRouterCommand command = new CheckRouterCommand();
                command.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
                command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
                command.setWait(30);
                final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
                CheckRouterAnswer answer = null;
                if (origAnswer instanceof CheckRouterAnswer) {
                    answer = (CheckRouterAnswer) origAnswer;
                } else {
                    s_logger.warn("Unable to update router " + router.getHostName() + "'s status");
                }
                RedundantState state = RedundantState.UNKNOWN;
                if (answer != null) {
                    if (answer.getResult()) {
                        state = answer.getState();
                    } else {
                        s_logger.info("Agent response doesn't seem to be correct ==> " + answer.getResult());
                    }
                }
                router.setRedundantState(state);
                updated = true;
            }
        }
        if (updated) {
            _routerDao.update(router.getId(), router);
        }
        final RedundantState currState = router.getRedundantState();
        if (prevState != currState) {
            final String title = "Redundant virtual router " + router.getInstanceName() + " just switch from " + prevState + " to " + currState;
            final String context = "Redundant virtual router (name: " + router.getHostName() + ", id: " + router.getId() + ") " + " just switch from " + prevState + " to " + currState;
            s_logger.info(context);
            if (currState == RedundantState.MASTER) {
                _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), title, context);
            }
        }
    }
}
Also used : CheckRouterCommand(com.cloud.agent.api.CheckRouterCommand) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) RedundantState(com.cloud.network.router.VirtualRouter.RedundantState) DomainRouterVO(com.cloud.vm.DomainRouterVO) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer)

Example 94 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeDeployment.

@Override
public boolean finalizeDeployment(final Commands cmds, final VirtualMachineProfile profile, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    final List<NicProfile> nics = profile.getNics();
    for (final NicProfile nic : nics) {
        if (nic.getTrafficType() == TrafficType.Public) {
            router.setPublicIpAddress(nic.getIPv4Address());
            router.setPublicNetmask(nic.getIPv4Netmask());
            router.setPublicMacAddress(nic.getMacAddress());
        } else if (nic.getTrafficType() == TrafficType.Control) {
            router.setPrivateIpAddress(nic.getIPv4Address());
            router.setPrivateMacAddress(nic.getMacAddress());
        }
    }
    _routerDao.update(router.getId(), router);
    finalizeCommandsOnStart(cmds, profile);
    return true;
}
Also used : NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 95 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO 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)

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