Search in sources :

Example 1 with ImageStoreResponse

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());
    }
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) ServerApiException(com.cloud.api.ServerApiException) ServerApiException(com.cloud.api.ServerApiException) ImageStore(com.cloud.storage.ImageStore)

Example 2 with ImageStoreResponse

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());
}
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 3 with ImageStoreResponse

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());
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ImageStoreJoinVO(com.cloud.api.query.vo.ImageStoreJoinVO)

Example 4 with ImageStoreResponse

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;
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) ImageStoreDetailResponse(com.cloud.api.response.ImageStoreDetailResponse)

Example 5 with ImageStoreResponse

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());
    }
}
Also used : ImageStoreResponse(com.cloud.api.response.ImageStoreResponse) ServerApiException(com.cloud.api.ServerApiException) DiscoveryException(com.cloud.exception.DiscoveryException) ImageStore(com.cloud.storage.ImageStore)

Aggregations

ImageStoreResponse (com.cloud.api.response.ImageStoreResponse)6 ImageStore (com.cloud.storage.ImageStore)4 ServerApiException (com.cloud.api.ServerApiException)3 DiscoveryException (com.cloud.exception.DiscoveryException)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 ImageStoreJoinVO (com.cloud.api.query.vo.ImageStoreJoinVO)1 ImageStoreDetailResponse (com.cloud.api.response.ImageStoreDetailResponse)1 StorageService (com.cloud.storage.StorageService)1 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 Test (org.junit.Test)1