Search in sources :

Example 1 with RegionResponse

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

the class RegionCmdTest method testCreateSuccess.

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

Example 2 with RegionResponse

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

the class ListRegionsCmd method execute.

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

Example 3 with RegionResponse

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

the class AddRegionCmd method execute.

@Override
public void execute() {
    Region region = _regionService.addRegion(getId(), getRegionName(), getEndPoint());
    if (region != null) {
        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(org.apache.cloudstack.api.response.RegionResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Region(org.apache.cloudstack.region.Region)

Example 4 with RegionResponse

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

the class UpdateRegionCmd method execute.

@Override
public void execute() {
    Region region = _regionService.updateRegion(getId(), getRegionName(), getEndPoint());
    if (region != null) {
        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(org.apache.cloudstack.api.response.RegionResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Region(org.apache.cloudstack.region.Region)

Example 5 with RegionResponse

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

the class ApiResponseHelper method createRegionResponse.

@Override
public RegionResponse createRegionResponse(Region region) {
    RegionResponse response = new RegionResponse();
    response.setId(region.getId());
    response.setName(region.getName());
    response.setEndPoint(region.getEndPoint());
    response.setObjectName("region");
    response.setGslbServiceEnabled(region.checkIfServiceEnabled(Region.Service.Gslb));
    response.setPortableipServiceEnabled(region.checkIfServiceEnabled(Region.Service.PortableIp));
    return response;
}
Also used : RegionResponse(org.apache.cloudstack.api.response.RegionResponse)

Aggregations

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