Search in sources :

Example 11 with GlusterVolumeSnapshotEntity

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

the class GlusterVolumeSnapshotDaoTest method testGetByName.

@Test
public void testGetByName() {
    newSnapshot = insertTestSnapshot();
    GlusterVolumeSnapshotEntity snapshot = dao.getByName(VOLUME_ID, NEW_SNAPSHOT_NAME);
    assertNotNull(snapshot);
    assertEquals(newSnapshot, snapshot);
}
Also used : GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) Test(org.junit.Test)

Example 12 with GlusterVolumeSnapshotEntity

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

the class GlusterSnapshotSyncJobTest method getSnapshotDetails.

private List<GlusterVolumeSnapshotEntity> getSnapshotDetails() {
    List<GlusterVolumeSnapshotEntity> snapshots = new ArrayList<>();
    GlusterVolumeSnapshotEntity snap1 = new GlusterVolumeSnapshotEntity();
    snap1.setClusterId(CLUSTER_ID_1);
    snap1.setCreatedAt(existingSnapsCreateDate);
    snap1.setDescription("");
    snap1.setId(existingSnapshotIds[0]);
    snap1.setSnapshotName(existingSnapshotNames[0]);
    snap1.setStatus(GlusterSnapshotStatus.DEACTIVATED);
    snap1.setVolumeId(VOLUME_ID_1);
    snapshots.add(snap1);
    GlusterVolumeSnapshotEntity snap2 = new GlusterVolumeSnapshotEntity();
    snap2.setClusterId(CLUSTER_ID_1);
    snap2.setCreatedAt(new Date());
    snap2.setDescription("");
    snap2.setId(newSnapshotId);
    snap2.setSnapshotName(newSnapshotName);
    snap2.setStatus(GlusterSnapshotStatus.ACTIVATED);
    snap2.setVolumeId(VOLUME_ID_1);
    snapshots.add(snap2);
    return snapshots;
}
Also used : GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) ArrayList(java.util.ArrayList) Date(java.util.Date)

Example 13 with GlusterVolumeSnapshotEntity

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

the class GlusterVolumeSnapshotInfoReturn method prepareVolumeSnapshotsList.

private List<GlusterVolumeSnapshotEntity> prepareVolumeSnapshotsList(Guid clusterId, Map<String, Object> snapshots) {
    List<GlusterVolumeSnapshotEntity> newSnapshotsList = new ArrayList<>();
    for (Map.Entry<String, Object> entry : snapshots.entrySet()) {
        String volumeName = entry.getKey();
        Map<String, Object> snapshotInfo = (Map<String, Object>) entry.getValue();
        Object[] volumeSnapshots = (Object[]) snapshotInfo.get(SNAPSHOTS);
        GlusterVolumeEntity volumeEntity = getGlusterVolumeDao().getByName(clusterId, volumeName);
        for (Object snapshot : volumeSnapshots) {
            Map<String, Object> individualSnapshot = (Map<String, Object>) snapshot;
            GlusterVolumeSnapshotEntity newSnapshot = new GlusterVolumeSnapshotEntity();
            newSnapshot.setClusterId(clusterId);
            newSnapshot.setVolumeId(volumeEntity.getId());
            newSnapshot.setSnapshotId(Guid.createGuidFromString((String) individualSnapshot.get(SNAPSHOT_ID)));
            newSnapshot.setSnapshotName((String) individualSnapshot.get(NAME));
            newSnapshot.setDescription((String) individualSnapshot.get(DESCRIPTION));
            newSnapshot.setStatus(GlusterSnapshotStatus.from((String) individualSnapshot.get(SNAP_VOLUME_STATUS)));
            try {
                Map<String, Object> createTimeDetail = (Map<String, Object>) individualSnapshot.get(CREATETIME);
                long millis = (Integer) createTimeDetail.get(EPOCH_TIME) * 1000L;
                Date createDate = new Date(millis);
                // Convert to UTC
                DateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
                format.setTimeZone(TimeZone.getTimeZone("Etc/UTC"));
                String formattedCreateDate = format.format(createDate);
                newSnapshot.setCreatedAt(new Date(formattedCreateDate));
            } catch (Exception e) {
                log.info("Could not populate creation time for snapshot '{}' of volume '{}' on cluster '{}': {}", snapshotInfo.get(NAME), volumeEntity.getName(), clusterId, e.getMessage());
                log.debug("Exception", e);
            }
            newSnapshotsList.add(newSnapshot);
        }
    }
    return newSnapshotsList;
}
Also used : GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) ArrayList(java.util.ArrayList) Date(java.util.Date) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Map(java.util.Map) SimpleDateFormat(java.text.SimpleDateFormat)

Example 14 with GlusterVolumeSnapshotEntity

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

the class GlusterVolumeSnapshotDaoTest method testRemoveMultiple.

@Test
public void testRemoveMultiple() {
    List<Guid> idsToRemove = new ArrayList<>();
    idsToRemove.add(EXISTING_SNAPSHOT_ID);
    idsToRemove.add(EXISTING_SNAPSHOT_ID_1);
    GlusterVolumeEntity volume = volumeDao.getById(VOLUME_ID);
    assertEquals(2, volume.getSnapshotsCount().intValue());
    dao.removeAll(idsToRemove);
    List<GlusterVolumeSnapshotEntity> snapshots = dao.getAllByVolumeId(VOLUME_ID);
    assertTrue(snapshots.isEmpty());
    GlusterVolumeEntity volume1 = volumeDao.getById(VOLUME_ID);
    assertEquals(0, volume1.getSnapshotsCount().intValue());
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) Test(org.junit.Test)

Example 15 with GlusterVolumeSnapshotEntity

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

the class GlusterVolumeSnapshotDaoTest method testUpdateAllInBatch.

@Test
public void testUpdateAllInBatch() {
    existingSnapshot = dao.getById(EXISTING_SNAPSHOT_ID);
    existingSnapshot1 = dao.getById(EXISTING_SNAPSHOT_ID_1);
    existingSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
    existingSnapshot1.setStatus(GlusterSnapshotStatus.DEACTIVATED);
    List<GlusterVolumeSnapshotEntity> snapshots = new ArrayList<>();
    snapshots.add(existingSnapshot);
    snapshots.add(existingSnapshot1);
    dao.updateAllInBatch(snapshots);
    GlusterVolumeSnapshotEntity tmpSnapshot = dao.getById(EXISTING_SNAPSHOT_ID);
    GlusterVolumeSnapshotEntity tmpSnapshot1 = dao.getById(EXISTING_SNAPSHOT_ID_1);
    assertEquals(GlusterSnapshotStatus.DEACTIVATED, tmpSnapshot.getStatus());
    assertEquals(GlusterSnapshotStatus.DEACTIVATED, tmpSnapshot1.getStatus());
}
Also used : GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

GlusterVolumeSnapshotEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity)25 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)12 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 Guid (org.ovirt.engine.core.compat.Guid)6 Date (java.util.Date)5 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)4 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)4 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)3 VDS (org.ovirt.engine.core.common.businessentities.VDS)3 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)3 HashMap (java.util.HashMap)2 CreateGlusterVolumeSnapshotParameters (org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters)2 GlusterVolumeGeoRepSessionParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters)2 CreateGlusterVolumeSnapshotVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeSnapshotVDSParameters)2 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)2 DateTimeFormat (com.google.gwt.i18n.client.DateTimeFormat)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Map (java.util.Map)1