|
28 | 28 | import javax.ejb.Local; |
29 | 29 | import javax.inject.Inject; |
30 | 30 |
|
| 31 | +import com.cloud.host.Host; |
31 | 32 | import org.apache.log4j.Logger; |
32 | 33 |
|
33 | 34 | import org.apache.cloudstack.storage.command.CopyCommand; |
|
42 | 43 | import com.cloud.agent.api.storage.CopyVolumeCommand; |
43 | 44 | import com.cloud.agent.api.storage.CreateVolumeOVACommand; |
44 | 45 | import com.cloud.agent.api.storage.PrepareOVAPackingCommand; |
45 | | -import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand; |
46 | 46 | import com.cloud.agent.api.to.DataObjectType; |
47 | 47 | import com.cloud.agent.api.to.DataStoreTO; |
48 | 48 | import com.cloud.agent.api.to.DataTO; |
@@ -294,92 +294,82 @@ public int compare(NicTO arg0, NicTO arg1) { |
294 | 294 | } |
295 | 295 |
|
296 | 296 | @Override @DB |
297 | | - public long getCommandHostDelegation(long hostId, Command cmd) { |
| 297 | + public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) { |
298 | 298 | boolean needDelegation = false; |
299 | 299 |
|
300 | | - if(cmd instanceof PrimaryStorageDownloadCommand || |
301 | | - cmd instanceof BackupSnapshotCommand || |
302 | | - cmd instanceof CreatePrivateTemplateFromVolumeCommand || |
303 | | - cmd instanceof CreatePrivateTemplateFromSnapshotCommand || |
304 | | - cmd instanceof CopyVolumeCommand || |
305 | | - cmd instanceof CreateVolumeOVACommand || |
306 | | - cmd instanceof PrepareOVAPackingCommand || |
307 | | - cmd instanceof CreateVolumeFromSnapshotCommand || |
308 | | - cmd instanceof CopyCommand) { |
309 | | - if (cmd instanceof CopyCommand) { |
310 | | - CopyCommand cpyCommand = (CopyCommand)cmd; |
311 | | - DataTO srcData = cpyCommand.getSrcTO(); |
312 | | - DataStoreTO srcStoreTO = srcData.getDataStore(); |
313 | | - DataTO destData = cpyCommand.getDestTO(); |
314 | | - DataStoreTO destStoreTO = destData.getDataStore(); |
315 | | - |
316 | | - if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && |
317 | | - srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) { |
318 | | - needDelegation = false; |
319 | | - } else { |
320 | | - needDelegation = true; |
321 | | - } |
| 300 | + if (cmd instanceof CopyCommand) { |
| 301 | + CopyCommand cpyCommand = (CopyCommand)cmd; |
| 302 | + DataTO srcData = cpyCommand.getSrcTO(); |
| 303 | + DataStoreTO srcStoreTO = srcData.getDataStore(); |
| 304 | + DataTO destData = cpyCommand.getDestTO(); |
| 305 | + DataStoreTO destStoreTO = destData.getDataStore(); |
| 306 | + |
| 307 | + if (!(HypervisorType.VMware == srcData.getHypervisorType() || |
| 308 | + HypervisorType.VMware == destData.getHypervisorType() |
| 309 | + )) { |
| 310 | + return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId)); |
| 311 | + } |
| 312 | + |
| 313 | + if (destData.getObjectType() == DataObjectType.VOLUME && destStoreTO.getRole() == DataStoreRole.Primary && |
| 314 | + srcData.getObjectType() == DataObjectType.TEMPLATE && srcStoreTO.getRole() == DataStoreRole.Primary) { |
| 315 | + needDelegation = false; |
322 | 316 | } else { |
323 | 317 | needDelegation = true; |
324 | 318 | } |
| 319 | + } |
325 | 320 |
|
| 321 | + if(!needDelegation) { |
| 322 | + return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId)); |
326 | 323 | } |
327 | | - /* Fang: remove this before checking in */ |
328 | | - // needDelegation = false; |
329 | 324 |
|
330 | | - if (cmd instanceof PrepareOVAPackingCommand || |
331 | | - cmd instanceof CreateVolumeOVACommand ) { |
| 325 | + HostVO host = _hostDao.findById(hostId); |
| 326 | + long dcId = host.getDataCenterId(); |
| 327 | + |
| 328 | + Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd); |
| 329 | + if(cmdTarget != null) { |
| 330 | + // TODO, we need to make sure agent is actually connected too |
| 331 | + |
332 | 332 | cmd.setContextParam("hypervisor", HypervisorType.VMware.toString()); |
333 | | - } |
334 | | - if(needDelegation) { |
335 | | - HostVO host = _hostDao.findById(hostId); |
336 | | - assert(host != null); |
337 | | - assert(host.getHypervisorType() == HypervisorType.VMware); |
338 | | - long dcId = host.getDataCenterId(); |
339 | | - |
340 | | - Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd); |
341 | | - if(cmdTarget != null) { |
342 | | - // TODO, we need to make sure agent is actually connected too |
343 | | - cmd.setContextParam("hypervisor", HypervisorType.VMware.toString()); |
| 333 | + if (host.getType() == Host.Type.Routing) { |
344 | 334 | Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId); |
345 | 335 | cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid"))); |
346 | 336 | cmd.setContextParam("username", hostDetails.get("username")); |
347 | 337 | cmd.setContextParam("password", hostDetails.get("password")); |
348 | 338 | cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName()); |
349 | 339 | cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName()); |
| 340 | + } |
350 | 341 |
|
351 | | - CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1); |
352 | | - _cmdExecLogDao.persist(execLog); |
353 | | - cmd.setContextParam("execid", String.valueOf(execLog.getId())); |
354 | | - |
355 | | - if(cmd instanceof BackupSnapshotCommand || |
356 | | - cmd instanceof CreatePrivateTemplateFromVolumeCommand || |
357 | | - cmd instanceof CreatePrivateTemplateFromSnapshotCommand || |
358 | | - cmd instanceof CopyVolumeCommand || |
359 | | - cmd instanceof CopyCommand || |
360 | | - cmd instanceof CreateVolumeOVACommand || |
361 | | - cmd instanceof PrepareOVAPackingCommand || |
362 | | - cmd instanceof CreateVolumeFromSnapshotCommand) { |
363 | | - |
364 | | - String workerName = _vmwareMgr.composeWorkerName(); |
365 | | - long checkPointId = 1; |
366 | | - // FIXME: Fix long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName)); |
367 | | - cmd.setContextParam("worker", workerName); |
368 | | - cmd.setContextParam("checkpoint", String.valueOf(checkPointId)); |
369 | | - |
370 | | - // some commands use 2 workers |
371 | | - String workerName2 = _vmwareMgr.composeWorkerName(); |
372 | | - long checkPointId2 = 1; |
373 | | - // FIXME: Fix long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2)); |
374 | | - cmd.setContextParam("worker2", workerName2); |
375 | | - cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2)); |
376 | | - } |
377 | | - |
378 | | - return cmdTarget.first().getId(); |
| 342 | + CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1); |
| 343 | + _cmdExecLogDao.persist(execLog); |
| 344 | + cmd.setContextParam("execid", String.valueOf(execLog.getId())); |
| 345 | + |
| 346 | + if(cmd instanceof BackupSnapshotCommand || |
| 347 | + cmd instanceof CreatePrivateTemplateFromVolumeCommand || |
| 348 | + cmd instanceof CreatePrivateTemplateFromSnapshotCommand || |
| 349 | + cmd instanceof CopyVolumeCommand || |
| 350 | + cmd instanceof CopyCommand || |
| 351 | + cmd instanceof CreateVolumeOVACommand || |
| 352 | + cmd instanceof PrepareOVAPackingCommand || |
| 353 | + cmd instanceof CreateVolumeFromSnapshotCommand) { |
| 354 | + |
| 355 | + String workerName = _vmwareMgr.composeWorkerName(); |
| 356 | + long checkPointId = 1; |
| 357 | + // FIXME: Fix long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName)); |
| 358 | + cmd.setContextParam("worker", workerName); |
| 359 | + cmd.setContextParam("checkpoint", String.valueOf(checkPointId)); |
| 360 | + |
| 361 | + // some commands use 2 workers |
| 362 | + String workerName2 = _vmwareMgr.composeWorkerName(); |
| 363 | + long checkPointId2 = 1; |
| 364 | + // FIXME: Fix long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2)); |
| 365 | + cmd.setContextParam("worker2", workerName2); |
| 366 | + cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2)); |
379 | 367 | } |
380 | | - } |
381 | 368 |
|
382 | | - return hostId; |
| 369 | + return new Pair<Boolean, Long>(Boolean.TRUE,cmdTarget.first().getId()); |
| 370 | + |
| 371 | + } |
| 372 | + return new Pair<Boolean, Long>(Boolean.FALSE, new Long(hostId)); |
383 | 373 | } |
384 | 374 |
|
385 | 375 | @Override |
|
0 commit comments