Search in sources :

Example 71 with VmTemplate

use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.

the class BackendStorageDomainTemplatesResource method list.

@Override
public Templates list() {
    Templates templates = new Templates();
    boolean unregistered = ParametersHelper.getBooleanParameter(httpHeaders, uriInfo, UNREGISTERED_CONSTRAINT_PARAMETER, true, false);
    if (unregistered) {
        List<org.ovirt.engine.core.common.businessentities.VmTemplate> unregisteredTemplates = getBackendCollection(QueryType.GetUnregisteredVmTemplates, new IdQueryParameters(storageDomainId));
        List<Template> collection = new ArrayList<>();
        for (org.ovirt.engine.core.common.businessentities.VmTemplate entity : unregisteredTemplates) {
            Template vmTemplate = map(entity);
            collection.add(addLinks(populate(vmTemplate, entity)));
        }
        templates.getTemplates().addAll(collection);
    } else {
        templates.getTemplates().addAll(getCollection());
    }
    return templates;
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) ArrayList(java.util.ArrayList) Templates(org.ovirt.engine.api.model.Templates) Template(org.ovirt.engine.api.model.Template) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 72 with VmTemplate

use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.

the class BackendTemplateCdromResource method get.

@Override
public Cdrom get() {
    GetVmTemplateParameters parameters = new GetVmTemplateParameters(templateId);
    VmTemplate entity = getEntity(VmTemplate.class, QueryType.GetVmTemplate, parameters, templateId.toString(), true);
    return addLinks(populate(map(entity), entity));
}
Also used : GetVmTemplateParameters(org.ovirt.engine.core.common.queries.GetVmTemplateParameters) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate)

Example 73 with VmTemplate

use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.

the class StorageHandlingCommandBase method canDetachStorageDomainWithVmsAndDisks.

protected boolean canDetachStorageDomainWithVmsAndDisks(StorageDomain storageDomain) {
    if (!storageDomain.getStorageDomainType().isDataDomain()) {
        return true;
    }
    List<VM> vmRelatedToDomain = vmDao.getAllForStorageDomain(storageDomain.getId());
    List<String> vmsInPreview = vmRelatedToDomain.stream().filter(vm -> !snapshotsValidator.vmNotInPreview(vm.getId()).isValid()).map(VM::getName).collect(Collectors.toList());
    List<VM> vmsWithDisksOnMultipleStorageDomain = vmDao.getAllVMsWithDisksOnOtherStorageDomain(storageDomain.getId());
    vmRelatedToDomain.removeAll(vmsWithDisksOnMultipleStorageDomain);
    List<String> entitiesDeleteProtected = new ArrayList<>();
    List<String> vmsInPool = new ArrayList<>();
    for (VM vm : vmRelatedToDomain) {
        if (vm.isDeleteProtected()) {
            entitiesDeleteProtected.add(vm.getName());
        }
        if (vm.getVmPoolId() != null) {
            vmsInPool.add(vm.getName());
        }
    }
    List<VmTemplate> templatesRelatedToDomain = vmTemplateDao.getAllForStorageDomain(storageDomain.getId());
    List<VmTemplate> vmTemplatesWithDisksOnMultipleStorageDomain = vmTemplateDao.getAllTemplatesWithDisksOnOtherStorageDomain(storageDomain.getId());
    templatesRelatedToDomain.removeAll(vmTemplatesWithDisksOnMultipleStorageDomain);
    entitiesDeleteProtected.addAll(templatesRelatedToDomain.stream().filter(VmBase::isDeleteProtected).map(VmTemplate::getName).collect(Collectors.toList()));
    boolean succeeded = true;
    if (!entitiesDeleteProtected.isEmpty()) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DELETE_PROTECTED);
        addValidationMessageVariable("vms", StringUtils.join(entitiesDeleteProtected, ","));
        succeeded = false;
    }
    if (!vmsInPool.isEmpty()) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_VMS_IN_POOL);
        addValidationMessageVariable("vms", StringUtils.join(vmsInPool, ","));
        succeeded = false;
    }
    if (!vmsInPreview.isEmpty()) {
        addValidationMessage(EngineMessage.ACTION_TYPE_FAILED_STORAGE_DELETE_VMS_IN_PREVIEW);
        addValidationMessageVariable("vms", StringUtils.join(vmsInPreview, ","));
        succeeded = false;
    }
    return succeeded;
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList)

Example 74 with VmTemplate

use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.

the class AuditLogableBaseTest method getVmTemplateNull.

@Test
public void getVmTemplateNull() {
    b.setVmTemplate(null);
    final VmTemplate t = b.getVmTemplate();
    assertNull(t);
}
Also used : VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) Test(org.junit.Test)

Example 75 with VmTemplate

use of org.ovirt.engine.core.common.businessentities.VmTemplate in project ovirt-engine by oVirt.

the class AuditLogableBaseTest method setUp.

@Before
public void setUp() {
    when(vmDao.get(GUID)).thenReturn(new VM());
    when(vmDao.get(GUID3)).thenThrow(new RuntimeException());
    final VDS vds1 = new VDS();
    vds1.setId(GUID);
    final VDS vds2 = new VDS();
    vds2.setId(GUID2);
    when(vdsDao.get(GUID)).thenReturn(vds1);
    when(vdsDao.get(GUID2)).thenReturn(vds2);
    when(vdsDao.get(GUID3)).thenThrow(new RuntimeException());
    final StoragePool p = new StoragePool();
    p.setId(GUID);
    when(storagePoolDao.get(GUID)).thenReturn(p);
    final StorageDomain domain = new StorageDomain();
    domain.setStatus(StorageDomainStatus.Active);
    final StorageDomain sd1 = new StorageDomain();
    sd1.setStatus(StorageDomainStatus.Inactive);
    final StorageDomain sd2 = new StorageDomain();
    sd2.setStatus(null);
    final List<StorageDomain> storageDomainList = Arrays.asList(sd1, sd2, domain);
    when(storageDomainDao.getForStoragePool(GUID, GUID)).thenReturn(domain);
    when(storageDomainDao.getAllForStorageDomain(GUID2)).thenReturn(storageDomainList);
    final VmTemplate t = new VmTemplate();
    t.setId(GUID);
    t.setName(NAME);
    when(vmTemplateDao.get(Guid.Empty)).thenReturn(t);
    when(vmTemplateDao.get(GUID)).thenReturn(new VmTemplate());
    final Cluster g = new Cluster();
    g.setClusterId(GUID);
    when(clusterDao.get(GUID)).thenReturn(g);
}
Also used : StorageDomain(org.ovirt.engine.core.common.businessentities.StorageDomain) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) VDS(org.ovirt.engine.core.common.businessentities.VDS) VmTemplate(org.ovirt.engine.core.common.businessentities.VmTemplate) VM(org.ovirt.engine.core.common.businessentities.VM) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Before(org.junit.Before)

Aggregations

VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)149 ArrayList (java.util.ArrayList)42 Guid (org.ovirt.engine.core.compat.Guid)40 Test (org.junit.Test)30 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)23 HashMap (java.util.HashMap)22 List (java.util.List)20 VM (org.ovirt.engine.core.common.businessentities.VM)19 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)16 Map (java.util.Map)13 QueryType (org.ovirt.engine.core.common.queries.QueryType)13 IdQueryParameters (org.ovirt.engine.core.common.queries.IdQueryParameters)12 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)11 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)11 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)11 Frontend (org.ovirt.engine.ui.frontend.Frontend)10 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)9 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)9 Collection (java.util.Collection)8 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)8