Skip to content

Commit d2b0c33

Browse files
authored
Merge pull request #28 from ablecloud-team/ablestack-bronto
bronto merge
2 parents 2ca9046 + da1384f commit d2b0c33

File tree

20 files changed

+569
-282
lines changed

20 files changed

+569
-282
lines changed

agent/conf/agent.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ iscsi.session.cleanup.enabled=false
271271
# Depending on the use case, this timeout might need increasing/decreasing.
272272
# heartbeat.update.timeout=60000
273273

274+
# This parameter specifies the timeout in seconds to retrieve the target's domain id when migrating a VM with KVM.
275+
# vm.migrate.domain.retrieve.timeout=10
276+
274277
# This parameter specifies if the host must be rebooted when something goes wrong with the heartbeat.
275278
# reboot.host.and.alert.management.on.heartbeat.timeout=true
276279

agent/src/main/java/com/cloud/agent/properties/AgentProperties.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ public class AgentProperties{
2929
* Heartbeat update timeout. <br>
3030
* Data type: int. <br>
3131
* Default value: 60000 (ms).
32-
*/
32+
*/
3333
public static final Property<Integer> HEARTBEAT_UPDATE_TIMEOUT = new Property<Integer>("heartbeat.update.timeout", 60000);
3434

35+
/**
36+
* The timeout in seconds to retrieve the target's domain id when migrating a VM with KVM. <br>
37+
* Data type: int. <br>
38+
* Default value: 10 (sec).
39+
*/
40+
public static final Property<Integer> VM_MIGRATE_DOMAIN_RETRIEVE_TIMEOUT = new Property<Integer>("vm.migrate.domain.retrieve.timeout", 10);
41+
3542
/**
3643
* Reboot host and alert management on heartbeat timeout. <br>
3744
* Data type: boolean.<br>

engine/schema/src/main/java/com/cloud/host/dao/HostDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
7575

7676
List<HostVO> findHypervisorHostInCluster(long clusterId);
7777

78+
HostVO findOldestExistentHypervisorHostInCluster(long clusterId);
79+
7880
List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag);
7981

8082
List<HostVO> findByDataCenterId(Long zoneId);

engine/schema/src/main/java/com/cloud/host/dao/HostDaoImpl.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,23 @@ public List<HostVO> findHypervisorHostInCluster(long clusterId) {
11681168
return listBy(sc);
11691169
}
11701170

1171+
@Override
1172+
public HostVO findOldestExistentHypervisorHostInCluster(long clusterId) {
1173+
SearchCriteria<HostVO> sc = TypeClusterStatusSearch.create();
1174+
sc.setParameters("type", Host.Type.Routing);
1175+
sc.setParameters("cluster", clusterId);
1176+
sc.setParameters("status", Status.Up);
1177+
sc.setParameters("resourceState", ResourceState.Enabled);
1178+
Filter orderByFilter = new Filter(HostVO.class, "created", true, null, null);
1179+
1180+
List<HostVO> hosts = search(sc, orderByFilter, null, false);
1181+
if (hosts != null && hosts.size() > 0) {
1182+
return hosts.get(0);
1183+
}
1184+
1185+
return null;
1186+
}
1187+
11711188
@Override
11721189
public List<Long> listAllHosts(long zoneId) {
11731190
SearchCriteria<Long> sc = HostIdSearch.create();

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtMigrateCommandWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
import com.cloud.agent.api.MigrateCommand;
6767
import com.cloud.agent.api.MigrateCommand.MigrateDiskInfo;
6868
import com.cloud.agent.api.to.VirtualMachineTO;
69+
import com.cloud.agent.properties.AgentProperties;
70+
import com.cloud.agent.properties.AgentPropertiesFileHandler;
6971
import com.cloud.hypervisor.kvm.resource.LibvirtComputingResource;
7072
import com.cloud.hypervisor.kvm.resource.LibvirtConnection;
7173
import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef;
@@ -239,7 +241,7 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
239241
}
240242
s_logger.info("Migration thread for " + vmName + " is done");
241243

242-
destDomain = migrateThread.get(10, TimeUnit.SECONDS);
244+
destDomain = migrateThread.get(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VM_MIGRATE_DOMAIN_RETRIEVE_TIMEOUT), TimeUnit.SECONDS);
243245

244246
if (destDomain != null) {
245247
deleteOrDisconnectDisksOnSourcePool(libvirtComputingResource, migrateDiskInfoList, disks);

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public interface VmwareManager {
4646
static final ConfigKey<Integer> s_vmwareOVAPackageTimeout = new ConfigKey<Integer>(Integer.class, "vmware.package.ova.timeout", "Advanced", "3600",
4747
"Vmware script timeout for ova packaging process", true, ConfigKey.Scope.Global, 1000);
4848

49+
static final ConfigKey<Boolean> s_vmwareCleanupPortGroups = new ConfigKey<Boolean>("Advanced", Boolean.class, "vmware.cleanup.port.groups", "false",
50+
"When set to true, the unused port groups are removed from VMware hypervisor hosts. WARNING: Native VMware HA might not work when enabled.", true, ConfigKey.Scope.Global);
51+
52+
public static final ConfigKey<Integer> VMWARE_STATS_TIME_WINDOW = new ConfigKey<Integer>("Advanced", Integer.class, "vmware.stats.time.window", "300",
53+
"VMware interval window (in seconds) to collect metrics. If this is set to less than 20, then default (300 seconds) will be used. The interval used must be enabled in vCenter for this change to work, "
54+
+ "otherwise the collection of metrics will result in an error. Check VMWare docs to know how to enable metrics interval.", true);
55+
4956
String composeWorkerName();
5057

5158
String getSystemVMIsoFileNameOnDatastore();

plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/manager/VmwareManagerImpl.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.cloud.exception.OperationTimedoutException;
5050
import com.cloud.exception.ResourceInUseException;
5151
import com.cloud.host.Host;
52+
import com.cloud.host.HostVO;
5253
import com.cloud.host.Status;
5354
import com.cloud.host.dao.HostDao;
5455
import com.cloud.host.dao.HostDetailsDao;
@@ -100,6 +101,7 @@
100101
import com.cloud.utils.FileUtil;
101102
import com.cloud.utils.NumbersUtil;
102103
import com.cloud.utils.Pair;
104+
import com.cloud.utils.UriUtils;
103105
import com.cloud.utils.component.ManagerBase;
104106
import com.cloud.utils.concurrency.NamedThreadFactory;
105107
import com.cloud.utils.db.DB;
@@ -136,6 +138,8 @@
136138
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
137139
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
138140
import org.apache.cloudstack.utils.identity.ManagementServerNode;
141+
import org.apache.commons.collections.MapUtils;
142+
import org.apache.commons.lang.StringUtils;
139143
import org.apache.log4j.Logger;
140144

141145
import javax.inject.Inject;
@@ -145,6 +149,7 @@
145149
import java.net.URI;
146150
import java.net.URISyntaxException;
147151
import java.net.URL;
152+
import java.net.URLDecoder;
148153
import java.rmi.RemoteException;
149154
import java.time.Duration;
150155
import java.time.Instant;
@@ -270,7 +275,7 @@ public String getConfigComponentName() {
270275

271276
@Override
272277
public ConfigKey<?>[] getConfigKeys() {
273-
return new ConfigKey<?>[] {s_vmwareNicHotplugWaitTimeout, s_vmwareCleanOldWorderVMs, templateCleanupInterval, s_vmwareSearchExcludeFolder, s_vmwareOVAPackageTimeout};
278+
return new ConfigKey<?>[] {s_vmwareNicHotplugWaitTimeout, s_vmwareCleanOldWorderVMs, templateCleanupInterval, s_vmwareSearchExcludeFolder, s_vmwareOVAPackageTimeout, s_vmwareCleanupPortGroups, VMWARE_STATS_TIME_WINDOW};
274279
}
275280
@Override
276281
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
@@ -446,6 +451,29 @@ private void prepareHost(HostMO hostMo, String privateTrafficLabel) throws Excep
446451
}
447452
}
448453

454+
private HostMO getOldestExistentHostInCluster(Long clusterId, VmwareContext serviceContext) throws Exception {
455+
HostVO host = hostDao.findOldestExistentHypervisorHostInCluster(clusterId);
456+
if (host == null) {
457+
return null;
458+
}
459+
460+
ManagedObjectReference morSrcHost = HypervisorHostHelper.getHypervisorHostMorFromGuid(host.getGuid());
461+
if (morSrcHost == null) {
462+
Map<String, String> clusterDetails = clusterDetailsDao.findDetails(clusterId);
463+
if (MapUtils.isEmpty(clusterDetails) || StringUtils.isBlank(clusterDetails.get("url"))) {
464+
return null;
465+
}
466+
467+
URI uriForHost = new URI(UriUtils.encodeURIComponent(clusterDetails.get("url") + "/" + host.getName()));
468+
morSrcHost = serviceContext.getHostMorByPath(URLDecoder.decode(uriForHost.getPath(), "UTF-8"));
469+
if (morSrcHost == null) {
470+
return null;
471+
}
472+
}
473+
474+
return new HostMO(serviceContext, morSrcHost);
475+
}
476+
449477
@Override
450478
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId, String hostInventoryPath)
451479
throws Exception {
@@ -498,6 +526,11 @@ public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceCon
498526
// For ESX host, we need to enable host firewall to allow VNC access
499527
HostMO hostMo = new HostMO(serviceContext, mor);
500528
prepareHost(hostMo, privateTrafficLabel);
529+
HostMO olderHostMo = getOldestExistentHostInCluster(clusterId, serviceContext);
530+
if (olderHostMo != null) {
531+
hostMo.copyPortGroupsFromHost(olderHostMo);
532+
}
533+
501534
returnedHostList.add(mor);
502535
return returnedHostList;
503536
} else {

0 commit comments

Comments
 (0)