Search in sources :

Example 1 with Configuration

use of org.apache.cloudstack.config.Configuration in project cloudstack by apache.

the class ListCfgsByCmd method execute.

@Override
public void execute() {
    Pair<List<? extends Configuration>, Integer> result = _mgr.searchForConfigurations(this);
    ListResponse<ConfigurationResponse> response = new ListResponse<ConfigurationResponse>();
    List<ConfigurationResponse> configResponses = new ArrayList<ConfigurationResponse>();
    for (Configuration cfg : result.first()) {
        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");
        }
        if (getDomainId() != null) {
            cfgResponse.setScope("domain");
        }
        if (getImageStoreId() != null) {
            cfgResponse.setScope("imagestore");
        }
        configResponses.add(cfgResponse);
    }
    response.setResponses(configResponses, result.second());
    response.setResponseName(getCommandName());
    setResponseObject(response);
}
Also used : ConfigurationResponse(org.apache.cloudstack.api.response.ConfigurationResponse) Configuration(org.apache.cloudstack.config.Configuration) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Configuration

use of org.apache.cloudstack.config.Configuration in project cloudstack by apache.

the class ResetCfgCmd method execute.

@Override
public void execute() {
    Pair<Configuration, String> cfg = _configService.resetConfiguration(this);
    if (cfg != null) {
        ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg.first());
        response.setResponseName(getCommandName());
        if (getZoneId() != null) {
            response.setScope(ConfigKey.Scope.Zone.name());
        }
        if (getClusterId() != null) {
            response.setScope(ConfigKey.Scope.Cluster.name());
        }
        if (getStoragepoolId() != null) {
            response.setScope(ConfigKey.Scope.StoragePool.name());
        }
        if (getDomainId() != null) {
            response.setScope(ConfigKey.Scope.Domain.name());
        }
        if (getAccountId() != null) {
            response.setScope(ConfigKey.Scope.Account.name());
        }
        if (getImageStoreId() != null) {
            response.setScope(ConfigKey.Scope.ImageStore.name());
        }
        response.setValue(cfg.second());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset config");
    }
}
Also used : ConfigurationResponse(org.apache.cloudstack.api.response.ConfigurationResponse) Configuration(org.apache.cloudstack.config.Configuration) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 3 with Configuration

use of org.apache.cloudstack.config.Configuration in project cloudstack by apache.

the class ListCfgCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    Configuration cfg = Mockito.mock(Configuration.class);
    listCfgsByCmd._mgr = mgr;
    listCfgsByCmd._responseGenerator = responseGenerator;
    List<Configuration> configList = new ArrayList<Configuration>();
    configList.add(cfg);
    Pair<List<? extends Configuration>, Integer> result = new Pair<List<? extends Configuration>, Integer>(configList, 1);
    try {
        Mockito.when(mgr.searchForConfigurations(listCfgsByCmd)).thenReturn(result);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    ConfigurationResponse cfgResponse = new ConfigurationResponse();
    cfgResponse.setName("Test case");
    Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(cfgResponse);
    listCfgsByCmd.execute();
    Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
    ListResponse<ConfigurationResponse> actualResponse = (ListResponse<ConfigurationResponse>) listCfgsByCmd.getResponseObject();
    Assert.assertEquals(cfgResponse, actualResponse.getResponses().get(0));
}
Also used : ConfigurationResponse(org.apache.cloudstack.api.response.ConfigurationResponse) Configuration(org.apache.cloudstack.config.Configuration) ListResponse(org.apache.cloudstack.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 org.apache.cloudstack.config.Configuration in project cloudstack by apache.

the class UpdateCfgCmd method execute.

@Override
public void execute() {
    if (StringUtils.isEmpty(getCfgName())) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Empty configuration name provided");
    }
    if (getCfgName().equalsIgnoreCase(RoleService.EnableDynamicApiChecker.key())) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Restricted configuration update not allowed");
    }
    Configuration cfg = _configService.updateConfiguration(this);
    if (cfg != null) {
        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");
        }
        if (getDomainId() != null) {
            response.setScope("domain");
        }
        response.setValue(value);
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update config");
    }
}
Also used : ConfigurationResponse(org.apache.cloudstack.api.response.ConfigurationResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) Configuration(org.apache.cloudstack.config.Configuration)

Example 5 with Configuration

use of org.apache.cloudstack.config.Configuration in project cloudstack by apache.

the class UpdateCfgCmdTest method testCreateSuccess.

@Test
public void testCreateSuccess() {
    Configuration cfg = Mockito.mock(Configuration.class);
    updateCfgCmd._configService = configService;
    updateCfgCmd._responseGenerator = responseGenerator;
    updateCfgCmd.setCfgName("some.cfg");
    try {
        Mockito.when(configService.updateConfiguration(updateCfgCmd)).thenReturn(cfg);
    } catch (Exception e) {
        Assert.fail("Received exception when success expected " + e.getMessage());
    }
    ConfigurationResponse response = new ConfigurationResponse();
    response.setName("Test case");
    Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(response);
    updateCfgCmd.execute();
    Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
    ConfigurationResponse actualResponse = (ConfigurationResponse) updateCfgCmd.getResponseObject();
    Assert.assertEquals(response, actualResponse);
    Assert.assertEquals("updateconfigurationresponse", response.getResponseName());
}
Also used : ConfigurationResponse(org.apache.cloudstack.api.response.ConfigurationResponse) Configuration(org.apache.cloudstack.config.Configuration) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Test(org.junit.Test)

Aggregations

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