Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.List;

import org.apache.cloudstack.api.command.admin.config.ResetCfgCmd;
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
Expand Down Expand Up @@ -76,6 +77,15 @@ public interface ConfigurationService {
*/
Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException;

/**
* Resets a configuration entry with default value
*
* @param cmd
* - the command wrapping name parameter
* @return updated configuration object if successful
*/
Pair<Configuration, String> resetConfiguration(ResetCfgCmd cmd) throws InvalidParameterValueException;

/**
* Create a service offering through the API
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@ public class ApiConstants {
public static final String VM_SNAPSHOT_MEMORY = "snapshotmemory";
public static final String VM_SNAPSHOT_QUIESCEVM = "quiescevm";
public static final String IMAGE_STORE_UUID = "imagestoreuuid";
public static final String IMAGE_STORE_ID = "imagestoreid";
public static final String GUEST_VM_CIDR = "guestvmcidr";
public static final String NETWORK_CIDR = "networkcidr";
public static final String RESERVED_IP_RANGE = "reservediprange";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package org.apache.cloudstack.api.command.admin.config;

import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.log4j.Logger;

import org.apache.cloudstack.api.response.AccountResponse;
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;

import com.cloud.user.Account;
import com.cloud.utils.Pair;

@APICommand(name = "resetConfiguration", description = "Resets a configuration. The configuration will be set to default value for global setting, and removed from account_details or domain_details for Account/Domain settings", responseObject = ConfigurationResponse.class,
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0")
public class ResetCfgCmd extends BaseCmd {
public static final Logger s_logger = Logger.getLogger(ResetCfgCmd.class.getName());
private static final String s_name = "resetconfigurationresponse";

/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the configuration", validations = {ApiArgValidator.NotNullOrEmpty})
private String cfgName;

@Parameter(name = ApiConstants.ZONE_ID,
type = CommandType.UUID,
entityType = ZoneResponse.class,
description = "the ID of the Zone to reset the parameter value for corresponding zone")
private Long zoneId;

@Parameter(name = ApiConstants.CLUSTER_ID,
type = CommandType.UUID,
entityType = ClusterResponse.class,
description = "the ID of the Cluster to reset the parameter value for corresponding cluster")
private Long clusterId;

@Parameter(name = ApiConstants.STORAGE_ID,
type = CommandType.UUID,
entityType = StoragePoolResponse.class,
description = "the ID of the Storage pool to reset the parameter value for corresponding storage pool")
private Long storagePoolId;

@Parameter(name = ApiConstants.DOMAIN_ID,
type = CommandType.UUID,
entityType = DomainResponse.class,
description = "the ID of the Domain to reset the parameter value for corresponding domain")
private Long domainId;

@Parameter(name = ApiConstants.ACCOUNT_ID,
type = CommandType.UUID,
entityType = AccountResponse.class,
description = "the ID of the Account to reset the parameter value for corresponding account")
private Long accountId;

@Parameter(name = ApiConstants.IMAGE_STORE_ID,
type = CommandType.UUID,
entityType = ImageStoreResponse.class,
description = "the ID of the Image Store to reset the parameter value for corresponding image store")
private Long imageStoreId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////

public String getCfgName() {
return cfgName;
}

public Long getZoneId() {
return zoneId;
}

public Long getClusterId() {
return clusterId;
}

public Long getStoragepoolId() {
return storagePoolId;
}

public Long getDomainId() {
return domainId;
}

public Long getAccountId() {
return accountId;
}

public Long getImageStoreId() {
return imageStoreId;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////

@Override
public String getCommandName() {
return s_name;
}

@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}

@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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
protected final SearchBuilder<ClusterDetailsVO> ClusterSearch;
protected final SearchBuilder<ClusterDetailsVO> DetailSearch;

private final String CpuOverprovisioningFactor = "cpu.overprovisioning.factor";
private final String MemoryOverprovisioningFactor = "mem.overprovisioning.factor";
private final String CpuOverCommitRatio = "cpuOvercommitRatio";
private final String MemoryOverCommitRatio = "memoryOvercommitRatio";

protected ClusterDetailsDaoImpl() {
ClusterSearch = createSearchBuilder();
ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
Expand All @@ -50,12 +55,7 @@ protected ClusterDetailsDaoImpl() {
public ClusterDetailsVO findDetail(long clusterId, String name) {
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
// This is temporary fix to support list/update configuration api for cpu and memory overprovisioning ratios
if (name.equalsIgnoreCase("cpu.overprovisioning.factor")) {
name = "cpuOvercommitRatio";
}
if (name.equalsIgnoreCase("mem.overprovisioning.factor")) {
name = "memoryOvercommitRatio";
}
name = getCpuMemoryOvercommitRatio(name);
sc.setParameters("clusterId", clusterId);
sc.setParameters("name", name);

Expand Down Expand Up @@ -103,18 +103,21 @@ public void persist(long clusterId, Map<String, String> details) {
expunge(sc);

for (Map.Entry<String, String> detail : details.entrySet()) {
String name = detail.getKey();
name = getCpuMemoryOvercommitRatio(name);
String value = detail.getValue();
if ("password".equals(detail.getKey())) {
value = DBEncryptionUtil.encrypt(value);
}
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), value);
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, name, value);
persist(vo);
}
txn.commit();
}

@Override
public void persist(long clusterId, String name, String value) {
name = getCpuMemoryOvercommitRatio(name);
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
Expand Down Expand Up @@ -147,4 +150,15 @@ public String getVmwareDcName(Long clusterId) {
dcName = tokens[3];
return dcName;
}

private String getCpuMemoryOvercommitRatio(String name) {
if (name.equalsIgnoreCase(CpuOverprovisioningFactor)) {
name = CpuOverCommitRatio;
}
if (name.equalsIgnoreCase(MemoryOverprovisioningFactor)) {
name = MemoryOverCommitRatio;
}

return name;
}
}
Loading