mirror of https://github.com/apache/cloudstack.git
Merge branch '4.22'
This commit is contained in:
commit
04b58acdd6
|
|
@ -30,6 +30,8 @@ public interface SnapshotDataFactory {
|
|||
|
||||
SnapshotInfo getSnapshot(long snapshotId, long storeId, DataStoreRole role);
|
||||
|
||||
SnapshotInfo getSnapshotIncludingRemoved(long snapshotId, long storeId, DataStoreRole role);
|
||||
|
||||
SnapshotInfo getSnapshotWithRoleAndZone(long snapshotId, DataStoreRole role, long zoneId);
|
||||
|
||||
SnapshotInfo getSnapshotOnPrimaryStore(long snapshotId);
|
||||
|
|
|
|||
|
|
@ -47,6 +47,8 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long>, StateDao<Snap
|
|||
|
||||
List<SnapshotVO> listAllByStatus(Snapshot.State... status);
|
||||
|
||||
List<SnapshotVO> listAllByStatusIncludingRemoved(Snapshot.State... status);
|
||||
|
||||
void updateVolumeIds(long oldVolId, long newVolId);
|
||||
|
||||
List<SnapshotVO> listByStatusNotIn(long volumeId, Snapshot.State... status);
|
||||
|
|
|
|||
|
|
@ -265,6 +265,13 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
|||
return listBy(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotVO> listAllByStatusIncludingRemoved(Snapshot.State... status) {
|
||||
SearchCriteria<SnapshotVO> sc = StatusSearch.create();
|
||||
sc.setParameters("status", (Object[])status);
|
||||
return listIncludingRemovedBy(sc, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotVO> listByIds(Object... ids) {
|
||||
SearchCriteria<SnapshotVO> sc = snapshotIdsSearch.create();
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements Usage
|
|||
private static final String DELETE_ALL = "DELETE FROM cloud_usage";
|
||||
private static final String DELETE_ALL_BY_ACCOUNTID = "DELETE FROM cloud_usage WHERE account_id = ?";
|
||||
private static final String DELETE_ALL_BY_INTERVAL = "DELETE FROM cloud_usage WHERE end_date < DATE_SUB(CURRENT_DATE(), INTERVAL ? DAY)";
|
||||
private static final String INSERT_ACCOUNT = "INSERT INTO cloud_usage.account (id, account_name, type, role_id, domain_id, removed, cleanup_needed) VALUES (?,?,?,?,?,?,?)";
|
||||
private static final String INSERT_ACCOUNT = "INSERT INTO cloud_usage.account (id, account_name, uuid, type, role_id, domain_id, removed, cleanup_needed) VALUES (?,?,?,?,?,?,?,?)";
|
||||
private static final String INSERT_USER_STATS = "INSERT INTO cloud_usage.user_statistics (id, data_center_id, account_id, public_ip_address, device_id, device_type, network_id, net_bytes_received,"
|
||||
+ " net_bytes_sent, current_bytes_received, current_bytes_sent, agg_bytes_received, agg_bytes_sent) VALUES (?,?,?,?,?,?,?,?,?,?, ?, ?, ?)";
|
||||
|
||||
|
|
@ -129,25 +129,26 @@ public class UsageDaoImpl extends GenericDaoBase<UsageVO, Long> implements Usage
|
|||
for (AccountVO acct : accounts) {
|
||||
pstmt.setLong(1, acct.getId());
|
||||
pstmt.setString(2, acct.getAccountName());
|
||||
pstmt.setInt(3, acct.getType().ordinal());
|
||||
pstmt.setString(3, acct.getUuid());
|
||||
pstmt.setInt(4, acct.getType().ordinal());
|
||||
|
||||
//prevent autoboxing NPE by defaulting to User role
|
||||
if(acct.getRoleId() == null){
|
||||
pstmt.setLong(4, RoleType.User.getId());
|
||||
pstmt.setLong(5, RoleType.User.getId());
|
||||
}else{
|
||||
pstmt.setLong(4, acct.getRoleId());
|
||||
pstmt.setLong(5, acct.getRoleId());
|
||||
}
|
||||
|
||||
pstmt.setLong(5, acct.getDomainId());
|
||||
pstmt.setLong(6, acct.getDomainId());
|
||||
|
||||
Date removed = acct.getRemoved();
|
||||
if (removed == null) {
|
||||
pstmt.setString(6, null);
|
||||
pstmt.setString(7, null);
|
||||
} else {
|
||||
pstmt.setString(6, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), acct.getRemoved()));
|
||||
pstmt.setString(7, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), acct.getRemoved()));
|
||||
}
|
||||
|
||||
pstmt.setBoolean(7, acct.getNeedsCleanup());
|
||||
pstmt.setBoolean(8, acct.getNeedsCleanup());
|
||||
|
||||
pstmt.addBatch();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
|
|||
|
||||
List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId);
|
||||
|
||||
List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snapshotId);
|
||||
|
||||
void duplicateCacheRecordsOnRegionStore(long storeId);
|
||||
|
||||
// delete the snapshot entry on primary data store to make sure that next snapshot will be full snapshot
|
||||
|
|
|
|||
|
|
@ -464,6 +464,13 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
|
|||
|
||||
@Override
|
||||
public List<SnapshotDataStoreVO> findBySnapshotId(long snapshotId) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = searchFilteringStoreIdEqStateEqStoreRoleEqIdEqUpdateCountEqSnapshotIdEqVolumeIdEq.create();
|
||||
sc.setParameters(SNAPSHOT_ID, snapshotId);
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotDataStoreVO> findBySnapshotIdWithNonDestroyedState(long snapshotId) {
|
||||
SearchCriteria<SnapshotDataStoreVO> sc = idStateNinSearch.create();
|
||||
sc.setParameters(SNAPSHOT_ID, snapshotId);
|
||||
sc.setParameters(STATE, State.Destroyed.name());
|
||||
|
|
|
|||
|
|
@ -303,7 +303,7 @@ public class DefaultSnapshotStrategy extends SnapshotStrategyBase {
|
|||
}
|
||||
|
||||
if (Snapshot.State.Error.equals(snapshotVO.getState())) {
|
||||
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
List<Long> deletedRefs = new ArrayList<>();
|
||||
for (SnapshotDataStoreVO ref : storeRefs) {
|
||||
boolean refZoneIdMatch = false;
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
|
|||
if (snapshot == null) { //snapshot may have been removed;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<SnapshotDataStoreVO> allSnapshotsAndDataStore = snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> allSnapshotsAndDataStore = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
if (CollectionUtils.isEmpty(allSnapshotsAndDataStore)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
|
@ -118,7 +118,23 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
|
|||
if (snapshot == null) {
|
||||
return null;
|
||||
}
|
||||
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(role, storeId, snapshotId);
|
||||
return getSnapshotOnStore(snapshot, storeId, role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotInfo getSnapshotIncludingRemoved(long snapshotId, long storeId, DataStoreRole role) {
|
||||
SnapshotVO snapshot = snapshotDao.findByIdIncludingRemoved(snapshotId);
|
||||
if (snapshot == null) {
|
||||
return null;
|
||||
}
|
||||
return getSnapshotOnStore(snapshot, storeId, role);
|
||||
}
|
||||
|
||||
private SnapshotInfo getSnapshotOnStore(SnapshotVO snapshot, long storeId, DataStoreRole role) {
|
||||
if (snapshot == null) {
|
||||
return null;
|
||||
}
|
||||
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(role, storeId, snapshot.getId());
|
||||
if (snapshotStore == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -207,7 +223,7 @@ public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
|
|||
|
||||
@Override
|
||||
public void updateOperationFailed(long snapshotId) throws NoTransitionException {
|
||||
List<SnapshotDataStoreVO> snapshotStoreRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> snapshotStoreRefs = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
for (SnapshotDataStoreVO snapshotStoreRef : snapshotStoreRefs) {
|
||||
SnapshotInfo snapshotInfo = getSnapshot(snapshotStoreRef.getSnapshotId(), snapshotStoreRef.getDataStoreId(), snapshotStoreRef.getRole());
|
||||
if (snapshotInfo != null) {
|
||||
|
|
|
|||
|
|
@ -474,8 +474,7 @@ public class SnapshotServiceImpl implements SnapshotService {
|
|||
if (res.isFailed()) {
|
||||
throw new CloudRuntimeException(res.getResult());
|
||||
}
|
||||
SnapshotInfo destSnapshot = res.getSnapshot();
|
||||
return destSnapshot;
|
||||
return res.getSnapshot();
|
||||
} catch (InterruptedException e) {
|
||||
logger.debug("failed copy snapshot", e);
|
||||
throw new CloudRuntimeException("Failed to copy snapshot", e);
|
||||
|
|
@ -483,7 +482,6 @@ public class SnapshotServiceImpl implements SnapshotService {
|
|||
logger.debug("Failed to copy snapshot", e);
|
||||
throw new CloudRuntimeException("Failed to copy snapshot", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Void copySnapshotAsyncCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, CopySnapshotContext<CommandResult> context) {
|
||||
|
|
@ -571,7 +569,6 @@ public class SnapshotServiceImpl implements SnapshotService {
|
|||
}
|
||||
|
||||
protected Void deleteSnapshotCallback(AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback, DeleteSnapshotContext<CommandResult> context) {
|
||||
|
||||
CommandResult result = callback.getResult();
|
||||
AsyncCallFuture<SnapshotResult> future = context.future;
|
||||
SnapshotInfo snapshot = context.snapshot;
|
||||
|
|
@ -729,7 +726,7 @@ public class SnapshotServiceImpl implements SnapshotService {
|
|||
|
||||
if (snapshot != null) {
|
||||
if (snapshot.getState() != Snapshot.State.BackedUp) {
|
||||
List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) {
|
||||
logger.debug("Remove snapshot {}, status {} on snapshot_store_ref table with id: {}", snapshot, snapshotDataStoreVO.getState(), snapshotDataStoreVO.getId());
|
||||
|
||||
|
|
@ -834,7 +831,6 @@ public class SnapshotServiceImpl implements SnapshotService {
|
|||
SnapshotObject srcSnapshot = (SnapshotObject)snapshot;
|
||||
srcSnapshot.processEvent(Event.DestroyRequested);
|
||||
srcSnapshot.processEvent(Event.OperationSucceeded);
|
||||
|
||||
srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
|
||||
|
||||
_snapshotDetailsDao.removeDetail(srcSnapshot.getId(), AsyncJob.Constants.MS_ID);
|
||||
|
|
@ -845,7 +841,6 @@ public class SnapshotServiceImpl implements SnapshotService {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -541,7 +541,6 @@ public class StorageSystemSnapshotStrategy extends SnapshotStrategyBase {
|
|||
logger.warn("Failed to clean up snapshot '" + snapshot.getId() + "' on primary storage: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private VMSnapshot takeHypervisorSnapshot(VolumeInfo volumeInfo) {
|
||||
|
|
|
|||
|
|
@ -109,6 +109,9 @@ public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {
|
|||
stateMachines.addTransition(State.Destroying, Event.DestroyRequested, State.Destroying);
|
||||
stateMachines.addTransition(State.Destroying, Event.OperationSucceeded, State.Destroyed);
|
||||
stateMachines.addTransition(State.Destroying, Event.OperationFailed, State.Destroying);
|
||||
stateMachines.addTransition(State.Destroyed, Event.DestroyRequested, State.Destroyed);
|
||||
stateMachines.addTransition(State.Destroyed, Event.OperationSucceeded, State.Destroyed);
|
||||
stateMachines.addTransition(State.Destroyed, Event.OperationFailed, State.Destroyed);
|
||||
stateMachines.addTransition(State.Failed, Event.DestroyRequested, State.Destroying);
|
||||
// TODO: further investigate why an extra event is sent when it is
|
||||
// already Ready for DownloadListener
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class StorPoolHelper {
|
|||
if (snapshotDetails != null) {
|
||||
return StorPoolStorageAdaptor.getVolumeNameFromPath(snapshotDetails.getValue(), true);
|
||||
} else {
|
||||
List<SnapshotDataStoreVO> snapshots = snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> snapshots = snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
if (!CollectionUtils.isEmpty(snapshots)) {
|
||||
for (SnapshotDataStoreVO snapshotDataStoreVO : snapshots) {
|
||||
String name = StorPoolStorageAdaptor.getVolumeNameFromPath(snapshotDataStoreVO.getInstallPath(), true);
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ public class StorPoolSnapshotStrategy implements SnapshotStrategy {
|
|||
}
|
||||
|
||||
protected boolean areLastSnapshotRef(long snapshotId) {
|
||||
List<SnapshotDataStoreVO> snapshotStoreRefs = _snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> snapshotStoreRefs = _snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
if (CollectionUtils.isEmpty(snapshotStoreRefs) || snapshotStoreRefs.size() == 1) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -343,7 +343,7 @@ public class StorPoolSnapshotStrategy implements SnapshotStrategy {
|
|||
}
|
||||
|
||||
if (Snapshot.State.Error.equals(snapshotVO.getState())) {
|
||||
List<SnapshotDataStoreVO> storeRefs = _snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> storeRefs = _snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
List<Long> deletedRefs = new ArrayList<>();
|
||||
for (SnapshotDataStoreVO ref : storeRefs) {
|
||||
boolean refZoneIdMatch = false;
|
||||
|
|
|
|||
|
|
@ -2110,41 +2110,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
}
|
||||
}
|
||||
|
||||
//destroy snapshots in destroying state in snapshot_store_ref
|
||||
List<SnapshotDataStoreVO> ssSnapshots = _snapshotStoreDao.listByState(ObjectInDataStoreStateMachine.State.Destroying);
|
||||
for (SnapshotDataStoreVO snapshotDataStoreVO : ssSnapshots) {
|
||||
String snapshotUuid = null;
|
||||
SnapshotVO snapshot = null;
|
||||
final String storeRole = snapshotDataStoreVO.getRole().toString().toLowerCase();
|
||||
if (logger.isDebugEnabled()) {
|
||||
snapshot = _snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
|
||||
if (snapshot == null) {
|
||||
logger.warn(String.format("Did not find snapshot [ID: %d] for which store reference is in destroying state; therefore, it cannot be destroyed.", snapshotDataStoreVO.getSnapshotId()));
|
||||
continue;
|
||||
}
|
||||
snapshotUuid = snapshot.getUuid();
|
||||
}
|
||||
|
||||
try {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Verifying if snapshot [%s] is in destroying state in %s data store ID: %d.", snapshotUuid, storeRole, snapshotDataStoreVO.getDataStoreId()));
|
||||
}
|
||||
SnapshotInfo snapshotInfo = snapshotFactory.getSnapshot(snapshotDataStoreVO.getSnapshotId(), snapshotDataStoreVO.getDataStoreId(), snapshotDataStoreVO.getRole());
|
||||
if (snapshotInfo != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Snapshot [%s] in destroying state found in %s data store [%s]; therefore, it will be destroyed.", snapshotUuid, storeRole, snapshotInfo.getDataStore().getUuid()));
|
||||
}
|
||||
_snapshotService.deleteSnapshot(snapshotInfo);
|
||||
} else if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Did not find snapshot [%s] in destroying state in %s data store ID: %d.", snapshotUuid, storeRole, snapshotDataStoreVO.getDataStoreId()));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to delete snapshot [{}] from storage due to: [{}].", snapshot, e.getMessage());
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to delete snapshot [{}] from storage.", snapshot, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
cleanupSnapshotsFromStoreRefInDestroyingState();
|
||||
cleanupSecondaryStorage(recurring);
|
||||
|
||||
List<VolumeVO> vols = volumeDao.listVolumesToBeDestroyed(new Date(System.currentTimeMillis() - ((long)StorageCleanupDelay.value() << 10)));
|
||||
|
|
@ -2184,20 +2150,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
}
|
||||
}
|
||||
|
||||
// remove snapshots in Error state
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listAllByStatus(Snapshot.State.Error);
|
||||
for (SnapshotVO snapshotVO : snapshots) {
|
||||
try {
|
||||
List<SnapshotDataStoreVO> storeRefs = _snapshotStoreDao.findBySnapshotId(snapshotVO.getId());
|
||||
for (SnapshotDataStoreVO ref : storeRefs) {
|
||||
_snapshotStoreDao.expunge(ref.getId());
|
||||
}
|
||||
_snapshotDao.expunge(snapshotVO.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to destroy snapshot [{}] due to: [{}].", snapshotVO, e.getMessage());
|
||||
logger.debug("Unable to destroy snapshot [{}].", snapshotVO, e);
|
||||
}
|
||||
}
|
||||
removeSnapshotsInErrorStatus();
|
||||
|
||||
// destroy uploaded volumes in abandoned/error state
|
||||
List<VolumeDataStoreVO> volumeDataStores = _volumeDataStoreDao.listByVolumeState(Volume.State.UploadError, Volume.State.UploadAbandoned);
|
||||
|
|
@ -2298,6 +2251,56 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
|
|||
}
|
||||
}
|
||||
|
||||
private void cleanupSnapshotsFromStoreRefInDestroyingState() {
|
||||
List<SnapshotDataStoreVO> storeRefSnapshotsInDestroyingState = _snapshotStoreDao.listByState(ObjectInDataStoreStateMachine.State.Destroying);
|
||||
for (SnapshotDataStoreVO snapshotDataStoreVO : storeRefSnapshotsInDestroyingState) {
|
||||
SnapshotVO snapshot = _snapshotDao.findById(snapshotDataStoreVO.getSnapshotId());
|
||||
if (snapshot == null) {
|
||||
logger.warn("Did not find snapshot [ID: {}] for which store reference is in destroying state; therefore, it cannot be destroyed.", snapshotDataStoreVO.getSnapshotId());
|
||||
continue;
|
||||
}
|
||||
deleteSnapshot(snapshot, snapshotDataStoreVO);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteSnapshot(SnapshotVO snapshot, SnapshotDataStoreVO snapshotDataStoreVO) {
|
||||
if (snapshot == null || snapshotDataStoreVO == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final String snapshotUuid = snapshot.getUuid();
|
||||
final String storeRole = snapshotDataStoreVO.getRole().toString().toLowerCase();
|
||||
logger.debug("Snapshot [{}] is in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());
|
||||
SnapshotInfo snapshotInfo = snapshotFactory.getSnapshotIncludingRemoved(snapshotDataStoreVO.getSnapshotId(), snapshotDataStoreVO.getDataStoreId(), snapshotDataStoreVO.getRole());
|
||||
if (snapshotInfo != null) {
|
||||
logger.debug("Snapshot [{}] in {} state found on {} data store [{}], it will be deleted.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotInfo.getDataStore().getUuid());
|
||||
_snapshotService.deleteSnapshot(snapshotInfo);
|
||||
} else {
|
||||
logger.debug("Did not find snapshot [{}] in {} state on {} data store ID: {}.", snapshotUuid, snapshotDataStoreVO.getState(), storeRole, snapshotDataStoreVO.getDataStoreId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to delete snapshot [{}] from storage due to: [{}].", snapshot, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeSnapshotsInErrorStatus() {
|
||||
List<SnapshotVO> snapshotsInErrorStatus = _snapshotDao.listAllByStatusIncludingRemoved(Snapshot.State.Error);
|
||||
for (SnapshotVO snapshotVO : snapshotsInErrorStatus) {
|
||||
try {
|
||||
List<SnapshotDataStoreVO> storeRefSnapshotsInErrorStatus = _snapshotStoreDao.findBySnapshotId(snapshotVO.getId());
|
||||
for (SnapshotDataStoreVO snapshotDataStoreVO : storeRefSnapshotsInErrorStatus) {
|
||||
deleteSnapshot(snapshotVO, snapshotDataStoreVO);
|
||||
_snapshotStoreDao.expunge(snapshotDataStoreVO.getId());
|
||||
}
|
||||
_snapshotDao.expunge(snapshotVO.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error("Unable to destroy snapshot [{}] due to: [{}].", snapshotVO, e.getMessage());
|
||||
logger.debug("Unable to destroy snapshot [{}].", snapshotVO, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isVolumeSuspectedDestroyDuplicateOfVmVolume(VolumeVO gcVolume) {
|
||||
if (gcVolume.getPath() == null) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -843,7 +843,7 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
|
|||
|
||||
protected Pair<List<SnapshotDataStoreVO>, List<Long>> getStoreRefsAndZonesForSnapshotDelete(long snapshotId, Long zoneId) {
|
||||
List<SnapshotDataStoreVO> snapshotStoreRefs = new ArrayList<>();
|
||||
List<SnapshotDataStoreVO> allSnapshotStoreRefs = _snapshotStoreDao.findBySnapshotId(snapshotId);
|
||||
List<SnapshotDataStoreVO> allSnapshotStoreRefs = _snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId);
|
||||
List<Long> zoneIds = new ArrayList<>();
|
||||
if (zoneId != null) {
|
||||
DataCenterVO zone = dataCenterDao.findById(zoneId);
|
||||
|
|
@ -1782,23 +1782,23 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
|
|||
if (asyncBackup) {
|
||||
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, snapshotBackupRetries - 1, snapshotStrategy, zoneIds, poolIds), 0, TimeUnit.SECONDS);
|
||||
} else {
|
||||
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
|
||||
if (backupedSnapshot != null) {
|
||||
SnapshotInfo backedUpSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
|
||||
if (backedUpSnapshot != null) {
|
||||
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class BackupSnapshotTask extends ManagedContextRunnable {
|
||||
SnapshotInfo snapshot;
|
||||
SnapshotInfo snapshotOnPrimary;
|
||||
int attempts;
|
||||
SnapshotStrategy snapshotStrategy;
|
||||
|
||||
List<Long> zoneIds;
|
||||
List<Long> poolIds;
|
||||
|
||||
public BackupSnapshotTask(SnapshotInfo snap, int maxRetries, SnapshotStrategy strategy, List<Long> zoneIds, List<Long> poolIds) {
|
||||
snapshot = snap;
|
||||
public BackupSnapshotTask(SnapshotInfo snapshot, int maxRetries, SnapshotStrategy strategy, List<Long> zoneIds, List<Long> poolIds) {
|
||||
snapshotOnPrimary = snapshot;
|
||||
attempts = maxRetries;
|
||||
snapshotStrategy = strategy;
|
||||
this.zoneIds = zoneIds;
|
||||
|
|
@ -1810,17 +1810,16 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
|
|||
try {
|
||||
logger.debug("Value of attempts is " + (snapshotBackupRetries - attempts));
|
||||
if (Boolean.TRUE.equals(SnapshotInfo.BackupSnapshotAfterTakingSnapshot.value()) && CollectionUtils.isEmpty(poolIds)) {
|
||||
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshot);
|
||||
|
||||
SnapshotInfo backupedSnapshot = snapshotStrategy.backupSnapshot(snapshotOnPrimary);
|
||||
if (backupedSnapshot != null) {
|
||||
snapshotStrategy.postSnapshotCreation(snapshot);
|
||||
copyNewSnapshotToZones(snapshot.getId(), snapshot.getDataCenterId(), zoneIds);
|
||||
snapshotStrategy.postSnapshotCreation(snapshotOnPrimary);
|
||||
copyNewSnapshotToZones(snapshotOnPrimary.getId(), snapshotOnPrimary.getDataCenterId(), zoneIds);
|
||||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(poolIds)) {
|
||||
for (Long poolId: poolIds) {
|
||||
copySnapshotOnPool(snapshot, snapshotStrategy, poolId);
|
||||
copySnapshotOnPool(snapshotOnPrimary, snapshotStrategy, poolId);
|
||||
}
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
|
|
@ -1830,11 +1829,11 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
|
|||
|
||||
private void decriseBackupSnapshotAttempts() {
|
||||
if (attempts >= 0) {
|
||||
logger.debug("Backing up of snapshot failed, for snapshot {}, left with {} more attempts", snapshot, attempts);
|
||||
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshot, --attempts, snapshotStrategy, zoneIds, poolIds), snapshotBackupRetryInterval, TimeUnit.SECONDS);
|
||||
logger.debug("Backing up of snapshot failed, for snapshot {}, left with {} more attempts", snapshotOnPrimary, attempts);
|
||||
backupSnapshotExecutor.schedule(new BackupSnapshotTask(snapshotOnPrimary, --attempts, snapshotStrategy, zoneIds, poolIds), snapshotBackupRetryInterval, TimeUnit.SECONDS);
|
||||
} else {
|
||||
logger.debug("Done with {} attempts in backing up of snapshot {}", snapshotBackupRetries, snapshot.getSnapshotVO());
|
||||
snapshotSrv.cleanupOnSnapshotBackupFailure(snapshot);
|
||||
logger.debug("Done with {} attempts in backing up of snapshot {}", snapshotBackupRetries, snapshotOnPrimary.getSnapshotVO());
|
||||
snapshotSrv.cleanupOnSnapshotBackupFailure(snapshotOnPrimary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2058,7 +2057,7 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
|
|||
public void markVolumeSnapshotsAsDestroyed(Volume volume) {
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listByVolumeId(volume.getId());
|
||||
for (SnapshotVO snapshot: snapshots) {
|
||||
List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshot.getId());
|
||||
List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshot.getId());
|
||||
if (CollectionUtils.isEmpty(snapshotDataStoreVOs)) {
|
||||
snapshot.setState(Snapshot.State.Destroyed);
|
||||
_snapshotDao.update(snapshot.getId(), snapshot);
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ public class SnapshotManagerImplTest {
|
|||
Mockito.when(ref1.getDataStoreId()).thenReturn(2L);
|
||||
Mockito.when(ref1.getRole()).thenReturn(DataStoreRole.Image);
|
||||
List<SnapshotDataStoreVO> snapshotStoreList = List.of(ref, ref1);
|
||||
Mockito.when(snapshotStoreDao.findBySnapshotId(snapshotId)).thenReturn(snapshotStoreList);
|
||||
Mockito.when(snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId)).thenReturn(snapshotStoreList);
|
||||
Mockito.when(dataStoreManager.getStoreZoneId(1L, DataStoreRole.Image)).thenReturn(100L);
|
||||
Mockito.when(dataStoreManager.getStoreZoneId(2L, DataStoreRole.Image)).thenReturn(101L);
|
||||
Pair<List<SnapshotDataStoreVO>, List<Long>> pair = snapshotManager.getStoreRefsAndZonesForSnapshotDelete(snapshotId, null);
|
||||
|
|
@ -189,7 +189,7 @@ public class SnapshotManagerImplTest {
|
|||
Mockito.when(ref2.getDataStoreId()).thenReturn(3L);
|
||||
Mockito.when(ref2.getRole()).thenReturn(DataStoreRole.Image);
|
||||
List<SnapshotDataStoreVO> snapshotStoreList = List.of(ref, ref1, ref2);
|
||||
Mockito.when(snapshotStoreDao.findBySnapshotId(snapshotId)).thenReturn(snapshotStoreList);
|
||||
Mockito.when(snapshotStoreDao.findBySnapshotIdWithNonDestroyedState(snapshotId)).thenReturn(snapshotStoreList);
|
||||
Mockito.when(dataStoreManager.getStoreZoneId(1L, DataStoreRole.Image)).thenReturn(zoneId);
|
||||
Mockito.when(dataStoreManager.getStoreZoneId(2L, DataStoreRole.Primary)).thenReturn(zoneId);
|
||||
Mockito.when(dataStoreManager.getStoreZoneId(3L, DataStoreRole.Image)).thenReturn(2L);
|
||||
|
|
|
|||
|
|
@ -2621,7 +2621,9 @@ export default {
|
|||
this.owner.domainid = null
|
||||
this.owner.projectid = OwnerOptions.selectedProject
|
||||
}
|
||||
if (OwnerOptions.initialized) {
|
||||
this.resetData()
|
||||
}
|
||||
},
|
||||
fetchZones (zoneId, listZoneAllow) {
|
||||
this.zones = []
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
<a-form layout="vertical" >
|
||||
<a-form-item :label="$t('label.owner.type')">
|
||||
<a-select
|
||||
@change="changeDomain"
|
||||
@change="changeAccountTypeOrDomain"
|
||||
v-model:value="selectedAccountType"
|
||||
defaultValue="account"
|
||||
autoFocus
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
</a-form-item>
|
||||
<a-form-item :label="$t('label.domain')" required>
|
||||
<a-select
|
||||
@change="changeDomain"
|
||||
@change="changeAccountTypeOrDomain"
|
||||
v-model:value="selectedDomain"
|
||||
showSearch
|
||||
optionFilterProp="label"
|
||||
|
|
@ -136,6 +136,7 @@ export default {
|
|||
components: { ResourceIcon },
|
||||
data () {
|
||||
return {
|
||||
initialized: false,
|
||||
domains: [],
|
||||
accounts: [],
|
||||
projects: [],
|
||||
|
|
@ -143,7 +144,8 @@ export default {
|
|||
selectedDomain: null,
|
||||
selectedAccount: null,
|
||||
selectedProject: null,
|
||||
loading: false
|
||||
loading: false,
|
||||
requestToken: 0
|
||||
}
|
||||
},
|
||||
props: {
|
||||
|
|
@ -177,7 +179,7 @@ export default {
|
|||
const domainIds = this.domains?.map(domain => domain.id)
|
||||
const ownerDomainId = this.$store.getters.project?.domainid || this.$store.getters.userInfo.domainid
|
||||
this.selectedDomain = domainIds?.includes(ownerDomainId) ? ownerDomainId : this.domains?.[0]?.id
|
||||
this.changeDomain()
|
||||
this.fetchOwnerData()
|
||||
})
|
||||
.catch((error) => {
|
||||
this.$notifyError(error)
|
||||
|
|
@ -186,8 +188,13 @@ export default {
|
|||
this.loading = false
|
||||
})
|
||||
},
|
||||
incrementAndGetRequestToken () {
|
||||
this.requestToken += 1
|
||||
return this.requestToken
|
||||
},
|
||||
fetchAccounts () {
|
||||
this.loading = true
|
||||
const currentToken = this.incrementAndGetRequestToken()
|
||||
getAPI('listAccounts', {
|
||||
response: 'json',
|
||||
domainId: this.selectedDomain,
|
||||
|
|
@ -196,6 +203,9 @@ export default {
|
|||
isrecursive: false
|
||||
})
|
||||
.then((response) => {
|
||||
if (currentToken !== this.requestToken) {
|
||||
return
|
||||
}
|
||||
this.accounts = response.listaccountsresponse.account || []
|
||||
if (this.override?.accounts && this.accounts) {
|
||||
this.accounts = this.accounts.filter(item => this.override.accounts.has(item.name))
|
||||
|
|
@ -214,10 +224,12 @@ export default {
|
|||
})
|
||||
.finally(() => {
|
||||
this.loading = false
|
||||
this.initialized = true
|
||||
})
|
||||
},
|
||||
fetchProjects () {
|
||||
this.loading = true
|
||||
const currentToken = this.incrementAndGetRequestToken()
|
||||
getAPI('listProjects', {
|
||||
response: 'json',
|
||||
domainId: this.selectedDomain,
|
||||
|
|
@ -227,6 +239,9 @@ export default {
|
|||
isrecursive: false
|
||||
})
|
||||
.then((response) => {
|
||||
if (currentToken !== this.requestToken) {
|
||||
return
|
||||
}
|
||||
this.projects = response.listprojectsresponse.project
|
||||
if (this.override?.projects && this.projects) {
|
||||
this.projects = this.projects.filter(item => this.override.projects.has(item.id))
|
||||
|
|
@ -240,9 +255,14 @@ export default {
|
|||
})
|
||||
.finally(() => {
|
||||
this.loading = false
|
||||
this.initialized = true
|
||||
})
|
||||
},
|
||||
changeDomain () {
|
||||
changeAccountTypeOrDomain () {
|
||||
this.initialized = true
|
||||
this.fetchOwnerData()
|
||||
},
|
||||
fetchOwnerData () {
|
||||
if (this.selectedAccountType === 'Account') {
|
||||
this.fetchAccounts()
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ export default {
|
|||
this.owner.domainid = null
|
||||
this.owner.projectid = OwnerOptions.selectedProject
|
||||
}
|
||||
if (isAdminOrDomainAdmin()) {
|
||||
if (OwnerOptions.initialized && isAdminOrDomainAdmin()) {
|
||||
this.updateVPCCheckAndFetchNetworkOfferingData()
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ export default {
|
|||
this.owner.domainid = null
|
||||
this.owner.projectid = OwnerOptions.selectedProject
|
||||
}
|
||||
if (isAdminOrDomainAdmin()) {
|
||||
if (OwnerOptions.initialized && this.isAdminOrDomainAdmin()) {
|
||||
this.updateVPCCheckAndFetchNetworkOfferingData()
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -272,23 +272,21 @@ export default {
|
|||
},
|
||||
fetchOwnerOptions (OwnerOptions) {
|
||||
this.owner = {}
|
||||
console.log('fetching owner')
|
||||
if (OwnerOptions.selectedAccountType === 'Account') {
|
||||
if (!OwnerOptions.selectedAccount) {
|
||||
return
|
||||
}
|
||||
console.log('fetched account')
|
||||
this.owner.account = OwnerOptions.selectedAccount
|
||||
this.owner.domainid = OwnerOptions.selectedDomain
|
||||
} else if (OwnerOptions.selectedAccountType === 'Project') {
|
||||
if (!OwnerOptions.selectedProject) {
|
||||
return
|
||||
}
|
||||
console.log('fetched project')
|
||||
this.owner.projectid = OwnerOptions.selectedProject
|
||||
}
|
||||
console.log('fetched owner')
|
||||
if (OwnerOptions.initialized) {
|
||||
this.fetchData()
|
||||
}
|
||||
},
|
||||
fetchData () {
|
||||
this.minCpu = store.getters.features.sharedfsvmmincpucount
|
||||
|
|
|
|||
|
|
@ -272,7 +272,9 @@ export default {
|
|||
}
|
||||
this.owner.projectid = OwnerOptions.selectedProject
|
||||
}
|
||||
if (OwnerOptions.initialized) {
|
||||
this.fetchData()
|
||||
}
|
||||
},
|
||||
fetchData () {
|
||||
if (this.createVolumeFromSnapshot) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue