mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
Fix DeleteSnapshotBackupCommand to pass dataStore information.
This commit is contained in:
parent
5b76e4914c
commit
4c174a6867
@ -17,6 +17,7 @@
|
||||
package com.cloud.agent.api;
|
||||
|
||||
import com.cloud.agent.api.LogLevel.Log4jLevel;
|
||||
import com.cloud.agent.api.to.DataStoreTO;
|
||||
import com.cloud.agent.api.to.S3TO;
|
||||
import com.cloud.agent.api.to.SwiftTO;
|
||||
|
||||
@ -26,14 +27,9 @@ import com.cloud.agent.api.to.SwiftTO;
|
||||
*/
|
||||
public class DeleteSnapshotBackupCommand extends SnapshotCommand {
|
||||
@LogLevel(Log4jLevel.Off)
|
||||
private SwiftTO swift;
|
||||
private S3TO s3;
|
||||
private DataStoreTO store;
|
||||
private Boolean all;
|
||||
|
||||
public SwiftTO getSwift() {
|
||||
return swift;
|
||||
}
|
||||
|
||||
public Boolean isAll() {
|
||||
return all;
|
||||
}
|
||||
@ -42,12 +38,8 @@ public class DeleteSnapshotBackupCommand extends SnapshotCommand {
|
||||
this.all = all;
|
||||
}
|
||||
|
||||
public void setSwift(SwiftTO swift) {
|
||||
this.swift = swift;
|
||||
}
|
||||
|
||||
public S3TO getS3() {
|
||||
return s3;
|
||||
public DataStoreTO getDataStore(){
|
||||
return store;
|
||||
}
|
||||
|
||||
protected DeleteSnapshotBackupCommand() {
|
||||
@ -78,8 +70,7 @@ public class DeleteSnapshotBackupCommand extends SnapshotCommand {
|
||||
* @param backupUUID The VHD which has to be deleted
|
||||
* @param childUUID The child VHD file of the backup whose parent is reset to its grandparent.
|
||||
*/
|
||||
public DeleteSnapshotBackupCommand(SwiftTO swift,
|
||||
S3TO s3,
|
||||
public DeleteSnapshotBackupCommand(DataStoreTO store,
|
||||
String secondaryStoragePoolURL,
|
||||
Long dcId,
|
||||
Long accountId,
|
||||
@ -87,8 +78,7 @@ public class DeleteSnapshotBackupCommand extends SnapshotCommand {
|
||||
String backupUUID, Boolean all)
|
||||
{
|
||||
super(null, secondaryStoragePoolURL, backupUUID, null, dcId, accountId, volumeId);
|
||||
setSwift(swift);
|
||||
this.s3 = s3;
|
||||
this.store = store;
|
||||
setAll(all);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,22 +265,22 @@ SecondaryStorageResource {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (destFile == null) {
|
||||
return new CopyCmdAnswer("Can't find template");
|
||||
return new CopyCmdAnswer("Can't find template");
|
||||
}
|
||||
|
||||
|
||||
DataTO newDestTO = null;
|
||||
|
||||
|
||||
if (destData.getObjectType() == DataObjectType.TEMPLATE) {
|
||||
TemplateObjectTO newTemplTO = new TemplateObjectTO();
|
||||
newTemplTO.setPath(destPath + File.separator + destFile.getName());
|
||||
newTemplTO.setName(destFile.getName());
|
||||
newDestTO = newTemplTO;
|
||||
} else {
|
||||
return new CopyCmdAnswer("not implemented yet");
|
||||
return new CopyCmdAnswer("not implemented yet");
|
||||
}
|
||||
|
||||
|
||||
return new CopyCmdAnswer(newDestTO);
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -1145,45 +1145,40 @@ SecondaryStorageResource {
|
||||
Long accountId = cmd.getAccountId();
|
||||
Long volumeId = cmd.getVolumeId();
|
||||
String name = cmd.getSnapshotUuid();
|
||||
try {
|
||||
SwiftTO swift = cmd.getSwift();
|
||||
S3TO s3 = cmd.getS3();
|
||||
if (swift == null) {
|
||||
final String result = deleteSnapshotBackupFromLocalFileSystem(
|
||||
secondaryStorageUrl, accountId, volumeId, name,
|
||||
cmd.isAll());
|
||||
if (result != null) {
|
||||
s_logger.warn(result);
|
||||
return new Answer(cmd, false, result);
|
||||
}
|
||||
} else if (s3 != null) {
|
||||
final String result = deleteSnapshotBackupfromS3(s3,
|
||||
secondaryStorageUrl, accountId, volumeId, name,
|
||||
cmd.isAll());
|
||||
if (result != null) {
|
||||
s_logger.warn(result);
|
||||
return new Answer(cmd, false, result);
|
||||
}
|
||||
} else {
|
||||
String filename;
|
||||
if (cmd.isAll()) {
|
||||
filename = "";
|
||||
} else {
|
||||
filename = name;
|
||||
}
|
||||
String result = swiftDelete(swift, "V-" + volumeId.toString(), filename);
|
||||
if (result != null) {
|
||||
String errMsg = "failed to delete snapshot " + filename + " , err=" + result;
|
||||
s_logger.warn(errMsg);
|
||||
return new Answer(cmd, false, errMsg);
|
||||
}
|
||||
DataStoreTO dstore = cmd.getDataStore();
|
||||
if ( dstore instanceof NfsTO ){
|
||||
final String result = deleteSnapshotBackupFromLocalFileSystem(
|
||||
secondaryStorageUrl, accountId, volumeId, name,
|
||||
cmd.isAll());
|
||||
if (result != null) {
|
||||
s_logger.warn(result);
|
||||
return new Answer(cmd, false, result);
|
||||
}
|
||||
return new Answer(cmd, true, "success");
|
||||
} catch (Exception e) {
|
||||
String errMsg = cmd + " Command failed due to " + e.toString();
|
||||
s_logger.warn(errMsg, e);
|
||||
return new Answer(cmd, false, errMsg);
|
||||
} else if (dstore instanceof S3TO ){
|
||||
final String result = deleteSnapshotBackupfromS3((S3TO)dstore,
|
||||
secondaryStorageUrl, accountId, volumeId, name,
|
||||
cmd.isAll());
|
||||
if (result != null) {
|
||||
s_logger.warn(result);
|
||||
return new Answer(cmd, false, result);
|
||||
}
|
||||
} else if (dstore instanceof SwiftTO ){
|
||||
String filename;
|
||||
if (cmd.isAll()) {
|
||||
filename = "";
|
||||
} else {
|
||||
filename = name;
|
||||
}
|
||||
String result = swiftDelete((SwiftTO)dstore, "V-" + volumeId.toString(), filename);
|
||||
if (result != null) {
|
||||
String errMsg = "failed to delete snapshot " + filename + " , err=" + result;
|
||||
s_logger.warn(errMsg);
|
||||
return new Answer(cmd, false, errMsg);
|
||||
}
|
||||
} else {
|
||||
return new Answer(cmd, false, "Unsupported image data store: " + dstore);
|
||||
}
|
||||
return new Answer(cmd, true, "success");
|
||||
}
|
||||
|
||||
Map<String, TemplateProp> swiftListTemplate(SwiftTO swift) {
|
||||
@ -1425,8 +1420,7 @@ SecondaryStorageResource {
|
||||
return new Answer(cmd, false, details);
|
||||
}
|
||||
return new Answer(cmd, true, null);
|
||||
}
|
||||
else if (dstore instanceof S3TO ){
|
||||
} else if (dstore instanceof S3TO ){
|
||||
final S3TO s3 = (S3TO)dstore;
|
||||
final Long accountId = cmd.getAccountId();
|
||||
final Long templateId = cmd.getTemplateId();
|
||||
@ -1458,8 +1452,7 @@ SecondaryStorageResource {
|
||||
s_logger.error(errorMessage, e);
|
||||
return new Answer(cmd, false, errorMessage);
|
||||
}
|
||||
}
|
||||
else if (dstore instanceof SwiftTO){
|
||||
} else if (dstore instanceof SwiftTO){
|
||||
SwiftTO swift = (SwiftTO)dstore;
|
||||
String container = "T-" + cmd.getTemplateId();
|
||||
String object = "";
|
||||
@ -1477,8 +1470,7 @@ SecondaryStorageResource {
|
||||
s_logger.warn(errMsg, e);
|
||||
return new Answer(cmd, false, errMsg);
|
||||
}
|
||||
}
|
||||
else{
|
||||
} else{
|
||||
return new Answer(cmd, false, "Unsupported image data store: " + dstore);
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public class SnapshotObject implements SnapshotInfo {
|
||||
private SnapshotVO snapshot;
|
||||
private DataStore store;
|
||||
@Inject
|
||||
protected SnapshotDao snapshotDao;
|
||||
protected SnapshotDao snapshotDao;
|
||||
@Inject
|
||||
protected VolumeDao volumeDao;
|
||||
@Inject protected VolumeDataFactory volFactory;
|
||||
@ -56,14 +56,14 @@ public class SnapshotObject implements SnapshotInfo {
|
||||
@Inject
|
||||
ObjectInDataStoreManager ojbectInStoreMgr;
|
||||
public SnapshotObject() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void configure(SnapshotVO snapshot, DataStore store) {
|
||||
this.snapshot = snapshot;
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
|
||||
public static SnapshotObject getSnapshotObject(SnapshotVO snapshot, DataStore store) {
|
||||
SnapshotObject snapObj = ComponentContext.inject(SnapshotObject.class);
|
||||
snapObj.configure(snapshot, store);
|
||||
@ -151,7 +151,7 @@ public class SnapshotObject implements SnapshotInfo {
|
||||
public String getPath() {
|
||||
return this.snapshot.getPath();
|
||||
}
|
||||
|
||||
|
||||
public void setPath(String path) {
|
||||
this.snapshot.setPath(path);
|
||||
}
|
||||
@ -195,7 +195,7 @@ public class SnapshotObject implements SnapshotInfo {
|
||||
public long getDomainId() {
|
||||
return this.snapshot.getDomainId();
|
||||
}
|
||||
|
||||
|
||||
public void setPrevSnapshotId(Long id) {
|
||||
this.snapshot.setPrevSnapshotId(id);
|
||||
}
|
||||
@ -204,7 +204,7 @@ public class SnapshotObject implements SnapshotInfo {
|
||||
public Long getDataCenterId() {
|
||||
return this.snapshot.getDataCenterId();
|
||||
}
|
||||
|
||||
|
||||
public void processEvent(Snapshot.Event event)
|
||||
throws NoTransitionException {
|
||||
stateMachineMgr.processEvent(this.snapshot, event);
|
||||
@ -214,15 +214,19 @@ public class SnapshotObject implements SnapshotInfo {
|
||||
public Long getPrevSnapshotId() {
|
||||
return this.snapshot.getPrevSnapshotId();
|
||||
}
|
||||
|
||||
|
||||
public void setBackupSnapshotId(String id) {
|
||||
this.snapshot.setBackupSnapshotId(id);
|
||||
}
|
||||
|
||||
|
||||
public String getBackupSnapshotId() {
|
||||
return this.snapshot.getBackupSnapshotId();
|
||||
}
|
||||
|
||||
public SnapshotVO getSnapshotVO(){
|
||||
return this.snapshot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataTO getTO() {
|
||||
// TODO Auto-generated method stub
|
||||
@ -232,6 +236,6 @@ public class SnapshotObject implements SnapshotInfo {
|
||||
@Override
|
||||
public void processEvent(org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event event, Answer answer) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,6 +44,8 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.framework.async.AsyncRpcConext;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -89,6 +91,8 @@ public class SnapshotServiceImpl implements SnapshotService {
|
||||
@Inject
|
||||
protected SnapshotDao _snapshotDao;
|
||||
@Inject
|
||||
protected SnapshotDataStoreDao _snapshotStoreDao;
|
||||
@Inject
|
||||
private ResourceManager _resourceMgr;
|
||||
@Inject
|
||||
protected SnapshotManager snapshotMgr;
|
||||
@ -461,9 +465,14 @@ public class SnapshotServiceImpl implements SnapshotService {
|
||||
|
||||
@DB
|
||||
protected boolean destroySnapshotBackUp(SnapshotVO snapshot) {
|
||||
DataStore store = objInStoreMgr.findStore(snapshot.getId(), DataObjectType.SNAPSHOT, DataStoreRole.Image);
|
||||
SnapshotDataStoreVO snapshotStore = this._snapshotStoreDao.findBySnapshot(snapshot.getId());
|
||||
if ( snapshotStore == null ){
|
||||
s_logger.debug("Can't find snapshot" + snapshot.getId() + " backed up into image store");
|
||||
return false;
|
||||
}
|
||||
DataStore store = this.dataStoreMgr.getDataStore(snapshotStore.getDataStoreId(), DataStoreRole.Image);
|
||||
if (store == null) {
|
||||
s_logger.debug("Can't find snapshot" + snapshot.getId() + " backed up into image store");
|
||||
s_logger.debug("Can't find mage store " + snapshotStore.getDataStoreId());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,7 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.ImageStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
|
||||
import org.apache.cloudstack.storage.image.store.TemplateObject;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotObject;
|
||||
import org.apache.cloudstack.storage.volume.VolumeObject;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -320,43 +321,44 @@ public class CloudStackImageStoreDriverImpl implements ImageStoreDriver {
|
||||
}
|
||||
|
||||
private void deleteSnapshot(DataObject data, AsyncCompletionCallback<CommandResult> callback) {
|
||||
Long snapshotId = data.getId();
|
||||
SnapshotVO snapshot = this.snapshotDao.findByIdIncludingRemoved(snapshotId);
|
||||
CommandResult result = new CommandResult();
|
||||
SnapshotObject snapshotObj = (SnapshotObject)data;
|
||||
DataStore secStore = snapshotObj.getDataStore();
|
||||
CommandResult result = new CommandResult();
|
||||
SnapshotVO snapshot = snapshotObj.getSnapshotVO();
|
||||
|
||||
if (snapshot == null) {
|
||||
s_logger.debug("Destroying snapshot " + snapshotId + " backup failed due to unable to find snapshot ");
|
||||
result.setResult("Unable to find snapshot: " + snapshotId);
|
||||
s_logger.debug("Destroying snapshot " + snapshotObj.getId() + " backup failed due to unable to find snapshot ");
|
||||
result.setResult("Unable to find snapshot: " + snapshotObj.getId());
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String secondaryStoragePoolUrl = this.snapshotMgr.getSecondaryStorageURL(snapshot);
|
||||
String secondaryStoragePoolUrl = secStore.getUri();
|
||||
Long dcId = snapshot.getDataCenterId();
|
||||
Long accountId = snapshot.getAccountId();
|
||||
Long volumeId = snapshot.getVolumeId();
|
||||
|
||||
String backupOfSnapshot = snapshot.getBackupSnapshotId();
|
||||
String backupOfSnapshot = snapshotObj.getBackupSnapshotId();
|
||||
if (backupOfSnapshot == null) {
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId());
|
||||
S3TO s3 = _s3Mgr.getS3TO();
|
||||
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
|
||||
swift, s3, secondaryStoragePoolUrl, dcId, accountId, volumeId,
|
||||
secStore.getTO(), secondaryStoragePoolUrl, dcId, accountId, volumeId,
|
||||
backupOfSnapshot, false);
|
||||
Answer answer = agentMgr.sendToSSVM(dcId, cmd);
|
||||
EndPoint ep = _epSelector.select(secStore);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
|
||||
if ((answer != null) && answer.getResult()) {
|
||||
snapshot.setBackupSnapshotId(null);
|
||||
snapshotDao.update(snapshotId, snapshot);
|
||||
snapshotDao.update(snapshotObj.getId(), snapshot);
|
||||
} else if (answer != null) {
|
||||
result.setResult(answer.getDetails());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("failed to delete snapshot: " + snapshotId + ": " + e.toString());
|
||||
s_logger.debug("failed to delete snapshot: " + snapshotObj.getId() + ": " + e.toString());
|
||||
result.setResult(e.toString());
|
||||
}
|
||||
callback.complete(result);
|
||||
|
||||
@ -45,6 +45,7 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.ImageStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
|
||||
import org.apache.cloudstack.storage.image.store.TemplateObject;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotObject;
|
||||
import org.apache.cloudstack.storage.volume.VolumeObject;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -279,48 +280,50 @@ public class S3ImageStoreDriverImpl implements ImageStoreDriver {
|
||||
}
|
||||
|
||||
private void deleteSnapshot(DataObject data, AsyncCompletionCallback<CommandResult> callback) {
|
||||
Long snapshotId = data.getId();
|
||||
SnapshotVO snapshot = this.snapshotDao.findByIdIncludingRemoved(snapshotId);
|
||||
CommandResult result = new CommandResult();
|
||||
if (snapshot == null) {
|
||||
s_logger.debug("Destroying snapshot " + snapshotId + " backup failed due to unable to find snapshot ");
|
||||
result.setResult("Unable to find snapshot: " + snapshotId);
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
SnapshotObject snapshotObj = (SnapshotObject)data;
|
||||
DataStore secStore = snapshotObj.getDataStore();
|
||||
CommandResult result = new CommandResult();
|
||||
SnapshotVO snapshot = snapshotObj.getSnapshotVO();
|
||||
|
||||
try {
|
||||
String secondaryStoragePoolUrl = this.snapshotMgr.getSecondaryStorageURL(snapshot);
|
||||
Long dcId = snapshot.getDataCenterId();
|
||||
Long accountId = snapshot.getAccountId();
|
||||
Long volumeId = snapshot.getVolumeId();
|
||||
if (snapshot == null) {
|
||||
s_logger.debug("Destroying snapshot " + snapshotObj.getId() + " backup failed due to unable to find snapshot ");
|
||||
result.setResult("Unable to find snapshot: " + snapshotObj.getId());
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
|
||||
String backupOfSnapshot = snapshot.getBackupSnapshotId();
|
||||
if (backupOfSnapshot == null) {
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId());
|
||||
S3TO s3 = _s3Mgr.getS3TO();
|
||||
try {
|
||||
String secondaryStoragePoolUrl = secStore.getUri();
|
||||
Long dcId = snapshot.getDataCenterId();
|
||||
Long accountId = snapshot.getAccountId();
|
||||
Long volumeId = snapshot.getVolumeId();
|
||||
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
|
||||
swift, s3, secondaryStoragePoolUrl, dcId, accountId, volumeId,
|
||||
backupOfSnapshot, false);
|
||||
Answer answer = agentMgr.sendToSSVM(dcId, cmd);
|
||||
String backupOfSnapshot = snapshotObj.getBackupSnapshotId();
|
||||
if (backupOfSnapshot == null) {
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((answer != null) && answer.getResult()) {
|
||||
snapshot.setBackupSnapshotId(null);
|
||||
snapshotDao.update(snapshotId, snapshot);
|
||||
} else if (answer != null) {
|
||||
result.setResult(answer.getDetails());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("failed to delete snapshot: " + snapshotId + ": " + e.toString());
|
||||
result.setResult(e.toString());
|
||||
}
|
||||
callback.complete(result);
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
|
||||
secStore.getTO(), secondaryStoragePoolUrl, dcId, accountId, volumeId,
|
||||
backupOfSnapshot, false);
|
||||
EndPoint ep = _epSelector.select(secStore);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
|
||||
if ((answer != null) && answer.getResult()) {
|
||||
snapshot.setBackupSnapshotId(null);
|
||||
snapshotDao.update(snapshotObj.getId(), snapshot);
|
||||
} else if (answer != null) {
|
||||
result.setResult(answer.getDetails());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("failed to delete snapshot: " + snapshotObj.getId() + ": " + e.toString());
|
||||
result.setResult(e.toString());
|
||||
}
|
||||
callback.complete(result);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteAsync(DataObject data,
|
||||
AsyncCompletionCallback<CommandResult> callback) {
|
||||
|
||||
@ -45,6 +45,7 @@ import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.ImageStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.store.ImageStoreImpl;
|
||||
import org.apache.cloudstack.storage.image.store.TemplateObject;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotObject;
|
||||
import org.apache.cloudstack.storage.volume.VolumeObject;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -273,46 +274,47 @@ public class SwiftImageStoreDriverImpl implements ImageStoreDriver {
|
||||
}
|
||||
|
||||
private void deleteSnapshot(DataObject data, AsyncCompletionCallback<CommandResult> callback) {
|
||||
Long snapshotId = data.getId();
|
||||
SnapshotVO snapshot = this.snapshotDao.findByIdIncludingRemoved(snapshotId);
|
||||
CommandResult result = new CommandResult();
|
||||
if (snapshot == null) {
|
||||
s_logger.debug("Destroying snapshot " + snapshotId + " backup failed due to unable to find snapshot ");
|
||||
result.setResult("Unable to find snapshot: " + snapshotId);
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
SnapshotObject snapshotObj = (SnapshotObject)data;
|
||||
DataStore secStore = snapshotObj.getDataStore();
|
||||
CommandResult result = new CommandResult();
|
||||
SnapshotVO snapshot = snapshotObj.getSnapshotVO();
|
||||
|
||||
try {
|
||||
String secondaryStoragePoolUrl = this.snapshotMgr.getSecondaryStorageURL(snapshot);
|
||||
Long dcId = snapshot.getDataCenterId();
|
||||
Long accountId = snapshot.getAccountId();
|
||||
Long volumeId = snapshot.getVolumeId();
|
||||
if (snapshot == null) {
|
||||
s_logger.debug("Destroying snapshot " + snapshotObj.getId() + " backup failed due to unable to find snapshot ");
|
||||
result.setResult("Unable to find snapshot: " + snapshotObj.getId());
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
|
||||
String backupOfSnapshot = snapshot.getBackupSnapshotId();
|
||||
if (backupOfSnapshot == null) {
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId());
|
||||
S3TO s3 = _s3Mgr.getS3TO();
|
||||
try {
|
||||
String secondaryStoragePoolUrl = secStore.getUri();
|
||||
Long dcId = snapshot.getDataCenterId();
|
||||
Long accountId = snapshot.getAccountId();
|
||||
Long volumeId = snapshot.getVolumeId();
|
||||
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
|
||||
swift, s3, secondaryStoragePoolUrl, dcId, accountId, volumeId,
|
||||
backupOfSnapshot, false);
|
||||
Answer answer = agentMgr.sendToSSVM(dcId, cmd);
|
||||
String backupOfSnapshot = snapshotObj.getBackupSnapshotId();
|
||||
if (backupOfSnapshot == null) {
|
||||
callback.complete(result);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((answer != null) && answer.getResult()) {
|
||||
snapshot.setBackupSnapshotId(null);
|
||||
snapshotDao.update(snapshotId, snapshot);
|
||||
} else if (answer != null) {
|
||||
result.setResult(answer.getDetails());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("failed to delete snapshot: " + snapshotId + ": " + e.toString());
|
||||
result.setResult(e.toString());
|
||||
}
|
||||
callback.complete(result);
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
|
||||
secStore.getTO(), secondaryStoragePoolUrl, dcId, accountId, volumeId,
|
||||
backupOfSnapshot, false);
|
||||
EndPoint ep = _epSelector.select(secStore);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
|
||||
if ((answer != null) && answer.getResult()) {
|
||||
snapshot.setBackupSnapshotId(null);
|
||||
snapshotDao.update(snapshotObj.getId(), snapshot);
|
||||
} else if (answer != null) {
|
||||
result.setResult(answer.getDetails());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("failed to delete snapshot: " + snapshotObj.getId() + ": " + e.toString());
|
||||
result.setResult(e.toString());
|
||||
}
|
||||
callback.complete(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -33,11 +33,14 @@ import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotPoliciesCmd;
|
||||
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
|
||||
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.VolumeDataFactory;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
|
||||
@ -198,6 +201,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
|
||||
@Inject SnapshotService snapshotSrv;
|
||||
@Inject VolumeDataFactory volFactory;
|
||||
@Inject SnapshotDataFactory snapshotFactory;
|
||||
@Inject EndPointSelector _epSelector;
|
||||
|
||||
|
||||
private int _totalRetries;
|
||||
@ -666,47 +670,18 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
|
||||
// This volume doesn't have any snapshots. Nothing do delete.
|
||||
continue;
|
||||
}
|
||||
List<HostVO> ssHosts = _ssvmMgr.listSecondaryStorageHostsInOneZone(dcId);
|
||||
SwiftTO swift = _swiftMgr.getSwiftTO();
|
||||
S3TO s3 = _s3Mgr.getS3TO();
|
||||
|
||||
checkObjectStorageConfiguration(swift, s3);
|
||||
|
||||
if (swift == null && s3 == null) {
|
||||
for (HostVO ssHost : ssHosts) {
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
|
||||
null, null, ssHost.getStorageUrl(), dcId,
|
||||
accountId, volumeId, "", true);
|
||||
Answer answer = null;
|
||||
try {
|
||||
answer = _agentMgr.sendToSSVM(dcId, cmd);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Failed to delete all snapshot for volume " + volumeId + " on secondary storage " + ssHost.getStorageUrl());
|
||||
}
|
||||
if ((answer != null) && answer.getResult()) {
|
||||
s_logger.debug("Deleted all snapshots for volume: " + volumeId + " under account: " + accountId);
|
||||
} else {
|
||||
success = false;
|
||||
if (answer != null) {
|
||||
s_logger.error(answer.getDetails());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(
|
||||
swift, s3, "", dcId, accountId, volumeId, "", true);
|
||||
Answer answer = null;
|
||||
try {
|
||||
answer = _agentMgr.sendToSSVM(dcId, cmd);
|
||||
} catch (Exception e) {
|
||||
final String storeType = s3 != null ? "S3" : "swift";
|
||||
s_logger.warn("Failed to delete all snapshot for volume " + volumeId + " on " + storeType);
|
||||
}
|
||||
List<DataStore> ssHosts = this.dataStoreMgr.getImageStoresByScope(new ZoneScope(dcId));
|
||||
for (DataStore ssHost : ssHosts) {
|
||||
DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand(ssHost.getTO(), ssHost.getUri(), dcId, accountId, volumeId, "",
|
||||
true);
|
||||
EndPoint ep = _epSelector.select(ssHost);
|
||||
Answer answer = ep.sendMessage(cmd);
|
||||
if ((answer != null) && answer.getResult()) {
|
||||
s_logger.debug("Deleted all snapshots for volume: " + volumeId + " under account: " + accountId);
|
||||
} else {
|
||||
success = false;
|
||||
if (answer != null) {
|
||||
s_logger.warn("Failed to delete all snapshot for volume " + volumeId + " on secondary storage " + ssHost.getUri());
|
||||
s_logger.error(answer.getDetails());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user