mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Merge pull request #1697 from myENA/feature/49_observe_snapshot_backup_rightafter
CLOUDSTACK-4858 Honors the snapshot.backup.rightafter configuration variable Unhides snapshot.backup.rightafter from global configuration If snapshot.backup.rightafter is set to false (defaults to true), snapshots are not backed up to secondary storage. This is the same as PR #1644 applied to 4.9, as per @jburwell * pr/1697: CLOUDSTACK-4858 Honors the snapshot.backup.rightafter configuration variable Unhides snapshot.backup.rightafter from global configuration Signed-off-by: Rajani Karuturi <rajani.karuturi@accelerite.com>
This commit is contained in:
commit
c101817d45
@ -44,7 +44,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotService;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
@ -178,6 +181,8 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
||||
ClusterManager clusterManager;
|
||||
@Inject
|
||||
StorageManager storageMgr;
|
||||
@Inject
|
||||
StorageStrategyFactory _storageStrategyFactory;
|
||||
|
||||
private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
|
||||
protected List<StoragePoolAllocator> _storagePoolAllocators;
|
||||
@ -383,6 +388,24 @@ public class VolumeOrchestrator extends ManagerBase implements VolumeOrchestrati
|
||||
DataStoreRole dataStoreRole = getDataStoreRole(snapshot);
|
||||
SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
|
||||
|
||||
|
||||
if(snapInfo == null && dataStoreRole == DataStoreRole.Image) {
|
||||
// snapshot is not backed up to secondary, let's do that now.
|
||||
snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
|
||||
|
||||
if (snapInfo == null) {
|
||||
throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId());
|
||||
}
|
||||
// We need to copy the snapshot onto secondary.
|
||||
SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.BACKUP);
|
||||
snapshotStrategy.backupSnapshot(snapInfo);
|
||||
|
||||
// Attempt to grab it again.
|
||||
snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole);
|
||||
if (snapInfo == null) {
|
||||
throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId() + " on secondary and could not create backup");
|
||||
}
|
||||
}
|
||||
// don't try to perform a sync if the DataStoreRole of the snapshot is equal to DataStoreRole.Primary
|
||||
if (!DataStoreRole.Primary.equals(dataStoreRole)) {
|
||||
try {
|
||||
|
||||
@ -47,6 +47,7 @@ public class SnapshotStateMachineManagerImpl implements SnapshotStateMachineMana
|
||||
stateMachine.addTransition(Snapshot.State.BackingUp, Event.OperationFailed, Snapshot.State.Error);
|
||||
stateMachine.addTransition(Snapshot.State.BackedUp, Event.DestroyRequested, Snapshot.State.Destroying);
|
||||
stateMachine.addTransition(Snapshot.State.BackedUp, Event.CopyingRequested, Snapshot.State.Copying);
|
||||
stateMachine.addTransition(Snapshot.State.BackedUp, Event.BackupToSecondary, Snapshot.State.BackingUp);
|
||||
stateMachine.addTransition(Snapshot.State.Copying, Event.OperationSucceeded, Snapshot.State.BackedUp);
|
||||
stateMachine.addTransition(Snapshot.State.Copying, Event.OperationFailed, Snapshot.State.BackedUp);
|
||||
stateMachine.addTransition(Snapshot.State.Destroying, Event.OperationSucceeded, Snapshot.State.Destroyed);
|
||||
|
||||
@ -39,6 +39,7 @@ import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreImpl;
|
||||
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.hypervisor.Hypervisor;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
@ -376,8 +377,24 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
|
||||
|
||||
snapshot = result.getSnashot();
|
||||
DataStore primaryStore = snapshot.getDataStore();
|
||||
boolean backupFlag = Boolean.parseBoolean(configDao.getValue(Config.BackupSnapshotAfterTakingSnapshot.toString()));
|
||||
|
||||
SnapshotInfo backupedSnapshot = backupSnapshot(snapshot);
|
||||
SnapshotInfo backupedSnapshot;
|
||||
if(backupFlag) {
|
||||
backupedSnapshot = backupSnapshot(snapshot);
|
||||
} else {
|
||||
// Fake it to get the transitions to fire in the proper order
|
||||
s_logger.debug("skipping backup of snapshot due to configuration "+Config.BackupSnapshotAfterTakingSnapshot.toString());
|
||||
|
||||
SnapshotObject snapObj = (SnapshotObject)snapshot;
|
||||
try {
|
||||
snapObj.processEvent(Snapshot.Event.OperationNotPerformed);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to change state: " + snapshot.getId() + ": " + e.toString());
|
||||
throw new CloudRuntimeException(e.toString());
|
||||
}
|
||||
backupedSnapshot = snapshot;
|
||||
}
|
||||
|
||||
try {
|
||||
SnapshotInfo parent = snapshot.getParent();
|
||||
|
||||
@ -512,7 +512,7 @@ public enum Config {
|
||||
null),
|
||||
SnapshotDeltaMax("Snapshots", SnapshotManager.class, Integer.class, "snapshot.delta.max", "16", "max delta snapshots between two full snapshots.", null),
|
||||
BackupSnapshotAfterTakingSnapshot(
|
||||
"Hidden",
|
||||
"Snapshots",
|
||||
SnapshotManager.class,
|
||||
Boolean.class,
|
||||
"snapshot.backup.rightafter",
|
||||
|
||||
@ -1019,7 +1019,13 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase implement
|
||||
DataStoreRole dataStoreRole = getDataStoreRole(snapshot, _snapshotStoreDao, dataStoreMgr);
|
||||
|
||||
SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, dataStoreRole);
|
||||
|
||||
if(snapshotStoreRef == null) {
|
||||
// The snapshot was not backed up to secondary. Find the snap on primary
|
||||
snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Primary);
|
||||
if(snapshotStoreRef == null) {
|
||||
throw new CloudRuntimeException("Could not find snapshot");
|
||||
}
|
||||
}
|
||||
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(),
|
||||
null, null, snapshotStoreRef.getPhysicalSize(), volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
|
||||
|
||||
|
||||
@ -75,7 +75,10 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy.SnapshotOperation;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
|
||||
@ -254,6 +257,8 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
@Inject
|
||||
private SnapshotDataFactory _snapshotFactory;
|
||||
@Inject
|
||||
StorageStrategyFactory _storageStrategyFactory;
|
||||
@Inject
|
||||
private TemplateService _tmpltSvr;
|
||||
@Inject
|
||||
private DataStoreManager _dataStoreMgr;
|
||||
@ -1493,6 +1498,21 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager,
|
||||
SnapshotInfo snapInfo = _snapshotFactory.getSnapshot(snapshotId, dataStoreRole);
|
||||
|
||||
if (dataStoreRole == DataStoreRole.Image) {
|
||||
if (snapInfo == null) {
|
||||
snapInfo = _snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Primary);
|
||||
if(snapInfo == null) {
|
||||
throw new CloudRuntimeException("Cannot find snapshot "+snapshotId);
|
||||
}
|
||||
// We need to copy the snapshot onto secondary.
|
||||
SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.BACKUP);
|
||||
snapshotStrategy.backupSnapshot(snapInfo);
|
||||
|
||||
// Attempt to grab it again.
|
||||
snapInfo = _snapshotFactory.getSnapshot(snapshotId, dataStoreRole);
|
||||
if(snapInfo == null) {
|
||||
throw new CloudRuntimeException("Cannot find snapshot " + snapshotId + " on secondary and could not create backup");
|
||||
}
|
||||
}
|
||||
DataStore snapStore = snapInfo.getDataStore();
|
||||
|
||||
if (snapStore != null) {
|
||||
|
||||
@ -68,6 +68,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StorageCacheManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.StorageStrategyFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
|
||||
@ -161,6 +162,9 @@ public class TemplateManagerImplTest {
|
||||
@Inject
|
||||
SnapshotDao snapshotDao;
|
||||
|
||||
@Inject
|
||||
StorageStrategyFactory storageStrategyFactory;
|
||||
|
||||
public class CustomThreadPoolExecutor extends ThreadPoolExecutor {
|
||||
AtomicInteger ai = new AtomicInteger(0);
|
||||
public CustomThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit,
|
||||
@ -453,6 +457,11 @@ public class TemplateManagerImplTest {
|
||||
return Mockito.mock(VMTemplateDao.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StorageStrategyFactory storageStrategyFactory() {
|
||||
return Mockito.mock(StorageStrategyFactory.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VMTemplatePoolDao vmTemplatePoolDao() {
|
||||
return Mockito.mock(VMTemplatePoolDao.class);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user