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());
}
}
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());
}
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;
}
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());
}
}
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());
}
}
Aggregations