use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CreateTemplateCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Template Id: " + getEntityUuid() + ((getSnapshotId() == null) ? " from volume Id: " + this._uuidMgr.getUuid(Volume.class, getVolumeId()) : " from snapshot Id: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId())));
VirtualMachineTemplate template = _templateService.createPrivateTemplate(this);
if (template != null) {
List<TemplateResponse> templateResponses;
if (isBareMetal()) {
templateResponses = _responseGenerator.createTemplateResponses(getResponseView(), template.getId(), vmId);
} else {
templateResponses = _responseGenerator.createTemplateResponses(getResponseView(), template.getId(), snapshotId, volumeId, false);
}
TemplateResponse response = new TemplateResponse();
if (templateResponses != null && !templateResponses.isEmpty()) {
response = templateResponses.get(0);
}
response.setResponseName(getCommandName());
setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create private template");
}
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CreateVolumeCmd method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + getEntityUuid() + ((getSnapshotId() == null) ? "" : " from snapshot: " + this._uuidMgr.getUuid(Snapshot.class, getSnapshotId())));
Volume volume = _volumeService.createVolume(this);
if (volume != null) {
VolumeResponse response = _responseGenerator.createVolumeResponse(getResponseView(), 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");
}
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CreateSnapshotFromVMSnapshotCmd method execute.
@Override
public void execute() {
s_logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis());
CallContext.current().setEventDetails("Vm Snapshot Id: " + this._uuidMgr.getUuid(VMSnapshot.class, getVMSnapshotId()));
Snapshot snapshot = null;
try {
snapshot = _snapshotService.backupSnapshotFromVmSnapshot(getEntityId(), getVmId(), getVolumeId(), getVMSnapshotId());
if (snapshot != null) {
SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId());
}
} catch (InvalidParameterValueException ex) {
throw ex;
} catch (Exception e) {
s_logger.debug("Failed to create snapshot", e);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId());
} finally {
if (snapshot == null) {
try {
_snapshotService.deleteSnapshot(getEntityId());
} catch (Exception e) {
s_logger.debug("Failed to clean failed snapshot" + getEntityId());
}
}
}
}
use of com.cloud.storage.Snapshot in project cloudstack by apache.
the class CreateSnapshotCmdTest method testCreateSuccess.
@Test
public void testCreateSuccess() {
AccountService accountService = Mockito.mock(AccountService.class);
Account account = Mockito.mock(Account.class);
Mockito.when(accountService.getAccount(anyLong())).thenReturn(account);
VolumeApiService volumeApiService = Mockito.mock(VolumeApiService.class);
Snapshot snapshot = Mockito.mock(Snapshot.class);
try {
Mockito.when(volumeApiService.takeSnapshot(nullable(Long.class), nullable(Long.class), isNull(), nullable(Account.class), nullable(Boolean.class), nullable(Snapshot.LocationType.class), nullable(Boolean.class), nullable(Map.class))).thenReturn(snapshot);
} catch (Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
responseGenerator = Mockito.mock(ResponseGenerator.class);
SnapshotResponse snapshotResponse = Mockito.mock(SnapshotResponse.class);
Mockito.when(responseGenerator.createSnapshotResponse(snapshot)).thenReturn(snapshotResponse);
Mockito.doNothing().when(snapshotResponse).setAccountName(anyString());
createSnapshotCmd._accountService = accountService;
createSnapshotCmd._responseGenerator = responseGenerator;
createSnapshotCmd._volumeService = volumeApiService;
try {
createSnapshotCmd.execute();
} catch (Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
}
use of com.cloud.storage.Snapshot in project cosmic by MissionCriticalCloud.
the class CreateVolumeCmdByAdmin method execute.
@Override
public void execute() {
CallContext.current().setEventDetails("Volume Id: " + getEntityId() + ((getSnapshotId() == null) ? "" : " from snapshot: " + getSnapshotId()));
final Volume volume = _volumeService.createVolume(this);
if (volume != null) {
final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
// FIXME - have to be moved to ApiResponseHelper
if (getSnapshotId() != null) {
final 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");
}
}
Aggregations