use of com.cloud.api.response.ConfigurationResponse in project CloudStack-archive by CloudStack-extras.
the class UpdateCfgCmd method execute.
@Override
public void execute() {
Configuration cfg = _configService.updateConfiguration(this);
if (cfg != null) {
ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update config");
}
}
use of com.cloud.api.response.ConfigurationResponse in project cosmic by MissionCriticalCloud.
the class ListCfgsByCmd method execute.
@Override
public void execute() {
final Pair<List<? extends Configuration>, Integer> result = _mgr.searchForConfigurations(this);
final ListResponse<ConfigurationResponse> response = new ListResponse<>();
final List<ConfigurationResponse> configResponses = new ArrayList<>();
for (final Configuration cfg : result.first()) {
final ConfigurationResponse cfgResponse = _responseGenerator.createConfigurationResponse(cfg);
cfgResponse.setObjectName("configuration");
if (getZoneId() != null) {
cfgResponse.setScope("zone");
}
if (getClusterId() != null) {
cfgResponse.setScope("cluster");
}
if (getStoragepoolId() != null) {
cfgResponse.setScope("storagepool");
}
if (getAccountId() != null) {
cfgResponse.setScope("account");
}
configResponses.add(cfgResponse);
}
response.setResponses(configResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.api.response.ConfigurationResponse in project cosmic by MissionCriticalCloud.
the class UpdateCfgCmd method execute.
@Override
public void execute() {
final Configuration cfg = _configService.updateConfiguration(this);
if (cfg != null) {
final ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg);
response.setResponseName(getCommandName());
if (getZoneId() != null) {
response.setScope("zone");
}
if (getClusterId() != null) {
response.setScope("cluster");
}
if (getStoragepoolId() != null) {
response.setScope("storagepool");
}
if (getAccountId() != null) {
response.setScope("account");
}
response.setValue(value);
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update config");
}
}
use of com.cloud.api.response.ConfigurationResponse in project cosmic by MissionCriticalCloud.
the class ListCfgCmdTest method testCreateSuccess.
@Test
public void testCreateSuccess() {
final Configuration cfg = Mockito.mock(Configuration.class);
listCfgsByCmd._mgr = mgr;
listCfgsByCmd._responseGenerator = responseGenerator;
final List<Configuration> configList = new ArrayList<>();
configList.add(cfg);
final Pair<List<? extends Configuration>, Integer> result = new Pair<>(configList, 1);
try {
Mockito.when(mgr.searchForConfigurations(listCfgsByCmd)).thenReturn(result);
} catch (final Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
final ConfigurationResponse cfgResponse = new ConfigurationResponse();
cfgResponse.setName("Test case");
Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(cfgResponse);
listCfgsByCmd.execute();
Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
final ListResponse<ConfigurationResponse> actualResponse = (ListResponse<ConfigurationResponse>) listCfgsByCmd.getResponseObject();
Assert.assertEquals(cfgResponse, actualResponse.getResponses().get(0));
}
use of com.cloud.api.response.ConfigurationResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createConfigurationResponse.
@Override
public ConfigurationResponse createConfigurationResponse(final Configuration cfg) {
final ConfigurationResponse cfgResponse = new ConfigurationResponse();
cfgResponse.setCategory(cfg.getCategory());
cfgResponse.setDescription(cfg.getDescription());
cfgResponse.setName(cfg.getName());
cfgResponse.setValue(cfg.getValue());
cfgResponse.setObjectName("configuration");
return cfgResponse;
}
Aggregations