@Override public void execute() { Pair<List<? extends Snapshot>, Integer> result = _snapshotService.listSnapshots(this); ListResponse<SnapshotResponse> response = new ListResponse<SnapshotResponse>(); List<SnapshotResponse> snapshotResponses = new ArrayList<SnapshotResponse>(); for (Snapshot snapshot : result.first()) { SnapshotResponse snapshotResponse = _responseGenerator.createSnapshotResponse(snapshot); snapshotResponse.setObjectName("snapshot"); snapshotResponses.add(snapshotResponse); } response.setResponses(snapshotResponses, result.second()); response.setResponseName(getCommandName()); setResponseObject(response); }
@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(anyLong(), anyLong(), anyLong(), any(Account.class), anyBoolean(), isNull(Snapshot.LocationType.class), anyBoolean())).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()); } }
@Override public void execute() { CallContext.current().setEventDetails("Snapshot Id: " + this._uuidMgr.getUuid(Snapshot.class, getId())); Snapshot snapshot = _snapshotService.revertSnapshot(getId()); if (snapshot != null) { SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot); response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to revert snapshot"); } } }
@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()); } } } }
@Override public void execute() { Snapshot snapshot; try { snapshot = _volumeService.takeSnapshot(getVolumeId(), getPolicyId(), getEntityId(), _accountService.getAccount(getEntityOwnerId()), getQuiescevm(), getLocationType(), getAsyncBackup()); if (snapshot != null) { SnapshotResponse response = _responseGenerator.createSnapshotResponse(snapshot); response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeId()); } } catch (Exception e) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot for volume " + getVolumeId()); } }