Search in sources :

Example 61 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method sendNetworkRulesToRouter.

protected boolean sendNetworkRulesToRouter(final long routerId, final long networkId) throws ResourceUnavailableException {
    final DomainRouterVO router = _routerDao.findById(routerId);
    final Commands cmds = new Commands(OnError.Continue);
    final VirtualRouterProvider vrProvider = _vrProviderDao.findById(router.getElementId());
    if (vrProvider == null) {
        throw new CloudRuntimeException("Cannot find related virtual router provider of router: " + router.getHostName());
    }
    final Provider provider = Network.Provider.getProvider(vrProvider.getType().toString());
    if (provider == null) {
        throw new CloudRuntimeException("Cannot find related provider of virtual router provider: " + vrProvider.getType().toString());
    }
    finalizeNetworkRulesForNetwork(cmds, router, provider, networkId);
    return _nwHelper.sendCommandsToRouter(router, cmds);
}
Also used : VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Commands(com.cloud.agent.manager.Commands) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.network.Network.Provider)

Example 62 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class SecurityGroupListener method processConnect.

@Override
public void processConnect(Host host, StartupCommand cmd, boolean forRebalance) {
    if (s_logger.isInfoEnabled())
        s_logger.info("Received a host startup notification");
    if (cmd instanceof StartupRoutingCommand) {
        //if (Boolean.toString(true).equals(host.getDetail("can_bridge_firewall"))) {
        try {
            int interval = MIN_TIME_BETWEEN_CLEANUPS + _cleanupRandom.nextInt(MIN_TIME_BETWEEN_CLEANUPS / 2);
            CleanupNetworkRulesCmd cleanupCmd = new CleanupNetworkRulesCmd(interval);
            Commands c = new Commands(cleanupCmd);
            _agentMgr.send(host.getId(), c, this);
            if (s_logger.isInfoEnabled())
                s_logger.info("Scheduled network rules cleanup, interval=" + cleanupCmd.getInterval());
        } catch (AgentUnavailableException e) {
            //usually hypervisors that do not understand sec group rules.
            s_logger.debug("Unable to schedule network rules cleanup for host " + host.getId(), e);
        }
        if (_workTracker != null) {
            _workTracker.processConnect(host.getId());
        }
    }
}
Also used : AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) CleanupNetworkRulesCmd(com.cloud.agent.api.CleanupNetworkRulesCmd)

Example 63 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class SecurityGroupManagerImpl method work.

@DB
public void work() {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Checking the database");
    }
    final SecurityGroupWorkVO work = _workDao.take(_serverId);
    if (work == null) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("Security Group work: no work found");
        }
        return;
    }
    final Long userVmId = work.getInstanceId();
    if (work.getStep() == Step.Done) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Security Group work: found a job in done state, rescheduling for vm: " + userVmId);
        }
        ArrayList<Long> affectedVms = new ArrayList<Long>();
        affectedVms.add(userVmId);
        scheduleRulesetUpdateToHosts(affectedVms, false, _timeBetweenCleanups * 1000l);
        return;
    }
    s_logger.debug("Working on " + work);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            UserVm vm = null;
            Long seqnum = null;
            boolean locked = false;
            try {
                vm = _userVMDao.acquireInLockTable(work.getInstanceId());
                if (vm == null) {
                    vm = _userVMDao.findById(work.getInstanceId());
                    if (vm == null) {
                        s_logger.info("VM " + work.getInstanceId() + " is removed");
                        locked = true;
                        return;
                    }
                    s_logger.warn("Unable to acquire lock on vm id=" + userVmId);
                    return;
                }
                locked = true;
                Long agentId = null;
                VmRulesetLogVO log = _rulesetLogDao.findByVmId(userVmId);
                if (log == null) {
                    s_logger.warn("Cannot find log record for vm id=" + userVmId);
                    return;
                }
                seqnum = log.getLogsequence();
                if (vm != null && vm.getState() == State.Running) {
                    Map<PortAndProto, Set<String>> ingressRules = generateRulesForVM(userVmId, SecurityRuleType.IngressRule);
                    Map<PortAndProto, Set<String>> egressRules = generateRulesForVM(userVmId, SecurityRuleType.EgressRule);
                    agentId = vm.getHostId();
                    if (agentId != null) {
                        // get nic secondary ip address
                        String privateIp = vm.getPrivateIpAddress();
                        NicVO nic = _nicDao.findByIp4AddressAndVmId(privateIp, vm.getId());
                        List<String> nicSecIps = null;
                        if (nic != null) {
                            if (nic.getSecondaryIp()) {
                                //get secondary ips of the vm
                                long networkId = nic.getNetworkId();
                                nicSecIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nic.getId());
                            }
                        }
                        SecurityGroupRulesCmd cmd = generateRulesetCmd(vm.getInstanceName(), nic.getIPv6Address(), vm.getPrivateIpAddress(), vm.getPrivateMacAddress(), vm.getId(), generateRulesetSignature(ingressRules, egressRules), seqnum, ingressRules, egressRules, nicSecIps);
                        Commands cmds = new Commands(cmd);
                        try {
                            _agentMgr.send(agentId, cmds, _answerListener);
                        } catch (AgentUnavailableException e) {
                            s_logger.debug("Unable to send ingress rules updates for vm: " + userVmId + "(agentid=" + agentId + ")");
                            _workDao.updateStep(work.getInstanceId(), seqnum, Step.Done);
                        }
                    }
                }
            } finally {
                if (locked) {
                    _userVMDao.releaseFromLockTable(userVmId);
                    _workDao.updateStep(work.getId(), Step.Done);
                }
            }
        }
    });
}
Also used : SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) ArrayList(java.util.ArrayList) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) UserVm(com.cloud.uservm.UserVm) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) NicVO(com.cloud.vm.NicVO) DB(com.cloud.utils.db.DB)

Example 64 with Commands

use of com.cloud.agent.manager.Commands in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method aggregationExecution.

protected boolean aggregationExecution(final AggregationControlCommand.Action action, final Network network, final List<DomainRouterVO> routers) throws AgentUnavailableException, ResourceUnavailableException {
    int errors = 0;
    for (final DomainRouterVO router : routers) {
        final String routerControlIp = _routerControlHelper.getRouterControlIp(router.getId());
        final String routerIpInNetwork = _routerControlHelper.getRouterIpInNetwork(network.getId(), router.getId());
        if (routerIpInNetwork == null) {
            // Nic hasn't been created in this router yet. Try to configure the next one.
            s_logger.warn("The Network is not configured in the router " + router.getHostName() + " yet. Try the next router!");
            errors++;
            continue;
        }
        final AggregationControlCommand cmd = new AggregationControlCommand(action, router.getInstanceName(), routerControlIp, routerIpInNetwork);
        final Commands cmds = new Commands(cmd);
        if (!_nwHelper.sendCommandsToRouter(router, cmds)) {
            return false;
        }
    }
    if (errors == routers.size()) {
        s_logger.error("aggregationExecution() on " + getClass().getName() + " failed! Network is not configured in any router.");
        return false;
    }
    return true;
}
Also used : AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) Commands(com.cloud.agent.manager.Commands) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Commands (com.cloud.agent.manager.Commands)64 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)22 VirtualRouter (com.cloud.network.router.VirtualRouter)19 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)17 Answer (com.cloud.agent.api.Answer)16 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)13 Network (com.cloud.network.Network)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 NicVO (com.cloud.vm.NicVO)10 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)9 ArrayList (java.util.ArrayList)9 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)8 UserVmVO (com.cloud.vm.UserVmVO)8 DataCenter (com.cloud.dc.DataCenter)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)7 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)6 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)6 StartAnswer (com.cloud.agent.api.StartAnswer)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6