use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ListLoadBalancerRuleInstancesCmdByAdmin method execute.
@Override
public void execute() {
final Pair<List<? extends UserVm>, List<String>> vmServiceMap = _lbService.listLoadBalancerInstances(this);
final List<? extends UserVm> result = vmServiceMap.first();
final List<String> serviceStates = vmServiceMap.second();
if (!isListLbVmip()) {
// list lb instances
final ListResponse<UserVmResponse> response = new ListResponse<>();
List<UserVmResponse> vmResponses = new ArrayList<>();
if (result != null) {
vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Restricted, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
for (int i = 0; i < result.size(); i++) {
vmResponses.get(i).setServiceState(serviceStates.get(i));
}
}
response.setResponses(vmResponses);
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
final ListResponse<LoadBalancerRuleVmMapResponse> lbRes = new ListResponse<>();
List<UserVmResponse> vmResponses = new ArrayList<>();
final List<LoadBalancerRuleVmMapResponse> listlbVmRes = new ArrayList<>();
if (result != null) {
vmResponses = _responseGenerator.createUserVmResponse(ResponseView.Full, "loadbalancerruleinstance", result.toArray(new UserVm[result.size()]));
final List<String> ipaddr = null;
for (int i = 0; i < result.size(); i++) {
final LoadBalancerRuleVmMapResponse lbRuleVmIpResponse = new LoadBalancerRuleVmMapResponse();
vmResponses.get(i).setServiceState(serviceStates.get(i));
lbRuleVmIpResponse.setUserVmResponse(vmResponses.get(i));
// get vm id from the uuid
final VirtualMachine lbvm = _entityMgr.findByUuid(VirtualMachine.class, vmResponses.get(i).getId());
lbRuleVmIpResponse.setIpAddr(_lbService.listLbVmIpAddress(getId(), lbvm.getId()));
lbRuleVmIpResponse.setObjectName("lbrulevmidip");
listlbVmRes.add(lbRuleVmIpResponse);
}
}
lbRes.setResponseName(getCommandName());
lbRes.setResponses(listlbVmRes);
setResponseObject(lbRes);
}
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class ExplicitDedicationProcessor method process.
/**
* This method will process the affinity group of type 'Explicit Dedication' for a deployment of a VM that demands dedicated resources.
* For ExplicitDedicationProcessor we need to add dedicated resources into the IncludeList based on the level we have dedicated resources available.
* For eg. if admin dedicates a pod to a domain, then all the user in that domain can use the resources of that pod.
* We need to take care of the situation when dedicated resources further have resources dedicated to sub-domain/account.
* This IncludeList is then used to update the avoid list for a given data center.
*/
@Override
public void process(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, ExcludeList avoid) {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
final Zone zone = zoneRepository.findById(vm.getDataCenterId()).orElse(null);
final List<DedicatedResourceVO> resourceList = new ArrayList<>();
if (vmGroupMappings != null && !vmGroupMappings.isEmpty()) {
for (final AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
if (vmGroupMapping != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Processing affinity group " + vmGroupMapping.getAffinityGroupId() + "of type 'ExplicitDedication' for VM Id: " + vm.getId());
}
final long affinityGroupId = vmGroupMapping.getAffinityGroupId();
final List<DedicatedResourceVO> dr = _dedicatedDao.listByAffinityGroupId(affinityGroupId);
resourceList.addAll(dr);
}
}
boolean canUse = false;
if (plan.getHostId() != null) {
final HostVO host = _hostDao.findById(plan.getHostId());
final ClusterVO clusterofHost = _clusterDao.findById(host.getClusterId());
final HostPodVO podOfHost = _podDao.findById(host.getPodId());
final Zone zoneOfHost = zoneRepository.findById(host.getDataCenterId()).orElse(null);
if (resourceList != null && resourceList.size() != 0) {
for (final DedicatedResourceVO resource : resourceList) {
if ((resource.getHostId() != null && resource.getHostId().longValue() == plan.getHostId().longValue()) || (resource.getClusterId() != null && resource.getClusterId().longValue() == clusterofHost.getId()) || (resource.getPodId() != null && resource.getPodId().longValue() == podOfHost.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId().longValue() == zoneOfHost.getId())) {
canUse = true;
}
}
}
if (!canUse) {
throw new CloudRuntimeException("Cannot use this host " + host.getName() + " for explicit dedication");
}
} else if (plan.getClusterId() != null) {
final ClusterVO cluster = _clusterDao.findById(plan.getClusterId());
final HostPodVO podOfCluster = _podDao.findById(cluster.getPodId());
final Zone zoneOfCluster = zoneRepository.findById(cluster.getDataCenterId()).orElse(null);
final List<HostVO> hostToUse = new ArrayList<>();
// check whether this cluster or its pod is dedicated
if (resourceList != null && resourceList.size() != 0) {
for (final DedicatedResourceVO resource : resourceList) {
if ((resource.getClusterId() != null && resource.getClusterId() == cluster.getId()) || (resource.getPodId() != null && resource.getPodId() == podOfCluster.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfCluster.getId())) {
canUse = true;
}
// cluster
if (!canUse) {
if (resource.getHostId() != null) {
final HostVO dHost = _hostDao.findById(resource.getHostId());
if (dHost.getClusterId() == cluster.getId()) {
hostToUse.add(dHost);
}
}
}
}
}
if (hostToUse.isEmpty() && !canUse) {
throw new CloudRuntimeException("Cannot use this cluster " + cluster.getName() + " for explicit dedication");
}
if (hostToUse != null && hostToUse.size() != 0) {
// add other non-dedicated hosts to avoid list
final List<HostVO> hostList = _hostDao.findByClusterId(cluster.getId());
for (final HostVO host : hostList) {
if (!hostToUse.contains(host)) {
avoid.addHost(host.getId());
}
}
}
} else if (plan.getPodId() != null) {
final HostPodVO pod = _podDao.findById(plan.getPodId());
final Zone zoneOfPod = zoneRepository.findById(pod.getDataCenterId()).orElse(null);
final List<ClusterVO> clustersToUse = new ArrayList<>();
final List<HostVO> hostsToUse = new ArrayList<>();
// check whether this cluster or its pod is dedicated
if (resourceList != null && resourceList.size() != 0) {
for (final DedicatedResourceVO resource : resourceList) {
if ((resource.getPodId() != null && resource.getPodId() == pod.getId()) || (resource.getDataCenterId() != null && resource.getDataCenterId() == zoneOfPod.getId())) {
canUse = true;
}
// this pod
if (!canUse) {
if (resource.getClusterId() != null) {
final ClusterVO dCluster = _clusterDao.findById(resource.getClusterId());
if (dCluster.getPodId() == pod.getId()) {
clustersToUse.add(dCluster);
}
}
if (resource.getHostId() != null) {
final HostVO dHost = _hostDao.findById(resource.getHostId());
if (dHost.getPodId() == pod.getId()) {
hostsToUse.add(dHost);
}
}
}
}
}
if (hostsToUse.isEmpty() && clustersToUse.isEmpty() && !canUse) {
throw new CloudRuntimeException("Cannot use this pod " + pod.getName() + " for explicit dedication");
}
if (clustersToUse != null && clustersToUse.size() != 0) {
// add other non-dedicated clusters to avoid list
final List<ClusterVO> clusterList = _clusterDao.listByPodId(pod.getId());
for (final ClusterVO cluster : clusterList) {
if (!clustersToUse.contains(cluster)) {
avoid.addCluster(cluster.getId());
}
}
}
if (hostsToUse != null && hostsToUse.size() != 0) {
// add other non-dedicated hosts to avoid list
final List<HostVO> hostList = _hostDao.findByPodId(pod.getId());
for (final HostVO host : hostList) {
if (!hostsToUse.contains(host)) {
avoid.addHost(host.getId());
}
}
}
} else {
// check all resources under this zone
if (resourceList != null && resourceList.size() != 0) {
avoid = updateAvoidList(resourceList, avoid, zone);
} else {
avoid.addZone(zone.getId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("No dedicated resources available for this domain or account under this group");
}
}
s_logger.debug("ExplicitDedicationProcessor returns Avoid List as: {}", avoid.toString());
}
}
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class DeploymentPlanningManagerImpl method finalizeReservation.
@DB
@Override
public String finalizeReservation(final DeployDestination plannedDestination, final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoids, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final long vmGroupCount = _affinityGroupVMMapDao.countAffinityGroupsForVm(vm.getId());
return Transaction.execute(new TransactionCallback<String>() {
@Override
public String doInTransaction(final TransactionStatus status) {
boolean saveReservation = true;
if (vmGroupCount > 0) {
final List<Long> groupIds = _affinityGroupVMMapDao.listAffinityGroupIdsByVmId(vm.getId());
final SearchCriteria<AffinityGroupVO> criteria = _affinityGroupDao.createSearchCriteria();
criteria.addAnd("id", SearchCriteria.Op.IN, groupIds.toArray(new Object[groupIds.size()]));
_affinityGroupDao.lockRows(criteria, null, true);
for (final AffinityGroupProcessor processor : _affinityProcessors) {
if (!processor.check(vmProfile, plannedDestination)) {
saveReservation = false;
break;
}
}
}
if (saveReservation) {
final VMReservationVO vmReservation = new VMReservationVO(vm.getId(), plannedDestination.getZone().getId(), plannedDestination.getPod().getId(), plannedDestination.getCluster().getId(), plannedDestination.getHost().getId());
if (planner != null) {
vmReservation.setDeploymentPlanner(planner.getName());
}
final Map<Long, Long> volumeReservationMap = new HashMap<>();
for (final Volume vo : plannedDestination.getStorageForDisks().keySet()) {
volumeReservationMap.put(vo.getId(), plannedDestination.getStorageForDisks().get(vo).getId());
}
vmReservation.setVolumeReservation(volumeReservationMap);
_reservationDao.persist(vmReservation);
return vmReservation.getUuid();
}
return null;
}
});
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class FirstFitPlanner method scanClustersForDestinationInZoneOrPod.
private List<Long> scanClustersForDestinationInZoneOrPod(final long id, final boolean isZone, final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final ServiceOffering offering = vmProfile.getServiceOffering();
final int requiredCpu = offering.getCpu();
final long requiredRam = offering.getRamSize() * 1024L * 1024L;
// list clusters under this zone by cpu and ram capacity
final Pair<List<Long>, Map<Long, Double>> clusterCapacityInfo = listClustersByCapacity(id, requiredCpu, requiredRam, avoid, isZone);
final List<Long> prioritizedClusterIds = clusterCapacityInfo.first();
if (!prioritizedClusterIds.isEmpty()) {
if (avoid.getClustersToAvoid() != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the clusterId list these clusters from avoid set: " + avoid.getClustersToAvoid());
}
prioritizedClusterIds.removeAll(avoid.getClustersToAvoid());
}
if (!isRootAdmin(vmProfile)) {
List<Long> disabledClusters = new ArrayList<>();
if (isZone) {
disabledClusters = listDisabledClusters(plan.getDataCenterId(), null);
} else {
disabledClusters = listDisabledClusters(plan.getDataCenterId(), id);
}
if (!disabledClusters.isEmpty()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Removing from the clusterId list these clusters that are disabled/clusters under disabled pods: " + disabledClusters);
}
prioritizedClusterIds.removeAll(disabledClusters);
}
}
removeClustersCrossingThreshold(prioritizedClusterIds, avoid, vmProfile, plan);
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No clusters found having a host with enough capacity, returning.");
}
return null;
}
if (!prioritizedClusterIds.isEmpty()) {
// return checkClustersforDestination(clusterList, vmProfile, plan, avoid, dc);
return reorderClusters(id, isZone, clusterCapacityInfo, vmProfile, plan);
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("No clusters found after removing disabled clusters and clusters in avoid list, returning.");
}
return null;
}
}
use of com.cloud.legacymodel.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class FirstFitPlanner method orderClusters.
@Override
public List<Long> orderClusters(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) throws InsufficientServerCapacityException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final Zone zone = zoneRepository.findById(vm.getDataCenterId()).orElse(null);
// check if datacenter is in avoid set
if (avoid.shouldAvoid(zone)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("DataCenter id = '" + zone.getId() + "' provided is in avoid set, DeploymentPlanner cannot allocate the VM, returning.");
}
return null;
}
List<Long> clusterList = new ArrayList<>();
if (plan.getClusterId() != null) {
final Long clusterIdSpecified = plan.getClusterId();
s_logger.debug("Searching resources only under specified Cluster: " + clusterIdSpecified);
final ClusterVO cluster = clusterDao.findById(plan.getClusterId());
if (cluster != null) {
if (avoid.shouldAvoid(cluster)) {
s_logger.debug("The specified cluster is in avoid set, returning.");
} else {
clusterList.add(clusterIdSpecified);
removeClustersCrossingThreshold(clusterList, avoid, vmProfile, plan);
}
} else {
s_logger.debug("The specified cluster cannot be found, returning.");
avoid.addCluster(plan.getClusterId());
return null;
}
} else if (plan.getPodId() != null) {
// consider clusters under this pod only
final Long podIdSpecified = plan.getPodId();
s_logger.debug("Searching resources only under specified Pod: " + podIdSpecified);
final HostPodVO pod = podDao.findById(podIdSpecified);
if (pod != null) {
if (avoid.shouldAvoid(pod)) {
s_logger.debug("The specified pod is in avoid set, returning.");
} else {
clusterList = scanClustersForDestinationInZoneOrPod(podIdSpecified, false, vmProfile, plan, avoid);
if (clusterList == null) {
avoid.addPod(plan.getPodId());
}
}
} else {
s_logger.debug("The specified Pod cannot be found, returning.");
avoid.addPod(plan.getPodId());
return null;
}
} else {
s_logger.debug("Searching all possible resources under this Zone: " + plan.getDataCenterId());
final boolean applyAllocationAtPods = Boolean.parseBoolean(configDao.getValue(Config.ApplyAllocationAlgorithmToPods.key()));
if (applyAllocationAtPods) {
// start scan at all pods under this zone.
clusterList = scanPodsForDestination(vmProfile, plan, avoid);
} else {
// start scan at clusters under this zone.
clusterList = scanClustersForDestinationInZoneOrPod(plan.getDataCenterId(), true, vmProfile, plan, avoid);
}
}
if (clusterList != null && !clusterList.isEmpty()) {
final ServiceOffering offering = vmProfile.getServiceOffering();
// In case of non-GPU VMs, protect GPU enabled Hosts and prefer VM deployment on non-GPU Hosts.
if ((serviceOfferingDetailsDao.findDetail(offering.getId(), GPU.Keys.vgpuType.toString()) == null) && !(hostGpuGroupsDao.listHostIds().isEmpty())) {
final int requiredCpu = offering.getCpu();
final long requiredRam = offering.getRamSize() * 1024L * 1024L;
reorderClustersBasedOnImplicitTags(clusterList, requiredCpu, requiredRam);
}
}
return clusterList;
}
Aggregations