@@ -180,7 +180,10 @@ protected Void createSnapshotAsyncCallback(AsyncCallbackDispatcher<AncientSnasph
180180
181181 try {
182182 SnapshotVO preSnapshotVO = this .snapshotMgr .getParentSnapshot (volume , snapshot );
183- String preSnapshotPath = preSnapshotVO .getPath ();
183+ String preSnapshotPath = null ;
184+ if (preSnapshotVO != null ) {
185+ preSnapshotPath = preSnapshotVO .getPath ();
186+ }
184187 SnapshotVO snapshotVO = this .snapshotDao .findById (snapshot .getId ());
185188 // The snapshot was successfully created
186189 if (preSnapshotPath != null && preSnapshotPath .equals (result .getPath ())) {
@@ -238,6 +241,11 @@ protected Void createSnapshotAsyncCallback(AsyncCallbackDispatcher<AncientSnasph
238241 } catch (Exception e ) {
239242 s_logger .debug ("Failed to create snapshot: " , e );
240243 snapResult .setResult (e .toString ());
244+ try {
245+ snapshot .processEvent (Snapshot .Event .OperationFailed );
246+ } catch (NoTransitionException e1 ) {
247+ s_logger .debug ("Failed to change snapshot state: " + e1 .toString ());
248+ }
241249 }
242250
243251 future .complete (snapResult );
@@ -263,19 +271,30 @@ protected SnapshotInfo createSnapshotOnPrimary(VolumeInfo volume, Long snapshotI
263271 s_logger .debug ("Failed to update snapshot state due to " + nte .getMessage ());
264272 throw new CloudRuntimeException ("Failed to update snapshot state due to " + nte .getMessage ());
265273 }
266- AsyncCallFuture <SnapshotResult > future = new AsyncCallFuture <SnapshotResult >();
267274
268- CreateSnapshotContext <CommandResult > context = new CreateSnapshotContext <CommandResult >(
269- null , volume , snapshot , future );
270- AsyncCallbackDispatcher <AncientSnasphotStrategy , CreateCmdResult > caller = AsyncCallbackDispatcher
271- .create (this );
272- caller .setCallback (
273- caller .getTarget ().createSnapshotAsyncCallback (null , null ))
274- .setContext (context );
275- PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver )volume .getDataStore ().getDriver ();
276-
277- primaryStore .takeSnapshot (snapshot , caller );
275+ AsyncCallFuture <SnapshotResult > future = new AsyncCallFuture <SnapshotResult >();
276+ try {
277+ CreateSnapshotContext <CommandResult > context = new CreateSnapshotContext <CommandResult >(
278+ null , volume , snapshot , future );
279+ AsyncCallbackDispatcher <AncientSnasphotStrategy , CreateCmdResult > caller = AsyncCallbackDispatcher
280+ .create (this );
281+ caller .setCallback (
282+ caller .getTarget ().createSnapshotAsyncCallback (null , null ))
283+ .setContext (context );
284+ PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver )volume .getDataStore ().getDriver ();
285+ primaryStore .takeSnapshot (snapshot , caller );
286+ } catch (Exception e ) {
287+ s_logger .debug ("Failed to take snapshot: " + snapshot .getId (), e );
288+ try {
289+ snapshot .processEvent (Snapshot .Event .OperationFailed );
290+ } catch (NoTransitionException e1 ) {
291+ s_logger .debug ("Failed to change state for event: OperationFailed" , e );
292+ }
293+ throw new CloudRuntimeException ("Failed to take snapshot" + snapshot .getId ());
294+ }
295+
278296 SnapshotResult result ;
297+
279298 try {
280299 result = future .get ();
281300 if (result .isFailed ()) {
@@ -390,6 +409,11 @@ public SnapshotInfo backupSnapshot(SnapshotInfo snapshot) {
390409 } catch (Exception e ) {
391410 s_logger .debug ("Failed to copy snapshot" , e );
392411 result .setResult ("Failed to copy snapshot:" +e .toString ());
412+ try {
413+ snapObj .processEvent (Snapshot .Event .OperationFailed );
414+ } catch (NoTransitionException e1 ) {
415+ s_logger .debug ("Failed to change state: " + e1 .toString ());
416+ }
393417 future .complete (result );
394418 }
395419
0 commit comments