Search in sources :

Example 1 with ImageStore

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

the class AddSecondaryStorageCmd method execute.

@Override
public void execute() {
    try {
        ImageStore result = _storageService.discoverImageStore(null, getUrl(), "NFS", getZoneId(), null);
        ImageStoreResponse storeResponse = null;
        if (result != null) {
            storeResponse = _responseGenerator.createImageStoreResponse(result);
            storeResponse.setResponseName(getCommandName());
            storeResponse.setObjectName("secondarystorage");
            setResponseObject(storeResponse);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
        }
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ImageStoreResponse(org.apache.cloudstack.api.response.ImageStoreResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DiscoveryException(com.cloud.exception.DiscoveryException) ImageStore(com.cloud.storage.ImageStore)

Example 2 with ImageStore

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

the class AddSecondaryStorageCmdTest method testExecuteForResult.

@Test
public void testExecuteForResult() throws Exception {
    StorageService resourceService = Mockito.mock(StorageService.class);
    addImageStoreCmd._storageService = resourceService;
    ImageStore store = Mockito.mock(ImageStore.class);
    Mockito.when(resourceService.discoverImageStore(isNull(), isNull(), isNull(), isNull(), isNull())).thenReturn(store);
    ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
    addImageStoreCmd._responseGenerator = responseGenerator;
    ImageStoreResponse responseHost = new ImageStoreResponse();
    responseHost.setName("Test");
    Mockito.doReturn(responseHost).when(responseGenerator).createImageStoreResponse(store);
    addImageStoreCmd.execute();
    Mockito.verify(responseGenerator).createImageStoreResponse(store);
    ImageStoreResponse actualResponse = (ImageStoreResponse) addImageStoreCmd.getResponseObject();
    assertEquals(responseHost, actualResponse);
    assertEquals("addimagestoreresponse", actualResponse.getResponseName());
}
Also used : ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) ImageStoreResponse(org.apache.cloudstack.api.response.ImageStoreResponse) StorageService(com.cloud.storage.StorageService) ImageStore(com.cloud.storage.ImageStore) Test(org.junit.Test)

Example 3 with ImageStore

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

the class CreateSecondaryStagingStoreCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    try {
        final ImageStore result = _storageService.createSecondaryStagingStore(this);
        ImageStoreResponse storeResponse = null;
        if (result != null) {
            storeResponse = _responseGenerator.createImageStoreResponse(result);
            storeResponse.setResponseName(getCommandName());
            storeResponse.setObjectName("secondarystorage");
            this.setResponseObject(storeResponse);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
        }
    } catch (final Exception ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) ServerApiException(com.cloud.api.ServerApiException) ServerApiException(com.cloud.api.ServerApiException) ImageStore(com.cloud.storage.ImageStore)

Example 4 with ImageStore

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

the class AddSecondaryStorageCmdTest method testExecuteForResult.

@Test
public void testExecuteForResult() throws Exception {
    final StorageService resourceService = Mockito.mock(StorageService.class);
    addImageStoreCmd._storageService = resourceService;
    final ImageStore store = Mockito.mock(ImageStore.class);
    Mockito.when(resourceService.discoverImageStore(anyString(), anyString(), anyString(), anyLong(), (Map) anyObject())).thenReturn(store);
    final ResponseGenerator responseGenerator = Mockito.mock(ResponseGenerator.class);
    addImageStoreCmd._responseGenerator = responseGenerator;
    final ImageStoreResponse responseHost = new ImageStoreResponse();
    responseHost.setName("Test");
    Mockito.when(responseGenerator.createImageStoreResponse(store)).thenReturn(responseHost);
    addImageStoreCmd.execute();
    Mockito.verify(responseGenerator).createImageStoreResponse(store);
    final ImageStoreResponse actualResponse = (ImageStoreResponse) addImageStoreCmd.getResponseObject();
    Assert.assertEquals(responseHost, actualResponse);
    Assert.assertEquals("addimagestoreresponse", actualResponse.getResponseName());
}
Also used : ResponseGenerator(com.cloud.api.ResponseGenerator) ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) StorageService(com.cloud.storage.StorageService) ImageStore(com.cloud.storage.ImageStore) Test(org.junit.Test)

Example 5 with ImageStore

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

the class UpdateCloudToUseObjectStoreCmd method execute.

@Override
public void execute() {
    try {
        ImageStore result = _storageService.migrateToObjectStore(getName(), getUrl(), getProviderName(), getDetails());
        ImageStoreResponse storeResponse = null;
        if (result != null) {
            storeResponse = _responseGenerator.createImageStoreResponse(result);
            storeResponse.setResponseName(getCommandName());
            storeResponse.setObjectName("imagestore");
            setResponseObject(storeResponse);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage");
        }
    } catch (DiscoveryException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : ImageStoreResponse(org.apache.cloudstack.api.response.ImageStoreResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) DiscoveryException(com.cloud.exception.DiscoveryException) ImageStore(com.cloud.storage.ImageStore)

Aggregations

ImageStore (com.cloud.storage.ImageStore)13 ImageStoreResponse (org.apache.cloudstack.api.response.ImageStoreResponse)8 DiscoveryException (com.cloud.exception.DiscoveryException)7 ServerApiException (org.apache.cloudstack.api.ServerApiException)7 ImageStoreResponse (com.cloud.api.response.ImageStoreResponse)4 ServerApiException (com.cloud.api.ServerApiException)3 StorageService (com.cloud.storage.StorageService)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 StoragePoolJoinVO (com.cloud.api.query.vo.StoragePoolJoinVO)1 StorageStats (com.cloud.storage.StorageStats)1 BigDecimal (java.math.BigDecimal)1 ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)1 ZoneScope (org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope)1