Search in sources :

Example 1 with DeleteVMSnapshotCommand

use of com.cloud.legacymodel.communication.command.DeleteVMSnapshotCommand 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 2 with DeleteVMSnapshotCommand

use of com.cloud.legacymodel.communication.command.DeleteVMSnapshotCommand in project cosmic by MissionCriticalCloud.

the class NotAValidCommand method testDeleteVMSnapshotCommand.

@Test
public void testDeleteVMSnapshotCommand() {
    final Connection conn = Mockito.mock(Connection.class);
    final VMSnapshotTO snapshotTO = Mockito.mock(VMSnapshotTO.class);
    final List<VolumeObjectTO> volumeTOs = new ArrayList<>();
    final DeleteVMSnapshotCommand vmSnapshot = new DeleteVMSnapshotCommand("Test", snapshotTO, volumeTOs, "Debian");
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(this.citrixResourceBase.getConnection()).thenReturn(conn);
    final Answer answer = wrapper.execute(vmSnapshot, this.citrixResourceBase);
    verify(this.citrixResourceBase, times(1)).getConnection();
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.legacymodel.communication.answer.RebootAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CreateAnswer(com.cloud.legacymodel.communication.answer.CreateAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) VMSnapshotTO(com.cloud.legacymodel.to.VMSnapshotTO) DeleteVMSnapshotCommand(com.cloud.legacymodel.communication.command.DeleteVMSnapshotCommand) Connection(com.xensource.xenapi.Connection) ArrayList(java.util.ArrayList) VolumeObjectTO(com.cloud.legacymodel.to.VolumeObjectTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Answer (com.cloud.legacymodel.communication.answer.Answer)2 DeleteVMSnapshotCommand (com.cloud.legacymodel.communication.command.DeleteVMSnapshotCommand)2 VMSnapshotTO (com.cloud.legacymodel.to.VMSnapshotTO)2 VolumeObjectTO (com.cloud.legacymodel.to.VolumeObjectTO)2 AttachAnswer (com.cloud.legacymodel.communication.answer.AttachAnswer)1 CreateAnswer (com.cloud.legacymodel.communication.answer.CreateAnswer)1 CreateVMSnapshotAnswer (com.cloud.legacymodel.communication.answer.CreateVMSnapshotAnswer)1 DeleteVMSnapshotAnswer (com.cloud.legacymodel.communication.answer.DeleteVMSnapshotAnswer)1 RebootAnswer (com.cloud.legacymodel.communication.answer.RebootAnswer)1 RevertToVMSnapshotAnswer (com.cloud.legacymodel.communication.answer.RevertToVMSnapshotAnswer)1 AgentUnavailableException (com.cloud.legacymodel.exceptions.AgentUnavailableException)1 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)1 NoTransitionException (com.cloud.legacymodel.exceptions.NoTransitionException)1 OperationTimedoutException (com.cloud.legacymodel.exceptions.OperationTimedoutException)1 GuestOSVO (com.cloud.storage.GuestOSVO)1 UserVmVO (com.cloud.vm.UserVmVO)1 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)1 Connection (com.xensource.xenapi.Connection)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1