use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.
the class ServerDBSyncImpl method syncVirtualMachine.
/*
* Virtual Machine Synchronization methods
*/
public boolean syncVirtualMachine() {
final ApiConnector api = _manager.getApiConnector();
try {
List<VMInstanceVO> vmDbList = _vmInstanceDao.listAll();
@SuppressWarnings("unchecked") List<VirtualMachine> vncVmList = (List<VirtualMachine>) api.list(VirtualMachine.class, null);
s_logger.debug("sync VM: CS size: " + vmDbList.size() + " VNC size: " + vncVmList.size());
return _dbSync.syncGeneric(VirtualMachine.class, vmDbList, vncVmList);
} catch (Exception ex) {
s_logger.warn("sync virtual-machines", ex);
}
return false;
}
use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.
the class HighAvailabilityManagerImpl method scheduleRestartForVmsOnHost.
@Override
public void scheduleRestartForVmsOnHost(final HostVO host, boolean investigate) {
if (host.getType() != Host.Type.Routing) {
return;
}
if (host.getHypervisorType() == HypervisorType.VMware || host.getHypervisorType() == HypervisorType.Hyperv) {
s_logger.info("Don't restart VMs on host " + host.getId() + " as it is a " + host.getHypervisorType().toString() + " host");
return;
}
s_logger.warn("Scheduling restart for VMs on host " + host.getId() + "-" + host.getName());
final List<VMInstanceVO> vms = _instanceDao.listByHostId(host.getId());
final DataCenterVO dcVO = _dcDao.findById(host.getDataCenterId());
// send an email alert that the host is down
StringBuilder sb = null;
List<VMInstanceVO> reorderedVMList = new ArrayList<VMInstanceVO>();
if ((vms != null) && !vms.isEmpty()) {
sb = new StringBuilder();
sb.append(" Starting HA on the following VMs:");
// collect list of vm names for the alert email
for (int i = 0; i < vms.size(); i++) {
VMInstanceVO vm = vms.get(i);
if (vm.getType() == VirtualMachine.Type.User) {
reorderedVMList.add(vm);
} else {
reorderedVMList.add(0, vm);
}
if (vm.isHaEnabled()) {
sb.append(" " + vm.getHostName());
}
}
}
// send an email alert that the host is down, include VMs
HostPodVO podVO = _podDao.findById(host.getPodId());
String hostDesc = "name: " + host.getName() + " (id:" + host.getId() + "), availability zone: " + dcVO.getName() + ", pod: " + podVO.getName();
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Host is down, " + hostDesc, "Host [" + hostDesc + "] is down." + ((sb != null) ? sb.toString() : ""));
for (VMInstanceVO vm : reorderedVMList) {
ServiceOfferingVO vmOffering = _serviceOfferingDao.findById(vm.getServiceOfferingId());
if (vmOffering.getUseLocalStorage()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Skipping HA on vm " + vm + ", because it uses local storage. Its fate is tied to the host.");
}
continue;
}
if (s_logger.isDebugEnabled()) {
s_logger.debug("Notifying HA Mgr of to restart vm " + vm.getId() + "-" + vm.getInstanceName());
}
vm = _instanceDao.findByUuid(vm.getUuid());
Long hostId = vm.getHostId();
if (hostId != null && !hostId.equals(host.getId())) {
s_logger.debug("VM " + vm.getInstanceName() + " is not on down host " + host.getId() + " it is on other host " + hostId + " VM HA is done");
continue;
}
scheduleRestart(vm, investigate);
}
}
use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.
the class HighAvailabilityManagerImpl method findTakenMigrationWork.
@Override
public List<VMInstanceVO> findTakenMigrationWork() {
List<HaWorkVO> works = _haDao.findTakenWorkItems(WorkType.Migration);
List<VMInstanceVO> vms = new ArrayList<VMInstanceVO>(works.size());
for (HaWorkVO work : works) {
VMInstanceVO vm = _instanceDao.findById(work.getInstanceId());
if (vm != null) {
vms.add(vm);
}
}
return vms;
}
use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.
the class HighAvailabilityManagerImpl method migrate.
public Long migrate(final HaWorkVO work) {
long vmId = work.getInstanceId();
long srcHostId = work.getHostId();
try {
work.setStep(Step.Migrating);
_haDao.update(work.getId(), work);
VMInstanceVO vm = _instanceDao.findById(vmId);
if (vm == null) {
return null;
}
// First try starting the vm with its original planner, if it doesn't succeed send HAPlanner as its an emergency.
_itMgr.migrateAway(vm.getUuid(), srcHostId);
return null;
} catch (InsufficientServerCapacityException e) {
s_logger.warn("Insufficient capacity for migrating a VM.");
_resourceMgr.maintenanceFailed(srcHostId);
return (System.currentTimeMillis() >> 10) + _migrateRetryInterval;
}
}
use of com.cloud.vm.VMInstanceVO in project cloudstack by apache.
the class VolumeStateListener method postStateTransitionEvent.
@Override
public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> transition, Volume vol, boolean status, Object opaque) {
pubishOnEventBus(transition.getEvent().name(), "postStateTransitionEvent", vol, transition.getCurrentState(), transition.getToState());
if (transition.isImpacted(StateMachine2.Transition.Impact.USAGE)) {
Long instanceId = vol.getInstanceId();
VMInstanceVO vmInstanceVO = null;
if (instanceId != null) {
vmInstanceVO = _vmInstanceDao.findById(instanceId);
}
if (instanceId == null || vmInstanceVO.getType() == VirtualMachine.Type.User) {
if (transition.getToState() == State.Ready) {
if (transition.getCurrentState() == State.Resizing) {
// Log usage event for volumes belonging user VM's only
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), vol.getDiskOfferingId(), vol.getTemplateId(), vol.getSize(), Volume.class.getName(), vol.getUuid());
} else {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_CREATE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), vol.getDiskOfferingId(), null, vol.getSize(), Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
}
} else if (transition.getToState() == State.Destroy && vol.getVolumeType() != Volume.Type.ROOT) {
//Do not Publish Usage Event for ROOT Disk as it would have been published already while destroying a VM
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_DELETE, vol.getAccountId(), vol.getDataCenterId(), vol.getId(), vol.getName(), Volume.class.getName(), vol.getUuid(), vol.isDisplayVolume());
} else if (transition.getToState() == State.Uploaded) {
//Currently we are not capturing Usage for Secondary Storage so Usage for this operation will be captured when it is moved to primary storage
}
}
}
return true;
}
Aggregations