Search in sources :

Example 11 with StorageDomainOvfInfo

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

the class ProcessOvfUpdateForStorageDomainCommand method updateOvfStoreContent.

protected boolean updateOvfStoreContent() {
    if (domainOvfStoresInfoForUpdate.isEmpty()) {
        return true;
    }
    updateDate = new Date();
    List<Guid> vmAndTemplatesIds = storageDomainDao.getVmAndTemplatesIdsByStorageDomainId(getParameters().getStorageDomainId(), false, false);
    vmAndTemplatesIds.addAll(vmStaticDao.getVmAndTemplatesIdsWithoutAttachedImageDisks(getParameters().getStoragePoolId(), false));
    byte[] bytes = buildOvfInfoFileByteArray(vmAndTemplatesIds);
    Pair<StorageDomainOvfInfo, DiskImage> lastOvfStoreForUpdate = domainOvfStoresInfoForUpdate.getLast();
    // possibly have some ovf data on storage)
    if (lastOvfStoreForUpdate.getFirst().getLastUpdated() != null) {
        domainOvfStoresInfoForUpdate.removeLast();
    } else {
        lastOvfStoreForUpdate = null;
    }
    boolean shouldUpdateLastOvfStore = false;
    failedOvfDisks = new ArrayList<>();
    for (Pair<StorageDomainOvfInfo, DiskImage> pair : domainOvfStoresInfoForUpdate) {
        shouldUpdateLastOvfStore |= performOvfUpdateForDomain(bytes, pair.getFirst(), pair.getSecond(), vmAndTemplatesIds);
    }
    // backup (if we did)
    if (shouldUpdateLastOvfStore && lastOvfStoreForUpdate != null) {
        performOvfUpdateForDomain(bytes, lastOvfStoreForUpdate.getFirst(), lastOvfStoreForUpdate.getSecond(), vmAndTemplatesIds);
    }
    if (!failedOvfDisks.isEmpty()) {
        addCustomValue("DataCenterName", getStoragePool().getName());
        addCustomValue("StorageDomainName", getStorageDomain().getName());
        addCustomValue("DisksIds", StringUtils.join(failedOvfDisks, ", "));
        auditLogDirector.log(this, AuditLogType.UPDATE_FOR_OVF_STORES_FAILED);
        return false;
    }
    return true;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) Date(java.util.Date)

Example 12 with StorageDomainOvfInfo

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

the class StorageDomainOvfInfoDaoTest method updateOvfUpdatedInfoWithRelevantExceptStatus.

@Test
public void updateOvfUpdatedInfoWithRelevantExceptStatus() {
    StorageDomainOvfInfo ovfInfo = dao.get(getExistingEntityId());
    ovfInfo.setStatus(StorageDomainOvfInfoStatus.DISABLED);
    dao.update(ovfInfo);
    StorageDomainOvfInfo ovfInfo1 = dao.getAllForDomain(FixturesTool.STORAGE_DOMAIN_NFS2_2).get(0);
    assertNotSame("domain shouldn't be ovf updated prior to test", StorageDomainOvfInfoStatus.UPDATED, ovfInfo1.getStatus());
    dao.updateOvfUpdatedInfo(Arrays.asList(ovfInfo.getStorageDomainId(), ovfInfo1.getStorageDomainId()), StorageDomainOvfInfoStatus.UPDATED, StorageDomainOvfInfoStatus.DISABLED);
    ovfInfo = dao.get(ovfInfo.getOvfDiskId());
    ovfInfo1 = dao.get(ovfInfo1.getOvfDiskId());
    assertEquals(StorageDomainOvfInfoStatus.DISABLED, ovfInfo.getStatus());
    assertEquals(StorageDomainOvfInfoStatus.UPDATED, ovfInfo1.getStatus());
}
Also used : StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo) Test(org.junit.Test)

Example 13 with StorageDomainOvfInfo

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

the class StorageDomainOvfInfoDaoTest method loadStorageDomainIdsForOvfIds.

@Test
public void loadStorageDomainIdsForOvfIds() {
    StorageDomainOvfInfo ovfInfo = dao.get(getExistingEntityId());
    assertTrue("domain shouldn't have stored ovfs prior to test", ovfInfo.getStoredOvfIds().isEmpty());
    Guid ovfId1 = Guid.newGuid();
    Guid ovfId2 = Guid.newGuid();
    List<Guid> ovfIds = Arrays.asList(ovfId1, ovfId2);
    ovfInfo.setStoredOvfIds(ovfIds);
    dao.update(ovfInfo);
    ovfInfo = dao.get(ovfInfo.getOvfDiskId());
    assertEquals(ovfIds.size(), ovfInfo.getStoredOvfIds().size());
    assertTrue(ovfInfo.getStoredOvfIds().containsAll(ovfIds));
    List<Guid> loadedStorageDomainIds = dao.loadStorageDomainIdsForOvfIds(ovfIds);
    assertEquals(1, loadedStorageDomainIds.size());
    assertEquals(ovfInfo.getStorageDomainId(), loadedStorageDomainIds.get(0));
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) StorageDomainOvfInfo(org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo) Test(org.junit.Test)

Aggregations

StorageDomainOvfInfo (org.ovirt.engine.core.common.businessentities.StorageDomainOvfInfo)13 Guid (org.ovirt.engine.core.compat.Guid)7 Test (org.junit.Test)6 LinkedList (java.util.LinkedList)3 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)3 DiskImage (org.ovirt.engine.core.common.businessentities.storage.DiskImage)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)2 StoragePoolIsoMap (org.ovirt.engine.core.common.businessentities.StoragePoolIsoMap)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 Assert.assertEquals (org.junit.Assert.assertEquals)1