Examples of DomainRouterVO


Examples of com.cloud.vm.DomainRouterVO

        });
    }

    @Override
    public DomainRouterVO persist(DomainRouterVO router) {
        DomainRouterVO virtualRouter =  _routerDao.persist(router);
        return virtualRouter;
    }
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

    InsufficientCapacityException, ConcurrentOperationException {
        Account caller = UserContext.current().getCaller();
        User callerUser = _accountMgr.getActiveUser(UserContext.current().getCallerUserId());

        // verify parameters
        DomainRouterVO router = _routerDao.findById(routerId);
        if (router == null) {
            throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
        }
        _accountMgr.checkAccess(caller, null, true, router);

        Account owner = _accountMgr.getAccount(router.getAccountId());

        // Check if all networks are implemented for the domR; if not - implement them
        DataCenter dc = _dcDao.findById(router.getDataCenterId());
        HostPodVO pod = null;
        if (router.getPodIdToDeployIn() != null) {
            pod = _podDao.findById(router.getPodIdToDeployIn());
        }
        DeployDestination dest = new DeployDestination(dc, pod, null, null);

        ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);

        List<NicVO> nics = _nicDao.listByVmId(routerId);

        for (NicVO nic : nics) {
            if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
                s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
                throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
            }
        }

        //After start network, check if it's already running
        router = _routerDao.findById(routerId);
        if (router.getState() == State.Running) {
            return router;
        }

        UserVO user = _userDao.findById(UserContext.current().getCallerUserId());
        Map<Param, Object> params = new HashMap<Param, Object>();
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

            lbs[i++] = lb;
        }
        String routerPublicIp = null;

        if (router instanceof DomainRouterVO) {
            DomainRouterVO domr = _routerDao.findById(router.getId());
            routerPublicIp = domr.getPublicIpAddress();
        }
       
        Network guestNetwork = _networkModel.getNetwork(guestNetworkId);
        Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
        NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(),
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

        if (!disconnectedRouters.get(0).getIsRedundantRouter()) {
            throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?",
                    DataCenter.class, disconnectedRouters.get(0).getDataCenterId());
        }

        DomainRouterVO connectedRouter = (DomainRouterVO)connectedRouters.get(0);
        DomainRouterVO disconnectedRouter = (DomainRouterVO)disconnectedRouters.get(0);

        if (s_logger.isDebugEnabled()) {
            s_logger.debug("About to stop the router " + disconnectedRouter.getInstanceName() + " due to: " + reason);
        }
        String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason;
        String context =  "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() + ") would be stopped after connecting back, due to: " + reason;
        _alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER,
                disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, context);
        disconnectedRouter.setStopPending(true);
        disconnectedRouter = _routerDao.persist(disconnectedRouter);

        int connRouterPR = getRealPriority(connectedRouter);
        int disconnRouterPR = getRealPriority(disconnectedRouter);
        if (connRouterPR < disconnRouterPR) {
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

            }
        }
       
        if(routerControlIpAddress == null) {
            s_logger.warn("Unable to find router's control ip in its attached NICs!. routerId: " + routerId);
            DomainRouterVO router = _routerDao.findById(routerId);
            return router.getPrivateIpAddress();
        }
           
        return routerControlIpAddress;
    }
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

    @Override
    public void prepareStop(VirtualMachineProfile<DomainRouterVO> profile){
        //Collect network usage before stopping Vm
        VMInstanceVO vm = profile.getVirtualMachine();

        DomainRouterVO router = _routerDao.findById(vm.getId());
        if(router == null){
            return;
        }

        String privateIP = router.getPrivateIpAddress();

        if (privateIP != null) {
            boolean forVpc = router.getVpcId() != null;
            List<? extends Nic> routerNics = _nicDao.listByVmId(router.getId());
            for (Nic routerNic : routerNics) {
                Network network = _networkModel.getNetwork(routerNic.getNetworkId());
                //Send network usage command for public nic in VPC VR
                //Send network usage command for isolated guest nic of non VPC VR
                if ((forVpc && network.getTrafficType() == TrafficType.Public) || (!forVpc && network.getTrafficType() == TrafficType.Guest && network.getGuestType() == Network.GuestType.Isolated)) {
                    final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
                            forVpc, routerNic.getIp4Address());
                    String routerType = router.getType().toString();
                    UserStatisticsVO previousStats = _userStatsDao.findBy(router.getAccountId(),
                            router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
                    NetworkUsageAnswer answer = null;
                    try {
                        answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd);
                    } catch (Exception e) {
                        s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId(), e);
                        continue;
                    }

                    if (answer != null) {
                        if (!answer.getResult()) {
                            s_logger.warn("Error while collecting network stats from router: " + router.getInstanceName() + " from host: " + router.getHostId() + "; details: " + answer.getDetails());
                            continue;
                        }
                        Transaction txn = Transaction.open(Transaction.CLOUD_DB);
                        try {
                            if ((answer.getBytesReceived() == 0) && (answer.getBytesSent() == 0)) {
                                s_logger.debug("Recieved and Sent bytes are both 0. Not updating user_statistics");
                                continue;
                            }
                            txn.start();
                            UserStatisticsVO stats = _userStatsDao.lock(router.getAccountId(),
                                    router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
                            if (stats == null) {
                                s_logger.warn("unable to find stats for account: " + router.getAccountId());
                                continue;
                            }

                            if (previousStats != null
                                    && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived())
                                    || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){
                                s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. " +
                                        "Ignoring current answer. Router: " + answer.getRouterName() + " Rcvd: " +
                                        answer.getBytesReceived() + "Sent: " + answer.getBytesSent());
                                continue;
                            }

                            if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) {
                                if (s_logger.isDebugEnabled()) {
                                    s_logger.debug("Received # of bytes that's less than the last one.  " +
                                            "Assuming something went wrong and persisting it. Router: " +
                                            answer.getRouterName() + " Reported: " + answer.getBytesReceived()
                                            + " Stored: " + stats.getCurrentBytesReceived());
                                }
                                stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                            }
                            stats.setCurrentBytesReceived(answer.getBytesReceived());
                            if (stats.getCurrentBytesSent() > answer.getBytesSent()) {
                                if (s_logger.isDebugEnabled()) {
                                    s_logger.debug("Received # of bytes that's less than the last one.  " +
                                            "Assuming something went wrong and persisting it. Router: " +
                                            answer.getRouterName() + " Reported: " + answer.getBytesSent()
                                            + " Stored: " + stats.getCurrentBytesSent());
                                }
                                stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                            }
                            stats.setCurrentBytesSent(answer.getBytesSent());
                            if (! _dailyOrHourly) {
                                //update agg bytes
                                stats.setAggBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
                                stats.setAggBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
                            }
                            _userStatsDao.update(stats.getId(), stats);
                            txn.commit();
                        } catch (Exception e) {
                            txn.rollback();
                            s_logger.warn("Unable to update user statistics for account: " + router.getAccountId()
                                    + " Rx: " + answer.getBytesReceived() + "; Tx: " + answer.getBytesSent());
                        } finally {
                            txn.close();
                        }
                    }
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

                }
            }
           
            PublicIp sourceNatIp = _vpcMgr.assignSourceNatIpAddressToVpc(owner, vpc);
           
            DomainRouterVO router = deployVpcRouter(owner, dest, plan, params, false, vpcVrProvider, offeringId,
                    vpc.getId(), sourceNatIp);
            routers.add(router);
           
        } finally {
            if (vpcLock != null) {
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

            InsufficientAddressCapacityException, InsufficientServerCapacityException, InsufficientCapacityException,
            StorageUnavailableException, ResourceUnavailableException {
       
        List<Pair<NetworkVO, NicProfile>> networks = createVpcRouterNetworks(owner, isRedundant, plan, new Pair<Boolean, PublicIp>(true, sourceNatIp),
                vpcId);
        DomainRouterVO router =
                super.deployRouter(owner, dest, plan, params, isRedundant, vrProvider, svcOffId, vpcId, networks, true,
                        _vpcMgr.getSupportedVpcHypervisors());
       
        return router;
    }
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

    public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException,
            InsufficientCapacityException {    
        boolean result = true;
       
        DomainRouterVO router = _routerDao.findById(vm.getId());
        if (router.getState() == State.Running) {
            try {
                PlugNicCommand plugNicCmd = new PlugNicCommand(nic, vm.getName(), vm.getType());
               
                Commands cmds = new Commands(OnError.Stop);
                cmds.addCommand("plugnic", plugNicCmd);                    
                _agentMgr.send(dest.getHost().getId(), cmds);
                PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
                if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
                    s_logger.warn("Unable to plug nic for vm " + vm.getName());
                    result = false;
                }
            } catch (OperationTimedoutException e) {
                throw new AgentUnavailableException("Unable to plug nic for router " + vm.getName() + " in network " + network,
                        dest.getHost().getId(), e);
            }
        } else {
            s_logger.warn("Unable to apply PlugNic, vm " + router + " is not in the right state " + router.getState());
           
            throw new ResourceUnavailableException("Unable to apply PlugNic on the backend," +
                    " vm " + vm + " is not in the right state", DataCenter.class, router.getDataCenterId());
        }
       
        return result;
    }
View Full Code Here

Examples of com.cloud.vm.DomainRouterVO

    @Override
    public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
            ReservationContext context, DeployDestination dest) throws ConcurrentOperationException, ResourceUnavailableException {
       
        boolean result = true;
        DomainRouterVO router = _routerDao.findById(vm.getId());
       
        if (router.getState() == State.Running) {
            try {
                Commands cmds = new Commands(OnError.Stop);
                UnPlugNicCommand unplugNicCmd = new UnPlugNicCommand(nic, vm.getName());
                cmds.addCommand("unplugnic", unplugNicCmd);
                _agentMgr.send(dest.getHost().getId(), cmds);
               
                UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class);
                if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
                    s_logger.warn("Unable to unplug nic from router " + router);
                    result = false;
                }
            } catch (OperationTimedoutException e) {
                throw new AgentUnavailableException("Unable to unplug nic from rotuer " + router + " from network " + network,
                        dest.getHost().getId(), e);
            }
        } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
            s_logger.debug("Vm " + router.getInstanceName() + " is in " + router.getState() +
                    ", so not sending unplug nic command to the backend");
        } else {
            s_logger.warn("Unable to apply unplug nic, Vm " + router + " is not in the right state " + router.getState());
           
            throw new ResourceUnavailableException("Unable to apply unplug nic on the backend," +
                    " vm " + router +" is not in the right state", DataCenter.class, router.getDataCenterId());
        }
      
        return result;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.