use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.
the class ListDedicatedZonesCmd method execute.
@Override
public void execute() {
Pair<List<? extends DedicatedResourceVO>, Integer> result = _dedicatedservice.listDedicatedZones(this);
ListResponse<DedicateZoneResponse> response = new ListResponse<DedicateZoneResponse>();
List<DedicateZoneResponse> Responses = new ArrayList<DedicateZoneResponse>();
if (result != null) {
for (DedicatedResources resource : result.first()) {
DedicateZoneResponse zoneResponse = _dedicatedservice.createDedicateZoneResponse(resource);
Responses.add(zoneResponse);
}
response.setResponses(Responses, result.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated zones");
}
}
use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.
the class QuotaEmailTemplateUpdateCmdTest method testQuotaEmailTemplateUpdateCmd.
@Test
public void testQuotaEmailTemplateUpdateCmd() throws NoSuchFieldException, IllegalAccessException {
QuotaEmailTemplateUpdateCmd cmd = new QuotaEmailTemplateUpdateCmd();
Field rbField = QuotaEmailTemplateUpdateCmd.class.getDeclaredField("_quotaResponseBuilder");
rbField.setAccessible(true);
rbField.set(cmd, responseBuilder);
// templatename parameter check
try {
cmd.execute();
} catch (ServerApiException e) {
assertTrue(e.getErrorCode().equals(ApiErrorCode.PARAM_ERROR));
}
// invalid template name test
cmd.setTemplateName("randomTemplate");
cmd.setTemplateBody("some body");
cmd.setTemplateSubject("some subject");
try {
cmd.execute();
} catch (ServerApiException e) {
assertTrue(e.getErrorCode().equals(ApiErrorCode.PARAM_ERROR));
}
// valid template test
cmd.setTemplateName(QuotaConfig.QuotaEmailTemplateTypes.QUOTA_EMPTY.toString());
Mockito.when(responseBuilder.updateQuotaEmailTemplate(Mockito.eq(cmd))).thenReturn(true);
cmd.execute();
Mockito.verify(responseBuilder, Mockito.times(1)).updateQuotaEmailTemplate(Mockito.eq(cmd));
}
use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.
the class ListDedicatedClustersCmd method execute.
@Override
public void execute() {
Pair<List<? extends DedicatedResourceVO>, Integer> result = dedicatedService.listDedicatedClusters(this);
ListResponse<DedicateClusterResponse> response = new ListResponse<DedicateClusterResponse>();
List<DedicateClusterResponse> Responses = new ArrayList<DedicateClusterResponse>();
if (result != null) {
for (DedicatedResources resource : result.first()) {
DedicateClusterResponse clusterResponse = dedicatedService.createDedicateClusterResponse(resource);
Responses.add(clusterResponse);
}
response.setResponses(Responses, result.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated clusters");
}
}
use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.
the class ListDedicatedPodsCmd method execute.
@Override
public void execute() {
Pair<List<? extends DedicatedResourceVO>, Integer> result = dedicatedService.listDedicatedPods(this);
ListResponse<DedicatePodResponse> response = new ListResponse<DedicatePodResponse>();
List<DedicatePodResponse> Responses = new ArrayList<DedicatePodResponse>();
if (result != null) {
for (DedicatedResources resource : result.first()) {
DedicatePodResponse podresponse = dedicatedService.createDedicatePodResponse(resource);
Responses.add(podresponse);
}
response.setResponses(Responses, result.second());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to list dedicated pods");
}
}
use of org.apache.cloudstack.api.ServerApiException in project cloudstack by apache.
the class DedicateClusterCmd method execute.
@Override
public void execute() {
List<? extends DedicatedResources> result = dedicatedService.dedicateCluster(getClusterId(), getDomainId(), getAccountName());
ListResponse<DedicateClusterResponse> response = new ListResponse<DedicateClusterResponse>();
List<DedicateClusterResponse> clusterResponseList = new ArrayList<DedicateClusterResponse>();
// List of result should always contain single element as only one cluster will be associated with each cluster ID.
if (result != null && result.size() == 1) {
DedicateClusterResponse clusterResponse = dedicatedService.createDedicateClusterResponse(result.get(0));
clusterResponse.setResponseName(getCommandName());
this.setResponseObject(clusterResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to dedicate cluster");
}
}
Aggregations