Search in sources :

Example 1 with RuleApplier

use of com.cloud.network.rules.RuleApplier 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() == Status.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.dc.DataCenter) Pod(com.cloud.dc.Pod) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) RuleApplier(com.cloud.network.rules.RuleApplier) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ArrayList(java.util.ArrayList) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 2 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class AdvancedNetworkTopology method applyDhcpEntry.

@Override
public boolean applyDhcpEntry(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final DeployDestination dest, final DomainRouterVO router) throws ResourceUnavailableException {
    s_logger.debug("APPLYING VPC DHCP ENTRY RULES");
    final String typeString = "dhcp entry";
    final Long podId = null;
    final boolean isPodLevelException = false;
    final boolean failWhenDisconnect = false;
    final DhcpEntryRules dhcpRules = new DhcpEntryRules(network, nic, profile, dest);
    return applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(dhcpRules));
}
Also used : RuleApplier(com.cloud.network.rules.RuleApplier) DhcpEntryRules(com.cloud.network.rules.DhcpEntryRules)

Example 3 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class AdvancedNetworkTopology method applyNetworkACLs.

@Override
public boolean applyNetworkACLs(final Network network, final List<? extends NetworkACLItem> rules, final VirtualRouter router, final boolean isPrivateGateway) throws ResourceUnavailableException {
    if (rules == null || rules.isEmpty()) {
        s_logger.debug("No network ACLs to be applied for network " + network.getId());
        return true;
    }
    s_logger.debug("APPLYING NETWORK ACLs RULES");
    final String typeString = "network acls";
    final boolean isPodLevelException = false;
    final boolean failWhenDisconnect = false;
    final Long podId = null;
    final NetworkAclsRules aclsRules = new NetworkAclsRules(network, rules, isPrivateGateway);
    final boolean result = applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(aclsRules));
    return result;
}
Also used : NetworkAclsRules(com.cloud.network.rules.NetworkAclsRules) RuleApplier(com.cloud.network.rules.RuleApplier)

Example 4 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class AdvancedNetworkTopology method associatePublicIP.

@Override
public boolean associatePublicIP(final Network network, final List<? extends PublicIpAddress> ipAddresses, final VirtualRouter router) throws ResourceUnavailableException {
    if (ipAddresses == null || ipAddresses.isEmpty()) {
        s_logger.debug("No ip association rules to be applied for network " + network.getId());
        return true;
    }
    if (network.getVpcId() == null) {
        return super.associatePublicIP(network, ipAddresses, router);
    }
    s_logger.debug("APPLYING VPC IP RULES");
    final String typeString = "vpc ip association";
    final boolean isPodLevelException = false;
    final boolean failWhenDisconnect = false;
    final Long podId = null;
    final NicPlugInOutRules nicPlugInOutRules = new NicPlugInOutRules(network, ipAddresses);
    nicPlugInOutRules.accept(_advancedVisitor, router);
    final VpcIpAssociationRules ipAssociationRules = new VpcIpAssociationRules(network, ipAddresses);
    final boolean result = applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(ipAssociationRules));
    if (result) {
        if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
            s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending NicPlugInOutRules command to the backend");
        } else {
            _advancedVisitor.visit(nicPlugInOutRules);
        }
    }
    return result;
}
Also used : NicPlugInOutRules(com.cloud.network.rules.NicPlugInOutRules) RuleApplier(com.cloud.network.rules.RuleApplier) VpcIpAssociationRules(com.cloud.network.rules.VpcIpAssociationRules)

Example 5 with RuleApplier

use of com.cloud.network.rules.RuleApplier in project cloudstack by apache.

the class BasicNetworkTopology method saveUserDataToRouter.

@Override
public boolean saveUserDataToRouter(final Network network, final NicProfile nic, final VirtualMachineProfile profile, final VirtualRouter router) throws ResourceUnavailableException {
    s_logger.debug("SAVE USERDATA TO ROUTE RULES");
    final String typeString = "save userdata entry";
    final boolean isPodLevelException = false;
    final boolean failWhenDisconnect = false;
    final Long podId = null;
    final UserdataToRouterRules userdataToRouterRules = new UserdataToRouterRules(network, nic, profile);
    return applyRules(network, router, typeString, isPodLevelException, podId, failWhenDisconnect, new RuleApplierWrapper<RuleApplier>(userdataToRouterRules));
}
Also used : RuleApplier(com.cloud.network.rules.RuleApplier) UserdataToRouterRules(com.cloud.network.rules.UserdataToRouterRules)

Aggregations

RuleApplier (com.cloud.network.rules.RuleApplier)17 DhcpEntryRules (com.cloud.network.rules.DhcpEntryRules)4 DataCenter (com.cloud.dc.DataCenter)2 Pod (com.cloud.dc.Pod)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 VirtualRouter (com.cloud.network.router.VirtualRouter)2 UserdataPwdRules (com.cloud.network.rules.UserdataPwdRules)2 ArrayList (java.util.ArrayList)2 FirewallRules (com.cloud.network.rules.FirewallRules)1 IpAssociationRules (com.cloud.network.rules.IpAssociationRules)1 LoadBalancingRules (com.cloud.network.rules.LoadBalancingRules)1 NetworkAclsRules (com.cloud.network.rules.NetworkAclsRules)1 NicPlugInOutRules (com.cloud.network.rules.NicPlugInOutRules)1 PasswordToRouterRules (com.cloud.network.rules.PasswordToRouterRules)1 SshKeyToRouterRules (com.cloud.network.rules.SshKeyToRouterRules)1 StaticNatRules (com.cloud.network.rules.StaticNatRules)1 UserdataToRouterRules (com.cloud.network.rules.UserdataToRouterRules)1 VpcIpAssociationRules (com.cloud.network.rules.VpcIpAssociationRules)1