Search in sources :

Example 51 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class ConsoleProxyManagerImpl method createProxyInstance.

protected Map<String, Object> createProxyInstance(final long dataCenterId, final VMTemplateVO template) throws ConcurrentOperationException {
    final long id = _consoleProxyDao.getNextInSequence(Long.class, "id");
    final String name = VirtualMachineName.getConsoleProxyName(id, _instance);
    final Zone zone = zoneRepository.findOne(dataCenterId);
    final Account systemAcct = _accountMgr.getSystemAccount();
    final DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
    final NetworkVO defaultNetwork = getDefaultNetworkForCreation(zone);
    final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(offerings.size() + 1);
    final NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<>(Arrays.asList(defaultNic)));
    for (final NetworkOffering offering : offerings) {
        networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList<>());
    }
    ServiceOfferingVO serviceOffering = _serviceOffering;
    if (serviceOffering == null) {
        serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.consoleProxyDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
    }
    ConsoleProxyVO proxy = new ConsoleProxyVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), 0, serviceOffering.getOfferHA());
    proxy.setDynamicallyScalable(template.isDynamicallyScalable());
    proxy = _consoleProxyDao.persist(proxy);
    try {
        _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
    } catch (final InsufficientCapacityException e) {
        logger.warn("InsufficientCapacity", e);
        throw new CloudRuntimeException("Insufficient capacity exception", e);
    }
    final Map<String, Object> context = new HashMap<>();
    context.put("dc", zone);
    final HostPodVO pod = _podDao.findById(proxy.getPodIdToDeployIn());
    context.put("pod", pod);
    context.put("proxyVmId", proxy.getId());
    return context;
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkOffering(com.cloud.offering.NetworkOffering) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Zone(com.cloud.db.model.Zone) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) HostPodVO(com.cloud.dc.HostPodVO) LinkedHashMap(java.util.LinkedHashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 52 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class StorageNetworkManagerImpl method checkOverlapPrivateIpRange.

private void checkOverlapPrivateIpRange(final long podId, final String startIp, final String endIp) {
    final HostPodVO pod = _podDao.findById(podId);
    if (pod == null) {
        throw new CloudRuntimeException("Cannot find pod " + podId);
    }
    final String[] IpRange = pod.getDescription().split("-");
    if ((IpRange[0] == null || IpRange[1] == null) || (!NetUtils.isValidIp4(IpRange[0]) || !NetUtils.isValidIp4(IpRange[1]))) {
        return;
    }
    if (NetUtils.ipRangesOverlap(startIp, endIp, IpRange[0], IpRange[1])) {
        throw new InvalidParameterValueException("The Storage network Start IP and endIP address range overlap with private IP :" + IpRange[0] + ":" + IpRange[1]);
    }
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostPodVO(com.cloud.dc.HostPodVO)

Example 53 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class StorageNetworkManagerImpl method createIpRange.

@Override
@DB
public StorageNetworkIpRange createIpRange(final CreateStorageNetworkIpRangeCmd cmd) throws SQLException {
    final Long podId = cmd.getPodId();
    final String startIp = cmd.getStartIp();
    String endIp = cmd.getEndIp();
    final Integer vlan = cmd.getVlan();
    final String netmask = cmd.getNetmask();
    if (endIp == null) {
        endIp = startIp;
    }
    if (!NetUtils.isValidIp4Netmask(netmask)) {
        throw new CloudRuntimeException("Invalid netmask:" + netmask);
    }
    final HostPodVO pod = _podDao.findById(podId);
    if (pod == null) {
        throw new CloudRuntimeException("Cannot find pod " + podId);
    }
    final Long zoneId = pod.getDataCenterId();
    final List<NetworkVO> nws = _networkDao.listByZoneAndTrafficType(zoneId, TrafficType.Storage);
    if (nws.size() == 0) {
        throw new CloudRuntimeException("Cannot find storage network in zone " + zoneId);
    }
    if (nws.size() > 1) {
        throw new CloudRuntimeException("Find more than one storage network in zone " + zoneId + "," + nws.size() + " found");
    }
    final NetworkVO nw = nws.get(0);
    checkOverlapPrivateIpRange(podId, startIp, endIp);
    checkOverlapStorageIpRange(podId, startIp, endIp);
    final StorageNetworkIpRangeVO range = null;
    final String endIpFinal = endIp;
    return Transaction.execute(new TransactionCallbackWithException<StorageNetworkIpRangeVO, SQLException>() {

        @Override
        public StorageNetworkIpRangeVO doInTransaction(final TransactionStatus status) throws SQLException {
            final StorageNetworkIpRangeVO range = new StorageNetworkIpRangeVO(zoneId, podId, nw.getId(), startIp, endIpFinal, vlan, netmask, cmd.getGateWay());
            _sNwIpRangeDao.persist(range);
            try {
                createStorageIpEntires(TransactionLegacy.currentTxn(), range.getId(), startIp, endIpFinal, zoneId);
            } catch (final SQLException e) {
                final StringBuilder err = new StringBuilder();
                err.append("Create storage network range failed.");
                err.append("startIp=" + startIp);
                err.append("endIp=" + endIpFinal);
                err.append("netmask=" + netmask);
                err.append("zoneId=" + zoneId);
                s_logger.debug(err.toString(), e);
                throw e;
            }
            return range;
        }
    });
}
Also used : StorageNetworkIpRangeVO(com.cloud.dc.StorageNetworkIpRangeVO) NetworkVO(com.cloud.network.dao.NetworkVO) SQLException(java.sql.SQLException) TransactionStatus(com.cloud.utils.db.TransactionStatus) HostPodVO(com.cloud.dc.HostPodVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Example 54 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method startRouter.

@Override
public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // verify parameters
    DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    final Account owner = _accountMgr.getAccount(router.getAccountId());
    // Check if all networks are implemented for the domR; if not -
    // implement them
    final Zone zone = zoneRepository.findOne(router.getDataCenterId());
    HostPodVO pod = null;
    if (router.getPodIdToDeployIn() != null) {
        pod = _podDao.findById(router.getPodIdToDeployIn());
    }
    final DeployDestination dest = new DeployDestination(zone, pod, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
    final List<NicVO> nics = _nicDao.listByVmId(routerId);
    for (final NicVO nic : nics) {
        if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
            s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
            throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
        }
    }
    // After start network, check if it's already running
    router = _routerDao.findById(routerId);
    if (router.getState() == VirtualMachine.State.Running) {
        return router;
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    final Map<Param, Object> params = new HashMap<>();
    if (reprogramNetwork) {
        params.put(Param.ReProgramGuestNetworks, true);
    } else {
        params.put(Param.ReProgramGuestNetworks, false);
    }
    final VirtualRouter virtualRouter = _nwHelper.startVirtualRouter(router, user, caller, params);
    if (virtualRouter == null) {
        throw new CloudRuntimeException("Failed to start router with id " + routerId);
    }
    return virtualRouter;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) HashMap(java.util.HashMap) Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) HostPodVO(com.cloud.dc.HostPodVO) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Param(com.cloud.vm.VirtualMachineProfile.Param) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 55 with HostPodVO

use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.

the class RouterDeploymentDefinition method findDestinations.

protected List<DeployDestination> findDestinations() {
    // dest has pod=null, for Basic Zone findOrDeployVRs for all Pods
    final List<DeployDestination> destinations = new ArrayList<>();
    // restart scenario otherwise it is a vm deployment scenario
    if (isBasic() && dest.getPod() == null) {
        // Find all pods in the data center with running or starting user vms
        final long dcId = dest.getZone().getId();
        final List<HostPodVO> pods = listByDataCenterIdVMTypeAndStates(dcId, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running);
        // Loop through all the pods skip those with running or starting VRs
        for (final HostPodVO pod : pods) {
            // Get list of VRs in starting or running state
            final long podId = pod.getId();
            final List<DomainRouterVO> virtualRouters = routerDao.listByPodIdAndStates(podId, VirtualMachine.State.Starting, VirtualMachine.State.Running);
            if (virtualRouters.size() > 1) {
                // FIXME Find or create a better and more specific exception for this
                throw new CloudRuntimeException("Pod can have utmost one VR in Basic Zone, please check!");
            }
            // Add virtualRouters to the routers, this avoids the situation when
            // all routers are skipped and VirtualRouterElement throws exception
            routers.addAll(virtualRouters);
            // If List size is one, we already have a starting or running VR, skip deployment
            if (virtualRouters.size() == 1) {
                logger.debug("Skipping VR deployment: Found a running or starting VR in Pod " + pod.getName() + " id=" + podId);
                continue;
            }
            // Add new DeployDestination for this pod
            destinations.add(new DeployDestination(dest.getZone(), pod, null, null));
        }
    } else {
        // Else, just add the supplied dest
        destinations.add(dest);
    }
    return destinations;
}
Also used : DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) HostPodVO(com.cloud.dc.HostPodVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

HostPodVO (com.cloud.dc.HostPodVO)126 ArrayList (java.util.ArrayList)52 HostVO (com.cloud.host.HostVO)47 ClusterVO (com.cloud.dc.ClusterVO)46 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)46 DataCenterVO (com.cloud.dc.DataCenterVO)39 Account (com.cloud.user.Account)25 DB (com.cloud.utils.db.DB)25 Test (org.junit.Test)23 ConfigurationException (javax.naming.ConfigurationException)22 TransactionStatus (com.cloud.utils.db.TransactionStatus)21 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)20 VMInstanceVO (com.cloud.vm.VMInstanceVO)18 Random (java.util.Random)18 VolumeVO (com.cloud.storage.VolumeVO)17 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)16 HashMap (java.util.HashMap)16 List (java.util.List)16 Zone (com.cloud.db.model.Zone)15 DataCenter (com.cloud.dc.DataCenter)14