Skip to content
Open
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,7 +18,6 @@

import javax.inject.Inject;


import org.apache.cloudstack.api.ACL;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
Expand All @@ -31,8 +30,8 @@
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.ratelimit.ApiRateLimitService;
import com.cloud.server.ManagementServer;

import com.cloud.configuration.Config;
import com.cloud.user.Account;

@APICommand(name = "resetApiLimit", responseObject = SuccessResponse.class, description = "Reset api count",
Expand Down Expand Up @@ -82,7 +81,7 @@ public long getEntityOwnerId() {

@Override
public void execute() {
boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key()));
boolean apiLimitEnabled = ManagementServer.ApiLimitEnabled.value();
if (!apiLimitEnabled) {
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "This api is only available when api.throttling.enabled = true.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import javax.inject.Inject;


import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
Expand All @@ -27,8 +26,8 @@
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.ratelimit.ApiRateLimitService;
import com.cloud.server.ManagementServer;

import com.cloud.configuration.Config;
import com.cloud.user.Account;

@APICommand(name = "getApiLimit", responseObject = ApiLimitResponse.class, description = "Get API limit count for the caller",
Expand Down Expand Up @@ -58,7 +57,7 @@ public long getEntityOwnerId() {

@Override
public void execute() {
boolean apiLimitEnabled = Boolean.parseBoolean(_configDao.getValue(Config.ApiLimitEnabled.key()));
boolean apiLimitEnabled = ManagementServer.ApiLimitEnabled.value();
if (!apiLimitEnabled) {
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "This api is only available when api.throttling.enabled = true.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
import org.apache.cloudstack.framework.config.Configurable;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;

import com.cloud.configuration.Config;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.RequestLimitException;
import com.cloud.server.ManagementServer;
import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.user.User;
Expand Down Expand Up @@ -82,25 +82,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu

if (_store == null) {
// get global configured duration and max values
String isEnabled = _configDao.getValue(Config.ApiLimitEnabled.key());
if (isEnabled != null) {
enabled = Boolean.parseBoolean(isEnabled);
}
String duration = _configDao.getValue(Config.ApiLimitInterval.key());
if (duration != null) {
timeToLive = Integer.parseInt(duration);
}
String maxReqs = _configDao.getValue(Config.ApiLimitMax.key());
if (maxReqs != null) {
maxAllowed = Integer.parseInt(maxReqs);
}
enabled = ManagementServer.ApiLimitEnabled.value();
timeToLive = ManagementServer.ApiLimitInterval.value();
maxAllowed = ManagementServer.ApiLimitMax.value();
// create limit store
EhcacheLimitStore cacheStore = new EhcacheLimitStore();
int maxElements = 10000;
String cachesize = _configDao.getValue(Config.ApiLimitCacheSize.key());
if (cachesize != null) {
maxElements = Integer.parseInt(cachesize);
}
int maxElements = ApiLimitCacheSize.value();
CacheManager cm = CacheManager.create();
Cache cache = new Cache("api-limit-cache", maxElements, false, false, timeToLive, timeToLive);
cm.addCache(cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.mockito.Mockito.when;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -34,10 +35,12 @@
import org.junit.Test;

import org.apache.cloudstack.api.response.ApiLimitResponse;
import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl;

import com.cloud.configuration.Config;
import com.cloud.exception.RequestLimitException;
import com.cloud.server.ManagementServer;
import com.cloud.user.Account;
import com.cloud.user.AccountService;
import com.cloud.user.AccountVO;
Expand All @@ -55,10 +58,10 @@ public class ApiRateLimitTest {
@BeforeClass
public static void setUp() throws ConfigurationException {

when(s_configDao.getValue(Config.ApiLimitInterval.key())).thenReturn(null);
when(s_configDao.getValue(Config.ApiLimitMax.key())).thenReturn(null);
when(s_configDao.getValue(Config.ApiLimitCacheSize.key())).thenReturn(null);
when(s_configDao.getValue(Config.ApiLimitEnabled.key())).thenReturn("true"); // enable api rate limiting
when(s_configDao.getValue(ManagementServer.ApiLimitInterval.key())).thenReturn(null);
when(s_configDao.getValue(ManagementServer.ApiLimitMax.key())).thenReturn(null);
when(s_configDao.getValue(ApiRateLimitService.ApiLimitCacheSize.key())).thenReturn(null);
when(s_configDao.getValue(ManagementServer.ApiLimitEnabled.key())).thenReturn("true"); // enable api rate limiting
s_limitService._configDao = s_configDao;

s_limitService.configure("ApiRateLimitTest", Collections.<String, Object> emptyMap());
Expand Down Expand Up @@ -240,6 +243,58 @@ public void verifySearchCounter() throws Exception {

}

// configure() assigns enabled/timeToLive/maxAllowed from the persisted config
// values before it (re-)creates the shared "api-limit-cache" ehcache; since that
// cache name is already owned by s_limitService for the lifetime of this test
// class, a second configure() call on a fresh instance may throw when it tries to
// register a cache of the same name again. That's fine here — the fields we're
// asserting on are already set by the time that happens, so we only care that
// configure() didn't fail for some other reason first.
private void configureTolerantOfDuplicateCache(ApiRateLimitServiceImpl service, Map<String, Object> params) throws ConfigurationException {
try {
service.configure("ApiRateLimitTest-wiring", params);
} catch (RuntimeException e) {
if (!(e instanceof net.sf.ehcache.CacheException)) {
throw e;
}
}
}

@Test
public void configureAppliesPersistedGlobalSettings() throws Exception {
ApiRateLimitServiceImpl service = new ApiRateLimitServiceImpl();
ConfigDepotImpl configDepot = mock(ConfigDepotImpl.class);
when(configDepot.getConfigStringValue(ManagementServer.ApiLimitEnabled.key(), ConfigKey.Scope.Global, null)).thenReturn("true");
when(configDepot.getConfigStringValue(ManagementServer.ApiLimitInterval.key(), ConfigKey.Scope.Global, null)).thenReturn("5");
when(configDepot.getConfigStringValue(ManagementServer.ApiLimitMax.key(), ConfigKey.Scope.Global, null)).thenReturn("100");
when(configDepot.getConfigStringValue(ApiRateLimitService.ApiLimitCacheSize.key(), ConfigKey.Scope.Global, null)).thenReturn("20000");
ConfigKey.init(configDepot);
try {
configureTolerantOfDuplicateCache(service, Collections.<String, Object> emptyMap());
} finally {
ConfigKey.init(null);
}

assertTrue(service.isEnabled());
assertEquals(5, service.getTimeToLive());
assertEquals(100, service.getMaxAllowed());
}

@Test
public void configureFallsBackToConfigKeyDefaultsWhenNothingPersisted() throws Exception {
ApiRateLimitServiceImpl service = new ApiRateLimitServiceImpl();
ConfigKey.init(mock(ConfigDepotImpl.class));
try {
configureTolerantOfDuplicateCache(service, Collections.<String, Object> emptyMap());
} finally {
ConfigKey.init(null);
}

assertEquals(Boolean.parseBoolean(ManagementServer.ApiLimitEnabled.defaultValue()), service.isEnabled());
assertEquals(Integer.parseInt(ManagementServer.ApiLimitInterval.defaultValue()), service.getTimeToLive());
assertEquals(Integer.parseInt(ManagementServer.ApiLimitMax.defaultValue()), service.getMaxAllowed());
}

@Test
public void disableApiLimit() throws Exception {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@

import javax.naming.ConfigurationException;


import com.cloud.configuration.Config;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.Pair;
import com.cloud.vm.VirtualMachineProfile;

Expand Down Expand Up @@ -188,8 +185,7 @@ private List<Long> orderByApplyingWeights(Pair<List<Long>, Map<Long, Double>> ca
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
super.configure(name, params);

String weight = configDao.getValue(Config.VmUserDispersionWeight.key());
_userDispersionWeight = NumbersUtil.parseFloat(weight, 1.0f);
_userDispersionWeight = VmUserDispersionWeight.value();

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;

import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.configuration.Config;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
Expand All @@ -48,6 +47,7 @@
import com.cloud.network.rules.LoadBalancerContainer;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.server.ManagementServer;
import com.cloud.utils.component.AdapterBase;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
Expand Down Expand Up @@ -166,10 +166,10 @@ public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) thro
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {

super.configure(name, params);
String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
String enabled = ManagementServer.ElasticLoadBalancerEnabled.value();
_enabled = (enabled == null) ? false : Boolean.parseBoolean(enabled);
if (_enabled) {
String traffType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key());
String traffType = ManagementServer.ElasticLoadBalancerNetwork.value();
if ("guest".equalsIgnoreCase(traffType)) {
_frontEndTrafficType = TrafficType.Guest;
} else if ("public".equalsIgnoreCase(traffType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.server.ManagementServer;
import com.cloud.service.ServiceOfferingVO;
import com.cloud.service.dao.ServiceOfferingDao;
import com.cloud.storage.Storage;
Expand Down Expand Up @@ -309,19 +310,19 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
throw new ConfigurationException(msg);
}

String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
String enabled = ManagementServer.ElasticLoadBalancerEnabled.value();
_enabled = (enabled == null) ? false : Boolean.parseBoolean(enabled);
logger.info("Elastic Load balancer enabled: " + _enabled);
if (_enabled) {
String traffType = _configDao.getValue(Config.ElasticLoadBalancerNetwork.key());
String traffType = ManagementServer.ElasticLoadBalancerNetwork.value();
if ("guest".equalsIgnoreCase(traffType)) {
_frontendTrafficType = TrafficType.Guest;
} else if ("public".equalsIgnoreCase(traffType)) {
_frontendTrafficType = TrafficType.Public;
} else
throw new ConfigurationException("ELB: Traffic type for front end of load balancer has to be guest or public; found : " + traffType);
logger.info("ELB: Elastic Load Balancer: will balance on " + traffType);
int gcIntervalMinutes = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmGcInterval.key()), 5);
int gcIntervalMinutes = NumbersUtil.parseInt(configs.get(ElasticLoadBalancerVmGcInterval.key()), 5);
if (gcIntervalMinutes < 5)
gcIntervalMinutes = 5;
logger.info("ELB: Elastic Load Balancer: scheduling GC to run every " + gcIntervalMinutes + " minutes");
Expand Down Expand Up @@ -485,7 +486,7 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, Depl
if (defaultDns2 != null) {
buf.append(" dns2=").append(defaultDns2);
}
String msPublicKey = _configDao.getValue("ssh.publickey");
String msPublicKey = ManagementServer.SshPublicKey.value();
buf.append(" authorized_key=").append(VirtualMachineGuru.getEncodedMsPublicKey(msPublicKey));

if (SystemVmEnableUserData.valueIn(dc.getId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
import com.cloud.api.response.NetScalerServicePackageResponse;
import com.cloud.api.response.NetscalerControlCenterResponse;
import com.cloud.api.response.NetscalerLoadBalancerResponse;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
Expand Down Expand Up @@ -141,7 +140,6 @@
import com.cloud.resource.ResourceState;
import com.cloud.resource.ServerResource;
import com.cloud.user.Account;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.crypt.DBEncryptionUtil;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
Expand Down Expand Up @@ -297,7 +295,7 @@ public HostVO allocateNCCResourceForNetwork(Network guestConfig) throws Configur
hostDetails.put("username", nccVO.getUsername());
hostDetails.put("password", DBEncryptionUtil.decrypt(nccVO.getPassword()));
hostDetails.put("deviceName", "netscaler control center");
hostDetails.put("cmdTimeOut", Long.toString(NumbersUtil.parseInt(_configDao.getValue(Config.NCCCmdTimeOut.key()), 600000)));
hostDetails.put("cmdTimeOut", Long.toString(NCCCmdTimeOut.value()));
ServerResource resource = new NetScalerControlCenterResource();
resource.configure(hostName, hostDetails);
final Host host = _resourceMgr.addHost(guestConfig.getDataCenterId(), resource, Host.Type.NetScalerControlCenter, hostDetails);
Expand Down Expand Up @@ -947,8 +945,7 @@ public NetscalerLoadBalancerResponse createNetscalerLoadBalancerResponse(Externa
response.setPrivateInterface(lbDetails.get("privateInterface"));
response.setDeviceName(lbDeviceVO.getDeviceName());
if (lbDeviceVO.getCapacity() == 0) {
long defaultLbCapacity = NumbersUtil
.parseLong(_configDao.getValue(Config.DefaultExternalLoadBalancerCapacity.key()), 50);
long defaultLbCapacity = DefaultExternalLoadBalancerCapacity.value();
response.setDeviceCapacity(defaultLbCapacity);
} else {
response.setDeviceCapacity(lbDeviceVO.getCapacity());
Expand Down Expand Up @@ -1161,8 +1158,7 @@ public boolean applyStaticNats(Network config, List<? extends StaticNat> rules)
return false;
}

boolean multiNetScalerDeployment = Boolean
.valueOf(_configDao.getValue(Config.EIPWithMultipleNetScalersEnabled.key()));
boolean multiNetScalerDeployment = EIPWithMultipleNetScalersEnabled.value();

try {
if (!multiNetScalerDeployment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import javax.inject.Inject;


import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;

Expand All @@ -35,7 +34,6 @@
import com.cloud.api.commands.ListPaloAltoFirewallNetworksCmd;
import com.cloud.api.commands.ListPaloAltoFirewallsCmd;
import com.cloud.api.response.PaloAltoFirewallResponse;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenter.NetworkType;
Expand Down Expand Up @@ -74,7 +72,6 @@
import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.utils.NumbersUtil;
import com.cloud.utils.db.EntityManager;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.NicProfile;
Expand Down Expand Up @@ -406,7 +403,7 @@ public PaloAltoFirewallResponse createPaloAltoFirewallResponse(ExternalFirewallD
}
response.setDeviceName(fwDeviceVO.getDeviceName());
if (fwDeviceVO.getCapacity() == 0) {
long defaultFwCapacity = NumbersUtil.parseLong(_configDao.getValue(Config.DefaultExternalFirewallCapacity.key()), 50);
long defaultFwCapacity = DefaultExternalFirewallCapacity.value();
response.setDeviceCapacity(defaultFwCapacity);
} else {
response.setDeviceCapacity(fwDeviceVO.getCapacity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.cloud.capacity.Capacity;
import com.cloud.capacity.CapacityVO;
import com.cloud.capacity.dao.CapacityDao;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.deploy.DeploymentClusterPlanner;
import com.cloud.deploy.DeploymentPlan;
Expand Down Expand Up @@ -288,7 +287,7 @@ private Pair<List<Long>, Map<Long, Double>> getOrderedHostsByCapacity(Long zoneI
double cpuToMemoryWeight = ConfigurationManager.HostCapacityTypeCpuMemoryWeight.value();
// Get capacity by which we should reorder
short capacityType = FirstFitPlanner.getHostCapacityTypeToOrderCluster(
_configDao.getValue(Config.HostCapacityTypeToOrderClusters.key()), cpuToMemoryWeight);
DeploymentClusterPlanner.HostCapacityTypeToOrderClusters.value(), cpuToMemoryWeight);
logger.debug("CapacityType: {} is used for Host ordering", FirstFitPlanner.getCapacityTypeName(capacityType));
if (capacityType >= 0) { // for CPU or RAM
return _capacityDao.orderHostsByFreeCapacity(zoneId, clusterId, capacityType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,8 @@ protected void weightBasedParametersForValidation() {
weightBasedParametersForValidation.add(CapacityManager.StorageAllocatedCapacityDisableThresholdForVolumeSize.key());
weightBasedParametersForValidation.add(DeploymentClusterPlanner.ClusterCPUCapacityDisableThreshold.key());
weightBasedParametersForValidation.add(DeploymentClusterPlanner.ClusterMemoryCapacityDisableThreshold.key());
weightBasedParametersForValidation.add(Config.AgentLoadThreshold.key());
weightBasedParametersForValidation.add(Config.VmUserDispersionWeight.key());
weightBasedParametersForValidation.add("agent.load.threshold");
weightBasedParametersForValidation.add(DeploymentClusterPlanner.VmUserDispersionWeight.key());
weightBasedParametersForValidation.add(CapacityManager.SecondaryStorageCapacityThreshold.key());
weightBasedParametersForValidation.add(ClusterDrsService.ClusterDrsImbalanceThreshold.key());
weightBasedParametersForValidation.add(ClusterDrsService.ClusterDrsImbalanceSkipThreshold.key());
Expand Down
Loading
Loading