Search in sources :

Example 1 with AggregationControlCommand

use of com.cloud.agent.api.routing.AggregationControlCommand in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    final NicProfile controlNic = getControlNic(profile);
    if (controlNic == null) {
        s_logger.error("Control network doesn't exist for the router " + router);
        return false;
    }
    finalizeSshAndVersionAndNetworkUsageOnStart(cmds, profile, router, controlNic);
    // restart network if restartNetwork = false is not specified in profile
    // parameters
    boolean reprogramGuestNtwks = true;
    if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
        reprogramGuestNtwks = false;
    }
    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());
    }
    final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
    for (final Long guestNetworkId : routerGuestNtwkIds) {
        final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start, router.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
        cmds.addCommand(startCmd);
        if (reprogramGuestNtwks) {
            finalizeIpAssocForNetwork(cmds, router, provider, guestNetworkId, null);
            finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId);
            finalizeMonitorService(cmds, profile, router, provider, guestNetworkId, true);
        }
        finalizeUserDataAndDhcpOnStart(cmds, router, provider, guestNetworkId);
        final AggregationControlCommand finishCmd = new AggregationControlCommand(Action.Finish, router.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
        cmds.addCommand(finishCmd);
    }
    return true;
}
Also used : VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.network.Network.Provider)

Example 2 with AggregationControlCommand

use of com.cloud.agent.api.routing.AggregationControlCommand in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
    final DomainRouterVO domainRouterVO = _routerDao.findById(profile.getId());
    Map<String, String> details = new HashMap<String, String>();
    if (profile.getHypervisorType() == Hypervisor.HypervisorType.VMware) {
        HypervisorGuru hvGuru = _hvGuruMgr.getGuru(profile.getHypervisorType());
        VirtualMachineTO vmTO = hvGuru.implement(profile);
        if (vmTO.getDetails() != null) {
            details = vmTO.getDetails();
        }
    }
    final boolean isVpc = domainRouterVO.getVpcId() != null;
    if (!isVpc) {
        return super.finalizeCommandsOnStart(cmds, profile);
    }
    if (domainRouterVO.getState() == State.Starting || domainRouterVO.getState() == State.Running) {
        // 1) FORM SSH CHECK COMMAND
        final NicProfile controlNic = getControlNic(profile);
        if (controlNic == null) {
            s_logger.error("Control network doesn't exist for the router " + domainRouterVO);
            return false;
        }
        finalizeSshAndVersionAndNetworkUsageOnStart(cmds, profile, domainRouterVO, controlNic);
        // 2) FORM PLUG NIC COMMANDS
        final List<Pair<Nic, Network>> guestNics = new ArrayList<Pair<Nic, Network>>();
        final List<Pair<Nic, Network>> publicNics = new ArrayList<Pair<Nic, Network>>();
        final List<Pair<Nic, Network>> privateGatewayNics = new ArrayList<Pair<Nic, Network>>();
        final Map<String, String> vlanMacAddress = new HashMap<String, String>();
        final List<? extends Nic> routerNics = _nicDao.listByVmIdOrderByDeviceId(profile.getId());
        for (final Nic routerNic : routerNics) {
            final Network network = _networkModel.getNetwork(routerNic.getNetworkId());
            if (network.getTrafficType() == TrafficType.Guest) {
                final Pair<Nic, Network> guestNic = new Pair<Nic, Network>(routerNic, network);
                if (_networkModel.isPrivateGateway(routerNic.getNetworkId())) {
                    privateGatewayNics.add(guestNic);
                } else {
                    guestNics.add(guestNic);
                }
            } else if (network.getTrafficType() == TrafficType.Public) {
                final Pair<Nic, Network> publicNic = new Pair<Nic, Network>(routerNic, network);
                publicNics.add(publicNic);
                final String vlanTag = BroadcastDomainType.getValue(routerNic.getBroadcastUri());
                vlanMacAddress.put(vlanTag, routerNic.getMacAddress());
            }
        }
        // Public and Guest networks start from device_id = 1
        int deviceId = 1;
        final List<Command> usageCmds = new ArrayList<Command>();
        // 3) PREPARE PLUG NIC COMMANDS
        try {
            // add VPC router to public networks
            final List<PublicIp> sourceNat = new ArrayList<PublicIp>(1);
            for (final Pair<Nic, Network> nicNtwk : publicNics) {
                final Nic publicNic = updateNicWithDeviceId(nicNtwk.first().getId(), deviceId);
                deviceId++;
                final Network publicNtwk = nicNtwk.second();
                final IPAddressVO userIp = _ipAddressDao.findByIpAndSourceNetworkId(publicNtwk.getId(), publicNic.getIPv4Address());
                if (userIp.isSourceNat()) {
                    final PublicIp publicIp = PublicIp.createFromAddrAndVlan(userIp, _vlanDao.findById(userIp.getVlanId()));
                    sourceNat.add(publicIp);
                    if (domainRouterVO.getPublicIpAddress() == null) {
                        final DomainRouterVO routerVO = _routerDao.findById(domainRouterVO.getId());
                        routerVO.setPublicIpAddress(publicNic.getIPv4Address());
                        routerVO.setPublicNetmask(publicNic.getIPv4Netmask());
                        routerVO.setPublicMacAddress(publicNic.getMacAddress());
                        _routerDao.update(routerVO.getId(), routerVO);
                    }
                }
                final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, publicNic.getNetworkId(), publicNic.getBroadcastUri().toString()), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details);
                cmds.addCommand(plugNicCmd);
                final VpcVO vpc = _vpcDao.findById(domainRouterVO.getVpcId());
                final NetworkUsageCommand netUsageCmd = new NetworkUsageCommand(domainRouterVO.getPrivateIpAddress(), domainRouterVO.getInstanceName(), true, publicNic.getIPv4Address(), vpc.getCidr());
                usageCmds.add(netUsageCmd);
                UserStatisticsVO stats = _userStatsDao.findBy(domainRouterVO.getAccountId(), domainRouterVO.getDataCenterId(), publicNtwk.getId(), publicNic.getIPv4Address(), domainRouterVO.getId(), domainRouterVO.getType().toString());
                if (stats == null) {
                    stats = new UserStatisticsVO(domainRouterVO.getAccountId(), domainRouterVO.getDataCenterId(), publicNic.getIPv4Address(), domainRouterVO.getId(), domainRouterVO.getType().toString(), publicNtwk.getId());
                    _userStatsDao.persist(stats);
                }
            }
            // create ip assoc for source nat
            if (!sourceNat.isEmpty()) {
                _commandSetupHelper.createVpcAssociatePublicIPCommands(domainRouterVO, sourceNat, cmds, vlanMacAddress);
            }
            // add VPC router to private gateway networks
            for (final Pair<Nic, Network> nicNtwk : privateGatewayNics) {
                final Nic guestNic = updateNicWithDeviceId(nicNtwk.first().getId(), deviceId);
                deviceId++;
                // plug guest nic
                final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, guestNic.getNetworkId(), null), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details);
                cmds.addCommand(plugNicCmd);
                // set private network
                final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(guestNic.getNetworkId(), guestNic.getIPv4Address());
                final Network network = _networkDao.findById(guestNic.getNetworkId());
                BroadcastDomainType.getValue(network.getBroadcastUri());
                final String netmask = NetUtils.getCidrNetmask(network.getCidr());
                final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, guestNic.getMacAddress());
                final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
                privateIps.add(ip);
                _commandSetupHelper.createVpcAssociatePrivateIPCommands(domainRouterVO, privateIps, cmds, true);
                final Long privateGwAclId = _vpcGatewayDao.getNetworkAclIdForPrivateIp(ipVO.getVpcId(), ipVO.getNetworkId(), ipVO.getIpAddress());
                if (privateGwAclId != null) {
                    // set network acl on private gateway
                    final List<NetworkACLItemVO> networkACLs = _networkACLItemDao.listByACL(privateGwAclId);
                    s_logger.debug("Found " + networkACLs.size() + " network ACLs to apply as a part of VPC VR " + domainRouterVO + " start for private gateway ip = " + ipVO.getIpAddress());
                    _commandSetupHelper.createNetworkACLsCommands(networkACLs, domainRouterVO, cmds, ipVO.getNetworkId(), true);
                }
            }
            // add VPC router to guest networks
            for (final Pair<Nic, Network> nicNtwk : guestNics) {
                final Nic guestNic = updateNicWithDeviceId(nicNtwk.first().getId(), deviceId);
                deviceId++;
                // plug guest nic
                final PlugNicCommand plugNicCmd = new PlugNicCommand(_nwHelper.getNicTO(domainRouterVO, guestNic.getNetworkId(), null), domainRouterVO.getInstanceName(), domainRouterVO.getType(), details);
                cmds.addCommand(plugNicCmd);
                // set guest network
                final VirtualMachine vm = _vmDao.findById(domainRouterVO.getId());
                final NicProfile nicProfile = _networkModel.getNicProfile(vm, guestNic.getNetworkId(), null);
                final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand(domainRouterVO, true, nicProfile);
                cmds.addCommand(setupCmd);
            }
        } catch (final Exception ex) {
            s_logger.warn("Failed to add router " + domainRouterVO + " to network due to exception ", ex);
            return false;
        }
        // 4) RE-APPLY ALL STATIC ROUTE RULES
        final List<? extends StaticRoute> routes = _staticRouteDao.listByVpcId(domainRouterVO.getVpcId());
        final List<StaticRouteProfile> staticRouteProfiles = new ArrayList<StaticRouteProfile>(routes.size());
        final Map<Long, VpcGateway> gatewayMap = new HashMap<Long, VpcGateway>();
        for (final StaticRoute route : routes) {
            VpcGateway gateway = gatewayMap.get(route.getVpcGatewayId());
            if (gateway == null) {
                gateway = _entityMgr.findById(VpcGateway.class, route.getVpcGatewayId());
                gatewayMap.put(gateway.getId(), gateway);
            }
            staticRouteProfiles.add(new StaticRouteProfile(route, gateway));
        }
        s_logger.debug("Found " + staticRouteProfiles.size() + " static routes to apply as a part of vpc route " + domainRouterVO + " start");
        if (!staticRouteProfiles.isEmpty()) {
            _commandSetupHelper.createStaticRouteCommands(staticRouteProfiles, domainRouterVO, cmds);
        }
        // 5) RE-APPLY ALL REMOTE ACCESS VPNs
        final RemoteAccessVpnVO vpn = _vpnDao.findByAccountAndVpc(domainRouterVO.getAccountId(), domainRouterVO.getVpcId());
        if (vpn != null) {
            _commandSetupHelper.createApplyVpnCommands(true, vpn, domainRouterVO, cmds);
        }
        // 6) REPROGRAM GUEST NETWORK
        boolean reprogramGuestNtwks = true;
        if (profile.getParameter(Param.ReProgramGuestNetworks) != null && (Boolean) profile.getParameter(Param.ReProgramGuestNetworks) == false) {
            reprogramGuestNtwks = false;
        }
        final VirtualRouterProvider vrProvider = _vrProviderDao.findById(domainRouterVO.getElementId());
        if (vrProvider == null) {
            throw new CloudRuntimeException("Cannot find related virtual router provider of router: " + domainRouterVO.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());
        }
        if (reprogramGuestNtwks && publicNics.size() > 0) {
            finalizeMonitorService(cmds, profile, domainRouterVO, provider, publicNics.get(0).second().getId(), true);
        }
        for (final Pair<Nic, Network> nicNtwk : guestNics) {
            final Nic guestNic = nicNtwk.first();
            final long guestNetworkId = guestNic.getNetworkId();
            final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start, domainRouterVO.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, domainRouterVO.getId()));
            cmds.addCommand(startCmd);
            if (reprogramGuestNtwks) {
                finalizeIpAssocForNetwork(cmds, domainRouterVO, provider, guestNetworkId, vlanMacAddress);
                finalizeNetworkRulesForNetwork(cmds, domainRouterVO, provider, guestNetworkId);
                finalizeMonitorService(cmds, profile, domainRouterVO, provider, guestNetworkId, true);
            }
            finalizeUserDataAndDhcpOnStart(cmds, domainRouterVO, provider, guestNetworkId);
            final AggregationControlCommand finishCmd = new AggregationControlCommand(Action.Finish, domainRouterVO.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, domainRouterVO.getId()));
            cmds.addCommand(finishCmd);
        }
        // Add network usage commands
        cmds.addCommands(usageCmds);
    }
    return true;
}
Also used : RemoteAccessVpnVO(com.cloud.network.dao.RemoteAccessVpnVO) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) NetworkACLItemVO(com.cloud.network.vpc.NetworkACLItemVO) HypervisorGuru(com.cloud.hypervisor.HypervisorGuru) StaticRouteProfile(com.cloud.network.vpc.StaticRouteProfile) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) VpcGateway(com.cloud.network.vpc.VpcGateway) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) Pair(com.cloud.utils.Pair) StaticRoute(com.cloud.network.vpc.StaticRoute) PublicIp(com.cloud.network.addr.PublicIp) Nic(com.cloud.vm.Nic) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) NicProfile(com.cloud.vm.NicProfile) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.network.Network.Provider) VpcVO(com.cloud.network.vpc.VpcVO) PlugNicCommand(com.cloud.agent.api.PlugNicCommand) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) Command(com.cloud.agent.api.Command) NetworkUsageCommand(com.cloud.agent.api.NetworkUsageCommand) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) IPAddressVO(com.cloud.network.dao.IPAddressVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) UserStatisticsVO(com.cloud.user.UserStatisticsVO) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 3 with AggregationControlCommand

use of com.cloud.agent.api.routing.AggregationControlCommand in project cloudstack by apache.

the class VirtualRoutingResource method executeRequest.

public Answer executeRequest(final NetworkElementCommand cmd) {
    boolean aggregated = false;
    String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    Lock lock;
    if (_vrLockMap.containsKey(routerName)) {
        lock = _vrLockMap.get(routerName);
    } else {
        lock = new ReentrantLock();
        _vrLockMap.put(routerName, lock);
    }
    lock.lock();
    try {
        ExecutionResult rc = _vrDeployer.prepareCommand(cmd);
        if (!rc.isSuccess()) {
            s_logger.error("Failed to prepare VR command due to " + rc.getDetails());
            return new Answer(cmd, false, rc.getDetails());
        }
        assert cmd.getRouterAccessIp() != null : "Why there is no access IP for VR?";
        if (cmd.isQuery()) {
            return executeQueryCommand(cmd);
        }
        if (cmd instanceof SetupKeyStoreCommand) {
            return execute((SetupKeyStoreCommand) cmd);
        }
        if (cmd instanceof SetupCertificateCommand) {
            return execute((SetupCertificateCommand) cmd);
        }
        if (cmd instanceof AggregationControlCommand) {
            return execute((AggregationControlCommand) cmd);
        }
        if (_vrAggregateCommandsSet.containsKey(routerName)) {
            _vrAggregateCommandsSet.get(routerName).add(cmd);
            aggregated = true;
            // TODO: Deal with group answer as well
            return new Answer(cmd);
        }
        List<ConfigItem> cfg = generateCommandCfg(cmd);
        if (cfg == null) {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        return applyConfig(cmd, cfg);
    } catch (final IllegalArgumentException e) {
        return new Answer(cmd, false, e.getMessage());
    } finally {
        lock.unlock();
        if (!aggregated) {
            ExecutionResult rc = _vrDeployer.cleanupCommand(cmd);
            if (!rc.isSuccess()) {
                s_logger.error("Failed to cleanup VR command due to " + rc.getDetails());
            }
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) SetupCertificateCommand(org.apache.cloudstack.ca.SetupCertificateCommand) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) SetupKeystoreAnswer(org.apache.cloudstack.ca.SetupKeystoreAnswer) Answer(com.cloud.agent.api.Answer) SetupCertificateAnswer(org.apache.cloudstack.ca.SetupCertificateAnswer) DiagnosticsAnswer(org.apache.cloudstack.diagnostics.DiagnosticsAnswer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) PrepareFilesAnswer(org.apache.cloudstack.diagnostics.PrepareFilesAnswer) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) ExecutionResult(com.cloud.utils.ExecutionResult) SetupKeyStoreCommand(org.apache.cloudstack.ca.SetupKeyStoreCommand) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 4 with AggregationControlCommand

use of com.cloud.agent.api.routing.AggregationControlCommand in project cosmic by MissionCriticalCloud.

the class VirtualRoutingResource method executeRequest.

public Answer executeRequest(final NetworkElementCommand cmd) {
    boolean aggregated = false;
    final String routerName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
    final Lock lock;
    if (_vrLockMap.containsKey(routerName)) {
        lock = _vrLockMap.get(routerName);
    } else {
        lock = new ReentrantLock();
        _vrLockMap.put(routerName, lock);
    }
    lock.lock();
    try {
        final ExecutionResult rc = _vrDeployer.prepareCommand(cmd);
        if (!rc.isSuccess()) {
            s_logger.error("Failed to prepare VR command due to " + rc.getDetails());
            return new Answer(cmd, false, rc.getDetails());
        }
        assert cmd.getRouterAccessIp() != null : "Why there is no access IP for VR?";
        if (cmd.isQuery()) {
            return executeQueryCommand(cmd);
        }
        if (cmd instanceof AggregationControlCommand) {
            return execute((AggregationControlCommand) cmd);
        }
        if (_vrAggregateCommandsSet.containsKey(routerName)) {
            _vrAggregateCommandsSet.get(routerName).add(cmd);
            aggregated = true;
            // TODO: Deal with group answer as well
            return new Answer(cmd);
        }
        final List<ConfigItem> cfg = generateCommandCfg(cmd);
        if (cfg == null) {
            return Answer.createUnsupportedCommandAnswer(cmd);
        }
        return applyConfig(cmd, cfg);
    } catch (final IllegalArgumentException e) {
        return new Answer(cmd, false, e.getMessage());
    } finally {
        lock.unlock();
        if (!aggregated) {
            final ExecutionResult rc = _vrDeployer.cleanupCommand(cmd);
            if (!rc.isSuccess()) {
                s_logger.error("Failed to cleanup VR command due to " + rc.getDetails());
            }
        }
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) ExecutionResult(com.cloud.utils.ExecutionResult) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock)

Example 5 with AggregationControlCommand

use of com.cloud.agent.api.routing.AggregationControlCommand in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method finalizeCommandsOnStart.

@Override
public boolean finalizeCommandsOnStart(final Commands cmds, final VirtualMachineProfile profile) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    final NicProfile controlNic = getControlNic(profile);
    if (controlNic == null) {
        s_logger.error("Control network doesn't exist for the router " + router);
        return false;
    }
    finalizeSshAndVersionAndNetworkUsageOnStart(cmds, profile, router, controlNic);
    // restart network if restartNetwork = false is not specified in profile
    // parameters
    boolean reprogramGuestNtwks = profile.getParameter(Param.ReProgramGuestNetworks) == null || (Boolean) profile.getParameter(Param.ReProgramGuestNetworks);
    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());
    }
    final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId());
    for (final Long guestNetworkId : routerGuestNtwkIds) {
        final AggregationControlCommand startCmd = new AggregationControlCommand(Action.Start, router.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
        cmds.addCommand(startCmd);
        if (reprogramGuestNtwks) {
            finalizeNetworkRulesForNetwork(cmds, router, provider, guestNetworkId);
        }
        final AggregationControlCommand finishCmd = new AggregationControlCommand(Action.Finish, router.getInstanceName(), controlNic.getIPv4Address(), _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
        cmds.addCommand(finishCmd);
    }
    return true;
}
Also used : VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AggregationControlCommand(com.cloud.agent.api.routing.AggregationControlCommand) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouterProvider(com.cloud.network.VirtualRouterProvider) Provider(com.cloud.network.Network.Provider)

Aggregations

AggregationControlCommand (com.cloud.agent.api.routing.AggregationControlCommand)10 DomainRouterVO (com.cloud.vm.DomainRouterVO)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 Answer (com.cloud.agent.api.Answer)4 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)3 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)3 GroupAnswer (com.cloud.agent.api.routing.GroupAnswer)3 Provider (com.cloud.network.Network.Provider)3 VirtualRouterProvider (com.cloud.network.VirtualRouterProvider)3 NicProfile (com.cloud.vm.NicProfile)3 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)2 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)2 Command (com.cloud.agent.api.Command)2 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)2 Commands (com.cloud.agent.manager.Commands)2 ExecutionResult (com.cloud.utils.ExecutionResult)2 Lock (java.util.concurrent.locks.Lock)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 ConfigurationException (javax.naming.ConfigurationException)2 AttachIsoCommand (com.cloud.agent.api.AttachIsoCommand)1