Search in sources :

Example 61 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class DefaultVMSnapshotStrategy method revertVMSnapshot.

@Override
public boolean revertVMSnapshot(final VMSnapshot vmSnapshot) {
    final VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    final UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.RevertRequested);
    } catch (final NoTransitionException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    boolean result = false;
    try {
        final VMSnapshotVO snapshot = vmSnapshotDao.findById(vmSnapshotVO.getId());
        final List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
        final String vmInstanceName = userVm.getInstanceName();
        final VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(snapshot).getParent();
        final VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(), snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent, true);
        final Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
        final GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        final RevertToVMSnapshotCommand revertToSnapshotCommand = new RevertToVMSnapshotCommand(vmInstanceName, userVm.getUuid(), vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
        final HostVO host = hostDao.findById(hostId);
        final GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
        if (guestOsMapping == null) {
            revertToSnapshotCommand.setPlatformEmulator(null);
        } else {
            revertToSnapshotCommand.setPlatformEmulator(guestOsMapping.getGuestOsName());
        }
        final RevertToVMSnapshotAnswer answer = (RevertToVMSnapshotAnswer) agentMgr.send(hostId, revertToSnapshotCommand);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            result = true;
        } else {
            String errMsg = "Revert VM: " + userVm.getInstanceName() + " to snapshot: " + vmSnapshotVO.getName() + " failed";
            if (answer != null && answer.getDetails() != null) {
                errMsg = errMsg + " due to " + answer.getDetails();
            }
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
    } catch (final OperationTimedoutException e) {
        s_logger.debug("Failed to revert vm snapshot", e);
        throw new CloudRuntimeException(e.getMessage());
    } catch (final AgentUnavailableException e) {
        s_logger.debug("Failed to revert vm snapshot", e);
        throw new CloudRuntimeException(e.getMessage());
    } finally {
        if (!result) {
            try {
                vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
            } catch (final NoTransitionException e1) {
                s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage());
            }
        }
    }
    return result;
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) RevertToVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RevertToVMSnapshotAnswer) RevertToVMSnapshotCommand(com.cloud.legacymodel.communication.command.RevertToVMSnapshotCommand) GuestOSVO(com.cloud.storage.GuestOSVO) HostVO(com.cloud.host.HostVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) VMSnapshotTO(com.cloud.legacymodel.to.VMSnapshotTO) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO)

Example 62 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class DefaultVMSnapshotStrategy method deleteVMSnapshot.

@Override
public boolean deleteVMSnapshot(final VMSnapshot vmSnapshot) {
    final UserVmVO userVm = userVmDao.findById(vmSnapshot.getVmId());
    final VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.ExpungeRequested);
    } catch (final NoTransitionException e) {
        s_logger.debug("Failed to change vm snapshot state with event ExpungeRequested");
        throw new CloudRuntimeException("Failed to change vm snapshot state with event ExpungeRequested: " + e.getMessage());
    }
    try {
        final Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
        final List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(vmSnapshot.getVmId());
        final String vmInstanceName = userVm.getInstanceName();
        final VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(vmSnapshotVO).getParent();
        final VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent, true);
        final GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        final DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs, guestOS.getDisplayName());
        final Answer answer = agentMgr.send(hostId, deleteSnapshotCommand);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            return true;
        } else {
            final String errMsg = (answer == null) ? null : answer.getDetails();
            s_logger.error("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
            throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + errMsg);
        }
    } catch (final OperationTimedoutException | AgentUnavailableException e) {
        throw new CloudRuntimeException("Delete vm snapshot " + vmSnapshot.getName() + " of vm " + userVm.getInstanceName() + " failed due to " + e.getMessage());
    }
}
Also used : UserVmVO(com.cloud.vm.UserVmVO) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) GuestOSVO(com.cloud.storage.GuestOSVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) DeleteVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.DeleteVMSnapshotAnswer) RevertToVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RevertToVMSnapshotAnswer) CreateVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.CreateVMSnapshotAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) VMSnapshotTO(com.cloud.legacymodel.to.VMSnapshotTO) DeleteVMSnapshotCommand(com.cloud.legacymodel.communication.command.DeleteVMSnapshotCommand) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO)

Example 63 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class DefaultVMSnapshotStrategy method processAnswer.

@DB
protected void processAnswer(final VMSnapshotVO vmSnapshot, final UserVm userVm, final Answer as, final Long hostId) {
    try {
        Transaction.execute(new TransactionCallbackWithExceptionNoReturn<NoTransitionException>() {

            @Override
            public void doInTransactionWithoutResult(final TransactionStatus status) throws NoTransitionException {
                if (as instanceof CreateVMSnapshotAnswer) {
                    final CreateVMSnapshotAnswer answer = (CreateVMSnapshotAnswer) as;
                    finalizeCreate(vmSnapshot, answer.getVolumeTOs());
                    vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationSucceeded);
                } else if (as instanceof RevertToVMSnapshotAnswer) {
                    final RevertToVMSnapshotAnswer answer = (RevertToVMSnapshotAnswer) as;
                    finalizeRevert(vmSnapshot, answer.getVolumeTOs());
                    vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationSucceeded);
                } else if (as instanceof DeleteVMSnapshotAnswer) {
                    final DeleteVMSnapshotAnswer answer = (DeleteVMSnapshotAnswer) as;
                    finalizeDelete(vmSnapshot, answer.getVolumeTOs());
                    vmSnapshotDao.remove(vmSnapshot.getId());
                }
            }
        });
    } catch (final Exception e) {
        final String errMsg = "Error while process answer: " + as.getClass() + " due to " + e.getMessage();
        s_logger.error(errMsg, e);
        throw new CloudRuntimeException(errMsg);
    }
}
Also used : CreateVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.CreateVMSnapshotAnswer) RevertToVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.RevertToVMSnapshotAnswer) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) TransactionStatus(com.cloud.utils.db.TransactionStatus) DeleteVMSnapshotAnswer(com.cloud.legacymodel.communication.answer.DeleteVMSnapshotAnswer) ConfigurationException(javax.naming.ConfigurationException) OperationTimedoutException(com.cloud.legacymodel.exceptions.OperationTimedoutException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) AgentUnavailableException(com.cloud.legacymodel.exceptions.AgentUnavailableException) DB(com.cloud.utils.db.DB)

Example 64 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class VolumeObject method processEvent.

@Override
public void processEvent(final ObjectInDataStoreStateMachine.Event event) {
    if (dataStore == null) {
        return;
    }
    try {
        Volume.Event volEvent = null;
        if (dataStore.getRole() == DataStoreRole.ImageCache) {
            objectInStoreMgr.update(this, event);
            return;
        }
        if (dataStore.getRole() == DataStoreRole.Image) {
            objectInStoreMgr.update(this, event);
            if (volumeVO.getState() == Volume.State.Migrating || volumeVO.getState() == Volume.State.Copying || volumeVO.getState() == Volume.State.Uploaded || volumeVO.getState() == Volume.State.Expunged) {
                return;
            }
            if (event == ObjectInDataStoreStateMachine.Event.CreateOnlyRequested) {
                volEvent = Volume.Event.UploadRequested;
            } else if (event == ObjectInDataStoreStateMachine.Event.MigrationRequested) {
                volEvent = Volume.Event.CopyRequested;
            }
        } else {
            if (event == ObjectInDataStoreStateMachine.Event.CreateRequested || event == ObjectInDataStoreStateMachine.Event.CreateOnlyRequested) {
                volEvent = Volume.Event.CreateRequested;
            } else if (event == ObjectInDataStoreStateMachine.Event.CopyingRequested) {
                volEvent = Volume.Event.CopyRequested;
            } else if (event == ObjectInDataStoreStateMachine.Event.MigrationRequested) {
                volEvent = Volume.Event.MigrationRequested;
            } else if (event == ObjectInDataStoreStateMachine.Event.MigrationCopyRequested) {
                volEvent = Event.MigrationCopyRequested;
            }
        }
        if (event == ObjectInDataStoreStateMachine.Event.DestroyRequested) {
            volEvent = Volume.Event.DestroyRequested;
        } else if (event == ObjectInDataStoreStateMachine.Event.ExpungeRequested) {
            volEvent = Volume.Event.ExpungingRequested;
        } else if (event == ObjectInDataStoreStateMachine.Event.OperationSuccessed) {
            volEvent = Volume.Event.OperationSucceeded;
        } else if (event == ObjectInDataStoreStateMachine.Event.MigrationCopySucceeded) {
            volEvent = Event.MigrationCopySucceeded;
        } else if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
            volEvent = Volume.Event.OperationFailed;
        } else if (event == ObjectInDataStoreStateMachine.Event.MigrationCopyFailed) {
            volEvent = Event.MigrationCopyFailed;
        } else if (event == ObjectInDataStoreStateMachine.Event.ResizeRequested) {
            volEvent = Volume.Event.ResizeRequested;
        }
        stateTransit(volEvent);
    } catch (final Exception e) {
        s_logger.debug("Failed to update state", e);
        throw new CloudRuntimeException("Failed to update state:" + e.toString());
    } finally {
        // state transit call reloads the volume from DB and so check for null as well
        if (event == ObjectInDataStoreStateMachine.Event.OperationFailed && (volumeVO != null && volumeVO.getState() != Volume.State.Copying && volumeVO.getState() != Volume.State.Uploaded && volumeVO.getState() != Volume.State.UploadError)) {
            objectInStoreMgr.deleteIfNotReady(this);
        }
    }
}
Also used : Volume(com.cloud.legacymodel.storage.Volume) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException)

Example 65 with CloudRuntimeException

use of com.cloud.legacymodel.exceptions.CloudRuntimeException in project cosmic by MissionCriticalCloud.

the class VolumeObject method stateTransit.

@Override
public boolean stateTransit(final Volume.Event event) {
    boolean result = false;
    try {
        volumeVO = volumeDao.findById(volumeVO.getId());
        if (volumeVO != null) {
            result = new StateMachine2Transitions(_volStateMachine).transitTo(volumeVO, event, null, volumeDao);
            volumeVO = volumeDao.findById(volumeVO.getId());
        }
    } catch (final NoTransitionException e) {
        final String errorMessage = "Failed to transit volume: " + getVolumeId() + ", due to: " + e.toString();
        s_logger.debug(errorMessage);
        throw new CloudRuntimeException(errorMessage);
    }
    return result;
}
Also used : StateMachine2Transitions(com.cloud.utils.fsm.StateMachine2Transitions) CloudRuntimeException(com.cloud.legacymodel.exceptions.CloudRuntimeException) NoTransitionException(com.cloud.legacymodel.exceptions.NoTransitionException)

Aggregations

CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)587 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)159 ArrayList (java.util.ArrayList)110 DB (com.cloud.utils.db.DB)90 Account (com.cloud.legacymodel.user.Account)84 SQLException (java.sql.SQLException)84 ActionEvent (com.cloud.event.ActionEvent)73 ConfigurationException (javax.naming.ConfigurationException)73 PreparedStatement (java.sql.PreparedStatement)68 HashMap (java.util.HashMap)68 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)62 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)52 HostVO (com.cloud.host.HostVO)50 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)50 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)50 XenAPIException (com.xensource.xenapi.Types.XenAPIException)47 Answer (com.cloud.legacymodel.communication.answer.Answer)45 XmlRpcException (org.apache.xmlrpc.XmlRpcException)45 TransactionStatus (com.cloud.utils.db.TransactionStatus)44 IOException (java.io.IOException)44