Search in sources :

Example 1 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class BasicNetworkTopology method applyRules.

@Override
public boolean applyRules(final Network network, final VirtualRouter router, final String typeString, final boolean isPodLevelException, final Long podId, final boolean failWhenDisconnect, final RuleApplierWrapper<RuleApplier> ruleApplierWrapper) throws ResourceUnavailableException {
    if (router == null) {
        s_logger.warn("Unable to apply " + typeString + ", virtual router doesn't exist in the network " + network.getId());
        throw new ResourceUnavailableException("Unable to apply " + typeString, DataCenter.class, network.getDataCenterId());
    }
    final RuleApplier ruleApplier = ruleApplierWrapper.getRuleType();
    final DataCenter dc = _dcDao.findById(network.getDataCenterId());
    final boolean isZoneBasic = dc.getNetworkType() == NetworkType.Basic;
    // isPodLevelException and podId is only used for basic zone
    assert !(!isZoneBasic && isPodLevelException || isZoneBasic && isPodLevelException && podId == null);
    final List<VirtualRouter> connectedRouters = new ArrayList<>();
    final List<VirtualRouter> disconnectedRouters = new ArrayList<>();
    boolean result = true;
    final String msg = "Unable to apply " + typeString + " on disconnected router ";
    if (router.getState() == State.Running) {
        s_logger.debug("Applying " + typeString + " in network " + network);
        if (router.isStopPending()) {
            if (_hostDao.findById(router.getHostId()).getState() == HostStatus.Up) {
                throw new ResourceUnavailableException("Unable to process due to the stop pending router " + router.getInstanceName() + " haven't been stopped after it's host coming back!", DataCenter.class, router.getDataCenterId());
            }
            s_logger.debug("Router " + router.getInstanceName() + " is stop pending, so not sending apply " + typeString + " commands to the backend");
            return false;
        }
        try {
            result = ruleApplier.accept(getVisitor(), router);
            connectedRouters.add(router);
        } catch (final AgentUnavailableException e) {
            s_logger.warn(msg + router.getInstanceName(), e);
            disconnectedRouters.add(router);
        }
        // disconnection, no need to proceed with the rest
        if (!result) {
            if (isZoneBasic && isPodLevelException) {
                throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", Pod.class, podId);
            }
            throw new ResourceUnavailableException("Unable to apply " + typeString + " on router ", DataCenter.class, router.getDataCenterId());
        }
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending apply " + typeString + " commands to the backend");
    } else {
        s_logger.warn("Unable to apply " + typeString + ", virtual router is not in the right state " + router.getState());
        if (isZoneBasic && isPodLevelException) {
            throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", Pod.class, podId);
        }
        throw new ResourceUnavailableException("Unable to apply " + typeString + ", virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    if (!connectedRouters.isEmpty()) {
        // Shouldn't we include this check inside the method?
        if (!isZoneBasic && !disconnectedRouters.isEmpty()) {
            // now, stop them for synchronization
            for (final VirtualRouter virtualRouter : disconnectedRouters) {
                // If we have at least 1 disconnected redundant router, callhandleSingleWorkingRedundantRouter().
                if (virtualRouter.getIsRedundantRouter()) {
                    _networkHelper.handleSingleWorkingRedundantRouter(connectedRouters, disconnectedRouters, msg);
                    break;
                }
            }
        }
    } else if (!disconnectedRouters.isEmpty()) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug(msg + router.getInstanceName() + "(" + router.getId() + ")");
        }
        if (isZoneBasic && isPodLevelException) {
            throw new ResourceUnavailableException(msg, Pod.class, podId);
        }
        throw new ResourceUnavailableException(msg, DataCenter.class, disconnectedRouters.get(0).getDataCenterId());
    }
    result = true;
    if (failWhenDisconnect) {
        result = !connectedRouters.isEmpty();
    }
    return result;
}
Also used : DataCenter(com.cloud.legacymodel.dc.DataCenter) Pod(com.cloud.legacymodel.dc.Pod) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) RuleApplier(com.cloud.network.rules.RuleApplier) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) ArrayList(java.util.ArrayList) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 2 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final UserdataPwdRules userdata) throws ResourceUnavailableException {
    final VirtualRouter router = userdata.getRouter();
    final Commands commands = new Commands(Command.OnError.Stop);
    final VirtualMachineProfile profile = userdata.getProfile();
    final NicVO nicVO = userdata.getNicVo();
    final DeployDestination destination = userdata.getDestination();
    if (router.getPodIdToDeployIn() == destination.getPod().getId()) {
        _commandSetupHelper.createPasswordCommand(router, profile, nicVO, commands);
        final VMOverviewTO vmOverview = _commandSetupHelper.createVmOverviewFromRouter(router);
        final UpdateVmOverviewCommand updateVmOverviewCommand = _commandSetupHelper.createUpdateVmOverviewCommand(router, vmOverview);
        commands.addCommand(updateVmOverviewCommand);
        return _networkGeneralHelper.sendCommandsToRouter(router, commands);
    }
    return true;
}
Also used : DeployDestination(com.cloud.deploy.DeployDestination) VMOverviewTO(com.cloud.legacymodel.to.VMOverviewTO) Commands(com.cloud.agent.manager.Commands) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter) UpdateVmOverviewCommand(com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand)

Example 3 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final StaticRoutesRules staticRoutesRules) throws ResourceUnavailableException {
    final VirtualRouter router = staticRoutesRules.getRouter();
    final Commands cmds = new Commands(Command.OnError.Continue);
    final NetworkOverviewTO networkOverview = _commandSetupHelper.createNetworkOverviewFromRouter(router, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null, null, null);
    final UpdateNetworkOverviewCommand updateNetworkOverviewCommand = _commandSetupHelper.createUpdateNetworkOverviewCommand(router, networkOverview);
    cmds.addCommand(updateNetworkOverviewCommand);
    return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
Also used : Commands(com.cloud.agent.manager.Commands) NetworkOverviewTO(com.cloud.legacymodel.to.NetworkOverviewTO) UpdateNetworkOverviewCommand(com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 4 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final NetworkAclsRules acls) throws ResourceUnavailableException {
    final VirtualRouter router = acls.getRouter();
    final Network network = acls.getNetwork();
    final Commands commands = new Commands(Command.OnError.Continue);
    final List<? extends NetworkACLItem> rules = acls.getRules();
    _commandSetupHelper.createNetworkACLsCommands(rules, router, commands, network.getId(), acls.isPrivateGateway());
    return _networkGeneralHelper.sendCommandsToRouter(router, commands);
}
Also used : Network(com.cloud.legacymodel.network.Network) Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Example 5 with VirtualRouter

use of com.cloud.legacymodel.network.VirtualRouter in project cosmic by MissionCriticalCloud.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final NicPlugInOutRules nicPlugInOutRules) throws ResourceUnavailableException {
    final VirtualRouter router = nicPlugInOutRules.getRouter();
    final Commands commands = nicPlugInOutRules.getNetUsageCommands();
    if (commands.size() > 0) {
        return _networkGeneralHelper.sendCommandsToRouter(router, commands);
    }
    return true;
}
Also used : Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.legacymodel.network.VirtualRouter)

Aggregations

VirtualRouter (com.cloud.legacymodel.network.VirtualRouter)36 Commands (com.cloud.agent.manager.Commands)21 UpdateVmOverviewCommand (com.cloud.legacymodel.communication.command.UpdateVmOverviewCommand)8 VMOverviewTO (com.cloud.legacymodel.to.VMOverviewTO)8 NicVO (com.cloud.vm.NicVO)8 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)8 UpdateNetworkOverviewCommand (com.cloud.legacymodel.communication.command.UpdateNetworkOverviewCommand)7 NetworkOverviewTO (com.cloud.legacymodel.to.NetworkOverviewTO)7 DomainRouterVO (com.cloud.vm.DomainRouterVO)7 ServerApiException (com.cloud.api.ServerApiException)5 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)5 Zone (com.cloud.db.model.Zone)5 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)5 Ip (com.cloud.legacymodel.network.Ip)5 UserVmVO (com.cloud.vm.UserVmVO)5 ArrayList (java.util.ArrayList)5 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)4 Network (com.cloud.legacymodel.network.Network)4 Config (com.cloud.configuration.Config)3 ZoneRepository (com.cloud.db.repository.ZoneRepository)3