Search in sources :

Example 1 with RegionResponse

use of com.cloud.api.response.RegionResponse in project cosmic by MissionCriticalCloud.

the class ListRegionsCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final List<? extends Region> result = _regionService.listRegions(this);
    final ListResponse<RegionResponse> response = new ListResponse<>();
    final List<RegionResponse> regionResponses = new ArrayList<>();
    for (final Region region : result) {
        final RegionResponse regionResponse = _responseGenerator.createRegionResponse(region);
        regionResponse.setObjectName("region");
        regionResponses.add(regionResponse);
    }
    response.setResponses(regionResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : RegionResponse(com.cloud.api.response.RegionResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) Region(com.cloud.region.Region)

Example 2 with RegionResponse

use of com.cloud.api.response.RegionResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createRegionResponse.

@Override
public RegionResponse createRegionResponse(final Region region) {
    final RegionResponse response = new RegionResponse();
    response.setId(region.getId());
    response.setName(region.getName());
    response.setEndPoint(region.getEndPoint());
    response.setObjectName("region");
    return response;
}
Also used : RegionResponse(com.cloud.api.response.RegionResponse)

Example 3 with RegionResponse

use of com.cloud.api.response.RegionResponse in project cosmic by MissionCriticalCloud.

the class RegionCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    final RegionService regionService = Mockito.mock(RegionService.class);
    final Region region = Mockito.mock(Region.class);
    Mockito.when(regionService.addRegion(Matchers.anyInt(), Matchers.anyString(), Matchers.anyString())).thenReturn(region);
    addRegionCmd._regionService = regionService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    final RegionResponse regionResponse = Mockito.mock(RegionResponse.class);
    Mockito.when(responseGenerator.createRegionResponse(region)).thenReturn(regionResponse);
    addRegionCmd._responseGenerator = responseGenerator;
    addRegionCmd.execute();
}
Also used : RegionResponse(com.cloud.api.response.RegionResponse) ResponseGenerator(com.cloud.api.ResponseGenerator) Region(com.cloud.region.Region) RegionService(com.cloud.region.RegionService) Test(org.junit.Test)

Example 4 with RegionResponse

use of com.cloud.api.response.RegionResponse in project cosmic by MissionCriticalCloud.

the class AddRegionCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Region region = _regionService.addRegion(getId(), getRegionName(), getEndPoint());
    if (region != null) {
        final RegionResponse response = _responseGenerator.createRegionResponse(region);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Region");
    }
}
Also used : RegionResponse(com.cloud.api.response.RegionResponse) ServerApiException(com.cloud.api.ServerApiException) Region(com.cloud.region.Region)

Example 5 with RegionResponse

use of com.cloud.api.response.RegionResponse in project cosmic by MissionCriticalCloud.

the class UpdateRegionCmd method execute.

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    final Region region = _regionService.updateRegion(getId(), getRegionName(), getEndPoint());
    if (region != null) {
        final RegionResponse response = _responseGenerator.createRegionResponse(region);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update Region");
    }
}
Also used : RegionResponse(com.cloud.api.response.RegionResponse) ServerApiException(com.cloud.api.ServerApiException) Region(com.cloud.region.Region)

Aggregations

RegionResponse (com.cloud.api.response.RegionResponse)5 Region (com.cloud.region.Region)4 ServerApiException (com.cloud.api.ServerApiException)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 ListResponse (com.cloud.api.response.ListResponse)1 RegionService (com.cloud.region.RegionService)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1