Search in sources :

Example 66 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class FirstFitPlannerTest method checkClusterListBasedOnHostTag.

@Test
public void checkClusterListBasedOnHostTag() throws InsufficientServerCapacityException {
    VirtualMachineProfileImpl vmProfile = mock(VirtualMachineProfileImpl.class);
    DataCenterDeployment plan = mock(DataCenterDeployment.class);
    ExcludeList avoids = mock(ExcludeList.class);
    initializeForTest(vmProfile, plan, avoids);
    List<Long> matchingClusters = initializeForClusterListBasedOnHostTag(vmProfile.getServiceOffering());
    List<Long> clusterList = planner.orderClusters(vmProfile, plan, avoids);
    assertTrue("Reordered cluster list have clusters which has hosts with specified host tag on offering", (clusterList.containsAll(matchingClusters)));
    assertTrue("Reordered cluster list does not have clusters which dont have hosts with matching host tag on offering", (!clusterList.contains(2L)));
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) Test(org.junit.Test)

Example 67 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class ServiceManagerImpl method createServiceVM.

/**
 * In the case of service instance the primary object is in the contrail API server. This object stores the
 * service instance parameters in the database.
 *
 * @param owner     Used to determine the project.
 * @param name      Service instance name (user specified).
 * @param template  Image to execute.
 * @param serviceOffering
 * @param left      Inside network.
 * @param right     Outside network.
 * @return
 */
/**
 * create a new ServiceVM object.
 * @return
 */
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "createServiceInstance", create = true)
private ServiceVirtualMachine createServiceVM(DataCenter zone, Account owner, VirtualMachineTemplate template, ServiceOffering serviceOffering, String name, ServiceInstance siObj, Network left, Network right) {
    long id = _vmDao.getNextInSequence(Long.class, "id");
    DataCenterDeployment plan = new DataCenterDeployment(zone.getId());
    LinkedHashMap<NetworkVO, List<? extends NicProfile>> networks = new LinkedHashMap<NetworkVO, List<? extends NicProfile>>();
    NetworkVO linklocal = (NetworkVO) _networkModel.getSystemNetworkByZoneAndTrafficType(zone.getId(), TrafficType.Management);
    networks.put(linklocal, new ArrayList<NicProfile>());
    networks.put((NetworkVO) left, new ArrayList<NicProfile>());
    networks.put((NetworkVO) right, new ArrayList<NicProfile>());
    String instanceName = VirtualMachineName.getVmName(id, owner.getId(), "SRV");
    long userId = CallContext.current().getCallingUserId();
    if (CallContext.current().getCallingAccount().getId() != owner.getId()) {
        List<UserVO> userVOs = _userDao.listByAccount(owner.getAccountId());
        if (!userVOs.isEmpty()) {
            userId = userVOs.get(0).getId();
        }
    }
    ServiceVirtualMachine svm = new ServiceVirtualMachine(id, instanceName, name, template.getId(), serviceOffering.getId(), template.getHypervisorType(), template.getGuestOSId(), zone.getId(), owner.getDomainId(), owner.getAccountId(), userId, false);
    // database synchronization code must be able to distinguish service instance VMs.
    Map<String, String> kvmap = new HashMap<String, String>();
    kvmap.put("service-instance", siObj.getUuid());
    Gson json = new Gson();
    String userData = json.toJson(kvmap);
    svm.setUserData(userData);
    try {
        _vmManager.allocate(instanceName, template, serviceOffering, networks, plan, template.getHypervisorType());
    } catch (InsufficientCapacityException ex) {
        throw new CloudRuntimeException("Insufficient capacity", ex);
    }
    CallContext.current().setEventDetails("Vm Id: " + svm.getId());
    return svm;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Gson(com.google.gson.Gson) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap) UserVO(com.cloud.user.UserVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ActionEvent(com.cloud.event.ActionEvent)

Example 68 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class ConfigurationManagerImpl method createDefaultSystemNetworks.

@Override
public void createDefaultSystemNetworks(final long zoneId) throws ConcurrentOperationException {
    final DataCenterVO zone = _zoneDao.findById(zoneId);
    final String networkDomain = null;
    // the zone creation
    if (zone != null) {
        final List<NetworkOfferingVO> ntwkOff = _networkOfferingDao.listSystemNetworkOfferings();
        for (final NetworkOfferingVO offering : ntwkOff) {
            final DataCenterDeployment plan = new DataCenterDeployment(zone.getId(), null, null, null, null, null);
            final NetworkVO userNetwork = new NetworkVO();
            final Account systemAccount = _accountDao.findById(Account.ACCOUNT_ID_SYSTEM);
            BroadcastDomainType broadcastDomainType = null;
            if (offering.getTrafficType() == TrafficType.Management) {
                broadcastDomainType = BroadcastDomainType.Native;
            } else if (offering.getTrafficType() == TrafficType.Control) {
                broadcastDomainType = BroadcastDomainType.LinkLocal;
            } else if (offering.getTrafficType() == TrafficType.Public) {
                if (zone.getNetworkType() == NetworkType.Advanced && !zone.isSecurityGroupEnabled() || zone.getNetworkType() == NetworkType.Basic) {
                    broadcastDomainType = BroadcastDomainType.Vlan;
                } else {
                    // so broadcastDomainType remains null! why have None/Undecided/UnKnown?
                    continue;
                }
            } else if (offering.getTrafficType() == TrafficType.Guest) {
                continue;
            }
            userNetwork.setBroadcastDomainType(broadcastDomainType);
            userNetwork.setNetworkDomain(networkDomain);
            _networkMgr.setupNetwork(systemAccount, offering, userNetwork, plan, null, null, false, Domain.ROOT_DOMAIN, null, null, null, true);
        }
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) BroadcastDomainType(com.cloud.network.Networks.BroadcastDomainType) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 69 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class SecondaryStorageManagerImpl method createSecStorageVmInstance.

protected Map<String, Object> createSecStorageVmInstance(long dataCenterId, SecondaryStorageVm.Role role) {
    DataStore secStore = _dataStoreMgr.getImageStoreWithFreeCapacity(dataCenterId);
    if (secStore == null) {
        String msg = String.format("No secondary storage available in zone %s, cannot create secondary storage VM.", dataCenterId);
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    long id = _secStorageVmDao.getNextInSequence(Long.class, "id");
    String name = VirtualMachineName.getSystemVmName(id, _instance, "s").intern();
    Account systemAcct = _accountMgr.getSystemAccount();
    DataCenterDeployment plan = new DataCenterDeployment(dataCenterId);
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    NetworkVO defaultNetwork = getDefaultNetworkForCreation(dc);
    List<? extends NetworkOffering> offerings = null;
    if (_sNwMgr.isStorageIpRangeAvailable(dataCenterId)) {
        offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork, NetworkOffering.SystemStorageNetwork);
    } else {
        offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork, NetworkOffering.SystemManagementNetwork);
    }
    LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(offerings.size() + 1);
    NicProfile defaultNic = new NicProfile();
    defaultNic.setDefaultNic(true);
    defaultNic.setDeviceId(2);
    try {
        networks.put(_networkMgr.setupNetwork(systemAcct, _networkOfferingDao.findById(defaultNetwork.getNetworkOfferingId()), plan, null, null, false).get(0), new ArrayList<>(Arrays.asList(defaultNic)));
        for (NetworkOffering offering : offerings) {
            networks.put(_networkMgr.setupNetwork(systemAcct, offering, plan, null, null, false).get(0), new ArrayList<>());
        }
    } catch (ConcurrentOperationException e) {
        s_logger.error(String.format("Unable to setup networks on %s due [%s].", dc.toString(), e.getMessage()), e);
        return new HashMap<>();
    }
    HypervisorType availableHypervisor = _resourceMgr.getAvailableHypervisor(dataCenterId);
    VMTemplateVO template = _templateDao.findSystemVMReadyTemplate(dataCenterId, availableHypervisor);
    if (template == null) {
        throw new CloudRuntimeException(String.format("Unable to find the system templates or it was not downloaded in %s.", dc.toString()));
    }
    ServiceOfferingVO serviceOffering = _serviceOffering;
    if (serviceOffering == null) {
        serviceOffering = _offeringDao.findDefaultSystemOffering(ServiceOffering.ssvmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dataCenterId));
    }
    SecondaryStorageVmVO secStorageVm = new SecondaryStorageVmVO(id, serviceOffering.getId(), name, template.getId(), template.getHypervisorType(), template.getGuestOSId(), dataCenterId, systemAcct.getDomainId(), systemAcct.getId(), _accountMgr.getSystemUser().getId(), role, serviceOffering.isOfferHA());
    secStorageVm.setDynamicallyScalable(template.isDynamicallyScalable());
    secStorageVm = _secStorageVmDao.persist(secStorageVm);
    try {
        _itMgr.allocate(name, template, serviceOffering, networks, plan, null);
        secStorageVm = _secStorageVmDao.findById(secStorageVm.getId());
    } catch (InsufficientCapacityException e) {
        String errorMessage = String.format("Unable to allocate secondary storage VM [%s] due to [%s].", name, e.getMessage());
        s_logger.warn(errorMessage, e);
        throw new CloudRuntimeException(errorMessage, e);
    }
    Map<String, Object> context = new HashMap<>();
    context.put("secStorageVmId", secStorageVm.getId());
    return context;
}
Also used : Account(com.cloud.user.Account) SecondaryStorageVmVO(com.cloud.vm.SecondaryStorageVmVO) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) VMTemplateVO(com.cloud.storage.VMTemplateVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) LinkedHashMap(java.util.LinkedHashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) List(java.util.List) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) NetworkVO(com.cloud.network.dao.NetworkVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) NetworkOffering(com.cloud.offering.NetworkOffering) NicProfile(com.cloud.vm.NicProfile) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HypervisorType(com.cloud.hypervisor.Hypervisor.HypervisorType) DataCenter(com.cloud.dc.DataCenter)

Example 70 with DataCenterDeployment

use of com.cloud.deploy.DataCenterDeployment in project cloudstack by apache.

the class RecreateHostAllocator method allocateTo.

@Override
public List<Host> allocateTo(VirtualMachineProfile vm, DeploymentPlan plan, Type type, ExcludeList avoid, int returnUpTo) {
    List<Host> hosts = super.allocateTo(vm, plan, type, avoid, returnUpTo);
    if (hosts != null && !hosts.isEmpty()) {
        return hosts;
    }
    s_logger.debug("First fit was unable to find a host");
    VirtualMachine.Type vmType = vm.getType();
    if (vmType == VirtualMachine.Type.User) {
        s_logger.debug("vm is not a system vm so let's just return empty list");
        return new ArrayList<Host>();
    }
    DataCenter dc = _dcDao.findById(plan.getDataCenterId());
    List<PodCluster> pcs = _resourceMgr.listByDataCenter(dc.getId());
    // basic network type for zone maps to direct untagged case
    if (dc.getNetworkType().equals(NetworkType.Basic)) {
        s_logger.debug("Direct Networking mode so we can only allow the host to be allocated in the same pod due to public ip address cannot change");
        List<VolumeVO> vols = _volsDao.findByInstance(vm.getId());
        VolumeVO vol = vols.get(0);
        long podId = vol.getPodId();
        s_logger.debug("Pod id determined from volume " + vol.getId() + " is " + podId);
        Iterator<PodCluster> it = pcs.iterator();
        while (it.hasNext()) {
            PodCluster pc = it.next();
            if (pc.getPod().getId() != podId) {
                it.remove();
            }
        }
    }
    Set<Pair<Long, Long>> avoidPcs = new HashSet<Pair<Long, Long>>();
    Set<Long> hostIdsToAvoid = avoid.getHostsToAvoid();
    if (hostIdsToAvoid != null) {
        for (Long hostId : hostIdsToAvoid) {
            Host h = _hostDao.findById(hostId);
            if (h != null) {
                avoidPcs.add(new Pair<Long, Long>(h.getPodId(), h.getClusterId()));
            }
        }
    }
    for (Pair<Long, Long> pcId : avoidPcs) {
        s_logger.debug("Removing " + pcId + " from the list of available pods");
        pcs.remove(new PodCluster(new HostPodVO(pcId.first()), pcId.second() != null ? new ClusterVO(pcId.second()) : null));
    }
    for (PodCluster p : pcs) {
        Long clusterId = p.getCluster() == null ? null : p.getCluster().getId();
        DataCenterDeployment newPlan = new DataCenterDeployment(plan.getDataCenterId(), p.getPod().getId(), clusterId, null, null, null);
        hosts = super.allocateTo(vm, newPlan, type, avoid, returnUpTo);
        if (hosts != null && !hosts.isEmpty()) {
            return hosts;
        }
    }
    s_logger.debug("Unable to find any available pods at all!");
    return new ArrayList<Host>();
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) HostPodVO(com.cloud.dc.HostPodVO) DataCenter(com.cloud.dc.DataCenter) VolumeVO(com.cloud.storage.VolumeVO) PodCluster(com.cloud.dc.PodCluster) VirtualMachine(com.cloud.vm.VirtualMachine) Pair(com.cloud.utils.Pair) HashSet(java.util.HashSet)

Aggregations

DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)89 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)45 ArrayList (java.util.ArrayList)28 Test (org.junit.Test)28 VirtualMachineProfileImpl (com.cloud.vm.VirtualMachineProfileImpl)24 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 StoragePool (com.cloud.storage.StoragePool)19 HashMap (java.util.HashMap)19 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)18 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)17 DeployDestination (com.cloud.deploy.DeployDestination)16 VolumeVO (com.cloud.storage.VolumeVO)16 LinkedHashMap (java.util.LinkedHashMap)16 StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)14 DeploymentPlan (com.cloud.deploy.DeploymentPlan)13 NetworkVO (com.cloud.network.dao.NetworkVO)13 List (java.util.List)13 DiskProfile (com.cloud.vm.DiskProfile)12 VMInstanceVO (com.cloud.vm.VMInstanceVO)12 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)11