Skip to content

Commit bf2cede

Browse files
committed
Merge branch 4.19 to main
2 parents 4ce8671 + cb4713f commit bf2cede

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@
4949
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
5050
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
5151
import org.apache.cloudstack.framework.config.dao.ConfigurationDaoImpl;
52+
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
5253
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
5354
import org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl;
55+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
56+
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDaoImpl;
5457
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
5558
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
5659
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
@@ -117,6 +120,8 @@ public class SystemVmTemplateRegistration {
117120
@Inject
118121
ImageStoreDao imageStoreDao;
119122
@Inject
123+
ImageStoreDetailsDao imageStoreDetailsDao;
124+
@Inject
120125
ClusterDao clusterDao;
121126
@Inject
122127
ConfigurationDao configurationDao;
@@ -130,6 +135,7 @@ public SystemVmTemplateRegistration() {
130135
templateDataStoreDao = new BasicTemplateDataStoreDaoImpl();
131136
vmInstanceDao = new VMInstanceDaoImpl();
132137
imageStoreDao = new ImageStoreDaoImpl();
138+
imageStoreDetailsDao = new ImageStoreDetailsDaoImpl();
133139
clusterDao = new ClusterDaoImpl();
134140
configurationDao = new ConfigurationDaoImpl();
135141
}
@@ -142,6 +148,14 @@ public SystemVmTemplateRegistration(String systemVmTemplateVersion) {
142148
this.systemVmTemplateVersion = systemVmTemplateVersion;
143149
}
144150

151+
public static String getMountCommand(String nfsVersion, String device, String dir) {
152+
String cmd = "sudo mount -t nfs";
153+
if (StringUtils.isNotBlank(nfsVersion)) {
154+
cmd = String.format("%s -o vers=%s", cmd, nfsVersion);
155+
}
156+
return String.format("%s %s %s", cmd, device, dir);
157+
}
158+
145159
public String getSystemVmTemplateVersion() {
146160
if (StringUtils.isEmpty(systemVmTemplateVersion)) {
147161
return String.format("%s.%s", CS_MAJOR_VERSION, CS_TINY_VERSION);
@@ -320,14 +334,14 @@ public void setUpdated(Date updated) {
320334
}
321335
};
322336

323-
public static boolean validateIfSeeded(String url, String path) {
337+
public static boolean validateIfSeeded(String url, String path, String nfsVersion) {
324338
String filePath = null;
325339
try {
326340
filePath = Files.createTempDirectory(TEMPORARY_SECONDARY_STORE).toString();
327341
if (filePath == null) {
328342
throw new CloudRuntimeException("Failed to create temporary directory to mount secondary store");
329343
}
330-
mountStore(url, filePath);
344+
mountStore(url, filePath, nfsVersion);
331345
int lastIdx = path.lastIndexOf(File.separator);
332346
String partialDirPath = path.substring(0, lastIdx);
333347
String templatePath = filePath + File.separator + partialDirPath;
@@ -427,14 +441,13 @@ private Pair<String, Long> getNfsStoreInZone(Long zoneId) {
427441
return new Pair<>(url, storeId);
428442
}
429443

430-
public static void mountStore(String storeUrl, String path) {
444+
public static void mountStore(String storeUrl, String path, String nfsVersion) {
431445
try {
432446
if (storeUrl != null) {
433447
URI uri = new URI(UriUtils.encodeURIComponent(storeUrl));
434448
String host = uri.getHost();
435449
String mountPath = uri.getPath();
436-
String mount = String.format(MOUNT_COMMAND, host + ":" + mountPath, path);
437-
Script.runSimpleBashScript(mount);
450+
Script.runSimpleBashScript(getMountCommand(nfsVersion, host + ":" + mountPath, path));
438451
}
439452
} catch (Exception e) {
440453
String msg = "NFS Store URL is not in the correct format";
@@ -773,7 +786,8 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
773786
throw new CloudRuntimeException("Failed to create temporary file path to mount the store");
774787
}
775788
Pair<String, Long> storeUrlAndId = getNfsStoreInZone(zoneId);
776-
mountStore(storeUrlAndId.first(), filePath);
789+
String nfsVersion = getNfsVersion(storeUrlAndId.second());
790+
mountStore(storeUrlAndId.first(), filePath, nfsVersion);
777791
List<String> hypervisorList = fetchAllHypervisors(zoneId);
778792
for (String hypervisor : hypervisorList) {
779793
Hypervisor.HypervisorType name = Hypervisor.HypervisorType.getType(hypervisor);
@@ -784,7 +798,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
784798
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
785799
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(templateId, DataStoreRole.Image);
786800
String installPath = templateDataStoreVO.getInstallPath();
787-
if (validateIfSeeded(storeUrlAndId.first(), installPath)) {
801+
if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
788802
continue;
789803
} else if (templateVO != null) {
790804
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath);
@@ -889,4 +903,17 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
889903
}
890904
});
891905
}
906+
907+
public String getNfsVersion(long storeId) {
908+
final String configKey = "secstorage.nfs.version";
909+
final Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
910+
if (storeDetails != null && storeDetails.containsKey(configKey)) {
911+
return storeDetails.get(configKey);
912+
}
913+
ConfigurationVO globalNfsVersion = configurationDao.findByName(configKey);
914+
if (globalNfsVersion != null) {
915+
return globalNfsVersion.getValue();
916+
}
917+
return null;
918+
}
892919
}

plugins/integrations/kubernetes-service/src/main/java/com/cloud/kubernetes/cluster/KubernetesClusterManagerImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -836,9 +836,8 @@ private void validateManagedKubernetesClusterCreateParameters(final CreateKubern
836836
if (network == null) {
837837
throw new InvalidParameterValueException(String.format("%s parameter must be specified along with %s parameter", ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, ApiConstants.NETWORK_ID));
838838
}
839-
if (isDirectAccess(network)) {
840-
throw new InvalidParameterValueException(String.format("%s parameter must be specified along with %s network or %s network",
841-
ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, Network.GuestType.Shared, NetworkOffering.NetworkMode.ROUTED));
839+
if (!Network.GuestType.Shared.equals(network.getGuestType()) || routedIpv4Manager.isRoutedNetwork(network)) {
840+
throw new InvalidParameterValueException(String.format("%s parameter must be specified when network type is not %s or is %s network", ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, Network.GuestType.Shared, NetworkOffering.NetworkMode.ROUTED));
842841
}
843842
}
844843

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
389389
ConfigDepot configDepot;
390390
@Inject
391391
ConfigurationDao configurationDao;
392+
@Inject
393+
private ImageStoreDetailsUtil imageStoreDetailsUtil;
392394

393395
protected List<StoragePoolDiscoverer> _discoverers;
394396

@@ -3488,6 +3490,7 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
34883490
throw new CloudRuntimeException("Failed to create temporary file path to mount the store");
34893491
}
34903492
Pair<String, Long> storeUrlAndId = new Pair<>(url, store.getId());
3493+
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(store.getId());
34913494
for (HypervisorType hypervisorType : hypSet) {
34923495
try {
34933496
if (HypervisorType.Simulator == hypervisorType) {
@@ -3504,15 +3507,16 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
35043507
templateVO = _templateStoreDao.findByTemplate(templateId, DataStoreRole.Image);
35053508
if (templateVO != null) {
35063509
try {
3507-
if (SystemVmTemplateRegistration.validateIfSeeded(url, templateVO.getInstallPath())) {
3510+
if (SystemVmTemplateRegistration.validateIfSeeded(
3511+
url, templateVO.getInstallPath(), nfsVersion)) {
35083512
continue;
35093513
}
35103514
} catch (Exception e) {
35113515
logger.error("Failed to validated if template is seeded", e);
35123516
}
35133517
}
35143518
}
3515-
SystemVmTemplateRegistration.mountStore(storeUrlAndId.first(), filePath);
3519+
SystemVmTemplateRegistration.mountStore(storeUrlAndId.first(), filePath, nfsVersion);
35163520
if (templateVO != null && vmTemplateVO != null) {
35173521
systemVmTemplateRegistration.registerTemplate(hypervisorAndTemplateName, storeUrlAndId, vmTemplateVO, templateVO, filePath);
35183522
} else {

server/src/main/java/org/apache/cloudstack/diagnostics/DiagnosticsServiceImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ public Long getDelay() {
478478

479479
private void cleanupOldDiagnosticFiles(DataStore store) {
480480
String mountPoint = null;
481-
mountPoint = serviceImpl.mountManager.getMountPoint(store.getUri(), null);
481+
mountPoint = serviceImpl.mountManager.getMountPoint(store.getUri(),
482+
serviceImpl.imageStoreDetailsUtil.getNfsVersion(store.getId()));
482483
if (StringUtils.isNotBlank(mountPoint)) {
483484
File directory = new File(mountPoint + File.separator + DIAGNOSTICS_DIRECTORY);
484485
if (directory.isDirectory()) {

0 commit comments

Comments
 (0)