[go: nahoru, domu]

Skip to content

Commit

Permalink
Merge branch '4.16' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshanaparti committed Jan 5, 2022
2 parents 610b2d0 + f071873 commit 30ae9ee
Show file tree
Hide file tree
Showing 88 changed files with 1,360 additions and 534 deletions.
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 @@ -714,6 +714,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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void execute() throws ResourceUnavailableException, InsufficientCapacityE
List<LDAPConfigResponse> responses = new ArrayList<LDAPConfigResponse>();

if (result.second() > 0) {
boolean useSSlConfig = _ldapConfiguration.getSSLStatus();
boolean useSSlConfig = _ldapConfiguration.getSSLStatus(null);
String searchBaseConfig = _ldapConfiguration.getBaseDn(null);
String bindDnConfig = _ldapConfiguration.getBindPrincipal(null);
for (LdapConfigurationVO ldapConfigurationVO : result.first()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public String getLastnameAttribute(final Long domainId) {
}

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

public boolean getSSLStatus() {
public boolean getSSLStatus(Long domainId) {
boolean sslStatus = false;
if (getTrustStore() != null && getTrustStorePassword() != null) {
if (getTrustStore(domainId) != null && getTrustStorePassword(domainId) != null) {
sslStatus = true;
}
return sslStatus;
}

public String getTrustStore() {
return ldapTrustStore.value();
public String getTrustStore(Long domainId) {
return ldapTrustStore.valueIn(domainId);
}

public String getTrustStorePassword() {
return ldapTrustStorePassword.value();
public String getTrustStorePassword(Long domainId) {
return ldapTrustStorePassword.valueIn(domainId);
}

public String getUsernameAttribute(final Long domainId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public LdapContext createUserContext(final String principal, final String passwo
return createInitialDirContext(principal, password, false, domainId);
}

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

if (sslStatus) {
s_logger.info("LDAP SSL enabled.");
environment.put(Context.SECURITY_PROTOCOL, "ssl");
System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore());
System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword());
System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore(domainId));
System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword(domainId));
}
}

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

enableSSL(environment);
enableSSL(environment, domainId);
setAuthentication(environment, isSystemContext, domainId);

if (principal != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class LdapContextFactorySpec extends spock.lang.Specification {
ldapConfiguration.getFirstnameAttribute() >> "givenname"
ldapConfiguration.getLastnameAttribute() >> "sn"
ldapConfiguration.getBaseDn(_) >> "dc=cloudstack,dc=org"
ldapConfiguration.getSSLStatus() >> true
ldapConfiguration.getTrustStore() >> "/tmp/ldap.ts"
ldapConfiguration.getTrustStorePassword() >> "password"
ldapConfiguration.getSSLStatus(domainId) >> true
ldapConfiguration.getTrustStore(domainId) >> "/tmp/ldap.ts"
ldapConfiguration.getTrustStorePassword(domainId) >> "password"
ldapConfiguration.getReadTimeout(_) >> 1000
ldapConfiguration.getLdapPageSize() >> 1

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void overrideConfigValue(LdapConfiguration ldapConfiguration, final Stri
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStore", "/tmp/ldap.ts");
ldapTestConfigTool.overrideConfigValue(ldapConfiguration, "ldapTrustStorePassword", "password");

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

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

String result = ldapConfiguration.getTrustStorePassword();
String result = ldapConfiguration.getTrustStorePassword(null);

assertEquals("The result is password", "password", result);
}
Expand Down
Loading

0 comments on commit 30ae9ee

Please sign in to comment.