Merge branch 4.19 to main

This commit is contained in:
João Jandre 2024-09-26 09:01:22 -03:00
commit bf2cedea79
4 changed files with 44 additions and 13 deletions

View File

@ -49,8 +49,11 @@ import com.cloud.vm.dao.VMInstanceDaoImpl;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine; import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.framework.config.dao.ConfigurationDao; import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.framework.config.dao.ConfigurationDaoImpl; import org.apache.cloudstack.framework.config.dao.ConfigurationDaoImpl;
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao; import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl; import org.apache.cloudstack.storage.datastore.db.ImageStoreDaoImpl;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDaoImpl;
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO; import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO; import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
@ -117,6 +120,8 @@ public class SystemVmTemplateRegistration {
@Inject @Inject
ImageStoreDao imageStoreDao; ImageStoreDao imageStoreDao;
@Inject @Inject
ImageStoreDetailsDao imageStoreDetailsDao;
@Inject
ClusterDao clusterDao; ClusterDao clusterDao;
@Inject @Inject
ConfigurationDao configurationDao; ConfigurationDao configurationDao;
@ -130,6 +135,7 @@ public class SystemVmTemplateRegistration {
templateDataStoreDao = new BasicTemplateDataStoreDaoImpl(); templateDataStoreDao = new BasicTemplateDataStoreDaoImpl();
vmInstanceDao = new VMInstanceDaoImpl(); vmInstanceDao = new VMInstanceDaoImpl();
imageStoreDao = new ImageStoreDaoImpl(); imageStoreDao = new ImageStoreDaoImpl();
imageStoreDetailsDao = new ImageStoreDetailsDaoImpl();
clusterDao = new ClusterDaoImpl(); clusterDao = new ClusterDaoImpl();
configurationDao = new ConfigurationDaoImpl(); configurationDao = new ConfigurationDaoImpl();
} }
@ -142,6 +148,14 @@ public class SystemVmTemplateRegistration {
this.systemVmTemplateVersion = systemVmTemplateVersion; this.systemVmTemplateVersion = systemVmTemplateVersion;
} }
public static String getMountCommand(String nfsVersion, String device, String dir) {
String cmd = "sudo mount -t nfs";
if (StringUtils.isNotBlank(nfsVersion)) {
cmd = String.format("%s -o vers=%s", cmd, nfsVersion);
}
return String.format("%s %s %s", cmd, device, dir);
}
public String getSystemVmTemplateVersion() { public String getSystemVmTemplateVersion() {
if (StringUtils.isEmpty(systemVmTemplateVersion)) { if (StringUtils.isEmpty(systemVmTemplateVersion)) {
return String.format("%s.%s", CS_MAJOR_VERSION, CS_TINY_VERSION); return String.format("%s.%s", CS_MAJOR_VERSION, CS_TINY_VERSION);
@ -320,14 +334,14 @@ public class SystemVmTemplateRegistration {
} }
}; };
public static boolean validateIfSeeded(String url, String path) { public static boolean validateIfSeeded(String url, String path, String nfsVersion) {
String filePath = null; String filePath = null;
try { try {
filePath = Files.createTempDirectory(TEMPORARY_SECONDARY_STORE).toString(); filePath = Files.createTempDirectory(TEMPORARY_SECONDARY_STORE).toString();
if (filePath == null) { if (filePath == null) {
throw new CloudRuntimeException("Failed to create temporary directory to mount secondary store"); throw new CloudRuntimeException("Failed to create temporary directory to mount secondary store");
} }
mountStore(url, filePath); mountStore(url, filePath, nfsVersion);
int lastIdx = path.lastIndexOf(File.separator); int lastIdx = path.lastIndexOf(File.separator);
String partialDirPath = path.substring(0, lastIdx); String partialDirPath = path.substring(0, lastIdx);
String templatePath = filePath + File.separator + partialDirPath; String templatePath = filePath + File.separator + partialDirPath;
@ -427,14 +441,13 @@ public class SystemVmTemplateRegistration {
return new Pair<>(url, storeId); return new Pair<>(url, storeId);
} }
public static void mountStore(String storeUrl, String path) { public static void mountStore(String storeUrl, String path, String nfsVersion) {
try { try {
if (storeUrl != null) { if (storeUrl != null) {
URI uri = new URI(UriUtils.encodeURIComponent(storeUrl)); URI uri = new URI(UriUtils.encodeURIComponent(storeUrl));
String host = uri.getHost(); String host = uri.getHost();
String mountPath = uri.getPath(); String mountPath = uri.getPath();
String mount = String.format(MOUNT_COMMAND, host + ":" + mountPath, path); Script.runSimpleBashScript(getMountCommand(nfsVersion, host + ":" + mountPath, path));
Script.runSimpleBashScript(mount);
} }
} catch (Exception e) { } catch (Exception e) {
String msg = "NFS Store URL is not in the correct format"; String msg = "NFS Store URL is not in the correct format";
@ -773,7 +786,8 @@ public class SystemVmTemplateRegistration {
throw new CloudRuntimeException("Failed to create temporary file path to mount the store"); throw new CloudRuntimeException("Failed to create temporary file path to mount the store");
} }
Pair<String, Long> storeUrlAndId = getNfsStoreInZone(zoneId); Pair<String, Long> storeUrlAndId = getNfsStoreInZone(zoneId);
mountStore(storeUrlAndId.first(), filePath); String nfsVersion = getNfsVersion(storeUrlAndId.second());
mountStore(storeUrlAndId.first(), filePath, nfsVersion);
List<String> hypervisorList = fetchAllHypervisors(zoneId); List<String> hypervisorList = fetchAllHypervisors(zoneId);
for (String hypervisor : hypervisorList) { for (String hypervisor : hypervisorList) {
Hypervisor.HypervisorType name = Hypervisor.HypervisorType.getType(hypervisor); Hypervisor.HypervisorType name = Hypervisor.HypervisorType.getType(hypervisor);
@ -784,7 +798,7 @@ public class SystemVmTemplateRegistration {
VMTemplateVO templateVO = vmTemplateDao.findById(templateId); VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(templateId, DataStoreRole.Image); TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(templateId, DataStoreRole.Image);
String installPath = templateDataStoreVO.getInstallPath(); String installPath = templateDataStoreVO.getInstallPath();
if (validateIfSeeded(storeUrlAndId.first(), installPath)) { if (validateIfSeeded(storeUrlAndId.first(), installPath, nfsVersion)) {
continue; continue;
} else if (templateVO != null) { } else if (templateVO != null) {
registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath); registerTemplate(hypervisorAndTemplateName, storeUrlAndId, templateVO, templateDataStoreVO, filePath);
@ -889,4 +903,17 @@ public class SystemVmTemplateRegistration {
} }
}); });
} }
public String getNfsVersion(long storeId) {
final String configKey = "secstorage.nfs.version";
final Map<String, String> storeDetails = imageStoreDetailsDao.getDetails(storeId);
if (storeDetails != null && storeDetails.containsKey(configKey)) {
return storeDetails.get(configKey);
}
ConfigurationVO globalNfsVersion = configurationDao.findByName(configKey);
if (globalNfsVersion != null) {
return globalNfsVersion.getValue();
}
return null;
}
} }

View File

@ -836,9 +836,8 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
if (network == null) { if (network == null) {
throw new InvalidParameterValueException(String.format("%s parameter must be specified along with %s parameter", ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, ApiConstants.NETWORK_ID)); throw new InvalidParameterValueException(String.format("%s parameter must be specified along with %s parameter", ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, ApiConstants.NETWORK_ID));
} }
if (isDirectAccess(network)) { if (!Network.GuestType.Shared.equals(network.getGuestType()) || routedIpv4Manager.isRoutedNetwork(network)) {
throw new InvalidParameterValueException(String.format("%s parameter must be specified along with %s network or %s network", 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));
ApiConstants.EXTERNAL_LOAD_BALANCER_IP_ADDRESS, Network.GuestType.Shared, NetworkOffering.NetworkMode.ROUTED));
} }
} }

View File

@ -389,6 +389,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
ConfigDepot configDepot; ConfigDepot configDepot;
@Inject @Inject
ConfigurationDao configurationDao; ConfigurationDao configurationDao;
@Inject
private ImageStoreDetailsUtil imageStoreDetailsUtil;
protected List<StoragePoolDiscoverer> _discoverers; protected List<StoragePoolDiscoverer> _discoverers;
@ -3488,6 +3490,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
throw new CloudRuntimeException("Failed to create temporary file path to mount the store"); throw new CloudRuntimeException("Failed to create temporary file path to mount the store");
} }
Pair<String, Long> storeUrlAndId = new Pair<>(url, store.getId()); Pair<String, Long> storeUrlAndId = new Pair<>(url, store.getId());
String nfsVersion = imageStoreDetailsUtil.getNfsVersion(store.getId());
for (HypervisorType hypervisorType : hypSet) { for (HypervisorType hypervisorType : hypSet) {
try { try {
if (HypervisorType.Simulator == hypervisorType) { if (HypervisorType.Simulator == hypervisorType) {
@ -3504,7 +3507,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
templateVO = _templateStoreDao.findByTemplate(templateId, DataStoreRole.Image); templateVO = _templateStoreDao.findByTemplate(templateId, DataStoreRole.Image);
if (templateVO != null) { if (templateVO != null) {
try { try {
if (SystemVmTemplateRegistration.validateIfSeeded(url, templateVO.getInstallPath())) { if (SystemVmTemplateRegistration.validateIfSeeded(
url, templateVO.getInstallPath(), nfsVersion)) {
continue; continue;
} }
} catch (Exception e) { } catch (Exception e) {
@ -3512,7 +3516,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
} }
} }
} }
SystemVmTemplateRegistration.mountStore(storeUrlAndId.first(), filePath); SystemVmTemplateRegistration.mountStore(storeUrlAndId.first(), filePath, nfsVersion);
if (templateVO != null && vmTemplateVO != null) { if (templateVO != null && vmTemplateVO != null) {
systemVmTemplateRegistration.registerTemplate(hypervisorAndTemplateName, storeUrlAndId, vmTemplateVO, templateVO, filePath); systemVmTemplateRegistration.registerTemplate(hypervisorAndTemplateName, storeUrlAndId, vmTemplateVO, templateVO, filePath);
} else { } else {

View File

@ -478,7 +478,8 @@ public class DiagnosticsServiceImpl extends ManagerBase implements PluggableServ
private void cleanupOldDiagnosticFiles(DataStore store) { private void cleanupOldDiagnosticFiles(DataStore store) {
String mountPoint = null; String mountPoint = null;
mountPoint = serviceImpl.mountManager.getMountPoint(store.getUri(), null); mountPoint = serviceImpl.mountManager.getMountPoint(store.getUri(),
serviceImpl.imageStoreDetailsUtil.getNfsVersion(store.getId()));
if (StringUtils.isNotBlank(mountPoint)) { if (StringUtils.isNotBlank(mountPoint)) {
File directory = new File(mountPoint + File.separator + DIAGNOSTICS_DIRECTORY); File directory = new File(mountPoint + File.separator + DIAGNOSTICS_DIRECTORY);
if (directory.isDirectory()) { if (directory.isDirectory()) {