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;
}
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));
}
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;
}
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);
}
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);
}
Aggregations