Skip to content

Commit ea95ac1

Browse files
author
Kelven Yang
committed
bug 8713 : finalize the implementation of supporting system vm pooling
1 parent 5f40543 commit ea95ac1

19 files changed

Lines changed: 244 additions & 95 deletions

‎api/src/com/cloud/agent/api/StartupCommand.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public Host.Type getHostType() {
6363
return type;
6464
}
6565

66+
public void setHostType(Host.Type type) {
67+
this.type = type;
68+
}
69+
6670
public String getIqn() {
6771
return iqn;
6872
}

‎api/src/com/cloud/host/Host.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public enum Type {
3030
Storage(false),
3131
Routing(false),
3232
SecondaryStorage(false),
33+
SecondaryStorageCmdExecutor(false),
3334
ConsoleProxy(true),
3435
ExternalFirewall(false),
3536
ExternalLoadBalancer(false),

‎core/src/com/cloud/storage/resource/NfsSecondaryStorageResource.java‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import com.cloud.utils.net.NetUtils;
7070
import com.cloud.utils.net.NfsUtils;
7171
import com.cloud.utils.script.Script;
72+
import com.cloud.vm.SecondaryStorageVm;
7273

7374
public class NfsSecondaryStorageResource extends ServerResourceBase implements ServerResource {
7475
private static final Logger s_logger = Logger.getLogger(NfsSecondaryStorageResource.class);
@@ -82,6 +83,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
8283
String _guid;
8384
String _nfsPath;
8485
String _mountParent;
86+
String _role;
8587
Map<String, Object> _params;
8688
StorageLayer _storage;
8789
boolean _inSystemVM = false;
@@ -183,8 +185,6 @@ public String allowOutgoingOnPrivate(String destCidr) {
183185
return null;
184186
}
185187

186-
187-
188188
private Answer execute(SecStorageFirewallCfgCommand cmd) {
189189
if (!_inSystemVM){
190190
return new Answer(cmd, true, null);
@@ -294,7 +294,10 @@ protected long convertFilesystemSize(final String size) {
294294

295295
@Override
296296
public Type getType() {
297-
return Host.Type.SecondaryStorage;
297+
if(SecondaryStorageVm.Role.templateProcessor.toString().equals(_role))
298+
return Host.Type.SecondaryStorage;
299+
300+
return Host.Type.SecondaryStorageCmdExecutor;
298301
}
299302

300303
@Override
@@ -353,6 +356,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
353356
s_logger.info("_configIpFirewallScr found in " + _configIpFirewallScr);
354357
}
355358

359+
_role = (String)params.get("role");
360+
if(_role == null)
361+
_role = SecondaryStorageVm.Role.templateProcessor.toString();
362+
s_logger.info("Secondary storage runs in role " + _role);
363+
356364
_guid = (String)params.get("guid");
357365
if (_guid == null) {
358366
throw new ConfigurationException("Unable to find the guid");
@@ -636,6 +644,7 @@ public StartupCommand[] initialize() {
636644

637645
final StartupStorageCommand cmd = new StartupStorageCommand(_parent, StoragePoolType.NetworkFilesystem, getTotalSize(), new HashMap<String, TemplateInfo>());
638646

647+
cmd.setHostType(getType());
639648
cmd.setResourceType(Storage.StorageResourceType.SECONDARY_STORAGE);
640649
cmd.setIqn(null);
641650

@@ -646,7 +655,10 @@ public StartupCommand[] initialize() {
646655
cmd.setName(_guid);
647656
cmd.setVersion(NfsSecondaryStorageResource.class.getPackage().getImplementationVersion());
648657
/* gather TemplateInfo in second storage */
649-
final Map<String, TemplateInfo> tInfo = _dlMgr.gatherTemplateInfo();
658+
659+
Map<String, TemplateInfo> tInfo = new HashMap<String, TemplateInfo>();
660+
if(SecondaryStorageVm.Role.templateProcessor.toString().equals(_role))
661+
tInfo = _dlMgr.gatherTemplateInfo();
650662
cmd.setTemplateInfo(tInfo);
651663
cmd.getHostDetails().put("mount.parent", _mountParent);
652664
cmd.getHostDetails().put("mount.path", _nfsPath);

‎core/src/com/cloud/vm/SecondaryStorageVm.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* Secondary Storage VM is a system VM instance that is used
2222
* to interface the management server to secondary storage
2323
*/
24-
public interface SecondaryStorageVm extends SystemVm {
24+
public interface SecondaryStorageVm extends SystemVm {
25+
enum Role { templateProcessor, commandExecutor }
2526
}
2627

‎core/src/com/cloud/vm/SecondaryStorageVmVO.java‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import javax.persistence.Column;
2323
import javax.persistence.DiscriminatorValue;
2424
import javax.persistence.Entity;
25+
import javax.persistence.EnumType;
26+
import javax.persistence.Enumerated;
2527
import javax.persistence.PrimaryKeyJoinColumn;
2628
import javax.persistence.Table;
2729
import javax.persistence.Temporal;
@@ -52,17 +54,20 @@ public class SecondaryStorageVmVO extends VMInstanceVO implements SecondaryStora
5254
private String guid;
5355

5456
@Column(name="nfs_share", nullable=false)
55-
private String nfsShare;
57+
private String nfsShare;
58+
59+
@Column(name="role", nullable=false)
60+
@Enumerated(value=EnumType.STRING)
61+
private Role role;
5662

5763
@Temporal(TemporalType.TIMESTAMP)
5864
@Column(name="last_update", updatable=true, nullable=true)
5965
private Date lastUpdateTime;
6066

61-
62-
6367
public SecondaryStorageVmVO(long id, long serviceOfferingId, String name, long templateId, HypervisorType hypervisorType, long guestOSId, long dataCenterId,
64-
long domainId, long accountId) {
68+
long domainId, long accountId, Role role) {
6569
super(id, serviceOfferingId, name, name, Type.SecondaryStorageVm, templateId, hypervisorType, guestOSId, domainId, accountId, true);
70+
this.role = role;
6671
}
6772

6873
protected SecondaryStorageVmVO() {
@@ -119,5 +124,13 @@ public void setNfsShare(String nfsShare) {
119124

120125
public String getNfsShare() {
121126
return nfsShare;
122-
}
127+
}
128+
129+
public Role getRole() {
130+
return this.role;
131+
}
132+
133+
public void setRole(Role role) {
134+
this.role = role;
135+
}
123136
}

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,23 +2488,26 @@ public HostVO createHost(final StartupCommand startup,
24882488
Host.Type type = null;
24892489

24902490
if (startup instanceof StartupStorageCommand) {
2491-
24922491
StartupStorageCommand ssCmd = ((StartupStorageCommand) startup);
2493-
if (ssCmd.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE) {
2494-
type = Host.Type.SecondaryStorage;
2495-
if (resource != null
2496-
&& resource instanceof DummySecondaryStorageResource) {
2497-
resource = null;
2498-
}
2492+
if(ssCmd.getHostType() == Host.Type.SecondaryStorageCmdExecutor) {
2493+
type = ssCmd.getHostType();
24992494
} else {
2500-
type = Host.Type.Storage;
2501-
}
2502-
final Map<String, String> hostDetails = ssCmd.getHostDetails();
2503-
if (hostDetails != null) {
2504-
if (details != null) {
2505-
details.putAll(hostDetails);
2495+
if (ssCmd.getResourceType() == Storage.StorageResourceType.SECONDARY_STORAGE) {
2496+
type = Host.Type.SecondaryStorage;
2497+
if (resource != null
2498+
&& resource instanceof DummySecondaryStorageResource) {
2499+
resource = null;
2500+
}
25062501
} else {
2507-
details = hostDetails;
2502+
type = Host.Type.Storage;
2503+
}
2504+
final Map<String, String> hostDetails = ssCmd.getHostDetails();
2505+
if (hostDetails != null) {
2506+
if (details != null) {
2507+
details.putAll(hostDetails);
2508+
} else {
2509+
details = hostDetails;
2510+
}
25082511
}
25092512
}
25102513
} else if (startup instanceof StartupRoutingCommand) {
@@ -2530,7 +2533,7 @@ public HostVO createHost(final StartupCommand startup,
25302533
type = Host.Type.PxeServer;
25312534
} else if (startup instanceof StartupExternalDhcpCommand) {
25322535
type = Host.Type.ExternalDhcp;
2533-
}else {
2536+
} else {
25342537
assert false : "Did someone add a new Startup command?";
25352538
}
25362539

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ public enum Config {
152152
MaxTemplateAndIsoSize("Advanced", ManagementServer.class, Long.class, "max.template.iso.size", "50", "The maximum size for a downloaded template or ISO (in GB).", null),
153153
SecStorageAllowedInternalDownloadSites("Advanced", ManagementServer.class, String.class, "secstorage.allowed.internal.sites", null, "Comma separated list of cidrs internal to the datacenter that can host template download servers", null),
154154
SecStorageEncryptCopy("Advanced", ManagementServer.class, Boolean.class, "secstorage.encrypt.copy", "false", "Use SSL method used to encrypt copy traffic between zones", "true,false"),
155-
SecStorageSecureCopyCert("Advanced", ManagementServer.class, String.class, "secstorage.ssl.cert.domain", "realhostip.com", "SSL certificate used to encrypt copy traffic between zones", null),
155+
SecStorageSecureCopyCert("Advanced", ManagementServer.class, String.class, "secstorage.ssl.cert.domain", "realhostip.com", "SSL certificate used to encrypt copy traffic between zones", null),
156+
SecStorageCapacityStandby("Advanced", AgentManager.class, Integer.class, "secstorage.capacity.standby", "10", "The minimal number of command execution sessions that system is able to serve immediately(standby capacity)", null),
157+
SecStorageSessionMax("Advanced", AgentManager.class, Integer.class, "secstorage.session.max", "50", "The max number of command execution sessions that a SSVM can handle", null),
158+
SecStorageCmdExecutionTimeMax("Advanced", AgentManager.class, Integer.class, "secstorage.cmd.execution.time.max", "30", "The max command execution time in minute", null),
159+
156160
DirectAttachNetworkEnabled("Advanced", ManagementServer.class, Boolean.class, "direct.attach.network.externalIpAllocator.enabled", "false", "Direct-attach VMs using external DHCP server", "true,false"),
157161
DirectAttachNetworkExternalAPIURL("Advanced", ManagementServer.class, String.class, "direct.attach.network.externalIpAllocator.url", null, "Direct-attach VMs using external DHCP server (API url)", null),
158162
CheckPodCIDRs("Advanced", ManagementServer.class, String.class, "check.pod.cidrs", "true", "If true, different pods must belong to different CIDR subnets.", "true,false"),

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,12 +1478,12 @@ public boolean isPoolReadyForScan(Long pool) {
14781478
}
14791479

14801480
@Override
1481-
public AfterScanAction scanPool(Long pool) {
1481+
public Pair<AfterScanAction, Object> scanPool(Long pool) {
14821482
long dataCenterId = pool.longValue();
14831483

14841484
ConsoleProxyLoadInfo proxyInfo = this._zoneProxyCountMap.get(dataCenterId);
14851485
if(proxyInfo == null)
1486-
return AfterScanAction.nop;
1486+
return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
14871487

14881488
ConsoleProxyLoadInfo vmInfo = this._zoneVmCountMap.get(dataCenterId);
14891489
if(vmInfo == null)
@@ -1493,20 +1493,20 @@ public AfterScanAction scanPool(Long pool) {
14931493
if(s_logger.isDebugEnabled())
14941494
s_logger.debug("Expand console proxy standby capacity for zone " + proxyInfo.getName());
14951495

1496-
return AfterScanAction.expand;
1496+
return new Pair<AfterScanAction, Object>(AfterScanAction.expand, null);
14971497
}
14981498

1499-
return AfterScanAction.nop;
1499+
return new Pair<AfterScanAction, Object>(AfterScanAction.nop, null);
15001500
}
15011501

15021502
@Override
1503-
public void expandPool(Long pool) {
1503+
public void expandPool(Long pool, Object actionArgs) {
15041504
long dataCenterId = pool.longValue();
15051505
allocCapacity(dataCenterId);
15061506
}
15071507

15081508
@Override
1509-
public void shrinkPool(Long pool) {
1509+
public void shrinkPool(Long pool, Object actionArgs) {
15101510
}
15111511

15121512
@Override

‎server/src/com/cloud/host/dao/HostDao.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ public interface HostDao extends GenericDao<HostVO, Long> {
9595
* @param macAddress
9696
* @return HostVO or null if not found.
9797
*/
98-
public HostVO findByGuid(String macAddress);
98+
public HostVO findByGuid(String macAddress);
99+
100+
public HostVO findByName(String name);
99101

100102

101103
/**

‎server/src/com/cloud/host/dao/HostDaoImpl.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
7575
protected final SearchBuilder<HostVO> PodSearch;
7676
protected final SearchBuilder<HostVO> TypeSearch;
7777
protected final SearchBuilder<HostVO> StatusSearch;
78-
protected final SearchBuilder<HostVO> NameLikeSearch;
78+
protected final SearchBuilder<HostVO> NameLikeSearch;
79+
protected final SearchBuilder<HostVO> NameSearch;
7980
protected final SearchBuilder<HostVO> SequenceSearch;
8081
protected final SearchBuilder<HostVO> DirectlyConnectedSearch;
8182
protected final SearchBuilder<HostVO> UnmanagedDirectConnectSearch;
@@ -183,6 +184,10 @@ public HostDaoImpl() {
183184
NameLikeSearch = createSearchBuilder();
184185
NameLikeSearch.and("name", NameLikeSearch.entity().getName(), SearchCriteria.Op.LIKE);
185186
NameLikeSearch.done();
187+
188+
NameSearch = createSearchBuilder();
189+
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
190+
NameSearch.done();
186191

187192
SequenceSearch = createSearchBuilder();
188193
SequenceSearch.and("id", SequenceSearch.entity().getId(), SearchCriteria.Op.EQ);
@@ -513,6 +518,12 @@ public boolean connect(HostVO host, long msId) {
513518
public HostVO findByGuid(String guid) {
514519
SearchCriteria<HostVO> sc = GuidSearch.create("guid", guid);
515520
return findOneBy(sc);
521+
}
522+
523+
@Override
524+
public HostVO findByName(String name) {
525+
SearchCriteria<HostVO> sc = NameSearch.create("name", name);
526+
return findOneBy(sc);
516527
}
517528

518529
@Override

0 commit comments

Comments
 (0)