Search in sources :

Example 21 with VMInstanceVO

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;
}
Also used : ApiConnector(net.juniper.contrail.api.ApiConnector) VMInstanceVO(com.cloud.vm.VMInstanceVO) List(java.util.List) ArrayList(java.util.ArrayList) InternalErrorException(com.cloud.exception.InternalErrorException) IOException(java.io.IOException) VirtualMachine(net.juniper.contrail.api.types.VirtualMachine)

Example 22 with VMInstanceVO

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);
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) HostPodVO(com.cloud.dc.HostPodVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 23 with VMInstanceVO

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;
}
Also used : ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO)

Example 24 with VMInstanceVO

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;
    }
}
Also used : VMInstanceVO(com.cloud.vm.VMInstanceVO) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException)

Example 25 with VMInstanceVO

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;
}
Also used : Volume(com.cloud.storage.Volume) VMInstanceVO(com.cloud.vm.VMInstanceVO)

Aggregations

VMInstanceVO (com.cloud.vm.VMInstanceVO)131 ArrayList (java.util.ArrayList)40 HostVO (com.cloud.host.HostVO)34 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)28 Account (com.cloud.user.Account)28 VolumeVO (com.cloud.storage.VolumeVO)24 Test (org.junit.Test)24 HostPodVO (com.cloud.dc.HostPodVO)15 HashMap (java.util.HashMap)14 NetworkVO (com.cloud.network.dao.NetworkVO)13 User (com.cloud.user.User)13 NicVO (com.cloud.vm.NicVO)13 VmWorkJobVO (org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO)13 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)12 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)12 ActionEvent (com.cloud.event.ActionEvent)11 Random (java.util.Random)11 Answer (com.cloud.agent.api.Answer)10 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)10