Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions engine/storage/datamotion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.8.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@
package org.apache.cloudstack.storage.motion;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import javax.inject.Inject;

Expand Down Expand Up @@ -68,9 +71,11 @@
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.maven.artifact.versioning.ComparableVersion;

import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
Expand Down Expand Up @@ -133,10 +138,6 @@
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.dao.VMInstanceDao;
import com.google.common.base.Preconditions;
import java.util.Arrays;
import java.util.HashSet;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;

public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
private static final Logger LOGGER = Logger.getLogger(StorageSystemDataMotionStrategy.class);
Expand Down Expand Up @@ -187,6 +188,14 @@ public class StorageSystemDataMotionStrategy implements DataMotionStrategy {
@Inject
VMTemplatePoolDao templatePoolDao;

private boolean isVMwareHostWithVersionOrHigher(Host host, String requiredVersion) {
if (!HypervisorType.VMware.equals(host.getHypervisorType()) || StringUtils.isBlank(requiredVersion)) {
return false;
}
ComparableVersion version = new ComparableVersion(host.getHypervisorVersion());
return version.compareTo(new ComparableVersion(requiredVersion)) >= 0;
}

@Override
public StrategyPriority canHandle(DataObject srcData, DataObject destData) {
if (srcData instanceof SnapshotInfo) {
Expand Down Expand Up @@ -2133,6 +2142,9 @@ protected String connectHostToVolume(Host host, long storagePoolId, String iqn)
}

private void disconnectHostFromVolume(Host host, long storagePoolId, String iqn) {
if (isVMwareHostWithVersionOrHigher(host, "6.5")) {
return;
}
ModifyTargetsCommand modifyTargetsCommand = getModifyTargetsCommand(storagePoolId, iqn, false);

sendModifyTargetsCommand(modifyTargetsCommand, host.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,17 @@ public static String syncVolumeToVmDefaultFolder(DatacenterMO dcMo, String vmNam
public static String syncVolumeToVmDefaultFolder(DatacenterMO dcMo, String vmName, DatastoreMO ds, String vmdkName, String excludeFolders) throws Exception {

assert (ds != null);

if (!ds.folderExists(String.format("[%s]", ds.getName()), vmName)) {
s_logger.info("VM folder does not exist on target datastore, we will create one. vm: " + vmName + ", datastore: " + ds.getName());

ds.makeDirectory(String.format("[%s] %s", ds.getName(), vmName), dcMo.getMor());
}

if (!ds.folderExists(String.format("[%s]", ds.getName()), HypervisorHostHelper.VSPHERE_DATASTORE_BASE_FOLDER)) {
s_logger.info(String.format("%s folder does not exist on target datastore, we will create one. vm: %s, datastore: %s", HypervisorHostHelper.VSPHERE_DATASTORE_BASE_FOLDER, vmName, ds.getName()));
ds.makeDirectory(String.format("[%s] %s", ds.getName(), HypervisorHostHelper.VSPHERE_DATASTORE_BASE_FOLDER), dcMo.getMor());
}

String[] vmdkLinkedCloneModeLegacyPair = getVmdkFilePairDatastorePath(ds, vmName, vmdkName, VmwareStorageLayoutType.CLOUDSTACK_LEGACY, true);
String[] vmdkFullCloneModeLegacyPair = getVmdkFilePairDatastorePath(ds, vmName, vmdkName, VmwareStorageLayoutType.CLOUDSTACK_LEGACY, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3117,6 +3117,9 @@ private void removeVmfsDatastore(Command cmd, VmwareHypervisorHost hyperHost, St

private void removeVmfsDatastore(Command cmd, VmwareHypervisorHost hyperHost, String datastoreName, String storageIpAddress, int storagePortNumber,
String iqn, List<Pair<ManagedObjectReference, String>> lstHosts) throws Exception {
if (HypervisorHostHelper.isHostVersionEqualOrHigher(hyperHost, "6.5")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this consider minor release version as well?

return;
}
VmwareContext context = hostService.getServiceContext(cmd);

unmountVmfsDatastore(context, hyperHost, datastoreName, lstHosts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;

import com.cloud.exception.CloudException;
Expand Down Expand Up @@ -314,16 +316,19 @@ public String[] listDirContent(String path) throws Exception {
public boolean fileExists(String fileFullPath) throws Exception {
DatastoreFile file = new DatastoreFile(fileFullPath);
DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());

HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();

s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
if (results != null) {
List<FileInfo> info = results.getFile();
if (info != null && info.size() > 0) {
s_logger.info("File " + fileFullPath + " exists on datastore");
return true;
Boolean folderExists = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this true by default?

if(StringUtils.isNotBlank(file.getDir())){

@sureshanaparti sureshanaparti Jul 12, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(StringUtils.isNotBlank(file.getDir())){
if (StringUtils.isNotBlank(file.getDir())) {

folderExists = folderExists(String.format("[%s]", file.getDatastoreName()), file.getDir());
}
if (folderExists){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (folderExists){
if (folderExists) {

HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
if (results != null) {
if (CollectionUtils.isNotEmpty(results.getFile())) {
s_logger.info("File " + fileFullPath + " exists on datastore");
return true;
}
}
}

Expand Down Expand Up @@ -364,7 +369,7 @@ public long fileDiskSize(String fileFullPath) throws Exception {

public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();

s_logger.info("Search folder " + folderName + " on " + folderParentDatastorePath);
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
if (results != null) {
List<FileInfo> info = results.getFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2339,4 +2339,20 @@ public static String getMinimumHostHardwareVersion(VmwareHypervisorHost host1, V
}
return hardwareVersion;
}

public static boolean isHostVersionEqualOrHigher(VmwareHypervisorHost host, String requiredVersion) {
if (StringUtils.isBlank(requiredVersion)) {
return false;
}
HostMO hostMo = new HostMO(host.getContext(), host.getMor());
String hostApiVersion = "";
try {
hostApiVersion = hostMo.getHostAboutInfo().getApiVersion();
} catch (Exception ignored) {}
if (StringUtils.isBlank(hostApiVersion)) {
return false;
}
ComparableVersion version = new ComparableVersion(hostApiVersion);
return version.compareTo(new ComparableVersion(requiredVersion)) >= 0;
}
}