Skip to content

Commit b63805c

Browse files
committed
Exclude those which have not existing data store ids
1 parent a4b1688 commit b63805c

3 files changed

Lines changed: 21 additions & 14 deletions

File tree

api/src/org/apache/cloudstack/api/command/user/snapshot/ListSnapshotsCmd.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ public void execute() {
115115
List<SnapshotResponse> snapshotResponses = new ArrayList<SnapshotResponse>();
116116
for (Snapshot snapshot : result.first()) {
117117
SnapshotResponse snapshotResponse = _responseGenerator.createSnapshotResponse(snapshot);
118-
snapshotResponse.setObjectName("snapshot");
119-
snapshotResponses.add(snapshotResponse);
118+
if (snapshotResponse != null) {
119+
snapshotResponse.setObjectName("snapshot");
120+
snapshotResponses.add(snapshotResponse);
121+
}
120122
}
121123
response.setResponses(snapshotResponses, result.second());
122124
response.setResponseName(getCommandName());

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
143143
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities;
144144
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
145+
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
145146
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
146147
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
147148
import org.apache.cloudstack.framework.jobs.AsyncJob;
@@ -493,7 +494,9 @@ public SnapshotResponse createSnapshotResponse(Snapshot snapshot) {
493494
snapshotInfo = (SnapshotInfo)snapshot;
494495
} else {
495496
DataStoreRole dataStoreRole = getDataStoreRole(snapshot, _snapshotStoreDao, _dataStoreMgr);
496-
497+
if (dataStoreRole == null){
498+
return null;
499+
}
497500
snapshotInfo = snapshotfactory.getSnapshot(snapshot.getId(), dataStoreRole);
498501
}
499502

@@ -526,16 +529,18 @@ public static DataStoreRole getDataStoreRole(Snapshot snapshot, SnapshotDataStor
526529
}
527530

528531
long storagePoolId = snapshotStore.getDataStoreId();
529-
DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
532+
if (! snapshotStore.getState().equals(ObjectInDataStoreStateMachine.State.Destroyed)){
533+
DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
530534

531-
Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
535+
Map<String, String> mapCapabilities = dataStore.getDriver().getCapabilities();
532536

533-
if (mapCapabilities != null) {
534-
String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
535-
Boolean supportsStorageSystemSnapshots = new Boolean(value);
537+
if (mapCapabilities != null) {
538+
String value = mapCapabilities.get(DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT.toString());
539+
Boolean supportsStorageSystemSnapshots = new Boolean(value);
536540

537-
if (supportsStorageSystemSnapshots) {
538-
return DataStoreRole.Primary;
541+
if (supportsStorageSystemSnapshots) {
542+
return DataStoreRole.Primary;
543+
}
539544
}
540545
}
541546

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,10 @@ public Pair<List<? extends Snapshot>, Integer> listSnapshots(ListSnapshotsCmd cm
516516
List<Long> ids = getIdsListFromCmd(cmd.getId(), cmd.getIds());
517517

518518
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
519-
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
520-
Long domainId = domainIdRecursiveListProject.first();
521-
Boolean isRecursive = domainIdRecursiveListProject.second();
522-
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
519+
_accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
520+
Long domainId = domainIdRecursiveListProject.first();
521+
Boolean isRecursive = domainIdRecursiveListProject.second();
522+
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
523523

524524
Filter searchFilter = new Filter(SnapshotVO.class, "created", false, cmd.getStartIndex(), cmd.getPageSizeVal());
525525
SearchBuilder<SnapshotVO> sb = _snapshotDao.createSearchBuilder();

0 commit comments

Comments
 (0)