use of com.cloud.api.response.ImageStoreResponse 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());
}
}
use of com.cloud.api.response.ImageStoreResponse 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());
}
use of com.cloud.api.response.ImageStoreResponse in project cosmic by MissionCriticalCloud.
the class ViewResponseHelper method createImageStoreResponse.
public static List<ImageStoreResponse> createImageStoreResponse(final ImageStoreJoinVO... stores) {
final Hashtable<Long, ImageStoreResponse> vrDataList = new Hashtable<>();
// Initialise the vrdatalist with the input data
for (final ImageStoreJoinVO vr : stores) {
ImageStoreResponse vrData = vrDataList.get(vr.getId());
if (vrData == null) {
// first time encountering this vm
vrData = ApiDBUtils.newImageStoreResponse(vr);
} else {
// update tags
vrData = ApiDBUtils.fillImageStoreDetails(vrData, vr);
}
vrDataList.put(vr.getId(), vrData);
}
return new ArrayList<>(vrDataList.values());
}
use of com.cloud.api.response.ImageStoreResponse in project cosmic by MissionCriticalCloud.
the class ImageStoreJoinDaoImpl method newImageStoreResponse.
@Override
public ImageStoreResponse newImageStoreResponse(final ImageStoreJoinVO ids) {
final ImageStoreResponse osResponse = new ImageStoreResponse();
osResponse.setId(ids.getUuid());
osResponse.setName(ids.getName());
osResponse.setProviderName(ids.getProviderName());
osResponse.setProtocol(ids.getProtocol());
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());
final String detailName = ids.getDetailName();
if (detailName != null && detailName.length() > 0 && !detailName.equals(ApiConstants.PASSWORD)) {
String detailValue = ids.getDetailValue();
if (detailName.equals(ApiConstants.KEY)) {
// ALWAYS return an empty value for the S3 secret key since that key is managed by Amazon and not CloudStack
detailValue = "";
}
final ImageStoreDetailResponse osdResponse = new ImageStoreDetailResponse(detailName, detailValue);
osResponse.addDetail(osdResponse);
}
osResponse.setObjectName("imagestore");
return osResponse;
}
use of com.cloud.api.response.ImageStoreResponse in project cosmic by MissionCriticalCloud.
the class AddImageStoreCmd method execute.
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
try {
final ImageStore result = _storageService.discoverImageStore(getName(), getUrl(), getProviderName(), getZoneId(), 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 (final DiscoveryException ex) {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
}
}
Aggregations