use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createSystemVmResponse.
@Override
public SystemVmResponse createSystemVmResponse(final VirtualMachine vm) {
final SystemVmResponse vmResponse = new SystemVmResponse();
if (vm.getType() == Type.SecondaryStorageVm || vm.getType() == Type.ConsoleProxy || vm.getType() == Type.DomainRouter) {
// SystemVm vm = (SystemVm) systemVM;
vmResponse.setId(vm.getUuid());
// vmResponse.setObjectId(vm.getId());
vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
vmResponse.setName(vm.getHostName());
if (vm.getPodIdToDeployIn() != null) {
final HostPodVO pod = ApiDBUtils.findPodById(vm.getPodIdToDeployIn());
if (pod != null) {
vmResponse.setPodId(pod.getUuid());
}
}
final VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
if (template != null) {
vmResponse.setTemplateId(template.getUuid());
}
vmResponse.setCreated(vm.getCreated());
if (vm.getHostId() != null) {
final Host host = ApiDBUtils.findHostById(vm.getHostId());
if (host != null) {
vmResponse.setHostId(host.getUuid());
vmResponse.setHostName(host.getName());
vmResponse.setHypervisor(host.getHypervisorType().toString());
}
}
if (vm.getState() != null) {
vmResponse.setState(vm.getState().toString());
}
// for console proxies, add the active sessions
if (vm.getType() == Type.ConsoleProxy) {
final ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
// proxy can be already destroyed
if (proxy != null) {
vmResponse.setActiveViewerSessions(proxy.getActiveSession());
}
}
final DataCenter zone = ApiDBUtils.findZoneById(vm.getDataCenterId());
if (zone != null) {
vmResponse.setZoneId(zone.getUuid());
vmResponse.setZoneName(zone.getName());
vmResponse.setDns1(zone.getDns1());
vmResponse.setDns2(zone.getDns2());
}
final List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
for (final NicProfile singleNicProfile : nicProfiles) {
final Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
if (network != null) {
if (network.getTrafficType() == TrafficType.Management) {
vmResponse.setPrivateIp(singleNicProfile.getIPv4Address());
vmResponse.setPrivateMacAddress(singleNicProfile.getMacAddress());
vmResponse.setPrivateNetmask(singleNicProfile.getIPv4Netmask());
} else if (network.getTrafficType() == TrafficType.Control) {
vmResponse.setLinkLocalIp(singleNicProfile.getIPv4Address());
vmResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
vmResponse.setLinkLocalNetmask(singleNicProfile.getIPv4Netmask());
} else if (network.getTrafficType() == TrafficType.Public) {
vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
} else if (network.getTrafficType() == TrafficType.Guest) {
/*
* In basic zone, public ip has TrafficType.Guest in case EIP service is not enabled.
* When EIP service is enabled in the basic zone, system VM by default get the public
* IP allocated for EIP. So return the guest/public IP accordingly.
* */
final NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
if (networkOffering.getElasticIp()) {
final IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(vm.getId());
if (ip != null) {
final Vlan vlan = ApiDBUtils.findVlanById(ip.getVlanId());
vmResponse.setPublicIp(ip.getAddress().addr());
vmResponse.setPublicNetmask(vlan.getVlanNetmask());
vmResponse.setGateway(vlan.getVlanGateway());
}
} else {
vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
}
}
}
}
}
vmResponse.setObjectName("systemvm");
return vmResponse;
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class UserConcentratedAllocator method allocateTo.
@Override
public Pair<Pod, Long> allocateTo(final VirtualMachineTemplate template, final ServiceOffering offering, final DataCenter zone, final long accountId, final Set<Long> avoids) {
final long zoneId = zone.getId();
final List<HostPodVO> podsInZone = _podDao.listByDataCenterId(zoneId);
if (podsInZone.size() == 0) {
s_logger.debug("No pods found in zone " + zone.getName());
return null;
}
// Find pods that have enough CPU/memory capacity
final List<HostPodVO> availablePods = new ArrayList<>();
final Map<Long, Long> podHostCandidates = new HashMap<>();
for (final HostPodVO pod : podsInZone) {
final long podId = pod.getId();
if (!avoids.contains(podId)) {
if (template != null && !templateAvailableInPod(template.getId(), pod.getDataCenterId(), podId)) {
continue;
}
if (offering != null) {
// test for enough memory in the pod (make sure to check for
// enough memory for the service offering, plus
// some extra padding for xen overhead
final long[] hostCandiates = new long[1];
boolean enoughCapacity = dataCenterAndPodHasEnoughCapacity(zoneId, podId, (offering.getRamSize()) * 1024L * 1024L, Capacity.CAPACITY_TYPE_MEMORY, hostCandiates);
if (!enoughCapacity) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Not enough RAM available in zone/pod to allocate storage for user VM (zone: " + zoneId + ", pod: " + podId + ")");
}
continue;
}
// test for enough CPU in the pod
enoughCapacity = dataCenterAndPodHasEnoughCapacity(zoneId, podId, (long) offering.getCpu(), Capacity.CAPACITY_TYPE_CPU, hostCandiates);
if (!enoughCapacity) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Not enough cpu available in zone/pod to allocate storage for user VM (zone: " + zoneId + ", pod: " + podId + ")");
}
continue;
}
podHostCandidates.put(podId, hostCandiates[0]);
}
// If the pod has VMs or volumes in it, return this pod
final List<UserVmVO> vmsInPod = _vmDao.listByAccountAndPod(accountId, pod.getId());
if (!vmsInPod.isEmpty()) {
return new Pair<>(pod, podHostCandidates.get(podId));
}
final List<VolumeVO> volumesInPod = _volumeDao.findByAccountAndPod(accountId, pod.getId());
if (!volumesInPod.isEmpty()) {
return new Pair<>(pod, podHostCandidates.get(podId));
}
availablePods.add(pod);
}
}
if (availablePods.size() == 0) {
s_logger.debug("There are no pods with enough memory/CPU capacity in zone " + zone.getName());
return null;
} else {
// Return a random pod
final int next = _rand.nextInt(availablePods.size());
final HostPodVO selectedPod = availablePods.get(next);
s_logger.debug("Found pod " + selectedPod.getName() + " in zone " + zone.getName());
return new Pair<>(selectedPod, podHostCandidates.get(selectedPod.getId()));
}
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class AlertManagerImpl method recalculateCapacity.
@Override
public void recalculateCapacity() {
if (s_logger.isDebugEnabled()) {
s_logger.debug("recalculating system capacity");
s_logger.debug("Executing cpu/ram capacity update");
}
// Calculate CPU and RAM capacities
// get all hosts...even if they are not in 'UP' state
final List<HostVO> hosts = _resourceMgr.listAllNotInMaintenanceHostsInOneZone(Host.Type.Routing, null);
if (hosts != null) {
for (final HostVO host : hosts) {
_capacityMgr.updateCapacityForHost(host);
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Done executing cpu/ram capacity update");
s_logger.debug("Executing storage capacity update");
}
// Calculate storage pool capacity
final List<StoragePoolVO> storagePools = _storagePoolDao.listAll();
for (final StoragePoolVO pool : storagePools) {
final long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
if (pool.isShared()) {
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
} else {
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Done executing storage capacity update");
s_logger.debug("Executing capacity updates for public ip and Vlans");
}
final List<Zone> zones = zoneRepository.findByRemovedIsNull();
for (final Zone zone : zones) {
final long zoneId = zone.getId();
// Calculate new Public IP capacity for Virtual Network
if (zone.getNetworkType() == NetworkType.Advanced) {
createOrUpdateIpCapacity(zoneId, null, Capacity.CAPACITY_TYPE_VIRTUAL_NETWORK_PUBLIC_IP, zone.getAllocationState());
}
// Calculate new Public IP capacity for Direct Attached Network
createOrUpdateIpCapacity(zoneId, null, Capacity.CAPACITY_TYPE_DIRECT_ATTACHED_PUBLIC_IP, zone.getAllocationState());
if (zone.getNetworkType() == NetworkType.Advanced) {
// Calculate VLAN's capacity
createOrUpdateVlanCapacity(zoneId, zone.getAllocationState());
}
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Done capacity updates for public ip and Vlans");
s_logger.debug("Executing capacity updates for private ip");
}
// Calculate new Private IP capacity
final List<HostPodVO> pods = _podDao.listAll();
for (final HostPodVO pod : pods) {
final long podId = pod.getId();
final long dcId = pod.getDataCenterId();
createOrUpdateIpCapacity(dcId, podId, Capacity.CAPACITY_TYPE_PRIVATE_IP, _configMgr.findPodAllocationState(pod));
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Done executing capacity updates for private ip");
s_logger.debug("Done recalculating system capacity");
}
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class AlertManagerImpl method checkForAlerts.
public void checkForAlerts() {
recalculateCapacity();
// abort if we can't possibly send an alert...
if (_emailAlert == null) {
return;
}
// Get all datacenters, pods and clusters in the system.
final List<Zone> zones = zoneRepository.findByRemovedIsNull();
final List<ClusterVO> clusterList = _clusterDao.listAll();
final List<HostPodVO> podList = _podDao.listAll();
// Get capacity types at different levels
final List<Short> dataCenterCapacityTypes = getCapacityTypesAtZoneLevel();
final List<Short> podCapacityTypes = getCapacityTypesAtPodLevel();
final List<Short> clusterCapacityTypes = getCapacityTypesAtClusterLevel();
// Generate Alerts for Zone Level capacities
for (final Zone zone : zones) {
for (final Short capacityType : dataCenterCapacityTypes) {
final List<SummedCapacity> capacity;
capacity = _capacityDao.findCapacityBy(capacityType.intValue(), zone.getId(), null, null);
if (capacityType == Capacity.CAPACITY_TYPE_SECONDARY_STORAGE) {
capacity.add(getUsedStats(capacityType, zone.getId(), null, null));
}
if (capacity == null || capacity.size() == 0) {
continue;
}
final double totalCapacity = capacity.get(0).getTotalCapacity();
final double usedCapacity = capacity.get(0).getUsedCapacity();
if (totalCapacity != 0 && usedCapacity / totalCapacity > _capacityTypeThresholdMap.get(capacityType)) {
generateEmailAlert(zone, null, null, totalCapacity, usedCapacity, capacityType);
}
}
}
// Generate Alerts for Pod Level capacities
for (final HostPodVO pod : podList) {
for (final Short capacityType : podCapacityTypes) {
final List<SummedCapacity> capacity = _capacityDao.findCapacityBy(capacityType.intValue(), pod.getDataCenterId(), pod.getId(), null);
if (capacity == null || capacity.size() == 0) {
continue;
}
final double totalCapacity = capacity.get(0).getTotalCapacity();
final double usedCapacity = capacity.get(0).getUsedCapacity();
if (totalCapacity != 0 && usedCapacity / totalCapacity > _capacityTypeThresholdMap.get(capacityType)) {
generateEmailAlert(zoneRepository.findOne(pod.getDataCenterId()), pod, null, totalCapacity, usedCapacity, capacityType);
}
}
}
// Generate Alerts for Cluster Level capacities
for (final ClusterVO cluster : clusterList) {
for (final Short capacityType : clusterCapacityTypes) {
final List<SummedCapacity> capacity;
capacity = _capacityDao.findCapacityBy(capacityType.intValue(), cluster.getDataCenterId(), null, cluster.getId());
// cpu and memory allocated capacity notification threshold can be defined at cluster level, so getting the value if they are defined at cluster level
final double threshold;
switch(capacityType) {
case Capacity.CAPACITY_TYPE_STORAGE:
capacity.add(getUsedStats(capacityType, cluster.getDataCenterId(), cluster.getPodId(), cluster.getId()));
threshold = StorageCapacityThreshold.valueIn(cluster.getId());
break;
case Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED:
threshold = StorageAllocatedCapacityThreshold.valueIn(cluster.getId());
break;
case Capacity.CAPACITY_TYPE_CPU:
threshold = CPUCapacityThreshold.valueIn(cluster.getId());
break;
case Capacity.CAPACITY_TYPE_MEMORY:
threshold = MemoryCapacityThreshold.valueIn(cluster.getId());
break;
default:
threshold = _capacityTypeThresholdMap.get(capacityType);
}
if (capacity == null || capacity.size() == 0) {
continue;
}
final double totalCapacity = capacity.get(0).getTotalCapacity();
final double usedCapacity = capacity.get(0).getUsedCapacity() + capacity.get(0).getReservedCapacity();
if (totalCapacity != 0 && usedCapacity / totalCapacity > threshold) {
generateEmailAlert(zoneRepository.findOne(cluster.getDataCenterId()), ApiDBUtils.findPodById(cluster.getPodId()), cluster, totalCapacity, usedCapacity, capacityType);
}
}
}
}
use of com.cloud.dc.HostPodVO in project cosmic by MissionCriticalCloud.
the class RouterDeploymentDefinitionTest method testListByDataCenterIdVMTypeAndStates.
@Test
public void testListByDataCenterIdVMTypeAndStates() {
// Prepare
final VMInstanceVO vmInstanceVO = mock(VMInstanceVO.class);
final SearchBuilder<VMInstanceVO> vmInstanceSearch = mock(SearchBuilder.class);
when(mockVmDao.createSearchBuilder()).thenReturn(vmInstanceSearch);
when(vmInstanceSearch.entity()).thenReturn(vmInstanceVO);
when(vmInstanceVO.getType()).thenReturn(VirtualMachine.Type.Instance);
when(vmInstanceVO.getState()).thenReturn(VirtualMachine.State.Stopped);
when(vmInstanceVO.getPodIdToDeployIn()).thenReturn(POD_ID1);
final SearchBuilder<HostPodVO> podIdSearch = mock(SearchBuilder.class);
when(mockPodDao.createSearchBuilder()).thenReturn(podIdSearch);
final SearchCriteria<HostPodVO> sc = mock(SearchCriteria.class);
final HostPodVO hostPodVO = mock(HostPodVO.class);
when(podIdSearch.entity()).thenReturn(hostPodVO);
when(hostPodVO.getId()).thenReturn(POD_ID1);
when(hostPodVO.getDataCenterId()).thenReturn(ZONE_ID);
when(podIdSearch.create()).thenReturn(sc);
final List<HostPodVO> expectedPods = mock(List.class);
when(mockPodDao.search(sc, null)).thenReturn(expectedPods);
// Execute
final List<HostPodVO> pods = deployment.listByDataCenterIdVMTypeAndStates(ZONE_ID, VirtualMachine.Type.User, VirtualMachine.State.Starting, VirtualMachine.State.Running);
// Assert
assertNotNull(pods);
assertEquals(expectedPods, pods);
verify(sc, times(1)).setParameters("dc", ZONE_ID);
verify(sc, times(1)).setJoinParameters("vmInstanceSearch", "type", VirtualMachine.Type.User);
verify(sc, times(1)).setJoinParameters("vmInstanceSearch", "states", VirtualMachine.State.Starting, VirtualMachine.State.Running);
verify(mockPodDao, times(1)).search(sc, null);
}
Aggregations