StateMachine2<Volume.State, Volume.Event, Volume> _stateMachine = Volume.State.getStateMachine();
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
VolumeDao volDao = locator.getDao(VolumeDao.class);
VMInstanceDao vmDao = locator.getDao(VMInstanceDao.class);
VirtualMachineManager vmMgr = locator.getManager(VirtualMachineManager.class);
Long vmInstanceId = null;
boolean success = true;
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
try {
txn.start();
for (Long volumeId : _volumesIds) {
VolumeVO volume = volDao.findById(volumeId);
if (volume == null) {
continue;
}
vmInstanceId = volume.getInstanceId();
if (_migrateState == StorageMigrationState.MIGRATING && volume.getState() == Volume.State.Migrating) {
try {
_stateMachine.transitTo(volume, Volume.Event.OperationFailed, null, volDao);
} catch (NoTransitionException e) {
s_logger.debug("Failed to transit volume state: " + e.toString());
success = false;
break;
}
}
}
if (vmInstanceId != null) {
VMInstanceVO vm = vmDao.findById(vmInstanceId);
if (vm != null && vm.getState() == VirtualMachine.State.Migrating) {
try {
vmMgr.stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
} catch (NoTransitionException e) {
s_logger.debug("Failed to transit vm state");
success = false;
}
}