@@ -156,7 +156,8 @@ public void expungeTemporarySnapshot(boolean kvmSnapshotOnlyInPrimaryStorage, Sn
156156 public boolean isStorageSupportSnapshotToTemplate (SnapshotInfo snapInfo ) {
157157 if (DataStoreRole .Primary .equals (snapInfo .getDataStore ().getRole ())) {
158158 Map <String , String > capabilities = snapInfo .getDataStore ().getDriver ().getCapabilities ();
159- return org .apache .commons .collections4 .MapUtils .isNotEmpty (capabilities ) && capabilities .containsKey (DataStoreCapabilities .CAN_CREATE_TEMPLATE_FROM_SNAPSHOT .toString ());
159+ return org .apache .commons .collections4 .MapUtils .isNotEmpty (capabilities )
160+ && Boolean .parseBoolean (capabilities .get (DataStoreCapabilities .CAN_CREATE_TEMPLATE_FROM_SNAPSHOT .toString ()));
160161 }
161162 return false ;
162163 }
@@ -214,36 +215,36 @@ protected boolean isSnapshotBackupable(SnapshotInfo snapInfo, DataStoreRole data
214215 * @return true if hypervisor is {@link HypervisorType#KVM} and data store role is {@link DataStoreRole#Primary} and global setting "snapshot.backup.to.secondary" is false,
215216 * else false.
216217 */
218+ public boolean isKvmSnapshotOnlyInPrimaryStorage (Snapshot snapshot , DataStoreRole dataStoreRole ) {
219+ return snapshot .getHypervisorType () == Hypervisor .HypervisorType .KVM && dataStoreRole == DataStoreRole .Primary && !backupSnapshotAfterTakingSnapshot ;
220+ }
221+
217222 public boolean isKvmSnapshotOnlyInPrimaryStorage (Snapshot snapshot , DataStoreRole dataStoreRole , Long zoneId ){
218223 List <SnapshotJoinVO > snapshots = snapshotJoinDao .listBySnapshotIdAndZoneId (zoneId , snapshot .getSnapshotId ());
219- boolean isKvmSnapshotOnlyInPrimaryStorage = snapshots .stream ().filter (s -> s .getStoreRole ().equals (DataStoreRole .Image )). count () == 0 ;
224+ boolean isKvmSnapshotOnlyInPrimaryStorage = snapshots .stream ().noneMatch (s -> s .getStoreRole ().equals (DataStoreRole .Image ));
220225
221226 return snapshot .getHypervisorType () == Hypervisor .HypervisorType .KVM && dataStoreRole == DataStoreRole .Primary && isKvmSnapshotOnlyInPrimaryStorage ;
222227 }
223228
224229 public DataStoreRole getDataStoreRole (Snapshot snapshot ) {
225230 SnapshotDataStoreVO snapshotStore = snapshotDataStoreDao .findOneBySnapshotAndDatastoreRole (snapshot .getId (), DataStoreRole .Primary );
226-
227231 if (snapshotStore == null ) {
228232 return DataStoreRole .Image ;
229233 }
230234
231235 long storagePoolId = snapshotStore .getDataStoreId ();
232-
233236 StoragePoolVO storagePoolVO = primaryDataStoreDao .findById (storagePoolId );
234237 if ((storagePoolTypesToValidateWithBackupSnapshotAfterTakingSnapshot .contains (storagePoolVO .getPoolType ()) || snapshot .getHypervisorType () == HypervisorType .KVM )
235238 && !backupSnapshotAfterTakingSnapshot ) {
236239 return DataStoreRole .Primary ;
237240 }
238241
239242 DataStore dataStore = dataStorageManager .getDataStore (storagePoolId , DataStoreRole .Primary );
240-
241243 if (dataStore == null ) {
242244 return DataStoreRole .Image ;
243245 }
244246
245247 Map <String , String > mapCapabilities = dataStore .getDriver ().getCapabilities ();
246-
247248 if (MapUtils .isNotEmpty (mapCapabilities ) && BooleanUtils .toBoolean (mapCapabilities .get (DataStoreCapabilities .STORAGE_SYSTEM_SNAPSHOT .toString ()))) {
248249 return DataStoreRole .Primary ;
249250 }
@@ -255,11 +256,13 @@ public DataStoreRole getDataStoreRole(Snapshot snapshot, Long zoneId) {
255256 if (zoneId == null ) {
256257 getDataStoreRole (snapshot );
257258 }
259+
258260 List <SnapshotJoinVO > snapshots = snapshotJoinDao .listBySnapshotIdAndZoneId (zoneId , snapshot .getId ());
259261 boolean snapshotOnPrimary = snapshots .stream ().anyMatch (s -> s .getStoreRole ().equals (DataStoreRole .Primary ));
260262 if (snapshotOnPrimary ) {
261263 return DataStoreRole .Primary ;
262264 }
265+
263266 return DataStoreRole .Image ;
264267 }
265268 /**
0 commit comments