Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public class EventTypes {

// Snapshots
public static final String EVENT_SNAPSHOT_CREATE = "SNAPSHOT.CREATE";
public static final String EVENT_SNAPSHOT_ON_PRIMARY = "SNAPSHOT.ON_PRIMARY";
public static final String EVENT_SNAPSHOT_OFF_PRIMARY = "SNAPSHOT.OFF_PRIMARY";
public static final String EVENT_SNAPSHOT_DELETE = "SNAPSHOT.DELETE";
public static final String EVENT_SNAPSHOT_REVERT = "SNAPSHOT.REVERT";
public static final String EVENT_SNAPSHOT_POLICY_CREATE = "SNAPSHOTPOLICY.CREATE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) {
addFullCloneFlagOnVMwareDest(destData.getTO());
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
cmd.setOptions(options);
s_logger.error("IR24 copySnapshot BACKUPSNAPSHOT " + srcData.getId() + " dest=" + destData.getId());
EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;

import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.Snapshot;
import com.cloud.storage.SnapshotVO;
Expand Down Expand Up @@ -195,7 +197,7 @@ public SnapshotResult takeSnapshot(SnapshotInfo snap) {
AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)).setContext(context);
PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver)snapshotOnPrimary.getDataStore().getDriver();
primaryStore.takeSnapshot(snapshot, caller);
primaryStore.takeSnapshot(snapshot, caller); // IR24 take snapshot on primary
} catch (Exception e) {
s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
try {
Expand All @@ -211,6 +213,11 @@ public SnapshotResult takeSnapshot(SnapshotInfo snap) {

try {
result = future.get();
s_logger.debug("IR24 creating snapshot on primary " + snap.getName() + " snapshotOnPrimary=" + snapshotOnPrimary.getSize() +
" snapshotOnPrimary.getPhysicalSize()=" + snapshotOnPrimary.getPhysicalSize());
// IR24 generate the off primary event
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_ON_PRIMARY, snap.getAccountId(), snap.getDataCenterId(), snap.getId(),
snap.getName(), null, null, snapshotOnPrimary.getSize(), snapshotOnPrimary.getSize(), snap.getClass().getName(), snap.getUuid());
return result;
} catch (InterruptedException e) {
s_logger.debug("Failed to create snapshot", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.to.DiskTO;
import com.cloud.dc.dao.ClusterDao;
import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
Expand Down Expand Up @@ -147,7 +150,9 @@ public boolean deleteSnapshot(Long snapshotId) {
* @return true if snapshot is removed, false otherwise
*/

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

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

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

snapshotObj.processEvent(Snapshot.Event.OperationSucceeded);
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_OFF_PRIMARY, snapshotObj.getAccountId(), snapshotObj.getDataCenterId(), snapshotId,
snapshotObj.getName(), null, null, 0L, snapshotObj.getClass().getName(), snapshotObj.getUuid());
}
catch (Exception e) {
s_logger.debug("Failed to delete snapshot: ", e);
Expand Down Expand Up @@ -261,6 +268,7 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshotInfo) {
if (snapshotOnPrimary != null && snapshotInfo.getLocationType() == Snapshot.LocationType.SECONDARY) {
// remove the snapshot on primary storage
try {
s_logger.warn("IR24 takeSnapshot deleteSnapshot snapshotOnPrimary " + snapshotOnPrimary.getName());
snapshotSvr.deleteSnapshot(snapshotOnPrimary);
} catch (Exception e) {
s_logger.warn("Failed to clean up snapshot on primary Id:" + snapshotOnPrimary.getId() + " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import org.apache.cloudstack.storage.to.SnapshotObjectTO;

import com.cloud.configuration.Config;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventUtils;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
Expand Down Expand Up @@ -83,11 +85,11 @@ public class XenserverSnapshotStrategy extends SnapshotStrategyBase {
private SnapshotDao _snapshotDao;

@Override
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) { // IR24 backing up snapshot
SnapshotInfo parentSnapshot = snapshot.getParent();

if (parentSnapshot != null && snapshot.getPath().equalsIgnoreCase(parentSnapshot.getPath())) {
s_logger.debug("backup an empty snapshot");
s_logger.debug("IR24 backupSnapshot backup an empty snapshot " + snapshot.getName());
// don't need to backup this snapshot
SnapshotDataStoreVO parentSnapshotOnBackupStore = snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
if (parentSnapshotOnBackupStore != null && parentSnapshotOnBackupStore.getState() == State.Ready) {
Expand Down Expand Up @@ -154,6 +156,7 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
}
} else {
// 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
s_logger.debug("IR24 backupSnapshot backup an empty snapshot remove " + oldestSnapshotOnPrimary.getId());
snapshotStoreDao.remove(oldestSnapshotOnPrimary.getId());
}
}
Expand Down Expand Up @@ -239,7 +242,7 @@ public boolean deleteSnapshot(Long snapshotId) {
}

if (snapshotVO.getState() == Snapshot.State.CreatedOnPrimary) {
s_logger.debug("delete snapshot on primary storage:");
s_logger.debug("IR 24: resource admin delete snapshot on primary storage:");
snapshotVO.setState(Snapshot.State.Destroyed);
snapshotDao.update(snapshotId, snapshotVO);
return true;
Expand Down Expand Up @@ -411,6 +414,9 @@ public SnapshotInfo takeSnapshot(SnapshotInfo snapshot) {
SnapshotDataStoreVO snapshotDataStoreVO = snapshotStoreDao.findByStoreSnapshot(primaryStore.getRole(), primaryStore.getId(), parentSnapshotId);
if (snapshotDataStoreVO != null) {
parentSnapshotId = snapshotDataStoreVO.getParentSnapshotId();
s_logger.debug("IR24 takeSnapshot remove " + snapshotDataStoreVO.getId());
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_OFF_PRIMARY, parent.getAccountId(), parent.getDataCenterId(), parent.getId(),
parent.getName(), null, null, 0L, 0L, parent.getClass().getName(), parent.getUuid());
snapshotStoreDao.remove(snapshotDataStoreVO.getId());
} else {
parentSnapshotId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
answer = (CreateVMSnapshotAnswer)agentMgr.send(hostId, ccmd);
if (answer != null && answer.getResult()) {
processAnswer(vmSnapshotVO, userVm, answer, hostId);
for (VolumeObjectTO volumeTO: answer.getVolumeTOs()){
s_logger.info("IR24 finalizeCreate name=" + volumeTO.getName() + ", size=" + volumeTO.getSize() + ", " + volumeTO.getVolumeType());
}
s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName());
result = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ObjectInDataStoreManagerImpl() {
}

@Override
public DataObject create(DataObject obj, DataStore dataStore) {
public DataObject create(DataObject obj, DataStore dataStore) { // IR24
if (dataStore.getRole() == DataStoreRole.Primary) {
if (obj.getType() == DataObjectType.TEMPLATE) {
VMTemplateStoragePoolVO vo = new VMTemplateStoragePoolVO(dataStore.getId(), obj.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ public EndPoint select(DataObject srcData, DataObject destData) {

@Override
public EndPoint select(DataObject srcData, DataObject destData, StorageAction action) {
s_logger.error("IR24 select BACKUPSNAPSHOT from primary to secondary " + srcData.getId() + " dest=" + destData.getId());
if (action == StorageAction.BACKUPSNAPSHOT && srcData.getDataStore().getRole() == DataStoreRole.Primary) {
SnapshotInfo srcSnapshot = (SnapshotInfo)srcData;
VolumeInfo volumeInfo = srcSnapshot.getBaseVolume();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal
CommandResult result = new CommandResult();
try {
EndPoint ep = null;
s_logger.debug("IR24 deleteAsync DeleteCommand of type " + data.getType() );
if (data.getType() == DataObjectType.VOLUME) {
ep = epSelector.select(data, StorageAction.DELETEVOLUME);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public Snapshot createSnapshot(Long volumeId, Long policyId, Long snapshotId, Ac
}

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