Search in sources :

Example 21 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO 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 22 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method prepareStop.

@Override
public void prepareStop(final VirtualMachineProfile profile) {
    // Collect network usage before stopping Vm
    final DomainRouterVO router = _routerDao.findById(profile.getVirtualMachine().getId());
    collectNetworkStatistics(router, null);
}
Also used : DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 23 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method rebootRouters.

private List<Long> rebootRouters(final List<DomainRouterVO> routers) {
    final List<Long> jobIds = new ArrayList<Long>();
    for (final DomainRouterVO router : routers) {
        if (!_nwHelper.checkRouterVersion(router)) {
            s_logger.debug("Upgrading template for router: " + router.getId());
            final Map<String, String> params = new HashMap<String, String>();
            params.put("ctxUserId", "1");
            params.put("ctxAccountId", "" + router.getAccountId());
            final RebootRouterCmd cmd = new RebootRouterCmd();
            ComponentContext.inject(cmd);
            params.put("id", "" + router.getId());
            params.put("ctxStartEventId", "1");
            final AsyncJobVO job = new AsyncJobVO("", User.UID_SYSTEM, router.getAccountId(), RebootRouterCmd.class.getName(), ApiGsonHelper.getBuilder().create().toJson(params), router.getId(), cmd.getInstanceType() != null ? cmd.getInstanceType().toString() : null, null);
            job.setDispatcher(_asyncDispatcher.getName());
            final long jobId = _asyncMgr.submitAsyncJob(job);
            jobIds.add(jobId);
        } else {
            s_logger.debug("Router: " + router.getId() + " is already at the latest version. No upgrade required");
        }
    }
    return jobIds;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RebootRouterCmd(org.apache.cloudstack.api.command.admin.router.RebootRouterCmd) DomainRouterVO(com.cloud.vm.DomainRouterVO) AsyncJobVO(org.apache.cloudstack.framework.jobs.impl.AsyncJobVO)

Example 24 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO 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 25 with DomainRouterVO

use of com.cloud.vm.DomainRouterVO in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method upgradeRouter.

@Override
@DB
public VirtualRouter upgradeRouter(final UpgradeRouterCmd cmd) {
    final Long routerId = cmd.getId();
    final Long serviceOfferingId = cmd.getServiceOfferingId();
    final Account caller = CallContext.current().getCallingAccount();
    final DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find router with id " + routerId);
    }
    _accountMgr.checkAccess(caller, null, true, router);
    if (router.getServiceOfferingId() == serviceOfferingId) {
        s_logger.debug("Router: " + routerId + "already has service offering: " + serviceOfferingId);
        return _routerDao.findById(routerId);
    }
    final ServiceOffering newServiceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
    if (newServiceOffering == null) {
        throw new InvalidParameterValueException("Unable to find service offering with id " + serviceOfferingId);
    }
    DiskOffering newDiskOffering = _entityMgr.findById(DiskOffering.class, newServiceOffering.getDiskOfferingId());
    if (newDiskOffering == null) {
        throw new InvalidParameterValueException("Unable to find disk offering: " + newServiceOffering.getDiskOfferingId());
    }
    // it cannot be used for user vms
    if (!newServiceOffering.isSystemUse()) {
        throw new InvalidParameterValueException("Cannot upgrade router vm to a non system service offering " + serviceOfferingId);
    }
    // Check that the router is stopped
    if (!router.getState().equals(VirtualMachine.State.Stopped)) {
        s_logger.warn("Unable to upgrade router " + router.toString() + " in state " + router.getState());
        throw new InvalidParameterValueException("Unable to upgrade router " + router.toString() + " in state " + router.getState() + "; make sure the router is stopped and not in an error state before upgrading.");
    }
    final ServiceOfferingVO currentServiceOffering = _serviceOfferingDao.findById(router.getServiceOfferingId());
    // offering
    if (_itMgr.isRootVolumeOnLocalStorage(routerId) != newDiskOffering.isUseLocalStorage()) {
        throw new InvalidParameterValueException("Can't upgrade, due to new local storage status : " + newDiskOffering.isUseLocalStorage() + " is different from " + "current local storage status of router " + routerId);
    }
    router.setServiceOfferingId(serviceOfferingId);
    if (_routerDao.update(routerId, router)) {
        return _routerDao.findById(routerId);
    } else {
        throw new CloudRuntimeException("Unable to upgrade router " + routerId);
    }
}
Also used : Account(com.cloud.user.Account) DiskOffering(com.cloud.offering.DiskOffering) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) DomainRouterVO(com.cloud.vm.DomainRouterVO) DB(com.cloud.utils.db.DB)

Aggregations

DomainRouterVO (com.cloud.vm.DomainRouterVO)253 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)64 ArrayList (java.util.ArrayList)60 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)47 DataCenterVO (com.cloud.dc.DataCenterVO)36 Network (com.cloud.network.Network)34 Test (org.junit.Test)32 NicProfile (com.cloud.vm.NicProfile)29 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)28 Zone (com.cloud.db.model.Zone)27 Account (com.cloud.user.Account)27 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 Vpc (com.cloud.network.vpc.Vpc)22 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)17 HashMap (java.util.HashMap)17 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)16 NetworkVO (com.cloud.network.dao.NetworkVO)16 UserVmVO (com.cloud.vm.UserVmVO)15 Answer (com.cloud.agent.api.Answer)14