Skip to content

Commit af48741

Browse files
author
Abhinandan Prateek
committed
WIP:VM snapshot on primary storage usage
1 parent 9d8eebf commit af48741

10 files changed

Lines changed: 35 additions & 6 deletions

File tree

api/src/com/cloud/event/EventTypes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ public class EventTypes {
233233

234234
// Snapshots
235235
public static final String EVENT_SNAPSHOT_CREATE = "SNAPSHOT.CREATE";
236+
public static final String EVENT_SNAPSHOT_ON_PRIMARY = "SNAPSHOT.ON_PRIMARY";
237+
public static final String EVENT_SNAPSHOT_OFF_PRIMARY = "SNAPSHOT.OFF_PRIMARY";
236238
public static final String EVENT_SNAPSHOT_DELETE = "SNAPSHOT.DELETE";
237239
public static final String EVENT_SNAPSHOT_REVERT = "SNAPSHOT.REVERT";
238240
public static final String EVENT_SNAPSHOT_POLICY_CREATE = "SNAPSHOTPOLICY.CREATE";

engine/storage/datamotion/src/org/apache/cloudstack/storage/motion/AncientDataMotionStrategy.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) {
548548
addFullCloneFlagOnVMwareDest(destData.getTO());
549549
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
550550
cmd.setOptions(options);
551+
s_logger.error("IR24 copySnapshot BACKUPSNAPSHOT " + srcData.getId() + " dest=" + destData.getId());
551552
EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
552553
if (ep == null) {
553554
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
5050
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
5151

52+
import com.cloud.event.EventTypes;
53+
import com.cloud.event.UsageEventUtils;
5254
import com.cloud.storage.DataStoreRole;
5355
import com.cloud.storage.Snapshot;
5456
import com.cloud.storage.SnapshotVO;
@@ -195,7 +197,7 @@ public SnapshotResult takeSnapshot(SnapshotInfo snap) {
195197
AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
196198
caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)).setContext(context);
197199
PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver)snapshotOnPrimary.getDataStore().getDriver();
198-
primaryStore.takeSnapshot(snapshot, caller);
200+
primaryStore.takeSnapshot(snapshot, caller); // IR24 take snapshot on primary
199201
} catch (Exception e) {
200202
s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
201203
try {
@@ -211,6 +213,11 @@ public SnapshotResult takeSnapshot(SnapshotInfo snap) {
211213

212214
try {
213215
result = future.get();
216+
s_logger.debug("IR24 creating snapshot on primary " + snap.getName() + " snapshotOnPrimary=" + snapshotOnPrimary.getSize() +
217+
" snapshotOnPrimary.getPhysicalSize()=" + snapshotOnPrimary.getPhysicalSize());
218+
// IR24 generate the off primary event
219+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_ON_PRIMARY, snap.getAccountId(), snap.getDataCenterId(), snap.getId(),
220+
snap.getName(), null, null, snapshotOnPrimary.getSize(), snapshotOnPrimary.getSize(), snap.getClass().getName(), snap.getUuid());
214221
return result;
215222
} catch (InterruptedException e) {
216223
s_logger.debug("Failed to create snapshot", e);

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/StorageSystemSnapshotStrategy.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import com.cloud.agent.AgentManager;
2020
import com.cloud.agent.api.to.DiskTO;
2121
import com.cloud.dc.dao.ClusterDao;
22+
import com.cloud.event.ActionEvent;
23+
import com.cloud.event.EventTypes;
24+
import com.cloud.event.UsageEventUtils;
2225
import com.cloud.exception.InvalidParameterValueException;
2326
import com.cloud.host.HostVO;
2427
import com.cloud.host.dao.HostDao;
@@ -147,7 +150,9 @@ public boolean deleteSnapshot(Long snapshotId) {
147150
* @return true if snapshot is removed, false otherwise
148151
*/
149152

153+
@ActionEvent(eventType = EventTypes.EVENT_SNAPSHOT_OFF_PRIMARY, eventDescription = "deleting snapshot", async = true)
150154
private boolean cleanupSnapshotOnPrimaryStore(long snapshotId) {
155+
s_logger.info("IR24 cleanupSnapshotOnPrimaryStore snapshotId " + snapshotId);
151156

152157
SnapshotObject snapshotObj = (SnapshotObject)snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Primary);
153158

@@ -176,6 +181,8 @@ private boolean cleanupSnapshotOnPrimaryStore(long snapshotId) {
176181
snapshotSvr.deleteSnapshot(snapshotObj);
177182

178183
snapshotObj.processEvent(Snapshot.Event.OperationSucceeded);
184+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_OFF_PRIMARY, snapshotObj.getAccountId(), snapshotObj.getDataCenterId(), snapshotId,
185+
snapshotObj.getName(), null, null, 0L, snapshotObj.getClass().getName(), snapshotObj.getUuid());
179186
}
180187
catch (Exception e) {
181188
s_logger.debug("Failed to delete snapshot: ", e);
@@ -261,6 +268,7 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshotInfo) {
261268
if (snapshotOnPrimary != null && snapshotInfo.getLocationType() == Snapshot.LocationType.SECONDARY) {
262269
// remove the snapshot on primary storage
263270
try {
271+
s_logger.warn("IR24 takeSnapshot deleteSnapshot snapshotOnPrimary " + snapshotOnPrimary.getName());
264272
snapshotSvr.deleteSnapshot(snapshotOnPrimary);
265273
} catch (Exception e) {
266274
s_logger.warn("Failed to clean up snapshot on primary Id:" + snapshotOnPrimary.getId() + " "

engine/storage/snapshot/src/org/apache/cloudstack/storage/snapshot/XenserverSnapshotStrategy.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
4141

4242
import com.cloud.configuration.Config;
43+
import com.cloud.event.EventTypes;
44+
import com.cloud.event.UsageEventUtils;
4345
import com.cloud.exception.InvalidParameterValueException;
4446
import com.cloud.hypervisor.Hypervisor;
4547
import com.cloud.hypervisor.Hypervisor.HypervisorType;
@@ -83,11 +85,11 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
8385
private SnapshotDao _snapshotDao;
8486

8587
@Override
86-
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
88+
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) { // IR24 backing up snapshot
8789
SnapshotInfo parentSnapshot = snapshot.getParent();
8890

8991
if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath())) {
90-
s_logger.debug("backup an empty snapshot");
92+
s_logger.debug("IR24 backupSnapshot backup an empty snapshot " + snapshot.getName());
9193
// don't need to backup this snapshot
9294
SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
9395
if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState() == State.Ready) {
@@ -154,6 +156,7 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
154156
}
155157
} else {
156158
// if there is an snapshot entry for previousPool(primary storage) of migrated volume, delete it becasue CS created one more snapshot entry for current pool
159+
s_logger.debug("IR24 backupSnapshot backup an empty snapshot remove " + oldestSnapshotOnPrimary.getId());
157160
snapshotStoreDao.remove(oldestSnapshotOnPrimary.getId());
158161
}
159162
}
@@ -239,7 +242,7 @@ public boolean deleteSnapshot(Long snapshotId) {
239242
}
240243

241244
if (snapshotVO.getState() == Snapshot.State.CreatedOnPrimary) {
242-
s_logger.debug("delete snapshot on primary storage:");
245+
s_logger.debug("IR 24: resource admin delete snapshot on primary storage:");
243246
snapshotVO.setState(Snapshot.State.Destroyed);
244247
snapshotDao.update(snapshotId, snapshotVO);
245248
return true;
@@ -411,6 +414,9 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshot) {
411414
SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(), primaryStore.getId(), parentSnapshotId);
412415
if (snapshotDataStoreVO != null) {
413416
parentSnapshotId = snapshotDataStoreVO.getParentSnapshotId();
417+
s_logger.debug("IR24 takeSnapshot remove " + snapshotDataStoreVO.getId());
418+
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_OFF_PRIMARY, parent.getAccountId(), parent.getDataCenterId(), parent.getId(),
419+
parent.getName(), null, null, 0L, 0L, parent.getClass().getName(), parent.getUuid());
414420
snapshotStoreDao.remove(snapshotDataStoreVO.getId());
415421
} else {
416422
parentSnapshotId = null;

engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
148148
answer = (CreateVMSnapshotAnswer)agentMgr.send(hostId, ccmd);
149149
if (answer != null && answer.getResult()) {
150150
processAnswer(vmSnapshotVO, userVm, answer, hostId);
151+
for (VolumeObjectTO volumeTO: answer.getVolumeTOs()){
152+
s_logger.info("IR24 finalizeCreate name=" + volumeTO.getName() + ", size=" + volumeTO.getSize() + ", " + volumeTO.getVolumeType());
153+
}
151154
s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName());
152155
result = true;
153156

engine/storage/src/org/apache/cloudstack/storage/datastore/ObjectInDataStoreManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public ObjectInDataStoreManagerImpl() {
106106
}
107107

108108
@Override
109-
public DataObject create(DataObject obj, DataStore dataStore) {
109+
public DataObject create(DataObject obj, DataStore dataStore) { // IR24
110110
if (dataStore.getRole() == DataStoreRole.Primary) {
111111
if (obj.getType() == DataObjectType.TEMPLATE) {
112112
VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId());

engine/storage/src/org/apache/cloudstack/storage/endpoint/DefaultEndPointSelector.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public EndPoint select(DataObject srcData, DataObject destData) {
206206

207207
@Override
208208
public EndPoint select(DataObject srcData, DataObject destData, StorageAction action) {
209+
s_logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId());
209210
if (action == StorageAction.BACKUPSNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
210211
SnapshotInfo srcSnapshot = (SnapshotInfo)srcData;
211212
VolumeInfo volumeInfo = srcSnapshot.getBaseVolume();

plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal
216216
CommandResult result = new CommandResult();
217217
try {
218218
EndPoint ep = null;
219+
s_logger.debug("IR24 deleteAsync DeleteCommand of type " + data.getType() );
219220
if (data.getType() == DataObjectType.VOLUME) {
220221
ep = epSelector.select(data, StorageAction.DELETEVOLUME);
221222
} else {

server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public Snapshot createSnapshot(Long volumeId, Long policyId, Long snapshotId, Ac
360360
}
361361

362362
@Override
363-
public Snapshot backupSnapshot(Long snapshotId) {
363+
public Snapshot backupSnapshot(Long snapshotId) { // IR24
364364
SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Image);
365365
if (snapshot != null) {
366366
throw new CloudRuntimeException("Already in the backup snapshot:" + snapshotId);

0 commit comments

Comments
 (0)