Search in sources :

Example 1 with ConfigurationResponse

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

Example 2 with ConfigurationResponse

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);
}
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 3 with ConfigurationResponse

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

Example 4 with ConfigurationResponse

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));
}
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 5 with ConfigurationResponse

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

Aggregations

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