use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class KVMFencerTest method testWithHosts.
@Test
public void testWithHosts() throws AgentUnavailableException, OperationTimedoutException {
final HostVO host = Mockito.mock(HostVO.class);
Mockito.when(host.getClusterId()).thenReturn(1l);
Mockito.when(host.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(host.getStatus()).thenReturn(Status.Up);
Mockito.when(host.getDataCenterId()).thenReturn(1l);
Mockito.when(host.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(1l);
final HostVO secondHost = Mockito.mock(HostVO.class);
Mockito.when(secondHost.getClusterId()).thenReturn(1l);
Mockito.when(secondHost.getHypervisorType()).thenReturn(HypervisorType.KVM);
Mockito.when(secondHost.getStatus()).thenReturn(Status.Up);
Mockito.when(secondHost.getDataCenterId()).thenReturn(1l);
Mockito.when(secondHost.getPodId()).thenReturn(1l);
Mockito.when(host.getId()).thenReturn(2l);
final VirtualMachine virtualMachine = Mockito.mock(VirtualMachine.class);
Mockito.when(resourceManager.listAllHostsInCluster(1l)).thenReturn(Arrays.asList(host, secondHost));
final FenceAnswer answer = new FenceAnswer(null, true, "ok");
Mockito.when(agentManager.send(Matchers.anyLong(), Matchers.any(FenceCommand.class))).thenReturn(answer);
Assert.assertTrue(fencer.fenceOff(virtualMachine, host));
}
use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class NetworkOrchestrator method createNicForVm.
@Override
public NicProfile createNicForVm(final Network network, final NicProfile requested, final ReservationContext context, final VirtualMachineProfile vmProfile, final boolean prepare) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final Zone zone = _zoneRepository.findOne(network.getDataCenterId());
final Host host = _hostDao.findById(vm.getHostId());
final DeployDestination dest = new DeployDestination(zone, null, null, host);
NicProfile nic = getNicProfileForVm(network, requested, vm);
// 1) allocate nic (if needed) Always allocate if it is a user vm
if (nic == null || vmProfile.getType() == VirtualMachine.Type.User) {
nic = allocateNic(requested, network, false, vmProfile);
if (nic == null) {
throw new CloudRuntimeException("Failed to allocate nic for vm " + vm + " in network " + network);
}
// Update vm_network_map table
if (vmProfile.getType() == VirtualMachine.Type.User) {
final VMNetworkMapVO vno = new VMNetworkMapVO(vm.getId(), network.getId());
_vmNetworkMapDao.persist(vno);
}
s_logger.debug("Nic is allocated successfully for vm " + vm + " in network " + network);
}
// 2) prepare nic
if (prepare) {
final Pair<NetworkGuru, NetworkVO> implemented = implementNetwork(nic.getNetworkId(), dest, context, vmProfile.getVirtualMachine().getType() == Type.DomainRouter);
if (implemented == null || implemented.first() == null) {
s_logger.warn("Failed to implement network id=" + nic.getNetworkId() + " as a part of preparing nic id=" + nic.getId());
throw new CloudRuntimeException("Failed to implement network id=" + nic.getNetworkId() + " as a part preparing nic id=" + nic.getId());
}
nic = prepareNic(vmProfile, dest, context, nic.getId(), implemented.second());
s_logger.debug("Nic is prepared successfully for vm " + vm + " in network " + network);
}
return nic;
}
use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class DefaultEndPointSelector method select.
@Override
public EndPoint select(final DataObject object, final StorageAction action) {
if (StorageAction.TAKESNAPSHOT.equals(action)) {
final SnapshotInfo snapshotInfo = (SnapshotInfo) object;
if (Hypervisor.HypervisorType.KVM.equals(snapshotInfo.getHypervisorType())) {
final VolumeInfo volumeInfo = snapshotInfo.getBaseVolume();
final VirtualMachine vm = volumeInfo.getAttachedVM();
if (vm != null && VirtualMachine.State.Running.equals(vm.getState())) {
final Long hostId = vm.getHostId();
return getEndPointFromHostId(hostId);
}
}
} else if (StorageAction.MIGRATEVOLUME.equals(action)) {
final VolumeInfo volumeInfo = (VolumeInfo) object;
if (Hypervisor.HypervisorType.KVM.equals(volumeInfo.getHypervisorType())) {
final VirtualMachine vm = volumeInfo.getAttachedVM();
if (vm != null && VirtualMachine.State.Running.equals(vm.getState()) && volumeInfo.isToBeLiveMigrated()) {
final Long hostId = vm.getHostId();
return getEndPointFromHostId(hostId);
}
}
}
return select(object);
}
use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class HostAntiAffinityProcessor method check.
@Override
public boolean check(final VirtualMachineProfile vmProfile, final DeployDestination plannedDestination) throws AffinityConflictException {
if (plannedDestination.getHost() == null) {
return true;
}
final long plannedHostId = plannedDestination.getHost().getId();
final VirtualMachine vm = vmProfile.getVirtualMachine();
final List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
for (final AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
// if more than 1 VM's are present in the group then check for
// conflict due to parallel deployment
final List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(vmGroupMapping.getAffinityGroupId());
groupVMIds.remove(vm.getId());
for (final Long groupVMId : groupVMIds) {
final VMReservationVO vmReservation = _reservationDao.findByVmId(groupVMId);
if (vmReservation != null && vmReservation.getHostId() != null && vmReservation.getHostId().equals(plannedHostId)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Planned destination for VM " + vm.getId() + " conflicts with an existing VM " + vmReservation.getVmId() + " reserved on the same host " + plannedHostId);
}
return false;
}
}
}
return true;
}
use of com.cloud.vm.VirtualMachine in project cosmic by MissionCriticalCloud.
the class HostAntiAffinityProcessor method process.
@Override
public void process(final VirtualMachineProfile vmProfile, final DeploymentPlan plan, final ExcludeList avoid) throws AffinityConflictException {
final VirtualMachine vm = vmProfile.getVirtualMachine();
final List<AffinityGroupVMMapVO> vmGroupMappings = _affinityGroupVMMapDao.findByVmIdType(vm.getId(), getType());
for (final AffinityGroupVMMapVO vmGroupMapping : vmGroupMappings) {
if (vmGroupMapping != null) {
final AffinityGroupVO group = _affinityGroupDao.findById(vmGroupMapping.getAffinityGroupId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Processing affinity group " + group.getName() + " for VM Id: " + vm.getId());
}
final List<Long> groupVMIds = _affinityGroupVMMapDao.listVmIdsByAffinityGroup(group.getId());
groupVMIds.remove(vm.getId());
for (final Long groupVMId : groupVMIds) {
final VMInstanceVO groupVM = _vmInstanceDao.findById(groupVMId);
if (groupVM != null && !groupVM.isRemoved()) {
if (groupVM.getHostId() != null) {
avoid.addHost(groupVM.getHostId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Added host " + groupVM.getHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host");
}
} else if (VirtualMachine.State.Stopped.equals(groupVM.getState()) && groupVM.getLastHostId() != null) {
final long secondsSinceLastUpdate = (DateUtil.currentGMTTime().getTime() - groupVM.getUpdateTime().getTime()) / 1000;
if (secondsSinceLastUpdate < _vmCapacityReleaseInterval) {
avoid.addHost(groupVM.getLastHostId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Added host " + groupVM.getLastHostId() + " to avoid set, since VM " + groupVM.getId() + " is present on the host, in Stopped state but has reserved capacity");
}
}
}
}
}
}
}
}
Aggregations