use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class StorageHandlingCommandBase method getEntitiesFromStorageOvfDisk.
protected List<OvfEntityData> getEntitiesFromStorageOvfDisk(Guid storageDomainId, Guid storagePoolId) {
// Initialize a new ArrayList with all the ovfDisks in the specified Storage Domain,
// so the entities can be removed from the list every time we register the latest OVF disk and we can keep the
// ovfDisks cache list updated.
List<DiskImage> ovfStoreDiskImages = new ArrayList<>(getAllOVFDisks(storageDomainId, storagePoolId));
if (!ovfStoreDiskImages.isEmpty()) {
while (!ovfStoreDiskImages.isEmpty()) {
Pair<DiskImage, Long> ovfDiskAndSize = getLatestOVFDisk(ovfStoreDiskImages);
DiskImage ovfDisk = ovfDiskAndSize.getFirst();
if (ovfDisk != null) {
try {
ActionReturnValue actionReturnValueReturnValue = runInternalAction(ActionType.RetrieveImageData, new RetrieveImageDataParameters(getParameters().getStoragePoolId(), storageDomainId, ovfDisk.getId(), ovfDisk.getImage().getId(), ovfDiskAndSize.getSecond()), cloneContextAndDetachFromParent());
getReturnValue().getVdsmTaskIdList().addAll(actionReturnValueReturnValue.getInternalVdsmTaskIdList());
if (actionReturnValueReturnValue.getSucceeded()) {
List<OvfEntityData> returnedMap = ovfUtils.getOvfEntities(actionReturnValueReturnValue.getActionReturnValue(), unregisteredDisks, storageDomainId);
return returnedMap;
} else {
log.error("Image data could not be retrieved for disk id '{}' in storage domain id '{}'", ovfDisk.getId(), storageDomainId);
}
} catch (RuntimeException e) {
// We are catching RuntimeException, since the call for OvfUtils.getOvfEntities will throw
// a RuntimeException if there is a problem to untar the file.
log.error("Image data could not be retrieved for disk id '{}' in storage domain id '{}': {}", ovfDisk.getId(), storageDomainId, e.getMessage());
log.debug("Exception", e);
}
ovfStoreDiskImages.remove(ovfDisk);
} else {
log.error("Couldn't find additional ovf store to retrieve the ovf data from in storage domain '{}'", storageDomainId);
break;
}
}
AuditLogable logable = new AuditLogableImpl();
logable.setStorageDomainId(storageDomainId);
logable.setStorageDomainName(storageDomainStaticDao.get(storageDomainId).getName());
auditLogDirector.log(logable, AuditLogType.RETRIEVE_OVF_STORE_FAILED);
} else {
log.warn("There are no OVF_STORE disks on storage domain id {}", storageDomainId);
}
return new ArrayList<>();
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class OvfUtils method getOvfEntities.
public List<OvfEntityData> getOvfEntities(byte[] tar, List<UnregisteredDisk> unregisteredDisks, Guid storageDomainId) {
List<OvfEntityData> ovfEntityDataFromTar = new ArrayList<>();
InputStream is = new ByteArrayInputStream(tar);
log.info("Start fetching files from tar file");
Map<String, ByteBuffer> filesFromTar;
try (TarInMemoryExport memoryTar = new TarInMemoryExport(is)) {
filesFromTar = memoryTar.unTar();
} catch (IOException e) {
throw new RuntimeException(String.format("Exception while getting OVFs files from tar file for domain %s", storageDomainId), e);
}
Entry<String, ByteBuffer> metaDataFileEntry = null;
for (Entry<String, ByteBuffer> fileEntry : filesFromTar.entrySet()) {
if (fileEntry.getKey().endsWith(OVF_FILE_EXT)) {
analyzeOvfFile(unregisteredDisks, storageDomainId, ovfEntityDataFromTar, fileEntry);
} else if (fileEntry.getKey().equals(OvfInfoFileConstants.MetaDataFileName)) {
metaDataFileEntry = fileEntry;
} else {
log.info("File '{}' is not an OVF file, will be ignored.", fileEntry.getKey());
}
}
analyzeOvfMetaDataFile(storageDomainId, ovfEntityDataFromTar, metaDataFileEntry);
log.info("Finish to fetch OVF files from tar file. The number of OVF entities are {}", ovfEntityDataFromTar.size());
return ovfEntityDataFromTar;
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class ProcessOvfUpdateForStorageDomainCommand method retrieveUnprocessedUnregisteredOvfData.
private List<Pair<Guid, String>> retrieveUnprocessedUnregisteredOvfData(Set<Guid> processedIds, Map<String, Object> metaDataForEntities) {
Map<String, Object> statusMap = (Map<String, Object>) metaDataForEntities.get(OvfInfoFileConstants.VmStatus);
List<OvfEntityData> ovfList = unregisteredOVFDataDao.getAllForStorageDomainByEntityType(getParameters().getStorageDomainId(), null);
List<Pair<Guid, String>> ovfData = new LinkedList<>();
for (OvfEntityData ovfEntityData : ovfList) {
if (!processedIds.contains(ovfEntityData.getEntityId())) {
Pair<Guid, String> data = new Pair<>(ovfEntityData.getEntityId(), ovfEntityData.getOvfData());
ovfData.add(data);
}
statusMap.putIfAbsent(ovfEntityData.getEntityId().toString(), ovfEntityData.getStatus().getValue());
}
return ovfData;
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class UnregisteredOVFDataDaoTest method testInsertTemplateToUnregisteredEntity.
@Test
public void testInsertTemplateToUnregisteredEntity() {
final String ovfExtraData = "<ovf> Some extra OVF data </ovf>";
OvfEntityData ovfEntityData = new OvfEntityData(FixturesTool.VM_TEMPLATE_RHEL5, "AnyVM", VmEntityType.TEMPLATE, ArchitectureType.x86_64, Version.getLast(), FixturesTool.STORAGE_DOMAIN_NFS2_1, null, ovfExtraData);
dao.saveOVFData(ovfEntityData);
List<OvfEntityData> fetchedOvfEntityData = dao.getByEntityIdAndStorageDomain(FixturesTool.VM_TEMPLATE_RHEL5, FixturesTool.STORAGE_DOMAIN_NFS2_1);
assertEquals(1, fetchedOvfEntityData.size());
assertTrue("The entity type should be template", fetchedOvfEntityData.get(0).getEntityType().isTemplateType());
assertEquals("The entity OVF extra data should be updated", ovfExtraData, fetchedOvfEntityData.get(0).getOvfExtraData());
}
use of org.ovirt.engine.core.common.businessentities.OvfEntityData in project ovirt-engine by oVirt.
the class GetUnregisteredVmTemplatesQuery method executeQueryCommand.
@Override
protected void executeQueryCommand() {
List<OvfEntityData> entityList = getOvfEntityList(VmEntityType.TEMPLATE);
List<VmTemplate> vmTemplates = new ArrayList<>();
for (OvfEntityData ovf : entityList) {
try {
vmTemplates.add(ovfHelper.readVmTemplateFromOvf(ovf.getOvfData()).getVmTemplate());
} catch (OvfReaderException e) {
log.debug("failed to parse a given ovf configuration: \n" + ovf.getOvfData(), e);
getQueryReturnValue().setExceptionString("failed to parse a given ovf configuration " + e.getMessage());
}
}
getQueryReturnValue().setSucceeded(true);
getQueryReturnValue().setReturnValue(vmTemplates);
}
Aggregations