Search in sources :

Example 1 with Region

use of com.cloud.region.Region 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 Region

use of com.cloud.region.Region 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 3 with Region

use of com.cloud.region.Region in project cosmic by MissionCriticalCloud.

the class RegionCmdTest method testCreateFailure.

@Test
public void testCreateFailure() {
    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(null);
    addRegionCmd._regionService = regionService;
    try {
        addRegionCmd.execute();
    } catch (final ServerApiException exception) {
        Assert.assertEquals("Failed to add Region", exception.getDescription());
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) Region(com.cloud.region.Region) RegionService(com.cloud.region.RegionService) Test(org.junit.Test)

Example 4 with Region

use of com.cloud.region.Region 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 Region

use of com.cloud.region.Region 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

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