Search in sources :

Example 1 with Configuration

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);
}
Also used : ConfigurationResponse(com.cloud.api.response.ConfigurationResponse) Configuration(com.cloud.config.Configuration) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Configuration

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");
    }
}
Also used : ConfigurationResponse(com.cloud.api.response.ConfigurationResponse) Configuration(com.cloud.config.Configuration) ServerApiException(com.cloud.api.ServerApiException)

Example 3 with Configuration

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));
}
Also used : ConfigurationResponse(com.cloud.api.response.ConfigurationResponse) Configuration(com.cloud.config.Configuration) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair) Test(org.junit.Test)

Example 4 with Configuration

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());
}
Also used : ConfigurationResponse(com.cloud.api.response.ConfigurationResponse) Configuration(com.cloud.config.Configuration) ServerApiException(com.cloud.api.ServerApiException) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Test(org.junit.Test)

Aggregations

ConfigurationResponse (com.cloud.api.response.ConfigurationResponse)4 Configuration (com.cloud.config.Configuration)4 ServerApiException (com.cloud.api.ServerApiException)2 ListResponse (com.cloud.api.response.ListResponse)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 Pair (com.cloud.utils.Pair)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1