Search in sources :

Example 26 with ResourceUnavailableException

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

the class VpcVirtualNetworkApplianceManagerImpl method stopRemoteAccessVpn.

@Override
public boolean stopRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException {
    boolean result = true;
    if (router.getState() == State.Running) {
        final Commands cmds = new Commands(Command.OnError.Continue);
        _commandSetupHelper.createApplyVpnCommands(false, vpn, router, cmds);
        result = result && _nwHelper.sendCommandsToRouter(router, cmds);
    } else if (router.getState() == State.Stopped) {
        s_logger.debug("Router " + router + " is in Stopped state, not sending deleteRemoteAccessVpn command to it");
    } else {
        s_logger.warn("Failed to stop remote access VPN: domR " + router + " is not in right state " + router.getState());
        throw new ResourceUnavailableException("Failed to stop remote access VPN: domR is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 27 with ResourceUnavailableException

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

the class VpcVirtualNetworkApplianceManagerImpl method setupVpcGuestNetwork.

protected boolean setupVpcGuestNetwork(final Network network, final VirtualRouter router, final boolean add, final NicProfile guestNic) throws ConcurrentOperationException, ResourceUnavailableException {
    boolean result = true;
    if (router.getState() == State.Running) {
        final SetupGuestNetworkCommand setupCmd = _commandSetupHelper.createSetupGuestNetworkCommand((DomainRouterVO) router, add, guestNic);
        final Commands cmds = new Commands(Command.OnError.Stop);
        cmds.addCommand("setupguestnetwork", setupCmd);
        _nwHelper.sendCommandsToRouter(router, cmds);
        final Answer setupAnswer = cmds.getAnswer("setupguestnetwork");
        final String setup = add ? "set" : "destroy";
        if (!(setupAnswer != null && setupAnswer.getResult())) {
            s_logger.warn("Unable to " + setup + " guest network on router " + router);
            result = false;
        }
        return result;
    } else if (router.getState() == State.Stopped || router.getState() == State.Stopping) {
        s_logger.debug("Router " + router.getInstanceName() + " is in " + router.getState() + ", so not sending setup guest network command to the backend");
        return true;
    } else {
        s_logger.warn("Unable to setup guest network on virtual router " + router + " is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to setup guest network on the backend," + " virtual router " + router + " is not in the right state", DataCenter.class, router.getDataCenterId());
    }
}
Also used : Answer(com.cloud.agent.api.Answer) DataCenter(com.cloud.dc.DataCenter) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) SetupGuestNetworkCommand(com.cloud.agent.api.SetupGuestNetworkCommand)

Example 28 with ResourceUnavailableException

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

the class VpcVirtualNetworkApplianceManagerImpl method setupVpcPrivateNetwork.

/**
 * @param router
 * @param add
 * @param privateNic
 * @return
 * @throws ResourceUnavailableException
 */
protected boolean setupVpcPrivateNetwork(final VirtualRouter router, final boolean add, final NicProfile privateNic) throws ResourceUnavailableException {
    if (router.getState() == State.Running) {
        final PrivateIpVO ipVO = _privateIpDao.findByIpAndSourceNetworkId(privateNic.getNetworkId(), privateNic.getIPv4Address());
        final Network network = _networkDao.findById(privateNic.getNetworkId());
        final String netmask = NetUtils.getCidrNetmask(network.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, network.getBroadcastUri().toString(), network.getGateway(), netmask, privateNic.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, add);
        try {
            if (_nwHelper.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  " + (add ? "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) DataCenter(com.cloud.dc.DataCenter) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Commands(com.cloud.agent.manager.Commands) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) 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)

Example 29 with ResourceUnavailableException

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

the class VpcVirtualNetworkApplianceManagerImpl method startRemoteAccessVpn.

@Override
public boolean startRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException {
    if (router.getState() != State.Running) {
        s_logger.warn("Unable to apply remote access VPN configuration, virtual router is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to apply remote access VPN configuration," + " virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    final Commands cmds = new Commands(Command.OnError.Stop);
    _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
    try {
        _agentMgr.send(router.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
        s_logger.debug("Failed to start remote access VPN: ", e);
        throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e);
    }
    Answer answer = cmds.getAnswer("users");
    if (answer == null || !answer.getResult()) {
        String errorMessage = (answer == null) ? "null answer object" : answer.getDetails();
        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 " + errorMessage);
        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 " + errorMessage, DataCenter.class, router.getDataCenterId());
    }
    answer = cmds.getAnswer("startVpn");
    if (answer == null || !answer.getResult()) {
        String errorMessage = (answer == null) ? "null answer object" : answer.getDetails();
        s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + errorMessage);
        throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + errorMessage, DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands)

Example 30 with ResourceUnavailableException

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

the class VirtualNetworkApplianceManagerImpl method rebootRouter.

@Override
@ActionEvent(eventType = EventTypes.EVENT_ROUTER_REBOOT, eventDescription = "rebooting router Vm", async = true)
public VirtualRouter rebootRouter(final long routerId, final boolean reprogramNetwork, final boolean forced) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Account caller = CallContext.current().getCallingAccount();
    // verify parameters
    final DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find domain router with id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    // Can reboot domain router only in Running state
    if (router == null || router.getState() != VirtualMachine.State.Running) {
        s_logger.warn("Unable to reboot, virtual router is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to reboot domR, it is not in right state " + router.getState(), DataCenter.class, router.getDataCenterId());
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    s_logger.debug("Stopping and starting router " + router + " as a part of router reboot");
    if (stop(router, forced, user, caller) != null) {
        return startRouter(routerId, reprogramNetwork);
    } else {
        throw new CloudRuntimeException("Failed to reboot router " + router);
    }
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO) ActionEvent(com.cloud.event.ActionEvent)

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