Skip to content

Commit 04013f2

Browse files
committed
Enable resetting config values to default value
Provide reset button to zone,cluster,domain,account, primary and secondary storage so that config values can be reset to default value
1 parent 562a7db commit 04013f2

15 files changed

Lines changed: 902 additions & 5 deletions

File tree

api/src/main/java/com/cloud/configuration/ConfigurationService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.List;
2020

21+
import org.apache.cloudstack.api.command.admin.config.ResetCfgCmd;
2122
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
2223
import org.apache.cloudstack.api.command.admin.network.CreateManagementNetworkIpRangeCmd;
2324
import org.apache.cloudstack.api.command.admin.network.CreateNetworkOfferingCmd;
@@ -74,6 +75,15 @@ public interface ConfigurationService {
7475
*/
7576
Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException;
7677

78+
/**
79+
* Resets a configuration entry with default value
80+
*
81+
* @param cmd
82+
* - the command wrapping name parameter
83+
* @return updated configuration object if successful
84+
*/
85+
Pair<Configuration, String> resetConfiguration(ResetCfgCmd cmd) throws InvalidParameterValueException;
86+
7787
/**
7888
* Create a service offering through the API
7989
*
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.config;
18+
19+
import org.apache.cloudstack.api.response.ImageStoreResponse;
20+
import org.apache.log4j.Logger;
21+
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.AccountResponse;
29+
import org.apache.cloudstack.api.response.ClusterResponse;
30+
import org.apache.cloudstack.api.response.ConfigurationResponse;
31+
import org.apache.cloudstack.api.response.DomainResponse;
32+
import org.apache.cloudstack.api.response.StoragePoolResponse;
33+
import org.apache.cloudstack.api.response.ZoneResponse;
34+
import org.apache.cloudstack.config.Configuration;
35+
36+
import com.cloud.user.Account;
37+
import com.cloud.utils.Pair;
38+
39+
@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,
40+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
41+
public class ResetCfgCmd extends BaseCmd {
42+
public static final Logger s_logger = Logger.getLogger(ResetCfgCmd.class.getName());
43+
private static final String s_name = "resetconfigurationresponse";
44+
45+
/////////////////////////////////////////////////////
46+
//////////////// API parameters /////////////////////
47+
/////////////////////////////////////////////////////
48+
49+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the configuration")
50+
private String cfgName;
51+
52+
@Parameter(name = ApiConstants.ZONE_ID,
53+
type = CommandType.UUID,
54+
entityType = ZoneResponse.class,
55+
description = "the ID of the Zone to reset the parameter value for corresponding zone")
56+
private Long zoneId;
57+
58+
@Parameter(name = ApiConstants.CLUSTER_ID,
59+
type = CommandType.UUID,
60+
entityType = ClusterResponse.class,
61+
description = "the ID of the Cluster to reset the parameter value for corresponding cluster")
62+
private Long clusterId;
63+
64+
@Parameter(name = ApiConstants.STORAGE_ID,
65+
type = CommandType.UUID,
66+
entityType = StoragePoolResponse.class,
67+
description = "the ID of the Storage pool to reset the parameter value for corresponding storage pool")
68+
private Long storagePoolId;
69+
70+
@Parameter(name = ApiConstants.DOMAIN_ID,
71+
type = CommandType.UUID,
72+
entityType = DomainResponse.class,
73+
description = "the ID of the Domain to reset the parameter value for corresponding domain")
74+
private Long domainId;
75+
76+
@Parameter(name = ApiConstants.ACCOUNT_ID,
77+
type = CommandType.UUID,
78+
entityType = AccountResponse.class,
79+
description = "the ID of the Account to reset the parameter value for corresponding account")
80+
private Long accountId;
81+
82+
@Parameter(name = ApiConstants.IMAGE_STORE_UUID,
83+
type = CommandType.UUID,
84+
entityType = ImageStoreResponse.class,
85+
description = "the ID of the Image Store to reset the parameter value for corresponding image store")
86+
private Long imageStoreId;
87+
88+
/////////////////////////////////////////////////////
89+
/////////////////// Accessors ///////////////////////
90+
/////////////////////////////////////////////////////
91+
92+
public String getCfgName() {
93+
return cfgName;
94+
}
95+
96+
public Long getZoneId() {
97+
return zoneId;
98+
}
99+
100+
public Long getClusterId() {
101+
return clusterId;
102+
}
103+
104+
public Long getStoragepoolId() {
105+
return storagePoolId;
106+
}
107+
108+
public Long getDomainId() {
109+
return domainId;
110+
}
111+
112+
public Long getAccountId() {
113+
return accountId;
114+
}
115+
116+
public Long getImageStoreId() {
117+
return imageStoreId;
118+
}
119+
120+
/////////////////////////////////////////////////////
121+
/////////////// API Implementation///////////////////
122+
/////////////////////////////////////////////////////
123+
124+
@Override
125+
public String getCommandName() {
126+
return s_name;
127+
}
128+
129+
@Override
130+
public long getEntityOwnerId() {
131+
return Account.ACCOUNT_ID_SYSTEM;
132+
}
133+
134+
@Override
135+
public void execute() {
136+
Pair<Configuration, String> cfg = _configService.resetConfiguration(this);
137+
if (cfg != null) {
138+
ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg.first());
139+
response.setResponseName(getCommandName());
140+
if (getZoneId() != null) {
141+
response.setScope("zone");
142+
}
143+
if (getClusterId() != null) {
144+
response.setScope("cluster");
145+
}
146+
if (getStoragepoolId() != null) {
147+
response.setScope("storagepool");
148+
}
149+
if (getDomainId() != null) {
150+
response.setScope("domain");
151+
}
152+
if (getAccountId() != null) {
153+
response.setScope("account");
154+
}
155+
if (getImageStoreId() != null) {
156+
response.setScope("imagestore");
157+
}
158+
response.setValue(cfg.second());
159+
this.setResponseObject(response);
160+
} else {
161+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset config");
162+
}
163+
}
164+
}

engine/schema/src/main/java/com/cloud/dc/ClusterDetailsDaoImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,31 @@ public void persist(long clusterId, Map<String, String> details) {
103103
expunge(sc);
104104

105105
for (Map.Entry<String, String> detail : details.entrySet()) {
106+
String name = detail.getKey();
107+
if (name.equalsIgnoreCase("cpu.overprovisioning.factor")) {
108+
name = "cpuOvercommitRatio";
109+
}
110+
if (name.equalsIgnoreCase("mem.overprovisioning.factor")) {
111+
name = "memoryOvercommitRatio";
112+
}
106113
String value = detail.getValue();
107114
if ("password".equals(detail.getKey())) {
108115
value = DBEncryptionUtil.encrypt(value);
109116
}
110-
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), value);
117+
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, name, value);
111118
persist(vo);
112119
}
113120
txn.commit();
114121
}
115122

116123
@Override
117124
public void persist(long clusterId, String name, String value) {
125+
if (name.equalsIgnoreCase("cpu.overprovisioning.factor")) {
126+
name = "cpuOvercommitRatio";
127+
}
128+
if (name.equalsIgnoreCase("mem.overprovisioning.factor")) {
129+
name = "memoryOvercommitRatio";
130+
}
118131
TransactionLegacy txn = TransactionLegacy.currentTxn();
119132
txn.start();
120133
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();

0 commit comments

Comments
 (0)