diff --git a/PRE-COMMIT.md b/PRE_COMMIT.md similarity index 97% rename from PRE-COMMIT.md rename to PRE_COMMIT.md index 9b76929d422..62dc296c99e 100644 --- a/PRE-COMMIT.md +++ b/PRE_COMMIT.md @@ -20,7 +20,7 @@ # pre-commit We run [pre-commit](https://pre-commit.com/) with -[GitHub Actions](https://github.com/apache/cloudstack/blob/main/.github/workflows/linter.yml) so installation on your +[GitHub Actions](https://github.com/apache/cloudstack/blob/main/.github/workflows/pre-commit.yml) so installation on your local machine is currently optional. The `pre-commit` [configuration file](https://github.com/apache/cloudstack/blob/main/.pre-commit-config.yaml) diff --git a/api/src/main/java/com/cloud/network/Networks.java b/api/src/main/java/com/cloud/network/Networks.java index 9f06a044111..5f767686dc9 100644 --- a/api/src/main/java/com/cloud/network/Networks.java +++ b/api/src/main/java/com/cloud/network/Networks.java @@ -78,7 +78,7 @@ public class Networks { } @Override public String getValueFrom(URI uri) { - return uri.getAuthority(); + return uri == null ? null : uri.getAuthority(); } }, Vswitch("vs", String.class), LinkLocal(null, null), Vnet("vnet", Long.class), Storage("storage", Integer.class), Lswitch("lswitch", String.class) { @@ -96,7 +96,7 @@ public class Networks { */ @Override public String getValueFrom(URI uri) { - return uri.getSchemeSpecificPart(); + return uri == null ? null : uri.getSchemeSpecificPart(); } }, Mido("mido", String.class), Pvlan("pvlan", String.class), @@ -177,7 +177,7 @@ public class Networks { * @return the scheme as BroadcastDomainType */ public static BroadcastDomainType getSchemeValue(URI uri) { - return toEnumValue(uri.getScheme()); + return toEnumValue(uri == null ? null : uri.getScheme()); } /** @@ -191,7 +191,7 @@ public class Networks { if (com.cloud.dc.Vlan.UNTAGGED.equalsIgnoreCase(str)) { return Native; } - return getSchemeValue(new URI(str)); + return getSchemeValue(str == null ? null : new URI(str)); } /** @@ -220,7 +220,7 @@ public class Networks { * @return the host part as String */ public String getValueFrom(URI uri) { - return uri.getHost(); + return uri == null ? null : uri.getHost(); } /** @@ -243,7 +243,7 @@ public class Networks { * @throws URISyntaxException the string is not even an uri */ public static String getValue(String uriString) throws URISyntaxException { - return getValue(new URI(uriString)); + return getValue(uriString == null ? null : new URI(uriString)); } /** diff --git a/api/src/test/java/com/cloud/network/NetworksTest.java b/api/src/test/java/com/cloud/network/NetworksTest.java index ef582924342..6f0f3fbd1ef 100644 --- a/api/src/test/java/com/cloud/network/NetworksTest.java +++ b/api/src/test/java/com/cloud/network/NetworksTest.java @@ -37,6 +37,24 @@ public class NetworksTest { public void setUp() { } + @Test + public void nullBroadcastDomainTypeTest() throws URISyntaxException { + BroadcastDomainType type = BroadcastDomainType.getTypeOf(null); + Assert.assertEquals("a null uri should mean a broadcasttype of undecided", BroadcastDomainType.UnDecided, type); + } + + @Test + public void nullBroadcastDomainTypeValueTest() { + URI uri = null; + Assert.assertNull(BroadcastDomainType.getValue(uri)); + } + + @Test + public void nullBroadcastDomainTypeStringValueTest() throws URISyntaxException { + String uriString = null; + Assert.assertNull(BroadcastDomainType.getValue(uriString)); + } + @Test public void emptyBroadcastDomainTypeTest() throws URISyntaxException { BroadcastDomainType type = BroadcastDomainType.getTypeOf(""); diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-42200to42300-cleanup.sql deleted file mode 100644 index f2f5dec5003..00000000000 --- a/engine/schema/src/main/resources/META-INF/db/schema-42200to42300-cleanup.sql +++ /dev/null @@ -1,20 +0,0 @@ --- Licensed to the Apache Software Foundation (ASF) under one --- or more contributor license agreements. See the NOTICE file --- distributed with this work for additional information --- regarding copyright ownership. The ASF licenses this file --- to you under the Apache License, Version 2.0 (the --- "License"); you may not use this file except in compliance --- with the License. You may obtain a copy of the License at --- --- http://www.apache.org/licenses/LICENSE-2.0 --- --- Unless required by applicable law or agreed to in writing, --- software distributed under the License is distributed on an --- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY --- KIND, either express or implied. See the License for the --- specific language governing permissions and limitations --- under the License. - ---; --- Schema upgrade cleanup from 4.22.0.0 to 4.23.0.0 ---; diff --git a/engine/schema/src/main/resources/META-INF/db/schema-42210to42300-cleanup.sql b/engine/schema/src/main/resources/META-INF/db/schema-42210to42300-cleanup.sql index f9921cd6cca..e2b066af780 100644 --- a/engine/schema/src/main/resources/META-INF/db/schema-42210to42300-cleanup.sql +++ b/engine/schema/src/main/resources/META-INF/db/schema-42210to42300-cleanup.sql @@ -16,5 +16,5 @@ -- under the License. --; --- Schema upgrade cleanup from 4.22.1.0 to 4.22.3.0 +-- Schema upgrade cleanup from 4.22.1.0 to 4.23.0.0 --; diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java index e8924ecf5eb..87544cfaa9d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java @@ -1689,7 +1689,11 @@ public class LibvirtStorageAdaptor implements StorageAdaptor { */ srcFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(srcPool, sourcePath)); srcFile.setFormat(sourceFormat); - destFile = new QemuImgFile(destPath); + if (destPool.getType() == StoragePoolType.RBD) { + destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool, destPath)); + } else { + destFile = new QemuImgFile(destPath); + } destFile.setFormat(destFormat); try { diff --git a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/api/VTreeMigrationInfo.java b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/api/VTreeMigrationInfo.java index f4e926bfd33..072b52b69d6 100644 --- a/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/api/VTreeMigrationInfo.java +++ b/plugins/storage/volume/scaleio/src/main/java/org/apache/cloudstack/storage/datastore/api/VTreeMigrationInfo.java @@ -59,7 +59,7 @@ public class VTreeMigrationInfo { } public void setMigrationStatus(String migrationStatus) { - this.migrationStatus = EnumUtils.fromString(MigrationStatus.class, migrationStatus, MigrationStatus.None); + this.migrationStatus = EnumUtils.getEnumIgnoreCase(MigrationStatus.class, migrationStatus, MigrationStatus.None); } public void setMigrationStatus(MigrationStatus migrationStatus) { diff --git a/server/src/main/java/com/cloud/api/ApiDBUtils.java b/server/src/main/java/com/cloud/api/ApiDBUtils.java index f7ffb039801..57eeb63ea9f 100644 --- a/server/src/main/java/com/cloud/api/ApiDBUtils.java +++ b/server/src/main/java/com/cloud/api/ApiDBUtils.java @@ -1767,7 +1767,7 @@ public class ApiDBUtils { return null; } String jobInstanceId = null; - ApiCommandResourceType jobInstanceType = EnumUtils.fromString(ApiCommandResourceType.class, job.getInstanceType(), ApiCommandResourceType.None); + ApiCommandResourceType jobInstanceType = EnumUtils.getEnumIgnoreCase(ApiCommandResourceType.class, job.getInstanceType(), ApiCommandResourceType.None); if (job.getInstanceId() == null) { // when assert is hit, implement 'getInstanceId' of BaseAsyncCmd and return appropriate instance id diff --git a/ui/src/views/AutogenView.vue b/ui/src/views/AutogenView.vue index 8c46ca64225..e0583cd97a4 100644 --- a/ui/src/views/AutogenView.vue +++ b/ui/src/views/AutogenView.vue @@ -1997,8 +1997,13 @@ export default { }, onSearch (opts) { const query = Object.assign({}, this.$route.query) - const searchFilters = this.$route?.meta?.searchFilters || [] - searchFilters.forEach(key => delete query[key]) + let searchFilters = this.$route?.meta?.searchFilters || [] + if (typeof searchFilters === 'function') { + searchFilters = searchFilters() + } + if (Array.isArray(searchFilters)) { + searchFilters.forEach(key => delete query[key]) + } delete query.name delete query.templatetype delete query.keyword diff --git a/utils/src/main/java/com/cloud/utils/EnumUtils.java b/utils/src/main/java/com/cloud/utils/EnumUtils.java index 380b595a0ad..1af29066ef1 100644 --- a/utils/src/main/java/com/cloud/utils/EnumUtils.java +++ b/utils/src/main/java/com/cloud/utils/EnumUtils.java @@ -29,30 +29,4 @@ public class EnumUtils extends org.apache.commons.lang3.EnumUtils { b.append("]"); return b.toString(); } - - public static > T fromString(Class clz, String value, T defaultVal) { - assert (clz != null); - - if (value != null) { - try { - return Enum.valueOf(clz, value.trim()); - } catch (IllegalArgumentException ex) { - assert (false); - } - } - return defaultVal; - } - - public static > T fromString(Class clz, String value) { - assert (clz != null); - - if (value != null) { - try { - return Enum.valueOf(clz, value.trim()); - } catch (IllegalArgumentException ex) { - assert (false); - } - } - return null; - } }