Skip to content

Commit 43136a8

Browse files
committed
CLOUDSTACK-8301: Enable configuring local storage use for system VMs at zone level
Backported from apache#263 for 4.5 branch, original bugfix by @koushik-das et al More information on: https://issues.apache.org/jira/browse/CLOUDSTACK-8301 https://cwiki.apache.org/confluence/display/CLOUDSTACK/Enable+configuring+local+storage+use+for+system+VMs+at+zone+level Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> (cherry picked from commit f28287b) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent ef86ff4 commit 43136a8

File tree

21 files changed

+998
-177
lines changed

21 files changed

+998
-177
lines changed

api/src/com/cloud/dc/DataCenter.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@
2020
import org.apache.cloudstack.acl.InfrastructureEntity;
2121
import org.apache.cloudstack.api.Identity;
2222
import org.apache.cloudstack.api.InternalIdentity;
23-
import org.apache.cloudstack.framework.config.ConfigKey;
2423

2524
import java.util.Map;
2625

2726
/**
2827
*
2928
*/
3029
public interface DataCenter extends InfrastructureEntity, Grouping, Identity, InternalIdentity {
31-
public static final String SystemVMUseLocalStorageCK = "system.vm.use.local.storage";
32-
public static final ConfigKey<Boolean> UseSystemVMLocalStorage = new ConfigKey<Boolean>(Boolean.class, SystemVMUseLocalStorageCK, "Advanced", "false",
33-
"Indicates whether to use local storage pools or shared storage pools for system VMs.", true, ConfigKey.Scope.Zone, null);
3430

3531
public enum NetworkType {
3632
Basic, Advanced,

client/WEB-INF/classes/resources/messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ label.load.balancer=Load Balancer
752752
label.load.balancing.policies=Load balancing policies
753753
label.load.balancing=Load Balancing
754754
label.loading=Loading
755-
label.local.storage.enabled=Local storage enabled
755+
label.local.storage.enabled=Enable local storage for User VMs
756+
label.local.storage.enabled.system.vms=Enable local storage for System VMs
756757
label.local.storage=Local Storage
757758
label.local=Local
758759
label.login=Login

engine/schema/src/com/cloud/service/dao/ServiceOfferingDao.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@
1616
// under the License.
1717
package com.cloud.service.dao;
1818

19-
import java.util.List;
20-
import java.util.Map;
21-
2219
import com.cloud.service.ServiceOfferingVO;
20+
import com.cloud.storage.Storage;
2321
import com.cloud.utils.db.GenericDao;
22+
import com.cloud.vm.VirtualMachine;
23+
24+
import java.util.List;
25+
import java.util.Map;
2426

2527
/*
2628
* Data Access Object for service_offering table
2729
*/
2830
public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long> {
2931
ServiceOfferingVO findByName(String name);
3032

33+
List<ServiceOfferingVO> createSystemServiceOfferings(String name, String uniqueName, int cpuCount, int ramSize, int cpuSpeed,
34+
Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, Storage.ProvisioningType provisioningType,
35+
boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse);
36+
3137
ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO vo);
3238

3339
List<ServiceOfferingVO> findPublicServiceOfferings();
@@ -49,4 +55,6 @@ public interface ServiceOfferingDao extends GenericDao<ServiceOfferingVO, Long>
4955
boolean isDynamic(long serviceOfferingId);
5056

5157
ServiceOfferingVO getcomputeOffering(ServiceOfferingVO serviceOffering, Map<String, String> customParameters);
58+
59+
ServiceOfferingVO findDefaultSystemOffering(String offeringName, Boolean useLocalStorage);
5260
}

engine/schema/src/com/cloud/service/dao/ServiceOfferingDaoImpl.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import javax.inject.Inject;
2626
import javax.persistence.EntityExistsException;
2727

28+
import com.cloud.storage.Storage;
29+
import com.cloud.vm.VirtualMachine;
2830
import org.apache.log4j.Logger;
2931
import org.springframework.stereotype.Component;
3032

@@ -110,6 +112,13 @@ public ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO offering
110112
vo.setSpeed(500);
111113
update(vo.getId(), vo);
112114
}
115+
if (!vo.getUniqueName().endsWith("-Local")) {
116+
if (vo.getUseLocalStorage()) {
117+
vo.setUniqueName(vo.getUniqueName() + "-Local");
118+
vo.setName(vo.getName() + " - Local Storage");
119+
update(vo.getId(), vo);
120+
}
121+
}
113122
return vo;
114123
}
115124
try {
@@ -238,4 +247,48 @@ public ServiceOfferingVO getcomputeOffering(ServiceOfferingVO serviceOffering, M
238247

239248
return dummyoffering;
240249
}
250+
251+
@Override
252+
public List<ServiceOfferingVO> createSystemServiceOfferings(String name, String uniqueName, int cpuCount, int ramSize, int cpuSpeed,
253+
Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, Storage.ProvisioningType provisioningType,
254+
boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse) {
255+
List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
256+
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText,
257+
provisioningType, false, recreatable, tags, systemUse, vmType, defaultUse);
258+
offering.setUniqueName(uniqueName);
259+
offering = persistSystemServiceOffering(offering);
260+
if (offering != null) {
261+
list.add(offering);
262+
}
263+
264+
boolean useLocal = true;
265+
if (offering.getUseLocalStorage()) { // if 1st one is already local then 2nd needs to be shared
266+
useLocal = false;
267+
}
268+
269+
offering = new ServiceOfferingVO(name + (useLocal ? " - Local Storage" : ""), cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText,
270+
provisioningType, useLocal, recreatable, tags, systemUse, vmType, defaultUse);
271+
offering.setUniqueName(uniqueName + (useLocal ? "-Local" : ""));
272+
offering = persistSystemServiceOffering(offering);
273+
if (offering != null) {
274+
list.add(offering);
275+
}
276+
277+
return list;
278+
}
279+
280+
@Override
281+
public ServiceOfferingVO findDefaultSystemOffering(String offeringName, Boolean useLocalStorage) {
282+
String name = offeringName;
283+
if (useLocalStorage != null && useLocalStorage.booleanValue()) {
284+
name += "-Local";
285+
}
286+
ServiceOfferingVO serviceOffering = findByName(name);
287+
if (serviceOffering == null) {
288+
String message = "System service offering " + name + " not found";
289+
s_logger.error(message);
290+
throw new CloudRuntimeException(message);
291+
}
292+
return serviceOffering;
293+
}
241294
}

plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ public class ElasticLoadBalancerManagerImpl extends ManagerBase implements Elast
148148
TrafficType _frontendTrafficType = TrafficType.Guest;
149149

150150
Account _systemAcct;
151-
ServiceOfferingVO _elasticLbVmOffering;
152151
ScheduledExecutorService _gcThreadPool;
153152
String _mgmtCidr;
154153

@@ -290,16 +289,19 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
290289
}
291290
_mgmtCidr = _configDao.getValue(Config.ManagementNetwork.key());
292291

293-
boolean useLocalStorage = Boolean.parseBoolean(configs.get(DataCenter.SystemVMUseLocalStorageCK));
294-
295292
_elasticLbVmRamSize = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmMemory.key()), DEFAULT_ELB_VM_RAMSIZE);
296293
_elasticLbvmCpuMHz = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmCpuMhz.key()), DEFAULT_ELB_VM_CPU_MHZ);
297294
_elasticLbvmNumCpu = NumbersUtil.parseInt(configs.get(Config.ElasticLoadBalancerVmNumVcpu.key()), 1);
298-
_elasticLbVmOffering = new ServiceOfferingVO("System Offering For Elastic LB VM", _elasticLbvmNumCpu,
299-
_elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null, Storage.ProvisioningType.THIN, useLocalStorage,
300-
true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true);
301-
_elasticLbVmOffering.setUniqueName(ServiceOffering.elbVmDefaultOffUniqueName);
302-
_elasticLbVmOffering = _serviceOfferingDao.persistSystemServiceOffering(_elasticLbVmOffering);
295+
296+
List<ServiceOfferingVO> offerings = _serviceOfferingDao.createSystemServiceOfferings("System Offering For Elastic LB VM",
297+
ServiceOffering.elbVmDefaultOffUniqueName, _elasticLbvmNumCpu, _elasticLbVmRamSize, _elasticLbvmCpuMHz, 0, 0, true, null,
298+
Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.ElasticLoadBalancerVm, true);
299+
// this can sometimes happen, if DB is manually or programmatically manipulated
300+
if (offerings == null || offerings.size() < 2) {
301+
String msg = "Data integrity problem : System Offering For Elastic LB VM has been removed?";
302+
s_logger.error(msg);
303+
throw new ConfigurationException(msg);
304+
}
303305

304306
String enabled = _configDao.getValue(Config.ElasticLoadBalancerEnabled.key());
305307
_enabled = (enabled == null) ? false : Boolean.parseBoolean(enabled);
@@ -322,7 +324,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
322324
_itMgr.registerGuru(VirtualMachine.Type.ElasticLoadBalancerVm, this);
323325
}
324326

325-
loadBalanceRuleHandler = new LoadBalanceRuleHandler(_elasticLbVmOffering, _instance, _systemAcct);
327+
loadBalanceRuleHandler = new LoadBalanceRuleHandler(_instance, _systemAcct);
326328

327329
return true;
328330
}

plugins/network-elements/elastic-loadbalancer/src/com/cloud/network/lb/LoadBalanceRuleHandler.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
import javax.inject.Inject;
2929

30+
import com.cloud.configuration.ConfigurationManagerImpl;
31+
import com.cloud.offering.ServiceOffering;
32+
import com.cloud.service.dao.ServiceOfferingDao;
3033
import org.apache.cloudstack.api.command.user.loadbalancer.CreateLoadBalancerRuleCmd;
3134
import org.apache.cloudstack.context.CallContext;
3235
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@@ -140,15 +143,15 @@ public class LoadBalanceRuleHandler {
140143
private PhysicalNetworkServiceProviderDao _physicalProviderDao;
141144
@Inject
142145
private VirtualRouterProviderDao _vrProviderDao;
146+
@Inject
147+
private ServiceOfferingDao _serviceOfferingDao;
143148

144149
static final private String ELB_VM_NAME_PREFIX = "l";
145150

146-
private final ServiceOfferingVO _elasticLbVmOffering;
147151
private final String _instance;
148152
private final Account _systemAcct;
149153

150-
public LoadBalanceRuleHandler(ServiceOfferingVO elasticLbVmOffering, String instance, Account systemAcct) {
151-
this._elasticLbVmOffering = elasticLbVmOffering;
154+
public LoadBalanceRuleHandler(String instance, Account systemAcct) {
152155
this._instance = instance;
153156
this._systemAcct = systemAcct;
154157
}
@@ -272,12 +275,13 @@ private DomainRouterVO deployELBVm(Network guestNetwork, DeployDestination dest,
272275
throw new CloudRuntimeException("Cannot find virtual router provider " + typeString + " as service provider " + provider.getId());
273276
}
274277

275-
elbVm = new DomainRouterVO(id, _elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX),
278+
ServiceOfferingVO elasticLbVmOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.elbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
279+
elbVm = new DomainRouterVO(id, elasticLbVmOffering.getId(), vrProvider.getId(), VirtualMachineName.getSystemVmName(id, _instance, ELB_VM_NAME_PREFIX),
276280
template.getId(), template.getHypervisorType(), template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false, RedundantState.UNKNOWN,
277-
_elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
281+
elasticLbVmOffering.getOfferHA(), false, VirtualMachine.Type.ElasticLoadBalancerVm, null);
278282
elbVm.setRole(Role.LB);
279283
elbVm = _routerDao.persist(elbVm);
280-
_itMgr.allocate(elbVm.getInstanceName(), template, _elasticLbVmOffering, networks, plan, null);
284+
_itMgr.allocate(elbVm.getInstanceName(), template, elasticLbVmOffering, networks, plan, null);
281285
elbVm = _routerDao.findById(elbVm.getId());
282286
//TODO: create usage stats
283287
}

plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.inject.Inject;
2828
import javax.naming.ConfigurationException;
2929

30+
import com.cloud.configuration.ConfigurationManagerImpl;
3031
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
3132
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3233
import org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO;
@@ -376,15 +377,15 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
376377

377378
//if offering wasn't set, try to get the default one
378379
if (_internalLbVmOfferingId == 0L) {
379-
boolean useLocalStorage = Boolean.parseBoolean(configs.get(DataCenter.SystemVMUseLocalStorageCK));
380-
ServiceOfferingVO newOff =
381-
new ServiceOfferingVO("System Offering For Internal LB VM", 1, InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_RAMSIZE,
380+
List<ServiceOfferingVO> offerings = _serviceOfferingDao.createSystemServiceOfferings("System Offering For Internal LB VM",
381+
ServiceOffering.internalLbVmDefaultOffUniqueName, 1, InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_RAMSIZE,
382382
InternalLoadBalancerVMManager.DEFAULT_INTERNALLB_VM_CPU_MHZ, null, null, true, null,
383-
Storage.ProvisioningType.THIN, useLocalStorage, true, null, true,
384-
VirtualMachine.Type.InternalLoadBalancerVm, true);
385-
newOff.setUniqueName(ServiceOffering.internalLbVmDefaultOffUniqueName);
386-
newOff = _serviceOfferingDao.persistSystemServiceOffering(newOff);
387-
_internalLbVmOfferingId = newOff.getId();
383+
Storage.ProvisioningType.THIN, true, null, true, VirtualMachine.Type.InternalLoadBalancerVm, true);
384+
if (offerings == null || offerings.size() < 2) {
385+
String msg = "Data integrity problem : System Offering For Internal LB VM has been removed?";
386+
s_logger.error(msg);
387+
throw new ConfigurationException(msg);
388+
}
388389
}
389390

390391
_itMgr.registerGuru(VirtualMachine.Type.InternalLoadBalancerVm, this);
@@ -616,9 +617,14 @@ protected List<DomainRouterVO> findOrDeployInternalLbVm(Network guestNetwork, Ip
616617
}
617618

618619
LinkedHashMap<Network, List<? extends NicProfile>> networks = createInternalLbVmNetworks(guestNetwork, plan, requestedGuestIp);
620+
long internalLbVmOfferingId = _internalLbVmOfferingId;
621+
if (internalLbVmOfferingId == 0L) {
622+
ServiceOfferingVO serviceOffering = _serviceOfferingDao.findDefaultSystemOffering(ServiceOffering.internalLbVmDefaultOffUniqueName, ConfigurationManagerImpl.SystemVMUseLocalStorage.valueIn(dest.getDataCenter().getId()));
623+
internalLbVmOfferingId = serviceOffering.getId();
624+
}
619625
//Pass startVm=false as we are holding the network lock that needs to be released at the end of vm allocation
620626
DomainRouterVO internalLbVm =
621-
deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, _internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false);
627+
deployInternalLbVm(owner, dest, plan, params, internalLbProviderId, internalLbVmOfferingId, guestNetwork.getVpcId(), networks, false);
622628
if (internalLbVm != null) {
623629
_internalLbVmDao.addRouterToGuestNetwork(internalLbVm, guestNetwork);
624630
internalLbVms.add(internalLbVm);

plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMManagerTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ public void setUp() {
121121
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
122122
1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
123123
off = setId(off, 1);
124-
Mockito.when(_svcOffDao.persistSystemServiceOffering(Matchers.any(ServiceOfferingVO.class))).thenReturn(off);
124+
List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
125+
list.add(off);
126+
list.add(off);
127+
Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(),
128+
Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(Storage.ProvisioningType.class), Matchers.anyBoolean(),
129+
Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
125130

126131
ComponentContext.initComponentsLifeCycle();
127132

plugins/network-elements/internal-loadbalancer/test/org/apache/cloudstack/internallbvmmgr/InternalLBVMServiceTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.apache.cloudstack.internallbvmmgr;
1818

1919
import java.lang.reflect.Field;
20+
import java.util.ArrayList;
21+
import java.util.List;
2022

2123
import javax.inject.Inject;
2224

@@ -91,7 +93,12 @@ public void setUp() {
9193
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1,
9294
1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
9395
off = setId(off, 1);
94-
Mockito.when(_svcOffDao.persistSystemServiceOffering(Matchers.any(ServiceOfferingVO.class))).thenReturn(off);
96+
List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
97+
list.add(off);
98+
list.add(off);
99+
Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(),
100+
Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(Storage.ProvisioningType.class), Matchers.anyBoolean(),
101+
Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
95102

96103
ComponentContext.initComponentsLifeCycle();
97104

server/src/com/cloud/configuration/Config.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,6 @@ public enum Config {
684684
"/var/cloudstack/mnt",
685685
"The mount point on the Management Server for Secondary Storage.",
686686
null),
687-
// UpgradeURL("Advanced", ManagementServer.class, String.class, "upgrade.url", "http://example.com:8080/client/agent/update.zip", "The upgrade URL is the URL of the management server that agents will connect to in order to automatically upgrade.", null),
688687
SystemVMAutoReserveCapacity(
689688
"Advanced",
690689
ManagementServer.class,

0 commit comments

Comments
 (0)