Search in sources :

Example 1 with ImageStoreResponse

use of org.apache.cloudstack.api.response.ImageStoreResponse 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 ImageStoreResponse

use of org.apache.cloudstack.api.response.ImageStoreResponse 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 ImageStoreResponse

use of org.apache.cloudstack.api.response.ImageStoreResponse in project cloudstack by apache.

the class ImageStoreJoinDaoImpl method newImageStoreResponse.

@Override
public ImageStoreResponse newImageStoreResponse(ImageStoreJoinVO ids) {
    ImageStoreResponse osResponse = new ImageStoreResponse();
    osResponse.setId(ids.getUuid());
    osResponse.setName(ids.getName());
    osResponse.setProviderName(ids.getProviderName());
    osResponse.setProtocol(ids.getProtocol());
    osResponse.setReadonly(ids.isReadonly());
    String url = ids.getUrl();
    // if store is type cifs, remove the password
    if (ids.getProtocol().equals("cifs".toString())) {
        url = StringUtils.cleanString(url);
    }
    osResponse.setUrl(url);
    osResponse.setScope(ids.getScope());
    osResponse.setZoneId(ids.getZoneUuid());
    osResponse.setZoneName(ids.getZoneName());
    StorageStats secStorageStats = ApiDBUtils.getSecondaryStorageStatistics(ids.getId());
    if (secStorageStats != null) {
        osResponse.setDiskSizeTotal(secStorageStats.getCapacityBytes());
        osResponse.setDiskSizeUsed(secStorageStats.getByteUsed());
    }
    osResponse.setHasAnnotation(annotationDao.hasAnnotations(ids.getUuid(), AnnotationService.EntityType.SECONDARY_STORAGE.name(), accountManager.isRootAdmin(CallContext.current().getCallingAccount().getId())));
    osResponse.setObjectName("imagestore");
    return osResponse;
}
Also used : ImageStoreResponse(org.apache.cloudstack.api.response.ImageStoreResponse) StorageStats(com.cloud.storage.StorageStats)

Example 4 with ImageStoreResponse

use of org.apache.cloudstack.api.response.ImageStoreResponse 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)

Example 5 with ImageStoreResponse

use of org.apache.cloudstack.api.response.ImageStoreResponse in project cloudstack by apache.

the class AddSwiftCmd method execute.

@Override
public void execute() {
    Map<String, String> dm = new HashMap<String, String>();
    dm.put(ApiConstants.ACCOUNT, getAccount());
    dm.put(ApiConstants.USERNAME, getUsername());
    dm.put(ApiConstants.KEY, getKey());
    try {
        ImageStore result = _storageService.discoverImageStore(null, getUrl(), "Swift", null, dm);
        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 Swift 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) HashMap(java.util.HashMap) DiscoveryException(com.cloud.exception.DiscoveryException) ImageStore(com.cloud.storage.ImageStore)

Aggregations

ImageStoreResponse (org.apache.cloudstack.api.response.ImageStoreResponse)11 ImageStore (com.cloud.storage.ImageStore)8 ServerApiException (org.apache.cloudstack.api.ServerApiException)7 DiscoveryException (com.cloud.exception.DiscoveryException)5 HashMap (java.util.HashMap)2 ImageStoreJoinVO (com.cloud.api.query.vo.ImageStoreJoinVO)1 StorageService (com.cloud.storage.StorageService)1 StorageStats (com.cloud.storage.StorageStats)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)1 ListImageStoresCmd (org.apache.cloudstack.api.command.admin.storage.ListImageStoresCmd)1 Test (org.junit.Test)1