Search in sources :

Example 1 with Volume

use of com.cloud.legacymodel.storage.Volume in project cosmic by MissionCriticalCloud.

the class LibvirtComputingResourceTest method testDestroyCommandError.

@Test
public void testDestroyCommandError() {
    final StoragePool pool = Mockito.mock(StoragePool.class);
    final Volume volume = Mockito.mock(Volume.class);
    final String vmName = "Test";
    final DestroyCommand command = new DestroyCommand(pool, volume, vmName);
    final KvmStoragePoolManager poolManager = Mockito.mock(KvmStoragePoolManager.class);
    final KvmStoragePool primary = Mockito.mock(KvmStoragePool.class);
    final VolumeTO vol = command.getVolume();
    when(this.libvirtComputingResource.getStoragePoolMgr()).thenReturn(poolManager);
    when(poolManager.getStoragePool(vol.getPoolType(), vol.getPoolUuid())).thenReturn(primary);
    when(primary.deletePhysicalDisk(vol.getPath(), null)).thenThrow(CloudRuntimeException.class);
    final LibvirtRequestWrapper wrapper = LibvirtRequestWrapper.getInstance();
    assertNotNull(wrapper);
    final Answer answer = wrapper.execute(command, this.libvirtComputingResource);
    assertFalse(answer.getResult());
    verify(this.libvirtComputingResource, times(1)).getStoragePoolMgr();
    verify(poolManager, times(1)).getStoragePool(vol.getPoolType(), vol.getPoolUuid());
}
Also used : Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) AttachAnswer(com.cloud.legacymodel.communication.answer.AttachAnswer) VolumeTO(com.cloud.legacymodel.to.VolumeTO) LibvirtRequestWrapper(com.cloud.agent.resource.kvm.wrapper.LibvirtRequestWrapper) NfsStoragePool(com.cloud.agent.resource.kvm.ha.KvmHaBase.NfsStoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) StoragePool(com.cloud.legacymodel.storage.StoragePool) KvmStoragePool(com.cloud.agent.resource.kvm.storage.KvmStoragePool) Volume(com.cloud.legacymodel.storage.Volume) DestroyCommand(com.cloud.legacymodel.communication.command.DestroyCommand) KvmStoragePoolManager(com.cloud.agent.resource.kvm.storage.KvmStoragePoolManager) Test(org.junit.Test)

Example 2 with Volume

use of com.cloud.legacymodel.storage.Volume in project cosmic by MissionCriticalCloud.

the class DetachVolumeCmdByAdmin method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("Volume Id: " + getId() + " VmId: " + getVirtualMachineId());
    final Volume result = _volumeService.detachVolumeFromVM(this);
    if (result != null) {
        final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
        response.setResponseName("volume");
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to detach volume");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.legacymodel.storage.Volume)

Example 3 with Volume

use of com.cloud.legacymodel.storage.Volume in project cosmic by MissionCriticalCloud.

the class ResizeVolumeCmdByAdmin method execute.

@Override
public void execute() throws ResourceAllocationException {
    Volume volume = null;
    try {
        CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G");
        volume = _volumeService.resizeVolume(this);
    } catch (final InvalidParameterValueException ex) {
        s_logger.info(ex.getMessage());
        throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage());
    }
    if (volume != null) {
        final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
        // FIXME - have to be moved to ApiResponseHelper
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) VolumeResponse(com.cloud.api.response.VolumeResponse) Volume(com.cloud.legacymodel.storage.Volume) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException)

Example 4 with Volume

use of com.cloud.legacymodel.storage.Volume in project cosmic by MissionCriticalCloud.

the class UploadVolumeCmdByAdmin method execute.

@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException {
    final Volume volume = _volumeService.uploadVolume(this);
    if (volume != null) {
        final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to upload volume");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.legacymodel.storage.Volume)

Example 5 with Volume

use of com.cloud.legacymodel.storage.Volume in project cosmic by MissionCriticalCloud.

the class MigrateVolumeCmdByAdmin method execute.

@Override
public void execute() {
    final Volume result;
    result = _volumeService.migrateVolume(this);
    if (result != null) {
        final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to migrate volume");
    }
}
Also used : VolumeResponse(com.cloud.api.response.VolumeResponse) ServerApiException(com.cloud.api.ServerApiException) Volume(com.cloud.legacymodel.storage.Volume)

Aggregations

Volume (com.cloud.legacymodel.storage.Volume)54 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)19 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)17 StoragePool (com.cloud.legacymodel.storage.StoragePool)17 ServerApiException (com.cloud.api.ServerApiException)16 VolumeResponse (com.cloud.api.response.VolumeResponse)15 VmWorkAttachVolume (com.cloud.vm.VmWorkAttachVolume)14 VmWorkMigrateVolume (com.cloud.vm.VmWorkMigrateVolume)14 HashMap (java.util.HashMap)11 Account (com.cloud.legacymodel.user.Account)10 PermissionDeniedException (com.cloud.legacymodel.exceptions.PermissionDeniedException)8 ArrayList (java.util.ArrayList)8 ActionEvent (com.cloud.event.ActionEvent)7 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)7 VmWorkDetachVolume (com.cloud.vm.VmWorkDetachVolume)7 VmWorkExtractVolume (com.cloud.vm.VmWorkExtractVolume)7 VmWorkResizeVolume (com.cloud.vm.VmWorkResizeVolume)7 Map (java.util.Map)7 ExecutionException (java.util.concurrent.ExecutionException)7 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)6