2525import org .apache .log4j .Logger ;
2626import org .springframework .stereotype .Component ;
2727
28- import org .apache .cloudstack .engine .orchestration .service .VolumeOrchestrationService ;
2928import org .apache .cloudstack .engine .subsystem .api .storage .ClusterScope ;
3029import org .apache .cloudstack .engine .subsystem .api .storage .CopyCommandResult ;
3130import org .apache .cloudstack .engine .subsystem .api .storage .DataMotionStrategy ;
4645import org .apache .cloudstack .framework .async .AsyncCompletionCallback ;
4746import org .apache .cloudstack .framework .config .dao .ConfigurationDao ;
4847import org .apache .cloudstack .storage .command .CopyCommand ;
49- import org .apache .cloudstack .storage .datastore .db .PrimaryDataStoreDao ;
50- import org .apache .cloudstack .storage .datastore .db .SnapshotDataStoreDao ;
51- import org .apache .cloudstack .storage .datastore .db .TemplateDataStoreDao ;
52- import org .apache .cloudstack .storage .datastore .db .VolumeDataStoreDao ;
5348import org .apache .cloudstack .storage .image .datastore .ImageStoreEntity ;
5449
5550import com .cloud .agent .api .Answer ;
6257import com .cloud .agent .api .to .VirtualMachineTO ;
6358import com .cloud .configuration .Config ;
6459import com .cloud .host .Host ;
65- import com .cloud .host .dao .HostDao ;
6660import com .cloud .server .ManagementService ;
6761import com .cloud .storage .DataStoreRole ;
68- import com .cloud .storage .StorageManager ;
6962import com .cloud .storage .StoragePool ;
7063import com .cloud .storage .VolumeVO ;
71- import com .cloud .storage .dao .DiskOfferingDao ;
72- import com .cloud .storage .dao .SnapshotDao ;
73- import com .cloud .storage .dao .VMTemplateDao ;
74- import com .cloud .storage .dao .VMTemplatePoolDao ;
7564import com .cloud .storage .dao .VolumeDao ;
76- import com .cloud .storage .snapshot .SnapshotManager ;
77- import com .cloud .template .TemplateManager ;
7865import com .cloud .utils .NumbersUtil ;
7966import com .cloud .utils .db .DB ;
8067import com .cloud .utils .exception .CloudRuntimeException ;
@@ -177,7 +164,13 @@ protected Answer copyObject(DataObject srcData, DataObject destData) {
177164
178165 CopyCommand cmd = new CopyCommand (srcForCopy .getTO (), destData .getTO (), _primaryStorageDownloadWait , _mgmtServer .getExecuteInSequence ());
179166 EndPoint ep = selector .select (srcForCopy , destData );
180- answer = ep .sendMessage (cmd );
167+ if (ep == null ) {
168+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
169+ s_logger .error (errMsg );
170+ answer = new Answer (cmd , false , errMsg );
171+ } else {
172+ answer = ep .sendMessage (cmd );
173+ }
181174
182175 if (cacheData != null ) {
183176 if (srcData .getType () == DataObjectType .VOLUME && destData .getType () == DataObjectType .VOLUME ) {
@@ -255,7 +248,14 @@ protected Answer copyVolumeFromSnapshot(DataObject snapObj, DataObject volObj) {
255248 }
256249
257250 CopyCommand cmd = new CopyCommand (srcData .getTO (), volObj .getTO (), _createVolumeFromSnapshotWait , _mgmtServer .getExecuteInSequence ());
258- Answer answer = ep .sendMessage (cmd );
251+ Answer answer = null ;
252+ if (ep == null ) {
253+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
254+ s_logger .error (errMsg );
255+ answer = new Answer (cmd , false , errMsg );
256+ } else {
257+ answer = ep .sendMessage (cmd );
258+ }
259259
260260 return answer ;
261261 } catch (Exception e ) {
@@ -273,7 +273,14 @@ protected Answer cloneVolume(DataObject template, DataObject volume) {
273273 CopyCommand cmd = new CopyCommand (template .getTO (), volume .getTO (), 0 , _mgmtServer .getExecuteInSequence ());
274274 try {
275275 EndPoint ep = selector .select (volume .getDataStore ());
276- Answer answer = ep .sendMessage (cmd );
276+ Answer answer = null ;
277+ if (ep == null ) {
278+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
279+ s_logger .error (errMsg );
280+ answer = new Answer (cmd , false , errMsg );
281+ } else {
282+ answer = ep .sendMessage (cmd );
283+ }
277284 return answer ;
278285 } catch (Exception e ) {
279286 s_logger .debug ("Failed to send to storage pool" , e );
@@ -315,7 +322,13 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
315322
316323 CopyCommand cmd = new CopyCommand (objOnImageStore .getTO (), destData .getTO (), _copyvolumewait , _mgmtServer .getExecuteInSequence ());
317324 EndPoint ep = selector .select (objOnImageStore , destData );
318- answer = ep .sendMessage (cmd );
325+ if (ep == null ) {
326+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
327+ s_logger .error (errMsg );
328+ answer = new Answer (cmd , false , errMsg );
329+ } else {
330+ answer = ep .sendMessage (cmd );
331+ }
319332
320333 if (answer == null || !answer .getResult ()) {
321334 if (answer != null ) {
@@ -333,7 +346,14 @@ protected Answer copyVolumeBetweenPools(DataObject srcData, DataObject destData)
333346 DataObject cacheData = cacheMgr .createCacheObject (srcData , destScope );
334347 CopyCommand cmd = new CopyCommand (cacheData .getTO (), destData .getTO (), _copyvolumewait , _mgmtServer .getExecuteInSequence ());
335348 EndPoint ep = selector .select (cacheData , destData );
336- Answer answer = ep .sendMessage (cmd );
349+ Answer answer = null ;
350+ if (ep == null ) {
351+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
352+ s_logger .error (errMsg );
353+ answer = new Answer (cmd , false , errMsg );
354+ } else {
355+ answer = ep .sendMessage (cmd );
356+ }
337357 // delete volume on cache store
338358 if (cacheData != null ) {
339359 cacheMgr .deleteCacheObject (cacheData );
@@ -348,15 +368,22 @@ protected Answer migrateVolumeToPool(DataObject srcData, DataObject destData) {
348368 StoragePool destPool = (StoragePool )dataStoreMgr .getDataStore (destData .getDataStore ().getId (), DataStoreRole .Primary );
349369 MigrateVolumeCommand command = new MigrateVolumeCommand (volume .getId (), volume .getPath (), destPool );
350370 EndPoint ep = selector .select (volume .getDataStore ());
351- MigrateVolumeAnswer answer = (MigrateVolumeAnswer ) ep .sendMessage (command );
371+ Answer answer = null ;
372+ if (ep == null ) {
373+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
374+ s_logger .error (errMsg );
375+ answer = new Answer (command , false , errMsg );
376+ } else {
377+ answer = ep .sendMessage (command );
378+ }
352379
353380 if (answer == null || !answer .getResult ()) {
354381 throw new CloudRuntimeException ("Failed to migrate volume " + volume + " to storage pool " + destPool );
355382 } else {
356383 // Update the volume details after migration.
357384 VolumeVO volumeVo = volDao .findById (volume .getId ());
358385 Long oldPoolId = volume .getPoolId ();
359- volumeVo .setPath (answer .getVolumePath ());
386+ volumeVo .setPath ((( MigrateVolumeAnswer ) answer ) .getVolumePath ());
360387 volumeVo .setFolder (destPool .getPath ());
361388 volumeVo .setPodId (destPool .getPodId ());
362389 volumeVo .setPoolId (destPool .getId ());
@@ -431,7 +458,14 @@ protected Answer createTemplateFromSnapshot(DataObject srcData, DataObject destD
431458 }
432459
433460 CopyCommand cmd = new CopyCommand (srcData .getTO (), destData .getTO (), _createprivatetemplatefromsnapshotwait , _mgmtServer .getExecuteInSequence ());
434- Answer answer = ep .sendMessage (cmd );
461+ Answer answer = null ;
462+ if (ep == null ) {
463+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
464+ s_logger .error (errMsg );
465+ answer = new Answer (cmd , false , errMsg );
466+ } else {
467+ answer = ep .sendMessage (cmd );
468+ }
435469
436470 // clean up snapshot copied to staging
437471 if (needCache && srcData != null ) {
@@ -455,11 +489,23 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) {
455489 CopyCommand cmd = new CopyCommand (srcData .getTO (), destData .getTO (), _backupsnapshotwait , _mgmtServer .getExecuteInSequence ());
456490 cmd .setCacheTO (cacheData .getTO ());
457491 EndPoint ep = selector .select (srcData , destData );
458- answer = ep .sendMessage (cmd );
492+ if (ep == null ) {
493+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
494+ s_logger .error (errMsg );
495+ answer = new Answer (cmd , false , errMsg );
496+ } else {
497+ answer = ep .sendMessage (cmd );
498+ }
459499 } else {
460500 CopyCommand cmd = new CopyCommand (srcData .getTO (), destData .getTO (), _backupsnapshotwait , _mgmtServer .getExecuteInSequence ());
461501 EndPoint ep = selector .select (srcData , destData );
462- answer = ep .sendMessage (cmd );
502+ if (ep == null ) {
503+ String errMsg = "No remote endpoint to send command, check if host or ssvm is down?" ;
504+ s_logger .error (errMsg );
505+ answer = new Answer (cmd , false , errMsg );
506+ } else {
507+ answer = ep .sendMessage (cmd );
508+ }
463509 }
464510 // clean up cache entry in case of failure
465511 if (answer == null || !answer .getResult ()) {
0 commit comments