diff --git a/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to451.java b/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to451.java index 218f4ec60b0..d56db8563c3 100644 --- a/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to451.java +++ b/engine/schema/src/com/cloud/upgrade/dao/Upgrade450to451.java @@ -22,6 +22,7 @@ import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.exception.CloudRuntimeException; import com.cloud.utils.script.Script; import org.apache.log4j.Logger; +import org.jasypt.exceptions.EncryptionOperationNotPossibleException; import java.io.File; import java.io.UnsupportedEncodingException; @@ -75,6 +76,7 @@ public class Upgrade450to451 implements DbUpgrade { encryptIpSecPresharedKeysOfRemoteAccessVpn(conn); encryptStoragePoolUserInfo(conn); updateUserVmDetailsWithNicAdapterType(conn); + upgradeVMWareLocalStorage(conn); } private void encryptKeyInKeyStore(Connection conn) { @@ -85,9 +87,11 @@ public class Upgrade450to451 implements DbUpgrade { selectStatement = conn.prepareStatement("SELECT ks.id, ks.key FROM cloud.keystore ks WHERE ks.key IS NOT null"); selectResultSet = selectStatement.executeQuery(); while (selectResultSet.next()) { + Long keyId = selectResultSet.getLong(1); + String preSharedKey = selectResultSet.getString(2); updateStatement = conn.prepareStatement("UPDATE cloud.keystore ks SET ks.key = ? WHERE ks.id = ?"); - updateStatement.setString(1, DBEncryptionUtil.encrypt(selectResultSet.getString(2))); - updateStatement.setLong(2, selectResultSet.getLong(1)); + updateStatement.setString(1, DBEncryptionUtil.encrypt(preSharedKey)); + updateStatement.setLong(2, keyId); updateStatement.executeUpdate(); updateStatement.close(); } @@ -121,10 +125,16 @@ public class Upgrade450to451 implements DbUpgrade { selectStatement = conn.prepareStatement("SELECT id, ipsec_psk FROM `cloud`.`remote_access_vpn`"); resultSet = selectStatement.executeQuery(); while (resultSet.next()) { + Long rowId = resultSet.getLong(1); String preSharedKey = resultSet.getString(2); + try { + preSharedKey = DBEncryptionUtil.decrypt(preSharedKey); + } catch (EncryptionOperationNotPossibleException ignored) { + s_logger.debug("The ipsec_psk preshared key id=" + rowId + "in remote_access_vpn is not encrypted, encrypting it."); + } updateStatement = conn.prepareStatement("UPDATE `cloud`.`remote_access_vpn` SET ipsec_psk=? WHERE id=?"); updateStatement.setString(1, DBEncryptionUtil.encrypt(preSharedKey)); - updateStatement.setLong(2, resultSet.getLong(1)); + updateStatement.setLong(2, rowId); updateStatement.executeUpdate(); updateStatement.close(); } @@ -193,4 +203,21 @@ public class Upgrade450to451 implements DbUpgrade { } s_logger.debug("Done. Updated user_vm_details table with nicAdapter entries by copying from vm_template_detail table. This affects only VM/templates with hypervisor_type as VMware."); } + + private void upgradeVMWareLocalStorage(Connection conn) { + PreparedStatement updatePstmt = null; + try { + updatePstmt = conn.prepareStatement("UPDATE storage_pool SET pool_type='VMFS',host_address=@newaddress WHERE (@newaddress:=concat('VMFS datastore: ', path)) IS NOT NULL AND scope = 'HOST' AND pool_type = 'LVM' AND id IN (SELECT * FROM (SELECT storage_pool.id FROM storage_pool,cluster WHERE storage_pool.cluster_id = cluster.id AND cluster.hypervisor_type='VMware') AS t);"); + updatePstmt.executeUpdate(); + } catch (SQLException e) { + throw new CloudRuntimeException("Unable to upgrade VMWare local storage pool type", e); + } finally { + try { + if (updatePstmt != null) + updatePstmt.close(); + } catch (SQLException e) { + } + s_logger.debug("Done, upgraded VMWare local storage pool type to VMFS and host_address to the VMFS format"); + } + } } diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java index 808cb5bdeea..9ac32d4757e 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java @@ -378,12 +378,22 @@ public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru, Co //NOTE: the hostid can be a hypervisor host, or a ssvm agent. For copycommand, if it's for volume upload, the hypervisor //type is empty, so we need to check the format of volume at first. if (cmd instanceof CopyCommand) { - CopyCommand cpyCommand = (CopyCommand)cmd; + CopyCommand cpyCommand = (CopyCommand) cmd; DataTO srcData = cpyCommand.getSrcTO(); DataStoreTO srcStoreTO = srcData.getDataStore(); DataTO destData = cpyCommand.getDestTO(); DataStoreTO destStoreTO = destData.getDataStore(); + boolean inSeq = true; + if ((srcData.getObjectType() == DataObjectType.SNAPSHOT) || (destData.getObjectType() == DataObjectType.SNAPSHOT)) { + inSeq = false; + } else if ((destStoreTO.getRole() == DataStoreRole.Image) || (destStoreTO.getRole() == DataStoreRole.ImageCache)) { + inSeq = false; + } else if (!VmwareFullClone.value()) { + inSeq = false; + } + cpyCommand.setExecuteInSequence(inSeq); + if (srcData.getObjectType() == DataObjectType.VOLUME) { VolumeObjectTO volumeObjectTO = (VolumeObjectTO)srcData; if (Storage.ImageFormat.OVA == volumeObjectTO.getFormat()) { diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java index fd108309a41..3c7735d79da 100755 --- a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java +++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java @@ -4194,7 +4194,7 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa DatastoreSummary dsSummary = dsMo.getSummary(); String address = hostMo.getHostName(); StoragePoolInfo pInfo = - new StoragePoolInfo(poolUuid, address, dsMo.getMor().getValue(), "", StoragePoolType.LVM, dsSummary.getCapacity(), dsSummary.getFreeSpace()); + new StoragePoolInfo(poolUuid, address, dsMo.getMor().getValue(), "", StoragePoolType.VMFS, dsSummary.getCapacity(), dsSummary.getFreeSpace()); StartupStorageCommand cmd = new StartupStorageCommand(); cmd.setName(poolUuid); cmd.setPoolInfo(pInfo); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index c8f5d292053..9c442acd545 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -41,6 +41,7 @@ import javax.ejb.Local; import javax.inject.Inject; import javax.naming.ConfigurationException; +import com.cloud.hypervisor.Hypervisor; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; @@ -542,7 +543,11 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } DataStore store; try { - StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), pInfo.getHostPath(), pInfo.getUuid()); + String hostAddress = pInfo.getHost(); + if (host.getHypervisorType() == Hypervisor.HypervisorType.VMware) { + hostAddress = "VMFS datastore: " + pInfo.getHostPath(); + } + StoragePoolVO pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, pInfo.getHostPath(), pInfo.getUuid()); if (pool == null && host.getHypervisorType() == HypervisorType.VMware) { // perform run-time upgrade. In versions prior to 2.2.12, there // is a bug that we don't save local datastore info (host path @@ -551,12 +556,12 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C // available on the host, to support smooth migration, we // need to perform runtime upgrade here if (pInfo.getHostPath().length() > 0) { - pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), "", pInfo.getUuid()); + pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, "", pInfo.getUuid()); } } if (pool == null) { //the path can be different, but if they have the same uuid, assume they are the same storage - pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), pInfo.getHost(), null, + pool = _storagePoolDao.findPoolByHostPath(host.getDataCenterId(), host.getPodId(), hostAddress, null, pInfo.getUuid()); if (pool != null) { s_logger.debug("Found a storage pool: " + pInfo.getUuid() + ", but with different hostpath " + pInfo.getHostPath() + ", still treat it as the same pool");