Search in sources :

Example 1 with Snapshot

use of com.cloud.storage.Snapshot in project CloudStack-archive by CloudStack-extras.

the class CreateSnapshotCmd method execute.

@Override
public void execute() {
    UserContext.current().setEventDetails("Volume Id: " + getVolumeId());
    Snapshot snapshot = _snapshotService.createSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()));
    if (snapshot != null) {
        SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + volumeId);
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) ServerApiException(com.cloud.api.ServerApiException) SnapshotResponse(com.cloud.api.response.SnapshotResponse)

Example 2 with Snapshot

use of com.cloud.storage.Snapshot in project cloudstack by apache.

the class CreateVolumeCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
    Volume volume = _volumeService.createVolume(this);
    if (volume != null) {
        VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
        //FIXME - have to be moved to ApiResponseHelper
        if (getSnapshotId() != null) {
            Snapshot snap = _entityMgr.findById(Snapshot.class, getSnapshotId());
            if (snap != null) {
                // if the volume was
                response.setSnapshotId(snap.getUuid());
            // created from a
            // snapshot,
            // snapshotId will
            // be set so we pass
            // it back in the
            // response
            }
        }
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create a volume");
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) VolumeResponse(org.apache.cloudstack.api.response.VolumeResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Volume(com.cloud.storage.Volume)

Example 3 with Snapshot

use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.

the class SnapshotManagerTest method testRevertSnapshotF3.

// vm on KVM, successful
@Test
public void testRevertSnapshotF3() {
    when(_vmDao.findById(anyLong())).thenReturn(vmMock);
    when(vmMock.getState()).thenReturn(State.Stopped);
    when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.KVM);
    when(volumeMock.getFormat()).thenReturn(ImageFormat.QCOW2);
    when(snapshotStrategy.revertSnapshot(Mockito.any(SnapshotInfo.class))).thenReturn(true);
    when(_volumeDao.update(anyLong(), any(VolumeVO.class))).thenReturn(true);
    final Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
    Assert.assertNotNull(snapshot);
}
Also used : VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) VolumeVO(com.cloud.storage.VolumeVO) Test(org.junit.Test)

Example 4 with Snapshot

use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.

the class SnapshotManagerTest method testRevertSnapshotF2.

// vm on Xenserver, return null
@Test
public void testRevertSnapshotF2() {
    when(_vmDao.findById(anyLong())).thenReturn(vmMock);
    when(vmMock.getState()).thenReturn(State.Stopped);
    when(vmMock.getHypervisorType()).thenReturn(Hypervisor.HypervisorType.XenServer);
    when(volumeMock.getFormat()).thenReturn(ImageFormat.VHD);
    final Snapshot snapshot = _snapshotMgr.revertSnapshot(TEST_SNAPSHOT_ID);
    Assert.assertNull(snapshot);
}
Also used : VMSnapshot(com.cloud.vm.snapshot.VMSnapshot) Snapshot(com.cloud.storage.Snapshot) Test(org.junit.Test)

Example 5 with Snapshot

use of com.cloud.storage.Snapshot in project cloudstack by apache.

the class CreateSnapshotCmd method create.

@Override
public void create() throws ResourceAllocationException {
    Snapshot snapshot = _volumeService.allocSnapshot(getVolumeId(), getPolicyId(), getSnapshotName(), getLocationType());
    if (snapshot != null) {
        setEntityId(snapshot.getId());
        setEntityUuid(snapshot.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot for volume" + getVolumeUuid());
    }
}
Also used : Snapshot(com.cloud.storage.Snapshot) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Aggregations

Snapshot (com.cloud.storage.Snapshot)43 VMSnapshot (com.cloud.vm.snapshot.VMSnapshot)19 Test (org.junit.Test)11 ServerApiException (org.apache.cloudstack.api.ServerApiException)10 ServerApiException (com.cloud.api.ServerApiException)8 Volume (com.cloud.storage.Volume)8 VolumeVO (com.cloud.storage.VolumeVO)8 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)7 SnapshotResponse (com.cloud.api.response.SnapshotResponse)6 Account (com.cloud.user.Account)6 SnapshotResponse (org.apache.cloudstack.api.response.SnapshotResponse)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 DataStoreRole (com.cloud.storage.DataStoreRole)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)3