Skip to content

Commit 30ae9ee

Browse files
Merge branch '4.16' into main
2 parents 610b2d0 + f071873 commit 30ae9ee

File tree

88 files changed

+1360
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1360
-534
lines changed

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;
@@ -76,6 +77,15 @@ public interface ConfigurationService {
7677
*/
7778
Configuration updateConfiguration(UpdateCfgCmd cmd) throws InvalidParameterValueException;
7879

80+
/**
81+
* Resets a configuration entry with default value
82+
*
83+
* @param cmd
84+
* - the command wrapping name parameter
85+
* @return updated configuration object if successful
86+
*/
87+
Pair<Configuration, String> resetConfiguration(ResetCfgCmd cmd) throws InvalidParameterValueException;
88+
7989
/**
8090
* Create a service offering through the API
8191
*

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ public class ApiConstants {
714714
public static final String VM_SNAPSHOT_MEMORY = "snapshotmemory";
715715
public static final String VM_SNAPSHOT_QUIESCEVM = "quiescevm";
716716
public static final String IMAGE_STORE_UUID = "imagestoreuuid";
717+
public static final String IMAGE_STORE_ID = "imagestoreid";
717718
public static final String GUEST_VM_CIDR = "guestvmcidr";
718719
public static final String NETWORK_CIDR = "networkcidr";
719720
public static final String RESERVED_IP_RANGE = "reservediprange";
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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.APICommand;
20+
import org.apache.cloudstack.api.ApiArgValidator;
21+
import org.apache.cloudstack.api.ApiConstants;
22+
import org.apache.cloudstack.api.ApiErrorCode;
23+
import org.apache.cloudstack.api.BaseCmd;
24+
import org.apache.cloudstack.api.Parameter;
25+
import org.apache.cloudstack.api.ServerApiException;
26+
import org.apache.cloudstack.api.response.ImageStoreResponse;
27+
import org.apache.cloudstack.framework.config.ConfigKey;
28+
import org.apache.log4j.Logger;
29+
30+
import org.apache.cloudstack.api.response.AccountResponse;
31+
import org.apache.cloudstack.api.response.ClusterResponse;
32+
import org.apache.cloudstack.api.response.ConfigurationResponse;
33+
import org.apache.cloudstack.api.response.DomainResponse;
34+
import org.apache.cloudstack.api.response.StoragePoolResponse;
35+
import org.apache.cloudstack.api.response.ZoneResponse;
36+
import org.apache.cloudstack.config.Configuration;
37+
38+
import com.cloud.user.Account;
39+
import com.cloud.utils.Pair;
40+
41+
@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,
42+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.16.0")
43+
public class ResetCfgCmd extends BaseCmd {
44+
public static final Logger s_logger = Logger.getLogger(ResetCfgCmd.class.getName());
45+
private static final String s_name = "resetconfigurationresponse";
46+
47+
/////////////////////////////////////////////////////
48+
//////////////// API parameters /////////////////////
49+
/////////////////////////////////////////////////////
50+
51+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "the name of the configuration", validations = {ApiArgValidator.NotNullOrEmpty})
52+
private String cfgName;
53+
54+
@Parameter(name = ApiConstants.ZONE_ID,
55+
type = CommandType.UUID,
56+
entityType = ZoneResponse.class,
57+
description = "the ID of the Zone to reset the parameter value for corresponding zone")
58+
private Long zoneId;
59+
60+
@Parameter(name = ApiConstants.CLUSTER_ID,
61+
type = CommandType.UUID,
62+
entityType = ClusterResponse.class,
63+
description = "the ID of the Cluster to reset the parameter value for corresponding cluster")
64+
private Long clusterId;
65+
66+
@Parameter(name = ApiConstants.STORAGE_ID,
67+
type = CommandType.UUID,
68+
entityType = StoragePoolResponse.class,
69+
description = "the ID of the Storage pool to reset the parameter value for corresponding storage pool")
70+
private Long storagePoolId;
71+
72+
@Parameter(name = ApiConstants.DOMAIN_ID,
73+
type = CommandType.UUID,
74+
entityType = DomainResponse.class,
75+
description = "the ID of the Domain to reset the parameter value for corresponding domain")
76+
private Long domainId;
77+
78+
@Parameter(name = ApiConstants.ACCOUNT_ID,
79+
type = CommandType.UUID,
80+
entityType = AccountResponse.class,
81+
description = "the ID of the Account to reset the parameter value for corresponding account")
82+
private Long accountId;
83+
84+
@Parameter(name = ApiConstants.IMAGE_STORE_ID,
85+
type = CommandType.UUID,
86+
entityType = ImageStoreResponse.class,
87+
description = "the ID of the Image Store to reset the parameter value for corresponding image store")
88+
private Long imageStoreId;
89+
90+
/////////////////////////////////////////////////////
91+
/////////////////// Accessors ///////////////////////
92+
/////////////////////////////////////////////////////
93+
94+
public String getCfgName() {
95+
return cfgName;
96+
}
97+
98+
public Long getZoneId() {
99+
return zoneId;
100+
}
101+
102+
public Long getClusterId() {
103+
return clusterId;
104+
}
105+
106+
public Long getStoragepoolId() {
107+
return storagePoolId;
108+
}
109+
110+
public Long getDomainId() {
111+
return domainId;
112+
}
113+
114+
public Long getAccountId() {
115+
return accountId;
116+
}
117+
118+
public Long getImageStoreId() {
119+
return imageStoreId;
120+
}
121+
122+
/////////////////////////////////////////////////////
123+
/////////////// API Implementation///////////////////
124+
/////////////////////////////////////////////////////
125+
126+
@Override
127+
public String getCommandName() {
128+
return s_name;
129+
}
130+
131+
@Override
132+
public long getEntityOwnerId() {
133+
return Account.ACCOUNT_ID_SYSTEM;
134+
}
135+
136+
@Override
137+
public void execute() {
138+
Pair<Configuration, String> cfg = _configService.resetConfiguration(this);
139+
if (cfg != null) {
140+
ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg.first());
141+
response.setResponseName(getCommandName());
142+
if (getZoneId() != null) {
143+
response.setScope(ConfigKey.Scope.Zone.name());
144+
}
145+
if (getClusterId() != null) {
146+
response.setScope(ConfigKey.Scope.Cluster.name());
147+
}
148+
if (getStoragepoolId() != null) {
149+
response.setScope(ConfigKey.Scope.StoragePool.name());
150+
}
151+
if (getDomainId() != null) {
152+
response.setScope(ConfigKey.Scope.Domain.name());
153+
}
154+
if (getAccountId() != null) {
155+
response.setScope(ConfigKey.Scope.Account.name());
156+
}
157+
if (getImageStoreId() != null) {
158+
response.setScope(ConfigKey.Scope.ImageStore.name());
159+
}
160+
response.setValue(cfg.second());
161+
this.setResponseObject(response);
162+
} else {
163+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reset config");
164+
}
165+
}
166+
}

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
3535
protected final SearchBuilder<ClusterDetailsVO> ClusterSearch;
3636
protected final SearchBuilder<ClusterDetailsVO> DetailSearch;
3737

38+
private final String CpuOverprovisioningFactor = "cpu.overprovisioning.factor";
39+
private final String MemoryOverprovisioningFactor = "mem.overprovisioning.factor";
40+
private final String CpuOverCommitRatio = "cpuOvercommitRatio";
41+
private final String MemoryOverCommitRatio = "memoryOvercommitRatio";
42+
3843
protected ClusterDetailsDaoImpl() {
3944
ClusterSearch = createSearchBuilder();
4045
ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
@@ -50,12 +55,7 @@ protected ClusterDetailsDaoImpl() {
5055
public ClusterDetailsVO findDetail(long clusterId, String name) {
5156
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
5257
// This is temporary fix to support list/update configuration api for cpu and memory overprovisioning ratios
53-
if (name.equalsIgnoreCase("cpu.overprovisioning.factor")) {
54-
name = "cpuOvercommitRatio";
55-
}
56-
if (name.equalsIgnoreCase("mem.overprovisioning.factor")) {
57-
name = "memoryOvercommitRatio";
58-
}
58+
name = getCpuMemoryOvercommitRatio(name);
5959
sc.setParameters("clusterId", clusterId);
6060
sc.setParameters("name", name);
6161

@@ -103,18 +103,21 @@ 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+
name = getCpuMemoryOvercommitRatio(name);
106108
String value = detail.getValue();
107109
if ("password".equals(detail.getKey())) {
108110
value = DBEncryptionUtil.encrypt(value);
109111
}
110-
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), value);
112+
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, name, value);
111113
persist(vo);
112114
}
113115
txn.commit();
114116
}
115117

116118
@Override
117119
public void persist(long clusterId, String name, String value) {
120+
name = getCpuMemoryOvercommitRatio(name);
118121
TransactionLegacy txn = TransactionLegacy.currentTxn();
119122
txn.start();
120123
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
@@ -147,4 +150,15 @@ public String getVmwareDcName(Long clusterId) {
147150
dcName = tokens[3];
148151
return dcName;
149152
}
153+
154+
private String getCpuMemoryOvercommitRatio(String name) {
155+
if (name.equalsIgnoreCase(CpuOverprovisioningFactor)) {
156+
name = CpuOverCommitRatio;
157+
}
158+
if (name.equalsIgnoreCase(MemoryOverprovisioningFactor)) {
159+
name = MemoryOverCommitRatio;
160+
}
161+
162+
return name;
163+
}
150164
}

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/api/command/LDAPConfigCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
189189
List<LDAPConfigResponse> responses = new ArrayList<LDAPConfigResponse>();
190190

191191
if (result.second() > 0) {
192-
boolean useSSlConfig = _ldapConfiguration.getSSLStatus();
192+
boolean useSSlConfig = _ldapConfiguration.getSSLStatus(null);
193193
String searchBaseConfig = _ldapConfiguration.getBaseDn(null);
194194
String bindDnConfig = _ldapConfiguration.getBindPrincipal(null);
195195
for (LdapConfigurationVO ldapConfigurationVO : result.first()) {

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapConfiguration.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public String getLastnameAttribute(final Long domainId) {
238238
}
239239

240240
public String getProviderUrl(final Long domainId) {
241-
final String protocol = getSSLStatus() == true ? "ldaps://" : "ldap://";
241+
final String protocol = getSSLStatus(domainId) == true ? "ldaps://" : "ldap://";
242242
final Pair<List<LdapConfigurationVO>, Integer> result = _ldapConfigurationDao.searchConfigurations(null, 0, domainId);
243243
final StringBuilder providerUrls = new StringBuilder();
244244
String delim = "";
@@ -270,20 +270,20 @@ public String getSearchGroupPrinciple(final Long domainId) {
270270
return ldapSearchGroupPrinciple.valueIn(domainId);
271271
}
272272

273-
public boolean getSSLStatus() {
273+
public boolean getSSLStatus(Long domainId) {
274274
boolean sslStatus = false;
275-
if (getTrustStore() != null && getTrustStorePassword() != null) {
275+
if (getTrustStore(domainId) != null && getTrustStorePassword(domainId) != null) {
276276
sslStatus = true;
277277
}
278278
return sslStatus;
279279
}
280280

281-
public String getTrustStore() {
282-
return ldapTrustStore.value();
281+
public String getTrustStore(Long domainId) {
282+
return ldapTrustStore.valueIn(domainId);
283283
}
284284

285-
public String getTrustStorePassword() {
286-
return ldapTrustStorePassword.value();
285+
public String getTrustStorePassword(Long domainId) {
286+
return ldapTrustStorePassword.valueIn(domainId);
287287
}
288288

289289
public String getUsernameAttribute(final Long domainId) {

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapContextFactory.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ public LdapContext createUserContext(final String principal, final String passwo
6666
return createInitialDirContext(principal, password, false, domainId);
6767
}
6868

69-
private void enableSSL(final Hashtable<String, String> environment) {
70-
final boolean sslStatus = _ldapConfiguration.getSSLStatus();
69+
private void enableSSL(final Hashtable<String, String> environment, Long domainId) {
70+
final boolean sslStatus = _ldapConfiguration.getSSLStatus(domainId);
7171

7272
if (sslStatus) {
7373
s_logger.info("LDAP SSL enabled.");
7474
environment.put(Context.SECURITY_PROTOCOL, "ssl");
75-
System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore());
76-
System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword());
75+
System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore(domainId));
76+
System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword(domainId));
7777
}
7878
}
7979

@@ -92,7 +92,7 @@ private Hashtable<String, String> getEnvironment(final String principal, final S
9292
environment.put("com.sun.jndi.ldap.read.timeout", _ldapConfiguration.getReadTimeout(domainId).toString());
9393
environment.put("com.sun.jndi.ldap.connect.pool", "true");
9494

95-
enableSSL(environment);
95+
enableSSL(environment, domainId);
9696
setAuthentication(environment, isSystemContext, domainId);
9797

9898
if (principal != null) {

plugins/user-authenticators/ldap/src/test/groovy/org/apache/cloudstack/ldap/LdapContextFactorySpec.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class LdapContextFactorySpec extends spock.lang.Specification {
4949
ldapConfiguration.getFirstnameAttribute() >> "givenname"
5050
ldapConfiguration.getLastnameAttribute() >> "sn"
5151
ldapConfiguration.getBaseDn(_) >> "dc=cloudstack,dc=org"
52-
ldapConfiguration.getSSLStatus() >> true
53-
ldapConfiguration.getTrustStore() >> "/tmp/ldap.ts"
54-
ldapConfiguration.getTrustStorePassword() >> "password"
52+
ldapConfiguration.getSSLStatus(domainId) >> true
53+
ldapConfiguration.getTrustStore(domainId) >> "/tmp/ldap.ts"
54+
ldapConfiguration.getTrustStorePassword(domainId) >> "password"
5555
ldapConfiguration.getReadTimeout(_) >> 1000
5656
ldapConfiguration.getLdapPageSize() >> 1
5757

plugins/user-authenticators/ldap/src/test/java/org/apache/cloudstack/ldap/LdapConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private void overrideConfigValue(LdapConfiguration ldapConfiguration, final Stri
7878
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStore", "/tmp/ldap.ts");
7979
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStorePassword", "password");
8080

81-
assertTrue("A request is made to get the status of SSL should result in true", ldapConfiguration.getSSLStatus());
81+
assertTrue("A request is made to get the status of SSL should result in true", ldapConfiguration.getSSLStatus(null));
8282
}
8383

8484
@Test public void getSearchGroupPrincipleReturnsSuccessfully() throws Exception {
@@ -93,7 +93,7 @@ private void overrideConfigValue(LdapConfiguration ldapConfiguration, final Stri
9393
// We have a ConfigDao with a value for truststore password
9494
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStorePassword", "password");
9595

96-
String result = ldapConfiguration.getTrustStorePassword();
96+
String result = ldapConfiguration.getTrustStorePassword(null);
9797

9898
assertEquals("The result is password", "password", result);
9999
}

0 commit comments

Comments
 (0)