Skip to content

Commit 3e3a0c0

Browse files
author
Daan Hoogland
committed
Merge branch '4.20'
2 parents be22bfe + 1a251c8 commit 3e3a0c0

File tree

18 files changed

+424
-190
lines changed

18 files changed

+424
-190
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ public static String[] toStrings(Host.Type... types) {
5353
return strs;
5454
}
5555
}
56-
public static final String HOST_UEFI_ENABLE = "host.uefi.enable";
57-
public static final String HOST_VOLUME_ENCRYPTION = "host.volume.encryption";
58-
public static final String HOST_INSTANCE_CONVERSION = "host.instance.conversion";
56+
57+
String HOST_UEFI_ENABLE = "host.uefi.enable";
58+
String HOST_VOLUME_ENCRYPTION = "host.volume.encryption";
59+
String HOST_INSTANCE_CONVERSION = "host.instance.conversion";
60+
String HOST_OVFTOOL_VERSION = "host.ovftool.version";
61+
String HOST_VIRTV2V_VERSION = "host.virtv2v.version";
5962

6063
/**
6164
* @return name of the machine.

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
6363
import org.apache.commons.collections.MapUtils;
6464
import org.apache.commons.lang3.BooleanUtils;
65+
import org.apache.commons.lang3.ObjectUtils;
6566
import org.apache.commons.lang3.StringUtils;
6667
import org.apache.logging.log4j.ThreadContext;
6768

@@ -801,11 +802,25 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
801802
Map<String, String> detailsMap = readyAnswer.getDetailsMap();
802803
if (detailsMap != null) {
803804
String uefiEnabled = detailsMap.get(Host.HOST_UEFI_ENABLE);
805+
String virtv2vVersion = detailsMap.get(Host.HOST_VIRTV2V_VERSION);
806+
String ovftoolVersion = detailsMap.get(Host.HOST_OVFTOOL_VERSION);
804807
logger.debug("Got HOST_UEFI_ENABLE [{}] for host [{}]:", uefiEnabled, host);
805-
if (uefiEnabled != null) {
808+
if (ObjectUtils.anyNotNull(uefiEnabled, virtv2vVersion, ovftoolVersion)) {
806809
_hostDao.loadDetails(host);
810+
boolean updateNeeded = false;
807811
if (!uefiEnabled.equals(host.getDetails().get(Host.HOST_UEFI_ENABLE))) {
808812
host.getDetails().put(Host.HOST_UEFI_ENABLE, uefiEnabled);
813+
updateNeeded = true;
814+
}
815+
if (StringUtils.isNotBlank(virtv2vVersion) && !virtv2vVersion.equals(host.getDetails().get(Host.HOST_VIRTV2V_VERSION))) {
816+
host.getDetails().put(Host.HOST_VIRTV2V_VERSION, virtv2vVersion);
817+
updateNeeded = true;
818+
}
819+
if (StringUtils.isNotBlank(ovftoolVersion) && !ovftoolVersion.equals(host.getDetails().get(Host.HOST_OVFTOOL_VERSION))) {
820+
host.getDetails().put(Host.HOST_OVFTOOL_VERSION, ovftoolVersion);
821+
updateNeeded = true;
822+
}
823+
if (updateNeeded) {
809824
_hostDao.saveDetails(host);
810825
}
811826
}

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package com.cloud.hypervisor.kvm.resource;
1818

1919
import static com.cloud.host.Host.HOST_INSTANCE_CONVERSION;
20+
import static com.cloud.host.Host.HOST_OVFTOOL_VERSION;
21+
import static com.cloud.host.Host.HOST_VIRTV2V_VERSION;
2022
import static com.cloud.host.Host.HOST_VOLUME_ENCRYPTION;
2123
import static org.apache.cloudstack.utils.linux.KVMHostInfo.isHostS390x;
2224

@@ -3908,7 +3910,14 @@ public StartupCommand[] initialize() {
39083910
cmd.setIqn(getIqn());
39093911
cmd.getHostDetails().put(HOST_VOLUME_ENCRYPTION, String.valueOf(hostSupportsVolumeEncryption()));
39103912
cmd.setHostTags(getHostTags());
3911-
cmd.getHostDetails().put(HOST_INSTANCE_CONVERSION, String.valueOf(hostSupportsInstanceConversion()));
3913+
boolean instanceConversionSupported = hostSupportsInstanceConversion();
3914+
cmd.getHostDetails().put(HOST_INSTANCE_CONVERSION, String.valueOf(instanceConversionSupported));
3915+
if (instanceConversionSupported) {
3916+
cmd.getHostDetails().put(HOST_VIRTV2V_VERSION, getHostVirtV2vVersion());
3917+
}
3918+
if (hostSupportsOvfExport()) {
3919+
cmd.getHostDetails().put(HOST_OVFTOOL_VERSION, getHostOvfToolVersion());
3920+
}
39123921
HealthCheckResult healthCheckResult = getHostHealthCheckResult();
39133922
if (healthCheckResult != HealthCheckResult.IGNORE) {
39143923
cmd.setHostHealthCheckResult(healthCheckResult == HealthCheckResult.SUCCESS);
@@ -5616,8 +5625,24 @@ public boolean hostSupportsOvfExport() {
56165625
return exitValue == 0;
56175626
}
56185627

5628+
public String getHostVirtV2vVersion() {
5629+
if (!hostSupportsInstanceConversion()) {
5630+
return "";
5631+
}
5632+
String cmd = String.format("%s | awk '{print $2}'", INSTANCE_CONVERSION_SUPPORTED_CHECK_CMD);
5633+
String version = Script.runSimpleBashScript(cmd);
5634+
return StringUtils.isNotBlank(version) ? version.split(",")[0] : "";
5635+
}
5636+
5637+
public String getHostOvfToolVersion() {
5638+
if (!hostSupportsOvfExport()) {
5639+
return "";
5640+
}
5641+
return Script.runSimpleBashScript(OVF_EXPORT_TOOl_GET_VERSION_CMD);
5642+
}
5643+
56195644
public boolean ovfExportToolSupportsParallelThreads() {
5620-
String ovfExportToolVersion = Script.runSimpleBashScript(OVF_EXPORT_TOOl_GET_VERSION_CMD);
5645+
String ovfExportToolVersion = getHostOvfToolVersion();
56215646
if (StringUtils.isBlank(ovfExportToolVersion)) {
56225647
return false;
56235648
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public Answer execute(final ReadyCommand command, final LibvirtComputingResource
4747
hostDetails.put(Host.HOST_UEFI_ENABLE, Boolean.TRUE.toString());
4848
}
4949

50+
if (libvirtComputingResource.hostSupportsInstanceConversion()) {
51+
hostDetails.put(Host.HOST_VIRTV2V_VERSION, libvirtComputingResource.getHostVirtV2vVersion());
52+
}
53+
54+
if (libvirtComputingResource.hostSupportsOvfExport()) {
55+
hostDetails.put(Host.HOST_OVFTOOL_VERSION, libvirtComputingResource.getHostOvfToolVersion());
56+
}
57+
5058
return new ReadyAnswer(command, hostDetails);
5159
}
5260

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixResizeVolumeCommandWrapper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ public Answer execute(final ResizeVolumeCommand command, final CitrixResourceBas
4949

5050
try {
5151

52-
if (command.getCurrentSize() >= newSize) {
53-
logger.info("No need to resize volume: " + volId +", current size " + toHumanReadableSize(command.getCurrentSize()) + " is same as new size " + toHumanReadableSize(newSize));
52+
if (command.getCurrentSize() == newSize) {
53+
logger.info("No need to resize volume [{}], current size [{}] is same as new size [{}].", volId, toHumanReadableSize(command.getCurrentSize()), toHumanReadableSize(newSize));
5454
return new ResizeVolumeAnswer(command, true, "success", newSize);
55+
} else if (command.getCurrentSize() > newSize) {
56+
logger.error("XenServer does not support volume shrink. Volume [{}] current size [{}] is smaller than new size [{}]", volId, toHumanReadableSize(command.getCurrentSize()), toHumanReadableSize(newSize));
57+
return new ResizeVolumeAnswer(command, false, "operation not supported");
5558
}
5659
if (command.isManaged()) {
5760
resizeSr(conn, command);

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapContextFactory.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package org.apache.cloudstack.ldap;
1818

19+
import java.io.FileInputStream;
1920
import java.io.IOException;
2021
import java.util.Hashtable;
2122

@@ -24,6 +25,7 @@
2425
import javax.naming.NamingException;
2526
import javax.naming.ldap.InitialLdapContext;
2627
import javax.naming.ldap.LdapContext;
28+
import java.security.KeyStore;
2729

2830
import org.apache.commons.lang3.StringUtils;
2931
import org.apache.logging.log4j.Logger;
@@ -52,14 +54,14 @@ public LdapContext createBindContext(final String providerUrl, Long domainId) th
5254
return createInitialDirContext(bindPrincipal, bindPassword, providerUrl, true, domainId);
5355
}
5456

55-
private LdapContext createInitialDirContext(final String principal, final String password, final boolean isSystemContext, Long domainId) throws NamingException, IOException {
57+
private LdapContext createInitialDirContext(final String principal, final String password, final boolean isSystemContext, Long domainId) throws NamingException {
5658
return createInitialDirContext(principal, password, null, isSystemContext, domainId);
5759
}
5860

5961
private LdapContext createInitialDirContext(final String principal, final String password, final String providerUrl, final boolean isSystemContext, Long domainId)
60-
throws NamingException, IOException {
62+
throws NamingException {
6163
Hashtable<String, String> environment = getEnvironment(principal, password, providerUrl, isSystemContext, domainId);
62-
logger.debug("initializing ldap with provider url: " + environment.get(Context.PROVIDER_URL));
64+
logger.debug("initializing ldap with provider url: {}", environment.get(Context.PROVIDER_URL));
6365
return new InitialLdapContext(environment, null);
6466
}
6567

@@ -73,8 +75,36 @@ private void enableSSL(final Hashtable<String, String> environment, Long domainI
7375
if (sslStatus) {
7476
logger.info("LDAP SSL enabled.");
7577
environment.put(Context.SECURITY_PROTOCOL, "ssl");
76-
System.setProperty("javax.net.ssl.trustStore", _ldapConfiguration.getTrustStore(domainId));
77-
System.setProperty("javax.net.ssl.trustStorePassword", _ldapConfiguration.getTrustStorePassword(domainId));
78+
String trustStore = _ldapConfiguration.getTrustStore(domainId);
79+
String trustStorePassword = _ldapConfiguration.getTrustStorePassword(domainId);
80+
81+
if (!validateTrustStore(trustStore, trustStorePassword)) {
82+
throw new RuntimeException("Invalid truststore or truststore password");
83+
}
84+
85+
System.setProperty("javax.net.ssl.trustStore", trustStore);
86+
System.setProperty("javax.net.ssl.trustStorePassword", trustStorePassword);
87+
}
88+
}
89+
90+
private boolean validateTrustStore(String trustStore, String trustStorePassword) {
91+
if (trustStore == null) {
92+
return true;
93+
}
94+
95+
if (trustStorePassword == null) {
96+
return false;
97+
}
98+
99+
try {
100+
KeyStore.getInstance("JKS").load(
101+
new FileInputStream(trustStore),
102+
trustStorePassword.toCharArray()
103+
);
104+
return true;
105+
} catch (Exception e) {
106+
logger.warn("Failed to validate truststore: {}", e.getMessage());
107+
return false;
78108
}
79109
}
80110

plugins/user-authenticators/ldap/src/main/java/org/apache/cloudstack/ldap/LdapManagerImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ private LdapConfigurationResponse addConfigurationInternal(final String hostname
184184
} catch (NamingException | IOException e) {
185185
logger.debug("NamingException while doing an LDAP bind", e);
186186
throw new InvalidParameterValueException("Unable to bind to the given LDAP server");
187+
} catch (RuntimeException e) {
188+
if (e.getMessage().contains("Invalid truststore")) {
189+
throw new InvalidParameterValueException("Invalid truststore or truststore password");
190+
}
191+
throw e;
187192
} finally {
188193
closeContext(context);
189194
}

server/src/main/java/com/cloud/alert/AlertManagerImpl.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
import com.cloud.utils.component.ManagerBase;
9090
import com.cloud.utils.concurrency.NamedThreadFactory;
9191
import com.cloud.utils.db.SearchCriteria;
92+
import com.cloud.utils.db.Transaction;
93+
import com.cloud.utils.db.TransactionCallbackNoReturn;
94+
import com.cloud.utils.db.TransactionStatus;
95+
9296
import org.jetbrains.annotations.Nullable;
9397

9498
public class AlertManagerImpl extends ManagerBase implements AlertManager, Configurable {
@@ -290,8 +294,13 @@ protected void recalculateHostCapacities() {
290294
Math.min(CapacityManager.CapacityCalculateWorkers.value(), hostIds.size())));
291295
for (Long hostId : hostIds) {
292296
futures.put(hostId, executorService.submit(() -> {
293-
final HostVO host = hostDao.findById(hostId);
294-
_capacityMgr.updateCapacityForHost(host);
297+
Transaction.execute(new TransactionCallbackNoReturn() {
298+
@Override
299+
public void doInTransactionWithoutResult(TransactionStatus status) {
300+
final HostVO host = hostDao.findById(hostId);
301+
_capacityMgr.updateCapacityForHost(host);
302+
}
303+
});
295304
return null;
296305
}));
297306
}
@@ -316,13 +325,18 @@ protected void recalculateStorageCapacities() {
316325
Math.min(CapacityManager.CapacityCalculateWorkers.value(), storagePoolIds.size())));
317326
for (Long poolId: storagePoolIds) {
318327
futures.put(poolId, executorService.submit(() -> {
319-
final StoragePoolVO pool = _storagePoolDao.findById(poolId);
320-
long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
321-
if (pool.isShared()) {
322-
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
323-
} else {
324-
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
325-
}
328+
Transaction.execute(new TransactionCallbackNoReturn() {
329+
@Override
330+
public void doInTransactionWithoutResult(TransactionStatus status) {
331+
final StoragePoolVO pool = _storagePoolDao.findById(poolId);
332+
long disk = _capacityMgr.getAllocatedPoolCapacity(pool, null);
333+
if (pool.isShared()) {
334+
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED, disk);
335+
} else {
336+
_storageMgr.createCapacityEntry(pool, Capacity.CAPACITY_TYPE_LOCAL_STORAGE, disk);
337+
}
338+
}
339+
});
326340
return null;
327341
}));
328342
}

0 commit comments

Comments
 (0)