16
16
// under the License.
17
17
package org .apache .cloudstack .storage .snapshot ;
18
18
19
- import java .util .ArrayList ;
20
- import java .util .List ;
21
-
22
- import javax .inject .Inject ;
19
+ import com .cloud .exception .InvalidParameterValueException ;
20
+ import com .cloud .hypervisor .kvm .storage .StorPoolStorageAdaptor ;
21
+ import com .cloud .storage .DataStoreRole ;
22
+ import com .cloud .storage .Snapshot ;
23
+ import com .cloud .storage .SnapshotVO ;
24
+ import com .cloud .storage .VolumeVO ;
25
+ import com .cloud .storage .dao .SnapshotDao ;
26
+ import com .cloud .storage .dao .SnapshotDetailsDao ;
27
+ import com .cloud .storage .dao .SnapshotDetailsVO ;
28
+ import com .cloud .storage .dao .SnapshotZoneDao ;
29
+ import com .cloud .storage .dao .VolumeDao ;
30
+ import com .cloud .utils .exception .CloudRuntimeException ;
31
+ import com .cloud .utils .fsm .NoTransitionException ;
23
32
24
33
import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
25
34
import org .apache .cloudstack .engine .subsystem .api .storage .DataStoreManager ;
40
49
import org .apache .cloudstack .storage .datastore .util .StorPoolUtil .SpApiResponse ;
41
50
import org .apache .cloudstack .storage .datastore .util .StorPoolUtil .SpConnectionDesc ;
42
51
import org .apache .commons .collections .CollectionUtils ;
43
- import org .apache .logging .log4j .Logger ;
44
52
import org .apache .logging .log4j .LogManager ;
53
+ import org .apache .logging .log4j .Logger ;
45
54
import org .springframework .stereotype .Component ;
46
55
47
- import com .cloud .exception .InvalidParameterValueException ;
48
- import com .cloud .hypervisor .kvm .storage .StorPoolStorageAdaptor ;
49
- import com .cloud .storage .DataStoreRole ;
50
- import com .cloud .storage .Snapshot ;
51
- import com .cloud .storage .SnapshotVO ;
52
- import com .cloud .storage .VolumeVO ;
53
- import com .cloud .storage .dao .SnapshotDao ;
54
- import com .cloud .storage .dao .SnapshotDetailsDao ;
55
- import com .cloud .storage .dao .SnapshotDetailsVO ;
56
- import com .cloud .storage .dao .SnapshotZoneDao ;
57
- import com .cloud .storage .dao .VolumeDao ;
58
- import com .cloud .utils .exception .CloudRuntimeException ;
59
- import com .cloud .utils .fsm .NoTransitionException ;
56
+ import javax .inject .Inject ;
57
+ import java .util .ArrayList ;
58
+ import java .util .List ;
60
59
61
60
62
61
@ Component
@@ -117,10 +116,11 @@ public boolean deleteSnapshot(Long snapshotId, Long zoneId) {
117
116
if (resp .getError () != null ) {
118
117
final String err = String .format ("Failed to clean-up Storpool snapshot %s. Error: %s" , name , resp .getError ());
119
118
StorPoolUtil .spLog (err );
120
- markSnapshotAsDestroyedIfAlreadyRemoved (snapshotId , resp );
119
+ markSnapshotAsDestroyedIfAlreadyRemoved (snapshotId , resp . getError (). getName (). equals ( StorPoolUtil . OBJECT_DOES_NOT_EXIST ) );
121
120
throw new CloudRuntimeException (err );
122
121
} else {
123
122
res = deleteSnapshotFromDbIfNeeded (snapshotVO , zoneId );
123
+ markSnapshotAsDestroyedIfAlreadyRemoved (snapshotId ,true );
124
124
StorPoolUtil .spLog ("StorpoolSnapshotStrategy.deleteSnapshot: executed successfully=%s, snapshot uuid=%s, name=%s" , res , snapshotVO .getUuid (), name );
125
125
}
126
126
} catch (Exception e ) {
@@ -129,15 +129,23 @@ public boolean deleteSnapshot(Long snapshotId, Long zoneId) {
129
129
}
130
130
}
131
131
132
+ List <SnapshotDataStoreVO > snapshots = _snapshotStoreDao .listBySnapshotIdAndState (snapshotId , State .Ready );
133
+ if (res || CollectionUtils .isEmpty (snapshots )) {
134
+ updateSnapshotToDestroyed (snapshotVO );
135
+ return true ;
136
+ }
132
137
return res ;
133
138
}
134
139
135
- private void markSnapshotAsDestroyedIfAlreadyRemoved (Long snapshotId , SpApiResponse resp ) {
136
- if (resp .getError ().getName ().equals ("objectDoesNotExist" )) {
137
- SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao .findBySourceSnapshot (snapshotId , DataStoreRole .Primary );
138
- if (snapshotOnPrimary != null ) {
139
- snapshotOnPrimary .setState (State .Destroyed );
140
- _snapshotStoreDao .update (snapshotOnPrimary .getId (), snapshotOnPrimary );
140
+ private void markSnapshotAsDestroyedIfAlreadyRemoved (Long snapshotId , boolean isSnapshotDeleted ) {
141
+ if (!isSnapshotDeleted ) {
142
+ return ;
143
+ }
144
+ List <SnapshotDataStoreVO > snapshotsOnStore = _snapshotStoreDao .listBySnapshotIdAndState (snapshotId , State .Ready );
145
+ for (SnapshotDataStoreVO snapshot : snapshotsOnStore ) {
146
+ if (snapshot .getInstallPath () != null && snapshot .getInstallPath ().contains (StorPoolUtil .SP_DEV_PATH )) {
147
+ snapshot .setState (State .Destroyed );
148
+ _snapshotStoreDao .update (snapshot .getId (), snapshot );
141
149
}
142
150
}
143
151
}
0 commit comments