Search in sources :

Example 1 with HypervisorType

use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.

the class VMSnapshotStrategyTest method testDeleteVMSnapshot.

@Test
public void testDeleteVMSnapshot() throws AgentUnavailableException, OperationTimedoutException {
    final Long hostId = 1L;
    final Long vmId = 1L;
    final Long guestOsId = 1L;
    final HypervisorType hypervisorType = HypervisorType.Any;
    final String hypervisorVersion = "default";
    final String guestOsName = "Other";
    final List<VolumeObjectTO> volumeObjectTOs = new ArrayList<>();
    final VMSnapshotVO vmSnapshot = Mockito.mock(VMSnapshotVO.class);
    final UserVmVO userVmVO = Mockito.mock(UserVmVO.class);
    Mockito.when(userVmVO.getGuestOSId()).thenReturn(guestOsId);
    Mockito.when(vmSnapshot.getVmId()).thenReturn(vmId);
    Mockito.when(vmSnapshotHelper.pickRunningHost(Matchers.anyLong())).thenReturn(hostId);
    Mockito.when(vmSnapshotHelper.getVolumeTOList(Matchers.anyLong())).thenReturn(volumeObjectTOs);
    Mockito.when(userVmDao.findById(Matchers.anyLong())).thenReturn(userVmVO);
    final GuestOSVO guestOSVO = Mockito.mock(GuestOSVO.class);
    Mockito.when(guestOSDao.findById(Matchers.anyLong())).thenReturn(guestOSVO);
    final GuestOSHypervisorVO guestOSHypervisorVO = Mockito.mock(GuestOSHypervisorVO.class);
    Mockito.when(guestOSHypervisorVO.getGuestOsName()).thenReturn(guestOsName);
    Mockito.when(guestOsHypervisorDao.findById(Matchers.anyLong())).thenReturn(guestOSHypervisorVO);
    Mockito.when(guestOsHypervisorDao.findByOsIdAndHypervisor(Matchers.anyLong(), Matchers.anyString(), Matchers.anyString())).thenReturn(guestOSHypervisorVO);
    final VMSnapshotTO vmSnapshotTO = Mockito.mock(VMSnapshotTO.class);
    Mockito.when(vmSnapshotHelper.getSnapshotWithParents(Matchers.any(VMSnapshotVO.class))).thenReturn(vmSnapshotTO);
    Mockito.when(vmSnapshotDao.findById(Matchers.anyLong())).thenReturn(vmSnapshot);
    Mockito.when(vmSnapshot.getId()).thenReturn(1L);
    Mockito.when(vmSnapshot.getCreated()).thenReturn(new Date());
    Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(null);
    final HostVO hostVO = Mockito.mock(HostVO.class);
    Mockito.when(hostDao.findById(Matchers.anyLong())).thenReturn(hostVO);
    Mockito.when(hostVO.getHypervisorType()).thenReturn(hypervisorType);
    Mockito.when(hostVO.getHypervisorVersion()).thenReturn(hypervisorVersion);
    Exception e = null;
    try {
        vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
    } catch (final CloudRuntimeException e1) {
        e = e1;
    }
    assertNotNull(e);
    final DeleteVMSnapshotAnswer answer = Mockito.mock(DeleteVMSnapshotAnswer.class);
    Mockito.when(answer.getResult()).thenReturn(true);
    Mockito.when(agentMgr.send(Matchers.anyLong(), Matchers.any(Command.class))).thenReturn(answer);
    final boolean result = vmSnapshotStrategy.deleteVMSnapshot(vmSnapshot);
    assertTrue(result);
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) ArrayList(java.util.ArrayList) GuestOSVO(com.cloud.storage.GuestOSVO) Date(java.util.Date) HostVO(com.cloud.host.HostVO) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) IOException(java.io.IOException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) HypervisorType(com.cloud.model.enumeration.HypervisorType) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotTO(com.cloud.legacymodel.to.VMSnapshotTO) Command(com.cloud.legacymodel.communication.command.Command) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) DeleteVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.DeleteVMSnapshotAnswer) Test(org.junit.Test)

Example 2 with HypervisorType

use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.

the class ConsoleProxyManagerImpl method startNew.

public ConsoleProxyVO startNew(final long dataCenterId) throws ConcurrentOperationException {
    logger.debug("Assign console proxy from a newly started instance for request from data center : " + dataCenterId);
    if (!allowToLaunchNew(dataCenterId)) {
        logger.warn("The number of launched console proxy on zone " + dataCenterId + " has reached to limit");
        return null;
    }
    final HypervisorType availableHypervisor = this._resourceMgr.getAvailableHypervisor(dataCenterId);
    final String templateName = retrieveTemplateName(dataCenterId);
    final VMTemplateVO template = this._templateDao.findRoutingTemplate(availableHypervisor, templateName, dataCenterId);
    if (template == null) {
        throw new CloudRuntimeException("Not able to find the System templates or not downloaded in zone " + dataCenterId);
    }
    final Map<String, Object> context = createProxyInstance(dataCenterId, template);
    final long proxyVmId = (Long) context.get("proxyVmId");
    if (proxyVmId == 0) {
        logger.trace("Creating proxy instance failed, data center id : " + dataCenterId);
        return null;
    }
    final ConsoleProxyVO proxy = this._consoleProxyDao.findById(proxyVmId);
    if (proxy != null) {
        SubscriptionMgr.getInstance().notifySubscribers(ConsoleProxyManager.ALERT_SUBJECT, this, new ConsoleProxyAlertEventArgs(ConsoleProxyAlertEventArgs.PROXY_CREATED, dataCenterId, proxy.getId(), proxy, null));
        return proxy;
    } else {
        logger.debug("Unable to allocate console proxy storage, remove the console proxy record from DB, proxy id: " + proxyVmId);
    }
    return null;
}
Also used : HypervisorType(com.cloud.model.enumeration.HypervisorType) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) VMTemplateVO(com.cloud.storage.VMTemplateVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO)

Example 3 with HypervisorType

use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.

the class CapacityManagerImpl method checkIfHostReachMaxGuestLimit.

@Override
public boolean checkIfHostReachMaxGuestLimit(final Host host) {
    final Long vmCount = this._vmDao.countActiveByHostId(host.getId());
    final HypervisorType hypervisorType = host.getHypervisorType();
    final String hypervisorVersion = host.getHypervisorVersion();
    final Long maxGuestLimit = this._hypervisorCapabilitiesDao.getMaxGuestsLimit(hypervisorType, hypervisorVersion);
    if (vmCount >= maxGuestLimit) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Host name: " + host.getName() + ", hostId: " + host.getId() + " already reached max Running VMs(count includes system VMs), limit is: " + maxGuestLimit + ",Running VM counts is: " + vmCount);
        }
        return true;
    }
    return false;
}
Also used : HypervisorType(com.cloud.model.enumeration.HypervisorType)

Example 4 with HypervisorType

use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.

the class ClusterDaoImpl method getAvailableHypervisorInZone.

@Override
public List<HypervisorType> getAvailableHypervisorInZone(final Long zoneId) {
    final SearchCriteria<ClusterVO> sc = AvailHyperSearch.create();
    if (zoneId != null) {
        sc.setParameters("zoneId", zoneId);
    }
    final List<ClusterVO> clusters = listBy(sc);
    final List<HypervisorType> hypers = new ArrayList<>(4);
    for (final ClusterVO cluster : clusters) {
        hypers.add(cluster.getHypervisorType());
    }
    return hypers;
}
Also used : HypervisorType(com.cloud.model.enumeration.HypervisorType) ClusterVO(com.cloud.dc.ClusterVO) ArrayList(java.util.ArrayList)

Example 5 with HypervisorType

use of com.cloud.model.enumeration.HypervisorType in project cosmic by MissionCriticalCloud.

the class TemplateServiceImpl method downloadBootstrapSysTemplate.

@Override
public void downloadBootstrapSysTemplate(final DataStore store) {
    final Set<VMTemplateVO> toBeDownloaded = new HashSet();
    final List<VMTemplateVO> rtngTmplts = _templateDao.listAllSystemVMTemplates();
    for (final VMTemplateVO rtngTmplt : rtngTmplts) {
        toBeDownloaded.add(rtngTmplt);
    }
    final List<HypervisorType> availHypers = _clusterDao.getAvailableHypervisorInZone(store.getScope().getScopeId());
    if (availHypers.isEmpty()) {
        /*
             * This is for cloudzone, local secondary storage resource started
             * before cluster created
             */
        availHypers.add(HypervisorType.KVM);
    }
    // bug 9809: resume ISO
    availHypers.add(HypervisorType.None);
    for (final VMTemplateVO template : toBeDownloaded) {
        if (availHypers.contains(template.getHypervisorType())) {
            // only download sys template applicable for current hypervisor
            final TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(store.getId(), template.getId());
            if (tmpltHost == null || tmpltHost.getState() != ObjectInDataStoreStateMachine.State.Ready) {
                final TemplateInfo tmplt = _templateFactory.getTemplate(template.getId(), DataStoreRole.Image);
                createTemplateAsync(tmplt, store, null);
            }
        }
    }
}
Also used : HypervisorType(com.cloud.model.enumeration.HypervisorType) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) VMTemplateVO(com.cloud.storage.VMTemplateVO) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) HashSet(java.util.HashSet)

Aggregations

HypervisorType (com.cloud.model.enumeration.HypervisorType)40 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)18 ArrayList (java.util.ArrayList)17 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)16 Account (com.cloud.legacymodel.user.Account)12 VMTemplateVO (com.cloud.storage.VMTemplateVO)8 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)7 ClusterVO (com.cloud.dc.ClusterVO)6 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)6 DB (com.cloud.utils.db.DB)6 UserVmVO (com.cloud.vm.UserVmVO)6 HostVO (com.cloud.host.HostVO)5 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)5 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)5 ResourceAllocationException (com.cloud.legacymodel.exceptions.ResourceAllocationException)5 NetworkVO (com.cloud.network.dao.NetworkVO)5 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)5 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)5 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)4 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)4