use of com.cloud.config.Configuration 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.config.Configuration 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.config.Configuration 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.config.Configuration in project cosmic by MissionCriticalCloud.
the class UpdateCfgCmdTest method testCreateSuccess.
@Test
public void testCreateSuccess() {
final Configuration cfg = Mockito.mock(Configuration.class);
updateCfgCmd._configService = configService;
updateCfgCmd._responseGenerator = responseGenerator;
try {
Mockito.when(configService.updateConfiguration(updateCfgCmd)).thenReturn(cfg);
} catch (final Exception e) {
Assert.fail("Received exception when success expected " + e.getMessage());
}
final ConfigurationResponse response = new ConfigurationResponse();
response.setName("Test case");
Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(response);
updateCfgCmd.execute();
Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
final ConfigurationResponse actualResponse = (ConfigurationResponse) updateCfgCmd.getResponseObject();
Assert.assertEquals(response, actualResponse);
Assert.assertEquals("updateconfigurationresponse", response.getResponseName());
}
Aggregations