Search in sources :

Example 51 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class AdvancedNetworkVisitor method visit.

@Override
public boolean visit(final PrivateGatewayRules privateGW) throws ResourceUnavailableException {
    final VirtualRouter router = privateGW.getRouter();
    final NicProfile nicProfile = privateGW.getNicProfile();
    final boolean isAddOperation = privateGW.isAddOperation();
    if (router.getState() == State.Running) {
        final PrivateIpVO ipVO = privateGW.retrivePrivateIP(this);
        final Network network = privateGW.retrievePrivateNetwork(this);
        final String netmask = NetUtils.getCidrNetmask(network.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, nicProfile.getMacAddress());
        final List<PrivateIpAddress> privateIps = new ArrayList<PrivateIpAddress>(1);
        privateIps.add(ip);
        final Commands cmds = new Commands(Command.OnError.Stop);
        _commandSetupHelper.createVpcAssociatePrivateIPCommands(router, privateIps, cmds, isAddOperation);
        try {
            if (_networkGeneralHelper.sendCommandsToRouter(router, cmds)) {
                s_logger.debug("Successfully applied ip association for ip " + ip + " in vpc network " + network);
                return true;
            } else {
                s_logger.warn("Failed to associate ip address " + ip + " in vpc network " + network);
                return false;
            }
        } catch (final Exception ex) {
            s_logger.warn("Failed to send  " + (isAddOperation ? "add " : "delete ") + " private network " + network + " commands to rotuer ");
            return false;
        }
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup private network command to the backend");
    } else {
        s_logger.warn("Unable to setup private gateway, virtual router " + router + " is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to setup Private gateway on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) ArrayList(java.util.ArrayList) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) NicProfile(com.cloud.vm.NicProfile) VirtualRouter(com.cloud.network.router.VirtualRouter) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DataCenter(com.cloud.dc.DataCenter) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 52 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class BasicNetworkVisitor method visit.

@Override
public boolean visit(final BasicVpnRules vpnRules) throws ResourceUnavailableException {
    final VirtualRouter router = vpnRules.getRouter();
    final List<? extends VpnUser> users = vpnRules.getUsers();
    final Commands cmds = new Commands(Command.OnError.Continue);
    _commandSetupHelper.createApplyVpnUsersCommand(users, router, cmds);
    return _networkGeneralHelper.sendCommandsToRouter(router, cmds);
}
Also used : Commands(com.cloud.agent.manager.Commands) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 53 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class AdvancedNetworkTopology method applyStaticRoutes.

@Override
public boolean applyStaticRoutes(final List<StaticRouteProfile> staticRoutes, final List<DomainRouterVO> routers) throws ResourceUnavailableException {
    s_logger.debug("APPLYING STATIC ROUTES RULES");
    if (staticRoutes == null || staticRoutes.isEmpty()) {
        s_logger.debug("No static routes to apply");
        return true;
    }
    final StaticRoutesRules routesRules = new StaticRoutesRules(staticRoutes);
    boolean result = true;
    for (final VirtualRouter router : routers) {
        if (router.getState() == State.Running) {
            result = result && routesRules.accept(_advancedVisitor, router);
        } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
            s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending StaticRoute command to the backend");
        } else {
            s_logger.warn("Unable to apply StaticRoute, virtual router is not in the right state " + router.getState());
            throw new ResourceUnavailableException("Unable to apply StaticRoute on the backend," + " virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
        }
    }
    return result;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) StaticRoutesRules(com.cloud.network.rules.StaticRoutesRules) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 54 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

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<VirtualRouter>();
    final List<VirtualRouter> disconnectedRouters = new ArrayList<VirtualRouter>();
    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 55 with VirtualRouter

use of com.cloud.network.router.VirtualRouter in project cloudstack by apache.

the class GetRouterHealthCheckResultsCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, InvalidParameterValueException, ServerApiException {
    CallContext.current().setEventDetails("Router Id: " + this._uuidMgr.getUuid(VirtualMachine.class, getRouterId()));
    VirtualRouter router = _routerService.findRouter(getRouterId());
    if (router == null || router.getRole() != VirtualRouter.Role.VIRTUAL_ROUTER) {
        throw new InvalidParameterValueException("Can't find router by routerId");
    }
    try {
        List<RouterHealthCheckResultResponse> healthChecks = _queryService.listRouterHealthChecks(this);
        RouterHealthCheckResultsListResponse routerResponse = new RouterHealthCheckResultsListResponse();
        routerResponse.setRouterId(router.getUuid());
        routerResponse.setHealthChecks(healthChecks);
        routerResponse.setObjectName("routerhealthchecks");
        routerResponse.setResponseName(getCommandName());
        setResponseObject(routerResponse);
    } catch (CloudRuntimeException ex) {
        ex.printStackTrace();
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to get health check results due to: " + ex.getLocalizedMessage());
    }
}
Also used : ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) RouterHealthCheckResultsListResponse(org.apache.cloudstack.api.response.RouterHealthCheckResultsListResponse) VirtualRouter(com.cloud.network.router.VirtualRouter) RouterHealthCheckResultResponse(org.apache.cloudstack.api.response.RouterHealthCheckResultResponse)

Aggregations

VirtualRouter (com.cloud.network.router.VirtualRouter)72 Commands (com.cloud.agent.manager.Commands)34 DomainRouterResponse (com.cloud.api.response.DomainRouterResponse)11 NicVO (com.cloud.vm.NicVO)11 ServerApiException (com.cloud.api.ServerApiException)10 UserVmVO (com.cloud.vm.UserVmVO)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)9 ArrayList (java.util.ArrayList)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 DataCenter (com.cloud.dc.DataCenter)8 Network (com.cloud.network.Network)8 DomainRouterResponse (org.apache.cloudstack.api.response.DomainRouterResponse)8 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)6 UpdateVmOverviewCommand (com.cloud.agent.api.UpdateVmOverviewCommand)5 VMOverviewTO (com.cloud.agent.api.to.overviews.VMOverviewTO)5 UpdateNetworkOverviewCommand (com.cloud.agent.api.UpdateNetworkOverviewCommand)4 NetworkOverviewTO (com.cloud.agent.api.to.overviews.NetworkOverviewTO)4 DeployDestination (com.cloud.deploy.DeployDestination)4 PvlanSetupCommand (com.cloud.agent.api.PvlanSetupCommand)2