Search in sources :

Example 31 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method processConnect.

@Override
public void processConnect(final Host host, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    final List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(host.getId());
    for (DomainRouterVO router : routers) {
        if (router.isStopPending()) {
            s_logger.info("Stopping router " + router.getInstanceName() + " due to stop pending flag found!");
            final VirtualMachine.State state = router.getState();
            if (state != VirtualMachine.State.Stopped && state != VirtualMachine.State.Destroyed) {
                try {
                    stopRouter(router.getId(), false);
                } catch (final ResourceUnavailableException e) {
                    s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
                    throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
                } catch (final ConcurrentOperationException e) {
                    s_logger.warn("Fail to stop router " + router.getInstanceName(), e);
                    throw new ConnectionException(false, "Fail to stop router " + router.getInstanceName());
                }
            }
            router.setStopPending(false);
            router = _routerDao.persist(router);
        }
    }
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) DomainRouterVO(com.cloud.vm.DomainRouterVO) ConnectionException(com.cloud.exception.ConnectionException) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 32 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method recoverRedundantNetwork.

// Ensure router status is update to date before execute this function. The
// function would try best to recover all routers except PRIMARY
protected void recoverRedundantNetwork(final DomainRouterVO primaryRouter, final DomainRouterVO backupRouter) {
    if (primaryRouter.getState() == VirtualMachine.State.Running && backupRouter.getState() == VirtualMachine.State.Running) {
        final HostVO primaryHost = _hostDao.findById(primaryRouter.getHostId());
        final HostVO backupHost = _hostDao.findById(backupRouter.getHostId());
        if (primaryHost.getState() == Status.Up && backupHost.getState() == Status.Up) {
            final String title = "Reboot " + backupRouter.getInstanceName() + " to ensure redundant virtual routers work";
            if (s_logger.isDebugEnabled()) {
                s_logger.debug(title);
            }
            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, backupRouter.getDataCenterId(), backupRouter.getPodIdToDeployIn(), title, title);
            try {
                rebootRouter(backupRouter.getId(), true, false);
            } catch (final ConcurrentOperationException e) {
                s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
            } catch (final ResourceUnavailableException e) {
                s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
            } catch (final InsufficientCapacityException e) {
                s_logger.warn("Fail to reboot " + backupRouter.getInstanceName(), e);
            }
        }
    }
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HostVO(com.cloud.host.HostVO) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO)

Example 33 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeStop.

@Override
public void finalizeStop(final VirtualMachineProfile profile, final Answer answer) {
    if (answer != null) {
        final VirtualMachine vm = profile.getVirtualMachine();
        final DomainRouterVO domR = _routerDao.findById(vm.getId());
        processStopOrRebootAnswer(domR, answer);
        final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
        for (final Nic nic : routerNics) {
            final Network network = _networkModel.getNetwork(nic.getNetworkId());
            final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
            if (network.getTrafficType() == TrafficType.Guest && nic.getBroadcastUri() != null && nic.getBroadcastUri().getScheme().equals("pvlan")) {
                final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
                final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
                try {
                    networkTopology.setupDhcpForPvlan(false, domR, domR.getHostId(), nicProfile);
                } catch (final ResourceUnavailableException e) {
                    s_logger.debug("ERROR in finalizeStop: ", e);
                }
            }
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Network(com.cloud.network.Network) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 34 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method startRemoteAccessVpn.

@Override
public boolean startRemoteAccessVpn(final Network network, final RemoteAccessVpn vpn, final List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
    if (routers == null || routers.isEmpty()) {
        s_logger.warn("Failed to start remote access VPN: no router found for account and zone");
        throw new ResourceUnavailableException("Failed to start remote access VPN: no router found for account and zone", DataCenter.class, network.getDataCenterId());
    }
    for (final VirtualRouter router : routers) {
        if (router.getState() != VirtualMachine.State.Running) {
            s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState());
            throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
        }
        final Commands cmds = new Commands(Command.OnError.Stop);
        _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
        if (!_nwHelper.sendCommandsToRouter(router, cmds)) {
            throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId());
        }
        Answer answer = cmds.getAnswer("users");
        if (answer == null) {
            s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to null answer");
            throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to null answer", DataCenter.class, router.getDataCenterId());
        }
        if (!answer.getResult()) {
            s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
            throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
        }
        answer = cmds.getAnswer("startVpn");
        if (!answer.getResult()) {
            s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
            throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
        }
    }
    return true;
}
Also used : GroupAnswer(com.cloud.agent.api.routing.GroupAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterMonitorResultsAnswer(com.cloud.agent.api.routing.GetRouterMonitorResultsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands)

Example 35 with ResourceUnavailableException

use of com.cloud.exception.ResourceUnavailableException in project cloudstack by apache.

the class NetworkHelperImpl method handleSingleWorkingRedundantRouter.

@Override
public void handleSingleWorkingRedundantRouter(final List<? extends VirtualRouter> connectedRouters, final List<? extends VirtualRouter> disconnectedRouters, final String reason) throws ResourceUnavailableException {
    if (connectedRouters.isEmpty() || disconnectedRouters.isEmpty()) {
        return;
    }
    for (final VirtualRouter virtualRouter : connectedRouters) {
        if (!virtualRouter.getIsRedundantRouter()) {
            throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId());
        }
    }
    for (final VirtualRouter virtualRouter : disconnectedRouters) {
        if (!virtualRouter.getIsRedundantRouter()) {
            throw new ResourceUnavailableException("Who is calling this with non-redundant router or non-domain router?", DataCenter.class, virtualRouter.getDataCenterId());
        }
    }
    final DomainRouterVO connectedRouter = (DomainRouterVO) connectedRouters.get(0);
    DomainRouterVO disconnectedRouter = (DomainRouterVO) disconnectedRouters.get(0);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("About to stop the router " + disconnectedRouter.getInstanceName() + " due to: " + reason);
    }
    final String title = "Virtual router " + disconnectedRouter.getInstanceName() + " would be stopped after connecting back, due to " + reason;
    final String context = "Virtual router (name: " + disconnectedRouter.getInstanceName() + ", id: " + disconnectedRouter.getId() + ") would be stopped after connecting back, due to: " + reason;
    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER, disconnectedRouter.getDataCenterId(), disconnectedRouter.getPodIdToDeployIn(), title, context);
    disconnectedRouter.setStopPending(true);
    disconnectedRouter = _routerDao.persist(disconnectedRouter);
}
Also used : ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)446 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)191 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)175 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)153 ArrayList (java.util.ArrayList)99 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)91 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)74 Account (com.cloud.user.Account)62 DomainRouterVO (com.cloud.vm.DomainRouterVO)60 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)59 ConfigurationException (javax.naming.ConfigurationException)53 DB (com.cloud.utils.db.DB)52 ServerApiException (org.apache.cloudstack.api.ServerApiException)51 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)47 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)47 ActionEvent (com.cloud.event.ActionEvent)46 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)46 DataCenter (com.cloud.dc.DataCenter)45 ServerApiException (com.cloud.api.ServerApiException)43 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)42