Search in sources :

Example 6 with OvfEntityData

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

the class GetUnregisteredVmsQueryTest method setUpQueryEntities.

private void setUpQueryEntities() throws OvfReaderException {
    // Set up the expected result
    VM vmReturnForOvf = new VM();
    vmReturnForOvf.setId(newVmGuid);
    vmReturnForOvf.setName("Name");
    String ovfData = new String("OVF data for the first VM");
    OvfEntityData ovfEntityData = new OvfEntityData(vmReturnForOvf.getId(), vmReturnForOvf.getName(), VmEntityType.VM, null, null, storageDomainId, ovfData, null);
    ovfEntityData.setStatus(vmStatus);
    List<OvfEntityData> expectedResultQuery1 = new ArrayList<>();
    expectedResultQuery1.add(ovfEntityData);
    List<OvfEntityData> expectedResult = new ArrayList<>();
    expectedResult.add(ovfEntityData);
    VM vmReturnForOvf2 = new VM();
    vmReturnForOvf2.setId(newVmGuid2);
    vmReturnForOvf2.setName("Name2");
    String ovfData2 = new String("OVF data for the second VM");
    OvfEntityData ovfEntityData2 = new OvfEntityData(vmReturnForOvf2.getId(), vmReturnForOvf2.getName(), VmEntityType.VM, null, null, storageDomainId, ovfData2, null);
    ovfEntityData2.setStatus(vmStatus2);
    expectedResult.add(ovfEntityData2);
    List<OvfEntityData> expectedResultQuery2 = new ArrayList<>();
    expectedResultQuery2.add(ovfEntityData);
    // Mock the Daos
    when(unregisteredOVFDataDaoMock.getAllForStorageDomainByEntityType(storageDomainId, entityType)).thenReturn(expectedResult);
    when(unregisteredOVFDataDaoMock.getByEntityIdAndStorageDomain(newVmGuid2, storageDomainId)).thenReturn(expectedResultQuery2);
    when(unregisteredOVFDataDaoMock.getByEntityIdAndStorageDomain(newVmGuid, storageDomainId)).thenReturn(expectedResultQuery1);
    // Mock OVF
    when(ovfHelperMock.readVmFromOvf(ovfData)).thenReturn(new FullEntityOvfData(vmReturnForOvf));
    when(ovfHelperMock.readVmFromOvf(ovfData2)).thenReturn(new FullEntityOvfData(vmReturnForOvf2));
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)

Example 7 with OvfEntityData

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

the class ScanStorageForUnregisteredDisksCommandTest method setUpCommandEntities.

@Before
public void setUpCommandEntities() throws OvfReaderException {
    QueryReturnValue vdcRetVal = generateQueryReturnValueForGetDiskImages();
    doReturn(vdcRetVal).when(cmd).getUnregisteredDisksFromHost();
    List<OvfEntityData> allEntities = new ArrayList<>();
    OvfEntityData ovf = new OvfEntityData();
    ovf.setEntityId(Guid.newGuid());
    ovf.setEntityName("Any Name");
    allEntities.add(ovf);
    when(unregisteredOVFDataDaoMock.getAllForStorageDomainByEntityType(storageId, null)).thenReturn(allEntities);
    doNothing().when(cmd).setVmsForUnregisteredDisks(allEntities);
    when(unregisteredOVFDataDaoMock.getAllForStorageDomainByEntityType(storageId, null)).thenReturn(allEntities);
    doNothing().when(cmd).removeUnregisteredDisks();
    doNothing().when(cmd).saveUnregisterDisk(any());
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) ArrayList(java.util.ArrayList) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) Before(org.junit.Before)

Example 8 with OvfEntityData

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

the class ScanStorageForUnregisteredDisksCommand method executeCommand.

@Override
protected void executeCommand() {
    // Get all disks from the Storage.
    QueryReturnValue vdcRetVal = getUnregisteredDisksFromHost();
    if (!vdcRetVal.getSucceeded()) {
        log.error("An error occurred while fetching unregistered disks from Storage Domain id '{}'", getParameters().getStorageDomainId());
        setSucceeded(false);
        return;
    }
    List<DiskImage> disksFromStorage = vdcRetVal.getReturnValue();
    castDiskImagesToUnregisteredDisks(disksFromStorage);
    // Filter out all existing disks in the setup.
    List<OvfEntityData> allEntities = unregisteredOVFDataDao.getAllForStorageDomainByEntityType(getParameters().getStorageDomainId(), null);
    setVmsForUnregisteredDisks(allEntities);
    // Initialize the unregistered Disks table - Remove all the data related to the Storage Domain.
    removeUnregisteredDisks();
    // Initialize all the disks in the DB.
    initUnregisteredDisksToDB();
    setSucceeded(true);
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage)

Example 9 with OvfEntityData

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

the class ScanStorageForUnregisteredDisksCommand method setVmsForUnregisteredDisks.

protected void setVmsForUnregisteredDisks(List<OvfEntityData> allEntities) {
    for (OvfEntityData ovfEntity : allEntities) {
        try {
            XmlDocument xmlDocument = new XmlDocument(ovfEntity.getOvfData());
            ovfUtils.updateUnregisteredDisksWithVMs(unregisteredDisks, ovfEntity.getEntityId(), ovfEntity.getEntityName(), xmlDocument);
        } catch (Exception e) {
            log.warn("Could not parse OVF data of VM");
            continue;
        }
    }
}
Also used : OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) XmlDocument(org.ovirt.engine.core.utils.ovf.xml.XmlDocument)

Example 10 with OvfEntityData

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

the class AttachStorageDomainToPoolCommand method executeCommand.

@Override
protected void executeCommand() {
    if (isCinderStorageDomain()) {
        handleCinderDomain();
        return;
    }
    if (getStoragePool().getStatus() == StoragePoolStatus.Uninitialized) {
        StoragePoolWithStoragesParameter parameters = new StoragePoolWithStoragesParameter(getStoragePool(), Collections.singletonList(getStorageDomain().getId()), getParameters().getSessionId());
        parameters.setIsInternal(true);
        parameters.setTransactionScopeOption(TransactionScopeOption.Suppress);
        ActionReturnValue returnValue = runInternalAction(ActionType.AddStoragePoolWithStorages, parameters, getContext().clone().withoutCompensationContext());
        setSucceeded(returnValue.getSucceeded());
        if (!returnValue.getSucceeded()) {
            getReturnValue().setFault(returnValue.getFault());
        }
    } else {
        map = storagePoolIsoMapDao.get(new StoragePoolIsoMapId(getStorageDomain().getId(), getParameters().getStoragePoolId()));
        if (map == null) {
            executeInNewTransaction(() -> {
                map = new StoragePoolIsoMap(getStorageDomain().getId(), getParameters().getStoragePoolId(), StorageDomainStatus.Locked);
                storagePoolIsoMapDao.save(map);
                getCompensationContext().snapshotNewEntity(map);
                getCompensationContext().stateChanged();
                return null;
            });
            List<Pair<Guid, Boolean>> hostsConnectionResults = connectHostsInUpToDomainStorageServer();
            if (isAllHostConnectionFailed(hostsConnectionResults)) {
                log.error("Cannot connect storage connection server, aborting attach storage domain operation.");
                setSucceeded(false);
                return;
            }
            // Forcibly detach only data storage domains.
            if (getStorageDomain().getStorageDomainType() == StorageDomainType.Data) {
                @SuppressWarnings("unchecked") Pair<StorageDomainStatic, Guid> domainFromIrs = (Pair<StorageDomainStatic, Guid>) runVdsCommand(VDSCommandType.HSMGetStorageDomainInfo, new HSMGetStorageDomainInfoVDSCommandParameters(getVdsId(), getParameters().getStorageDomainId())).getReturnValue();
                // If the storage domain is already related to another Storage Pool, detach it by force.
                Guid storagePoolId = domainFromIrs.getSecond();
                if (storagePoolId != null) {
                    // Master domain version is not relevant since force remove at
                    // DetachStorageDomainVdsCommand does not use it.
                    // Storage pool id can be empty
                    DetachStorageDomainVDSCommandParameters detachParams = new DetachStorageDomainVDSCommandParameters(getStoragePoolIdFromVds(), getParameters().getStorageDomainId(), Guid.Empty, 0);
                    detachParams.setForce(true);
                    detachParams.setDetachFromOldStoragePool(true);
                    try {
                        runVdsCommand(VDSCommandType.DetachStorageDomain, detachParams);
                    } catch (EngineException e) {
                        log.warn("Detaching Storage Domain '{}' from it's previous storage pool '{}'" + " has failed. The meta data of the Storage Domain might still" + " indicate that it is attached to a different Storage Pool.", getParameters().getStorageDomainId(), Guid.Empty, 0);
                        throw e;
                    }
                }
                if (diskProfileDao.getAllForStorageDomain(getStorageDomain().getId()).isEmpty()) {
                    createDefaultDiskProfile();
                }
            }
            runVdsCommand(VDSCommandType.AttachStorageDomain, new AttachStorageDomainVDSCommandParameters(getParameters().getStoragePoolId(), getParameters().getStorageDomainId()));
            final List<OvfEntityData> unregisteredEntitiesFromOvfDisk = new ArrayList<>();
            if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                List<OvfEntityData> returnValueFromStorageOvfDisk = getEntitiesFromStorageOvfDisk(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
                unregisteredEntitiesFromOvfDisk.addAll(returnValueFromStorageOvfDisk);
            }
            List<DiskImage> ovfStoreDiskImages = getAllOVFDisks(getParameters().getStorageDomainId(), getStoragePoolIdFromVds());
            executeInNewTransaction(() -> {
                final StorageDomainType sdType = getStorageDomain().getStorageDomainType();
                map.setStatus(StorageDomainStatus.Maintenance);
                storagePoolIsoMapDao.updateStatus(map.getId(), map.getStatus());
                if (sdType == StorageDomainType.Master) {
                    calcStoragePoolStatusByDomainsStatus();
                }
                if (getStorageDomain().getStorageDomainType().isDataDomain()) {
                    registerAllOvfDisks(ovfStoreDiskImages, getParameters().getStorageDomainId());
                    // Update unregistered entities
                    for (OvfEntityData ovf : unregisteredEntitiesFromOvfDisk) {
                        unregisteredOVFDataDao.removeEntity(ovf.getEntityId(), getParameters().getStorageDomainId());
                        unregisteredOVFDataDao.saveOVFData(ovf);
                        log.info("Adding OVF data of entity id '{}' and entity name '{}'", ovf.getEntityId(), ovf.getEntityName());
                    }
                    initUnregisteredDisksToDB(getParameters().getStorageDomainId());
                }
                // upgrade the domain format to the storage pool format
                updateStorageDomainFormatIfNeeded(getStorageDomain());
                return null;
            });
            if (getParameters().getActivate()) {
                attemptToActivateDomain();
            }
            setSucceeded(true);
        }
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainType(org.ovirt.engine.core.common.businessentities.StorageDomainType) AttachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.AttachStorageDomainVDSCommandParameters) DetachStorageDomainVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DetachStorageDomainVDSCommandParameters) StoragePoolIsoMap(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap) EngineException(org.ovirt.engine.core.common.errors.EngineException) ArrayList(java.util.ArrayList) StoragePoolIsoMapId(org.ovirt.engine.core.common.businessentities.StoragePoolIsoMapId) HSMGetStorageDomainInfoVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.HSMGetStorageDomainInfoVDSCommandParameters) Guid(org.ovirt.engine.core.compat.Guid) StoragePoolWithStoragesParameter(org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) OvfEntityData(org.ovirt.engine.core.common.businessentities.OvfEntityData) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

OvfEntityData (org.ovirt.engine.core.common.businessentities.OvfEntityData)21 ArrayList (java.util.ArrayList)10 VM (org.ovirt.engine.core.common.businessentities.VM)4 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)4 FullEntityOvfData (org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData)4 Guid (org.ovirt.engine.core.compat.Guid)4 OvfReaderException (org.ovirt.engine.core.utils.ovf.OvfReaderException)4 VmTemplate (org.ovirt.engine.core.common.businessentities.VmTemplate)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 Pair (org.ovirt.engine.core.common.utils.Pair)2 XmlDocument (org.ovirt.engine.core.utils.ovf.xml.XmlDocument)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1