From 5e42af7f2530203e9da8e10b5d7cb2c1f251c8a4 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 3 Dec 2020 16:01:19 +0200 Subject: [PATCH 1/4] proper changes to use only enum of HypervisorType --- .../cloudstack/storage/test/VolumeServiceTest.java | 2 ++ .../CloudStackPrimaryDataStoreLifeCycleImpl.java | 9 ++++----- .../main/java/com/cloud/storage/StorageManagerImpl.java | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeServiceTest.java b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeServiceTest.java index 9a680ed7fd38..5ed0cc3f1fa4 100644 --- a/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeServiceTest.java +++ b/engine/storage/integration-test/src/test/java/org/apache/cloudstack/storage/test/VolumeServiceTest.java @@ -276,6 +276,7 @@ public void testCreatePrimaryStorage() { params.put("path", uri.getPath()); params.put("protocol", StoragePoolType.NetworkFilesystem); params.put("dcId", dcId.toString()); + params.put("hypervisorType", HypervisorType.None); params.put("clusterId", clusterId.toString()); params.put("name", this.primaryName); params.put("port", "1"); @@ -318,6 +319,7 @@ public DataStore createPrimaryDataStore() { params.put("path", uri.getPath()); params.put("protocol", Storage.StoragePoolType.NetworkFilesystem); params.put("dcId", dcId.toString()); + params.put("hypervisorType", HypervisorType.None); params.put("clusterId", clusterId.toString()); params.put("name", this.primaryName); params.put("port", "1"); diff --git a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java index 068b26fe70a3..85f0ef0093b6 100644 --- a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java +++ b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java @@ -64,7 +64,6 @@ import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper; -import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import javax.inject.Inject; @@ -132,7 +131,7 @@ public DataStore initialize(Map dsInfos) { Long zoneId = (Long)dsInfos.get("zoneId"); String url = (String)dsInfos.get("url"); String providerName = (String)dsInfos.get("providerName"); - String hypervisorType = (String)dsInfos.get("hypervisorType"); + HypervisorType hypervisorType = (HypervisorType)dsInfos.get("hypervisorType"); if (clusterId != null && podId == null) { throw new InvalidParameterValueException("Cluster id requires pod id"); } @@ -250,7 +249,7 @@ public DataStore initialize(Map dsInfos) { parameters.setPath(hostPath.replaceFirst("/", "")); parameters.setUserInfo(userInfo); } else if (scheme.equalsIgnoreCase("PreSetup")) { - if (StringUtils.isNotBlank(hypervisorType) && HypervisorType.getType(hypervisorType).equals(HypervisorType.VMware)) { + if (hypervisorType.equals(HypervisorType.VMware)) { validateVcenterDetails(zoneId, podId, clusterId,storageHost); } parameters.setType(StoragePoolType.PreSetup); @@ -258,7 +257,7 @@ public DataStore initialize(Map dsInfos) { parameters.setPort(0); parameters.setPath(hostPath); } else if (scheme.equalsIgnoreCase("DatastoreCluster")) { - if (StringUtils.isNotBlank(hypervisorType) && HypervisorType.getType(hypervisorType).equals(HypervisorType.VMware)) { + if (hypervisorType.equals(HypervisorType.VMware)) { validateVcenterDetails(zoneId, podId, clusterId,storageHost); } parameters.setType(StoragePoolType.DatastoreCluster); @@ -338,7 +337,7 @@ public DataStore initialize(Map dsInfos) { uuid = (String)existingUuid; } else if (scheme.equalsIgnoreCase("sharedmountpoint") || scheme.equalsIgnoreCase("clvm")) { uuid = UUID.randomUUID().toString(); - } else if (scheme.equalsIgnoreCase("PreSetup") && !(StringUtils.isNotBlank(hypervisorType) && HypervisorType.getType(hypervisorType).equals(HypervisorType.VMware))) { + } else if (scheme.equalsIgnoreCase("PreSetup") && !hypervisorType.equals(HypervisorType.VMware)) { uuid = hostPath.replace("/", ""); } else { uuid = UUID.nameUUIDFromBytes((storageHost + hostPath).getBytes()).toString(); diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java index 6224a774449f..96589f163715 100644 --- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java @@ -722,7 +722,7 @@ public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws Resource params.put("zoneId", zone.getId()); params.put("clusterId", clusterId); params.put("podId", podId); - params.put("hypervisorType", hypervisorType.toString()); + params.put("hypervisorType", hypervisorType); params.put("url", cmd.getUrl()); params.put("tags", cmd.getTags()); params.put("name", cmd.getStoragePoolName()); From 9cce1d3df84c6f8a963ac9cc17566c02dd1b7435 Mon Sep 17 00:00:00 2001 From: Alexandru Bagu Date: Sun, 13 Dec 2020 11:28:38 +0200 Subject: [PATCH 2/4] Update plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java Defensive check Co-authored-by: dahn --- .../lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java index 85f0ef0093b6..d8a5bfbf1938 100644 --- a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java +++ b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java @@ -249,7 +249,7 @@ public DataStore initialize(Map dsInfos) { parameters.setPath(hostPath.replaceFirst("/", "")); parameters.setUserInfo(userInfo); } else if (scheme.equalsIgnoreCase("PreSetup")) { - if (hypervisorType.equals(HypervisorType.VMware)) { + if (HypervisorType.VMware.equals(hypervisorType)) { validateVcenterDetails(zoneId, podId, clusterId,storageHost); } parameters.setType(StoragePoolType.PreSetup); From 8ea07c5a2139fff75913e3e817c85a415b17acac Mon Sep 17 00:00:00 2001 From: Alexandru Bagu Date: Sun, 13 Dec 2020 11:28:56 +0200 Subject: [PATCH 3/4] Update plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java Defensive check Co-authored-by: dahn --- .../lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java index d8a5bfbf1938..5e8336ceb136 100644 --- a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java +++ b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java @@ -337,7 +337,7 @@ public DataStore initialize(Map dsInfos) { uuid = (String)existingUuid; } else if (scheme.equalsIgnoreCase("sharedmountpoint") || scheme.equalsIgnoreCase("clvm")) { uuid = UUID.randomUUID().toString(); - } else if (scheme.equalsIgnoreCase("PreSetup") && !hypervisorType.equals(HypervisorType.VMware)) { + } else if ("PreSetup".equalsIgnoreCase(scheme) && !HypervisorType.VMware.equals(hypervisorType)) { uuid = hostPath.replace("/", ""); } else { uuid = UUID.nameUUIDFromBytes((storageHost + hostPath).getBytes()).toString(); From a6914e0e9ddf71acf4a9b9a246c47b281e080fb3 Mon Sep 17 00:00:00 2001 From: Alexandru Bagu Date: Sun, 13 Dec 2020 11:32:33 +0200 Subject: [PATCH 4/4] Update plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java Defensive check Co-authored-by: dahn --- .../lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java index 5e8336ceb136..1b2e41ab3867 100644 --- a/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java +++ b/plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java @@ -257,7 +257,7 @@ public DataStore initialize(Map dsInfos) { parameters.setPort(0); parameters.setPath(hostPath); } else if (scheme.equalsIgnoreCase("DatastoreCluster")) { - if (hypervisorType.equals(HypervisorType.VMware)) { + if (HypervisorType.VMware.equals(hypervisorType)) { validateVcenterDetails(zoneId, podId, clusterId,storageHost); } parameters.setType(StoragePoolType.DatastoreCluster);