hostCpuUsedMap, hostMemoryUsedMap;
+
+
+ @Mock
+ private ServiceOfferingDao serviceOfferingDao;
+
+
+ private AutoCloseable closeable;
+
+ @Before
+ public void setUp() throws NoSuchFieldException, IllegalAccessException {
+ closeable = MockitoAnnotations.openMocks(this);
+
+
+ vm1 = Mockito.mock(VirtualMachine.class);
+ vm2 = Mockito.mock(VirtualMachine.class);
+ vm3 = Mockito.mock(VirtualMachine.class); // vm to migrate
+
+ destHost = Mockito.mock(Host.class);
+ hostVmMap = new HashMap<>();
+ hostVmMap.put(1L, Collections.singletonList(vm1));
+ hostVmMap.put(2L, Arrays.asList(vm2, vm3));
+
+ serviceOffering = Mockito.mock(ServiceOfferingVO.class);
+ Mockito.when(vm3.getHostId()).thenReturn(2L);
+
+ Mockito.when(destHost.getId()).thenReturn(1L);
+
+ Mockito.when(serviceOffering.getCpu()).thenReturn(1);
+ Mockito.when(serviceOffering.getSpeed()).thenReturn(1000);
+ Mockito.when(serviceOffering.getRamSize()).thenReturn(512);
+
+ overrideDefaultConfigValue(ClusterDrsImbalanceThreshold, "_defaultValue", "0.5");
+
+ cpuList = Arrays.asList(1L, 2L);
+ memoryList = Arrays.asList(512L, 2048L);
+
+ hostCpuUsedMap = new HashMap<>();
+ hostCpuUsedMap.put(1L, 1000L);
+ hostCpuUsedMap.put(2L, 2000L);
+
+ hostMemoryUsedMap = new HashMap<>();
+ hostMemoryUsedMap.put(1L, 512L * 1024L * 1024L);
+ hostMemoryUsedMap.put(2L, 2048L * 1024L * 1024L);
+ }
+
+ private void overrideDefaultConfigValue(final ConfigKey configKey, final String name,
+ final Object o) throws IllegalAccessException, NoSuchFieldException {
+ Field f = ConfigKey.class.getDeclaredField(name);
+ f.setAccessible(true);
+ f.set(configKey, o);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ closeable.close();
+ }
+
+ /**
+ * needsDrs tests
+ * Scenarios to test for needsDrs
+ *
1. cluster with cpu metric
+ *
2. cluster with memory metric
+ *
3. cluster with "unknown" metric
+ *
+ *
CPU imbalance = 0.333
+ *
Memory imbalance = 0.6
+ */
+
+ /*
+ 1. cluster with cpu metric
+ 0.3333 > 0.5 -> False
+ */
+ @Test
+ public void needsDrsWithCpu() throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu");
+ assertFalse(balanced.needsDrs(clusterId, cpuList, memoryList));
+ }
+
+ /*
+ 2. cluster with memory metric
+ 0.6 > 0.5 -> True
+ */
+ @Test
+ public void needsDrsWithMemory() throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory");
+ assertTrue(balanced.needsDrs(clusterId, cpuList, memoryList));
+ }
+
+ /* 3. cluster with "unknown" metric */
+ @Test
+ public void needsDrsWithUnknown() throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "unknown");
+ assertThrows(ConfigurationException.class, () -> balanced.needsDrs(clusterId, cpuList, memoryList));
+ }
+
+ /**
+ * getMetrics tests
+ *
Scenarios to test for getMetrics
+ *
1. cluster with cpu metric
+ *
2. cluster with memory metric
+ *
3. cluster with default metric
+ *
+ *
Pre
+ *
CPU imbalance = 0.333333
+ *
Memory imbalance = 0.6
+ *
+ *
Post
+ *
CPU imbalance = 0.3333
+ *
Memory imbalance = 0.2
+ *
+ *
Cost 512.0
+ *
Benefit (0.6-0.2) * 8192 = 3276.8
+ */
+
+ /*
+ 1. cluster with cpu metric
+ improvement = 0.3333 - 0.3333 = 0.0
+ */
+ @Test
+ public void getMetricsWithCpu() throws NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu");
+ Ternary result = balanced.getMetrics(clusterId, vm3, serviceOffering, destHost,
+ hostCpuUsedMap, hostMemoryUsedMap, false);
+ assertEquals(0.0, result.first(), 0.01);
+ assertEquals(0.0, result.second(), 0.0);
+ assertEquals(1.0, result.third(), 0.0);
+ }
+
+ /*
+ 2. cluster with memory metric
+ improvement = 0.6 - 0.2 = 0.4
+ */
+ @Test
+ public void getMetricsWithMemory() throws NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory");
+ Ternary result = balanced.getMetrics(clusterId, vm3, serviceOffering, destHost,
+ hostCpuUsedMap, hostMemoryUsedMap, false);
+ assertEquals(0.4, result.first(), 0.01);
+ assertEquals(0, result.second(), 0.0);
+ assertEquals(1, result.third(), 0.0);
+ }
+
+ /*
+ 3. cluster with default metric
+ improvement = 0.3333 + 0.6 - 0.3333 - 0.2 = 0.4
+ */
+ @Test
+ public void getMetricsWithDefault() throws NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "both");
+ Ternary result = balanced.getMetrics(clusterId, vm3, serviceOffering, destHost,
+ hostCpuUsedMap, hostMemoryUsedMap, false);
+ assertEquals(0.4, result.first(), 0.01);
+ assertEquals(0, result.second(), 0.0);
+ assertEquals(1, result.third(), 0.0);
+ }
+}
diff --git a/plugins/drs/cluster/condensed/pom.xml b/plugins/drs/cluster/condensed/pom.xml
new file mode 100644
index 00000000000..ea8acdc6d1b
--- /dev/null
+++ b/plugins/drs/cluster/condensed/pom.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ 4.0.0
+ Apache CloudStack Plugin - Cluster DRS Algorithm - Condensed
+ cloud-plugin-cluster-drs-condensed
+
+ org.apache.cloudstack
+ cloudstack-plugins
+ 4.19.0.0-SNAPSHOT
+ ../../../pom.xml
+
+
diff --git a/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java b/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java
new file mode 100644
index 00000000000..aefd11905ef
--- /dev/null
+++ b/plugins/drs/cluster/condensed/src/main/java/org/apache/cloudstack/cluster/Condensed.java
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+package org.apache.cloudstack.cluster;
+
+import com.cloud.host.Host;
+import com.cloud.offering.ServiceOffering;
+import com.cloud.utils.Pair;
+import com.cloud.utils.Ternary;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.VirtualMachine;
+
+import javax.naming.ConfigurationException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsImbalanceThreshold;
+import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsMetric;
+
+public class Condensed extends AdapterBase implements ClusterDrsAlgorithm {
+
+ @Override
+ public String getName() {
+ return "condensed";
+ }
+
+ @Override
+ public boolean needsDrs(long clusterId, List cpuList, List memoryList) throws ConfigurationException {
+ Double cpuImbalance = getClusterImbalance(cpuList);
+ Double memoryImbalance = getClusterImbalance(memoryList);
+ double threshold = getThreshold(clusterId);
+ String metric = ClusterDrsMetric.valueIn(clusterId);
+ switch (metric) {
+ case "cpu":
+ return cpuImbalance < threshold;
+ case "memory":
+ return memoryImbalance < threshold;
+ default:
+ throw new ConfigurationException(
+ String.format("Invalid metric: %s for cluster: %d", metric, clusterId));
+ }
+ }
+
+ private double getThreshold(long clusterId) throws ConfigurationException {
+ return ClusterDrsImbalanceThreshold.valueIn(clusterId);
+ }
+
+ @Override
+ public Ternary getMetrics(long clusterId, VirtualMachine vm,
+ ServiceOffering serviceOffering, Host destHost,
+ Map hostCpuUsedMap, Map hostMemoryUsedMap,
+ Boolean requiresStorageMotion) {
+ Double preCpuImbalance = getClusterImbalance(new ArrayList<>(hostCpuUsedMap.values()));
+ Double preMemoryImbalance = getClusterImbalance(new ArrayList<>(hostMemoryUsedMap.values()));
+
+ Pair imbalancePair = getImbalancePostMigration(serviceOffering, vm, destHost, hostCpuUsedMap,
+ hostMemoryUsedMap);
+ Double postCpuImbalance = imbalancePair.first();
+ Double postMemoryImbalance = imbalancePair.second();
+
+ // This needs more research to determine the cost and benefit of a migration
+ // TODO: Cost should be a factor of the VM size and the host capacity
+ // TODO: Benefit should be a factor of the VM size and the host capacity and the number of VMs on the host
+ double cost = 0;
+ double benefit = 1;
+
+ String metric = ClusterDrsMetric.valueIn(clusterId);
+ double improvement;
+ switch (metric) {
+ case "cpu":
+ improvement = postCpuImbalance - preCpuImbalance;
+ break;
+ case "memory":
+ improvement = postMemoryImbalance - preMemoryImbalance;
+ break;
+ default:
+ improvement = postCpuImbalance + postMemoryImbalance - preCpuImbalance - preMemoryImbalance;
+ }
+ return new Ternary<>(improvement, cost, benefit);
+ }
+}
diff --git a/plugins/drs/cluster/condensed/src/main/resources/META-INF/cloudstack/condensed/module.properties b/plugins/drs/cluster/condensed/src/main/resources/META-INF/cloudstack/condensed/module.properties
new file mode 100644
index 00000000000..0581736b17b
--- /dev/null
+++ b/plugins/drs/cluster/condensed/src/main/resources/META-INF/cloudstack/condensed/module.properties
@@ -0,0 +1,18 @@
+# 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.
+name=condensed
+parent=cluster
diff --git a/plugins/drs/cluster/condensed/src/main/resources/META-INF/cloudstack/condensed/spring-condensed-context.xml b/plugins/drs/cluster/condensed/src/main/resources/META-INF/cloudstack/condensed/spring-condensed-context.xml
new file mode 100644
index 00000000000..dffa7d85da7
--- /dev/null
+++ b/plugins/drs/cluster/condensed/src/main/resources/META-INF/cloudstack/condensed/spring-condensed-context.xml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
diff --git a/plugins/drs/cluster/condensed/src/test/java/org/apache/cloudstack/cluster/CondensedTest.java b/plugins/drs/cluster/condensed/src/test/java/org/apache/cloudstack/cluster/CondensedTest.java
new file mode 100644
index 00000000000..d8cf581768a
--- /dev/null
+++ b/plugins/drs/cluster/condensed/src/test/java/org/apache/cloudstack/cluster/CondensedTest.java
@@ -0,0 +1,221 @@
+/*
+ * 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.
+ */
+
+package org.apache.cloudstack.cluster;
+
+import com.cloud.host.Host;
+import com.cloud.service.ServiceOfferingVO;
+import com.cloud.utils.Ternary;
+import com.cloud.vm.VirtualMachine;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import javax.naming.ConfigurationException;
+import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsImbalanceThreshold;
+import static org.apache.cloudstack.cluster.ClusterDrsService.ClusterDrsMetric;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
+import static org.junit.Assert.assertTrue;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CondensedTest {
+
+ @InjectMocks
+ Condensed condensed;
+
+ VirtualMachine vm1, vm2, vm3;
+
+ Host destHost;
+
+ ServiceOfferingVO serviceOffering;
+
+ long clusterId = 1L;
+
+ Map> hostVmMap;
+
+ List cpuList, memoryList;
+
+ Map hostCpuUsedMap, hostMemoryUsedMap;
+
+
+ private AutoCloseable closeable;
+
+ @Before
+ public void setUp() throws NoSuchFieldException, IllegalAccessException {
+ closeable = MockitoAnnotations.openMocks(this);
+
+ vm1 = Mockito.mock(VirtualMachine.class);
+ vm2 = Mockito.mock(VirtualMachine.class);
+ vm3 = Mockito.mock(VirtualMachine.class); // vm to migrate
+
+ destHost = Mockito.mock(Host.class);
+ hostVmMap = new HashMap<>();
+ hostVmMap.put(1L, Collections.singletonList(vm1));
+ hostVmMap.put(2L, Arrays.asList(vm2, vm3));
+
+ serviceOffering = Mockito.mock(ServiceOfferingVO.class);
+ Mockito.when(vm3.getHostId()).thenReturn(2L);
+
+ Mockito.when(destHost.getId()).thenReturn(1L);
+
+ Mockito.when(serviceOffering.getCpu()).thenReturn(1);
+ Mockito.when(serviceOffering.getSpeed()).thenReturn(1000);
+ Mockito.when(serviceOffering.getRamSize()).thenReturn(512);
+
+ overrideDefaultConfigValue(ClusterDrsImbalanceThreshold, "_defaultValue", "0.5");
+
+ cpuList = Arrays.asList(1L, 2L);
+ memoryList = Arrays.asList(512L, 2048L);
+
+ hostCpuUsedMap = new HashMap<>();
+ hostCpuUsedMap.put(1L, 1000L);
+ hostCpuUsedMap.put(2L, 2000L);
+
+ hostMemoryUsedMap = new HashMap<>();
+ hostMemoryUsedMap.put(1L, 512L * 1024L * 1024L);
+ hostMemoryUsedMap.put(2L, 2048L * 1024L * 1024L);
+ }
+
+ private void overrideDefaultConfigValue(final ConfigKey configKey,
+ final String name,
+ final Object o) throws IllegalAccessException, NoSuchFieldException {
+ Field f = ConfigKey.class.getDeclaredField(name);
+ f.setAccessible(true);
+ f.set(configKey, o);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ closeable.close();
+ }
+
+ /**
+ * needsDrs tests
+ *
Scenarios to test for needsDrs
+ *
1. cluster with cpu metric
+ *
2. cluster with memory metric
+ *
3. cluster with "unknown" metric
+ *
+ *
CPU imbalance = 0.333
+ *
Memory imbalance = 0.6
+ */
+
+ /*
+ 1. cluster with cpu metric
+ 0.3333 < 0.5 -> True
+ */
+ @Test
+ public void needsDrsWithCpu() throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu");
+ assertTrue(condensed.needsDrs(clusterId, cpuList, memoryList));
+ }
+
+ /*
+ 2. cluster with memory metric
+ 0.6 < 0.5 -> False
+ */
+ @Test
+ public void needsDrsWithMemory() throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory");
+ assertFalse(condensed.needsDrs(clusterId, cpuList, memoryList));
+ }
+
+ /* 3. cluster with "unknown" metric */
+ @Test
+ public void needsDrsWithUnknown() throws ConfigurationException, NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "unknown");
+ assertThrows(ConfigurationException.class, () -> condensed.needsDrs(clusterId, cpuList, memoryList));
+ }
+
+ /**
+ * getMetrics tests
+ *
Scenarios to test for getMetrics
+ *
1. cluster with cpu metric
+ *
2. cluster with memory metric
+ *
3. cluster with default metric
+ *
+ *
Pre
+ *
CPU imbalance = 0.333333
+ *
Memory imbalance = 0.6
+ *
+ *
Post
+ *
CPU imbalance = 0.3333
+ *
Memory imbalance = 0.2
+ *
+ *
Cost 512.0
+ *
Benefit (0.2-0.6) * 8192 = -3276.8
+ */
+
+ /*
+ 1. cluster with cpu metric
+ improvement = 0.3333 - 0.3333 = 0.0
+ */
+ @Test
+ public void getMetricsWithCpu() throws NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "cpu");
+ Ternary result = condensed.getMetrics(clusterId, vm3, serviceOffering, destHost,
+ hostCpuUsedMap, hostMemoryUsedMap, false);
+ assertEquals(0.0, result.first(), 0.0);
+ assertEquals(0, result.second(), 0.0);
+ assertEquals(1, result.third(), 0.0);
+ }
+
+ /*
+ 2. cluster with memory metric
+ improvement = 0.2 - 0.6 = -0.4
+ */
+ @Test
+ public void getMetricsWithMemory() throws NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "memory");
+ Ternary result = condensed.getMetrics(clusterId, vm3, serviceOffering, destHost,
+ hostCpuUsedMap, hostMemoryUsedMap, false);
+ assertEquals(-0.4, result.first(), 0.01);
+ assertEquals(0, result.second(), 0.0);
+ assertEquals(1, result.third(), 0.0);
+ }
+
+ /*
+ 3. cluster with default metric
+ improvement = 0.3333 + 0.2 - 0.3333 - 0.6 = -0.4
+ */
+ @Test
+ public void getMetricsWithDefault() throws NoSuchFieldException, IllegalAccessException {
+ overrideDefaultConfigValue(ClusterDrsMetric, "_defaultValue", "both");
+ Ternary result = condensed.getMetrics(clusterId, vm3, serviceOffering, destHost,
+ hostCpuUsedMap, hostMemoryUsedMap, false);
+ assertEquals(-0.4, result.first(), 0.0001);
+ assertEquals(0, result.second(), 0.0);
+ assertEquals(1, result.third(), 0.0);
+ }
+}
diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
index ae0fa637bf0..f7ec09ca50f 100644
--- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
+++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java
@@ -1014,9 +1014,9 @@ public class KVMStorageProcessor implements StorageProcessor {
command.add("-b", isCreatedFromVmSnapshot ? snapshotDisk.getPath() : snapshot.getPath());
command.add(NAME_OPTION, snapshotName);
command.add("-p", snapshotDestPath);
- if (isCreatedFromVmSnapshot) {
- descName = UUID.randomUUID().toString();
- }
+
+ descName = UUID.randomUUID().toString();
+
command.add("-t", descName);
final String result = command.execute();
if (result != null) {
@@ -1041,18 +1041,7 @@ public class KVMStorageProcessor implements StorageProcessor {
if (isCreatedFromVmSnapshot) {
s_logger.debug("Ignoring removal of vm snapshot on primary as this snapshot is created from vm snapshot");
} else if (primaryPool.getType() != StoragePoolType.RBD) {
- String snapshotPath = snapshot.getPath();
- String backupSnapshotAfterTakingSnapshot = cmd.getOptions() == null ? null : cmd.getOptions().get(SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key());
-
- if (backupSnapshotAfterTakingSnapshot == null || BooleanUtils.toBoolean(backupSnapshotAfterTakingSnapshot)) {
- try {
- Files.deleteIfExists(Paths.get(snapshotPath));
- } catch (IOException ex) {
- s_logger.error(String.format("Failed to delete snapshot [%s] on primary storage [%s].", snapshotPath, primaryPool.getUuid()), ex);
- }
- } else {
- s_logger.debug(String.format("This backup is temporary, not deleting snapshot [%s] on primary storage [%s]", snapshotPath, primaryPool.getUuid()));
- }
+ deleteSnapshotOnPrimary(cmd, snapshot, primaryPool);
}
try {
@@ -1064,6 +1053,27 @@ public class KVMStorageProcessor implements StorageProcessor {
}
}
}
+
+ private void deleteSnapshotOnPrimary(final CopyCommand cmd, final SnapshotObjectTO snapshot,
+ KVMStoragePool primaryPool) {
+ String snapshotPath = snapshot.getPath();
+ String backupSnapshotAfterTakingSnapshot = null;
+ boolean deleteSnapshotOnPrimary = true;
+ if (cmd.getOptions() != null) {
+ backupSnapshotAfterTakingSnapshot = cmd.getOptions().get(SnapshotInfo.BackupSnapshotAfterTakingSnapshot.key());
+ deleteSnapshotOnPrimary = cmd.getOptions().get("typeDescription") == null;
+ }
+
+ if ((backupSnapshotAfterTakingSnapshot == null || BooleanUtils.toBoolean(backupSnapshotAfterTakingSnapshot)) && deleteSnapshotOnPrimary) {
+ try {
+ Files.deleteIfExists(Paths.get(snapshotPath));
+ } catch (IOException ex) {
+ s_logger.error(String.format("Failed to delete snapshot [%s] on primary storage [%s].", snapshotPath, primaryPool.getUuid()), ex);
+ }
+ } else {
+ s_logger.debug(String.format("This backup is temporary, not deleting snapshot [%s] on primary storage [%s]", snapshotPath, primaryPool.getUuid()));
+ }
+ }
protected synchronized void attachOrDetachISO(final Connect conn, final String vmName, String isoPath, final boolean isAttach, Map params) throws
LibvirtException, InternalErrorException {
DiskDef iso = new DiskDef();
diff --git a/plugins/pom.xml b/plugins/pom.xml
index bc28c777db7..b050b77f041 100755
--- a/plugins/pom.xml
+++ b/plugins/pom.xml
@@ -73,6 +73,9 @@
deployment-planners/user-concentrated-pod
deployment-planners/user-dispersing
+ drs/cluster/balanced
+ drs/cluster/condensed
+
event-bus/inmemory
event-bus/kafka
event-bus/rabbitmq
diff --git a/server/src/main/java/com/cloud/api/ApiDBUtils.java b/server/src/main/java/com/cloud/api/ApiDBUtils.java
index d30e8b82920..5d821d38f2e 100644
--- a/server/src/main/java/com/cloud/api/ApiDBUtils.java
+++ b/server/src/main/java/com/cloud/api/ApiDBUtils.java
@@ -1533,6 +1533,10 @@ public class ApiDBUtils {
return s_ipAddressDao.findByAssociatedVmId(vmId);
}
+ public static IpAddress findIpByAssociatedVmIdAndNetworkId(long vmId, long networkId) {
+ return s_ipAddressDao.findByVmIdAndNetworkId(networkId, vmId);
+ }
+
public static String getHaTag() {
return s_haMgr.getHaTag();
}
@@ -1864,6 +1868,10 @@ public class ApiDBUtils {
return s_userVmJoinDao.newUserVmView(userVms);
}
+ public static List newUserVmView(VirtualMachine... vms) {
+ return s_userVmJoinDao.newUserVmView(vms);
+ }
+
public static SecurityGroupResponse newSecurityGroupResponse(SecurityGroupJoinVO vsg, Account caller) {
return s_securityGroupJoinDao.newSecurityGroupResponse(vsg, caller);
}
diff --git a/server/src/main/java/com/cloud/api/ApiResponseHelper.java b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
index 656564d9851..4ce58fc1003 100644
--- a/server/src/main/java/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/main/java/com/cloud/api/ApiResponseHelper.java
@@ -3739,7 +3739,7 @@ public class ApiResponseHelper implements ResponseGenerator {
response.setName(guestOS.getDisplayName());
response.setDescription(guestOS.getDisplayName());
response.setId(guestOS.getUuid());
- response.setIsUserDefined(String.valueOf(guestOS.getIsUserDefined()));
+ response.setIsUserDefined(guestOS.getIsUserDefined());
response.setForDisplay(guestOS.getForDisplay());
GuestOSCategoryVO category = ApiDBUtils.findGuestOsCategoryById(guestOS.getCategoryId());
if (category != null) {
diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
index 491104b654c..93b858077f6 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -34,6 +34,22 @@ import java.util.stream.Stream;
import javax.inject.Inject;
+import com.cloud.host.Host;
+import com.cloud.host.dao.HostDao;
+import com.cloud.network.as.AutoScaleVmGroupVmMapVO;
+import com.cloud.network.as.dao.AutoScaleVmGroupDao;
+import com.cloud.network.as.dao.AutoScaleVmGroupVmMapDao;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.storage.dao.VolumeDao;
+import com.cloud.user.SSHKeyPairVO;
+import com.cloud.user.dao.SSHKeyPairDao;
+import com.cloud.vm.InstanceGroupVMMapVO;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.UserVmDetailVO;
+import com.cloud.vm.dao.InstanceGroupVMMapDao;
+import com.cloud.vm.dao.NicDao;
+import com.cloud.vm.dao.UserVmDetailsDao;
import org.apache.cloudstack.acl.ControlledEntity;
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
import org.apache.cloudstack.acl.SecurityChecker;
@@ -83,6 +99,7 @@ import org.apache.cloudstack.api.command.user.snapshot.CopySnapshotCmd;
import org.apache.cloudstack.api.command.user.snapshot.ListSnapshotsCmd;
import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import org.apache.cloudstack.api.command.user.template.ListTemplatesCmd;
+import org.apache.cloudstack.api.command.user.template.ListVnfTemplatesCmd;
import org.apache.cloudstack.api.command.user.vm.ListVMsCmd;
import org.apache.cloudstack.api.command.user.vmgroup.ListVMGroupsCmd;
import org.apache.cloudstack.api.command.user.volume.ListResourceDetailsCmd;
@@ -118,6 +135,8 @@ import org.apache.cloudstack.api.response.UserResponse;
import org.apache.cloudstack.api.response.UserVmResponse;
import org.apache.cloudstack.api.response.VolumeResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.cloudstack.backup.BackupOfferingVO;
+import org.apache.cloudstack.backup.dao.BackupOfferingDao;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreCapabilities;
@@ -201,10 +220,10 @@ import com.cloud.exception.CloudAuthenticationException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.ha.HighAvailabilityManager;
-import com.cloud.host.Host;
import com.cloud.hypervisor.Hypervisor;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.RouterHealthCheckResult;
+import com.cloud.network.VNF;
import com.cloud.network.VpcVirtualNetworkApplianceService;
import com.cloud.network.dao.RouterHealthCheckResultDao;
import com.cloud.network.dao.RouterHealthCheckResultVO;
@@ -247,7 +266,6 @@ import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.StoragePoolTagsDao;
import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.storage.dao.VolumeDao;
import com.cloud.tags.ResourceTagVO;
import com.cloud.tags.dao.ResourceTagDao;
import com.cloud.template.VirtualMachineTemplate.State;
@@ -281,6 +299,8 @@ import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.UserVmDao;
import com.cloud.vm.dao.VMInstanceDao;
+import static com.cloud.vm.VmDetailConstants.SSH_PUBLIC_KEY;
+
@Component
public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements QueryService, Configurable {
@@ -289,7 +309,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private static final String ID_FIELD = "id";
@Inject
- private AccountManager _accountMgr;
+ private AccountManager accountMgr;
@Inject
private ProjectManager _projectMgr;
@@ -316,7 +336,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private UserVmJoinDao _userVmJoinDao;
@Inject
- private UserVmDao _userVmDao;
+ private UserVmDao userVmDao;
@Inject
private VMInstanceDao _vmInstanceDao;
@@ -325,7 +345,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private SecurityGroupJoinDao _securityGroupJoinDao;
@Inject
- private SecurityGroupVMMapDao _securityGroupVMMapDao;
+ private SecurityGroupVMMapDao securityGroupVMMapDao;
@Inject
private DomainRouterJoinDao _routerJoinDao;
@@ -346,7 +366,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private ProjectAccountJoinDao _projectAccountJoinDao;
@Inject
- private HostJoinDao _hostJoinDao;
+ private HostJoinDao hostJoinDao;
@Inject
private VolumeJoinDao _volumeJoinDao;
@@ -429,7 +449,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private AffinityGroupDomainMapDao _affinityGroupDomainMapDao;
@Inject
- private ResourceTagDao _resourceTagDao;
+ private ResourceTagDao resourceTagDao;
@Inject
private DataStoreManager dataStoreManager;
@@ -447,7 +467,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private RouterHealthCheckResultDao routerHealthCheckResultDao;
@Inject
- private PrimaryDataStoreDao _storagePoolDao;
+ private PrimaryDataStoreDao storagePoolDao;
@Inject
private StoragePoolDetailsDao _storagePoolDetailsDao;
@@ -470,8 +490,37 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private ManagementServerHostDao msHostDao;
@Inject
- private SnapshotJoinDao snapshotJoinDao;
+ private NetworkDao networkDao;
+ @Inject
+ private NicDao nicDao;
+
+ @Inject
+ private HostDao hostDao;
+
+ @Inject
+ private InstanceGroupVMMapDao instanceGroupVMMapDao;
+
+ @Inject
+ private AffinityGroupVMMapDao affinityGroupVMMapDao;
+
+ @Inject
+ private UserVmDetailsDao userVmDetailsDao;
+
+ @Inject
+ private SSHKeyPairDao sshKeyPairDao;
+
+ @Inject
+ private BackupOfferingDao backupOfferingDao;
+
+ @Inject
+ private AutoScaleVmGroupDao autoScaleVmGroupDao;
+
+ @Inject
+ private AutoScaleVmGroupVmMapDao autoScaleVmGroupVmMapDao;
+
+ @Inject
+ private SnapshotJoinDao snapshotJoinDao;
@Inject
EntityManager entityManager;
@@ -595,13 +644,13 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private Pair, Integer> getUserListInternal(Account caller, List permittedAccounts, boolean listAll, Long id, Object username, Object type,
String accountName, Object state, String keyword, Long domainId, boolean recursive, Filter searchFilter) {
Ternary domainIdRecursiveListProject = new Ternary(domainId, recursive, null);
- _accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, listAll, false);
+ accountMgr.buildACLSearchParameters(caller, id, accountName, null, permittedAccounts, domainIdRecursiveListProject, listAll, false);
domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
SearchBuilder sb = _userAccountJoinDao.createSearchBuilder();
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("username", sb.entity().getUsername(), Op.LIKE);
if (id != null && id == 1) {
// system user should NOT be searchable
@@ -627,7 +676,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
SearchCriteria sc = sb.create();
// building ACL condition
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (keyword != null) {
SearchCriteria ssc = _userAccountJoinDao.createSearchCriteria();
@@ -687,7 +736,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private Pair, Integer> searchForEventsInternal(ListEventsCmd cmd) {
Account caller = CallContext.current().getCallingAccount();
- boolean isRootAdmin = _accountMgr.isRootAdmin(caller.getId());
+ boolean isRootAdmin = accountMgr.isRootAdmin(caller.getId());
List permittedAccounts = new ArrayList();
Long id = cmd.getId();
@@ -727,12 +776,12 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
}
if (!isRootAdmin && object instanceof ControlledEntity) {
ControlledEntity entity = (ControlledEntity)object;
- _accountMgr.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, entity.getAccountId() == caller.getId(), entity);
+ accountMgr.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, entity.getAccountId() == caller.getId(), entity);
}
}
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
+ accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -743,7 +792,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
searchFilter.addOrderBy(EventJoinVO.class, "id", false);
SearchBuilder sb = _eventJoinDao.createSearchBuilder();
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("levelL", sb.entity().getLevel(), SearchCriteria.Op.LIKE);
@@ -762,10 +811,10 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
SearchCriteria sc = sb.create();
// building ACL condition
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
// For end users display only enabled events
- if (!_accountMgr.isRootAdmin(caller.getId())) {
+ if (!accountMgr.isRootAdmin(caller.getId())) {
sc.setParameters("displayEvent", true);
}
@@ -880,14 +929,14 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
+ accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), projectId, permittedAccounts, domainIdRecursiveListProject, listAll, false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
Filter searchFilter = new Filter(ResourceTagJoinVO.class, "resourceType", false, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder sb = _resourceTagJoinDao.createSearchBuilder();
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("key", sb.entity().getKey(), SearchCriteria.Op.EQ);
sb.and("value", sb.entity().getValue(), SearchCriteria.Op.EQ);
@@ -902,7 +951,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// now set the SC criteria...
SearchCriteria sc = sb.create();
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (key != null) {
sc.setParameters("key", key);
@@ -952,7 +1001,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List permittedAccounts = new ArrayList();
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
+ accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -960,13 +1009,13 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Filter searchFilter = new Filter(InstanceGroupJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
SearchBuilder sb = _vmGroupJoinDao.createSearchBuilder();
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
SearchCriteria sc = sb.create();
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (keyword != null) {
SearchCriteria ssc = _vmGroupJoinDao.createSearchCriteria();
@@ -997,7 +1046,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
ResponseView respView = ResponseView.Restricted;
Account caller = CallContext.current().getCallingAccount();
- if (_accountMgr.isRootAdmin(caller.getId())) {
+ if (accountMgr.isRootAdmin(caller.getId())) {
respView = ResponseView.Full;
}
List vmResponses = ViewResponseHelper.createUserVmResponse(respView, "virtualmachine", cmd.getDetails(), cmd.getAccumulate(), cmd.getShowUserData(),
@@ -1019,21 +1068,79 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
}
private Pair, Integer> searchForUserVMsInternal(ListVMsCmd cmd) {
+ Pair, Integer> vmIdPage = searchForUserVMIdsAndCount(cmd);
+
+ Integer count = vmIdPage.second();
+ Long[] idArray = vmIdPage.first().toArray(new Long[0]);
+
+ if (count == 0) {
+ return new Pair<>(new ArrayList<>(), count);
+ }
+
+ // search vm details by ids
+ List vms = _userVmJoinDao.searchByIds( idArray);
+ return new Pair<>(vms, count);
+ }
+
+ private Pair, Integer> searchForUserVMIdsAndCount(ListVMsCmd cmd) {
Account caller = CallContext.current().getCallingAccount();
List permittedAccounts = new ArrayList<>();
-
boolean listAll = cmd.listAll();
Long id = cmd.getId();
+ Boolean display = cmd.getDisplay();
+ String hypervisor = cmd.getHypervisor();
+ String state = cmd.getState();
+ Long zoneId = cmd.getZoneId();
+ Long templateId = cmd.getTemplateId();
+ Long serviceOfferingId = cmd.getServiceOfferingId();
+ Boolean isHaEnabled = cmd.getHaEnabled();
+ String keyword = cmd.getKeyword();
+ Long networkId = cmd.getNetworkId();
+ Long isoId = cmd.getIsoId();
+ String vmHostName = cmd.getName();
+ Long hostId = null;
+ Long podId = null;
+ Long clusterId = null;
+ Long groupId = cmd.getGroupId();
+ Long vpcId = cmd.getVpcId();
+ Long affinityGroupId = cmd.getAffinityGroupId();
+ String keyPairName = cmd.getKeyPairName();
+ Long securityGroupId = cmd.getSecurityGroupId();
+ Long autoScaleVmGroupId = cmd.getAutoScaleVmGroupId();
+ Long backupOfferingId = cmd.getBackupOfferingId();
+ Long storageId = null;
+ StoragePoolVO pool = null;
Long userId = cmd.getUserId();
Map tags = cmd.getTags();
- Boolean display = cmd.getDisplay();
+
+ boolean isAdmin = false;
+ boolean isRootAdmin = false;
+
+ if (accountMgr.isAdmin(caller.getId())) {
+ isAdmin = true;
+ }
+
+ if (accountMgr.isRootAdmin(caller.getId())) {
+ isRootAdmin = true;
+ podId = (Long) getObjectPossibleMethodValue(cmd, "getPodId");
+ clusterId = (Long) getObjectPossibleMethodValue(cmd, "getClusterId");
+ hostId = (Long) getObjectPossibleMethodValue(cmd, "getHostId");
+ storageId = (Long) getObjectPossibleMethodValue(cmd, "getStorageId");
+ if (storageId != null) {
+ pool = storagePoolDao.findById( storageId);
+ if (pool == null) {
+ throw new InvalidParameterValueException("Unable to find specified storage pool");
+ }
+ }
+ }
+
Ternary domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
+ accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, listAll, false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
- Filter searchFilter = new Filter(UserVmJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
+ Filter searchFilter = new Filter(UserVmVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
List ids = null;
if (cmd.getId() != null) {
@@ -1046,302 +1153,336 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
ids = cmd.getIds();
}
- // first search distinct vm id by using query criteria and pagination
- SearchBuilder sb = _userVmJoinDao.createSearchBuilder();
- sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct ids
+ SearchBuilder userVmSearchBuilder = userVmDao.createSearchBuilder();
+ userVmSearchBuilder.select(null, Func.DISTINCT, userVmSearchBuilder.entity().getId());
+ accountMgr.buildACLSearchBuilder(userVmSearchBuilder, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
-
- String hypervisor = cmd.getHypervisor();
- Object name = cmd.getName();
- String state = cmd.getState();
- Object zoneId = cmd.getZoneId();
- Object keyword = cmd.getKeyword();
- boolean isAdmin = false;
- boolean isRootAdmin = false;
- if (_accountMgr.isAdmin(caller.getId())) {
- isAdmin = true;
- }
- if (_accountMgr.isRootAdmin(caller.getId())) {
- isRootAdmin = true;
- }
-
- Object groupId = cmd.getGroupId();
- Object networkId = cmd.getNetworkId();
if (HypervisorType.getType(hypervisor) == HypervisorType.None && hypervisor != null) {
// invalid hypervisor type input
throw new InvalidParameterValueException("Invalid HypervisorType " + hypervisor);
}
- Object templateId = cmd.getTemplateId();
- Object isoId = cmd.getIsoId();
- Object vpcId = cmd.getVpcId();
- Object affinityGroupId = cmd.getAffinityGroupId();
- Object keyPairName = cmd.getKeyPairName();
- Object serviceOffId = cmd.getServiceOfferingId();
- Object securityGroupId = cmd.getSecurityGroupId();
- Object backupOfferingId = cmd.getBackupOfferingId();
- Object isHaEnabled = cmd.getHaEnabled();
- Object autoScaleVmGroupId = cmd.getAutoScaleVmGroupId();
- Object pod = null;
- Object clusterId = null;
- Object hostId = null;
- Object storageId = null;
- if (_accountMgr.isRootAdmin(caller.getId())) {
- pod = getObjectPossibleMethodValue(cmd, "getPodId");
- clusterId = getObjectPossibleMethodValue(cmd, "getClusterId");
- hostId = getObjectPossibleMethodValue(cmd, "getHostId");
- storageId = getObjectPossibleMethodValue(cmd, "getStorageId");
- }
-
- sb.and("displayName", sb.entity().getDisplayName(), SearchCriteria.Op.LIKE);
- sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN);
- sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
- sb.and("stateEQ", sb.entity().getState(), SearchCriteria.Op.EQ);
- sb.and("stateNEQ", sb.entity().getState(), SearchCriteria.Op.NEQ);
- sb.and("stateNIN", sb.entity().getState(), SearchCriteria.Op.NIN);
- sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
- sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
- if (clusterId != null) {
- sb.and().op("clusterId", sb.entity().getClusterId(), SearchCriteria.Op.EQ);
- sb.or("clusterHostId", sb.entity().getHostId(), Op.IN);
- sb.or("clusterLastHostId", sb.entity().getLastHostId(), Op.IN);
- sb.cp();
- }
- sb.and("hypervisorType", sb.entity().getHypervisorType(), SearchCriteria.Op.EQ);
- sb.and("hostIdEQ", sb.entity().getHostId(), SearchCriteria.Op.EQ);
- sb.and("templateId", sb.entity().getTemplateId(), SearchCriteria.Op.EQ);
- sb.and("isoId", sb.entity().getIsoId(), SearchCriteria.Op.EQ);
- sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ);
-
- if (serviceOffId != null) {
- sb.and("serviceOfferingId", sb.entity().getServiceOfferingId(), SearchCriteria.Op.EQ);
- }
-
- if (backupOfferingId != null) {
- sb.and("backupOfferingId", sb.entity().getBackupOfferingId(), SearchCriteria.Op.EQ);
- }
-
- if (display != null) {
- sb.and("display", sb.entity().isDisplayVm(), SearchCriteria.Op.EQ);
- }
-
- if (isHaEnabled != null) {
- sb.and("haEnabled", sb.entity().isHaEnabled(), SearchCriteria.Op.EQ);
- }
-
- if (groupId != null && (Long)groupId != -1) {
- sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ);
- }
-
- if (userId != null) {
- sb.and("userId", sb.entity().getUserId(), SearchCriteria.Op.EQ);
- }
-
- if (networkId != null) {
- sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ);
- }
-
- if (vpcId != null && networkId == null) {
- sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ);
- }
-
- if (storageId != null) {
- StoragePoolVO poolVO = _storagePoolDao.findById((Long) storageId);
- if (poolVO.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
- sb.and("poolId", sb.entity().getPoolId(), SearchCriteria.Op.IN);
- } else {
- sb.and("poolId", sb.entity().getPoolId(), SearchCriteria.Op.EQ);
- }
- }
-
- if (affinityGroupId != null) {
- sb.and("affinityGroupId", sb.entity().getAffinityGroupId(), SearchCriteria.Op.EQ);
- }
-
- if (keyPairName != null) {
- sb.and("keyPairName", sb.entity().getKeypairNames(), SearchCriteria.Op.FIND_IN_SET);
- }
-
- if (!isRootAdmin) {
- sb.and("displayVm", sb.entity().isDisplayVm(), SearchCriteria.Op.EQ);
- }
-
- if (securityGroupId != null) {
- sb.and("securityGroupId", sb.entity().getSecurityGroupId(), SearchCriteria.Op.EQ);
- }
-
- if (autoScaleVmGroupId != null) {
- sb.and("autoScaleVmGroupId", sb.entity().getAutoScaleVmGroupId(), SearchCriteria.Op.EQ);
- }
-
- // populate the search criteria with the values passed in
- SearchCriteria sc = sb.create();
-
- // building ACL condition
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
-
- if (tags != null && !tags.isEmpty()) {
- SearchCriteria tagSc = _userVmJoinDao.createSearchCriteria();
- for (Map.Entry entry : tags.entrySet()) {
- SearchCriteria tsc = _userVmJoinDao.createSearchCriteria();
- tsc.addAnd("tagKey", SearchCriteria.Op.EQ, entry.getKey());
- tsc.addAnd("tagValue", SearchCriteria.Op.EQ, entry.getValue());
- tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc);
- }
- sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc);
- }
-
- if (groupId != null && (Long)groupId != -1) {
- sc.setParameters("instanceGroupId", groupId);
- }
-
- if (keyword != null) {
- SearchCriteria ssc = _userVmJoinDao.createSearchCriteria();
- String likeKeyword = String.format("%%%s%%", keyword);
- ssc.addOr("displayName", SearchCriteria.Op.LIKE, likeKeyword);
- ssc.addOr("name", SearchCriteria.Op.LIKE, likeKeyword);
- if (isRootAdmin) {
- ssc.addOr("instanceName", SearchCriteria.Op.LIKE, likeKeyword);
- }
- ssc.addOr("ipAddress", SearchCriteria.Op.LIKE, likeKeyword);
- ssc.addOr("publicIpAddress", SearchCriteria.Op.LIKE, likeKeyword);
- ssc.addOr("ip6Address", SearchCriteria.Op.LIKE, likeKeyword);
- ssc.addOr("state", SearchCriteria.Op.EQ, keyword);
- sc.addAnd("displayName", SearchCriteria.Op.SC, ssc);
- }
-
- if (serviceOffId != null) {
- sc.setParameters("serviceOfferingId", serviceOffId);
- }
-
- if (backupOfferingId != null) {
- sc.setParameters("backupOfferingId", backupOfferingId);
- }
-
- if (securityGroupId != null) {
- sc.setParameters("securityGroupId", securityGroupId);
- }
-
- if (autoScaleVmGroupId != null) {
- sc.setParameters("autoScaleVmGroupId", autoScaleVmGroupId);
- }
-
- if (display != null) {
- sc.setParameters("display", display);
- }
-
- if (isHaEnabled != null) {
- sc.setParameters("haEnabled", isHaEnabled);
- }
if (ids != null && !ids.isEmpty()) {
- sc.setParameters("idIN", ids.toArray());
+ userVmSearchBuilder.and("idIN", userVmSearchBuilder.entity().getId(), Op.IN);
+ }
+
+ userVmSearchBuilder.and("displayName", userVmSearchBuilder.entity().getDisplayName(), Op.LIKE);
+ userVmSearchBuilder.and("stateEQ", userVmSearchBuilder.entity().getState(), Op.EQ);
+ userVmSearchBuilder.and("stateNEQ", userVmSearchBuilder.entity().getState(), Op.NEQ);
+ userVmSearchBuilder.and("stateNIN", userVmSearchBuilder.entity().getState(), Op.NIN);
+
+ if (hostId != null) {
+ userVmSearchBuilder.and("hostId", userVmSearchBuilder.entity().getHostId(), Op.EQ);
+ }
+
+ if (zoneId != null) {
+ userVmSearchBuilder.and("dataCenterId", userVmSearchBuilder.entity().getDataCenterId(), Op.EQ);
}
if (templateId != null) {
- sc.setParameters("templateId", templateId);
+ userVmSearchBuilder.and("templateId", userVmSearchBuilder.entity().getTemplateId(), Op.EQ);
+ }
+
+ if (hypervisor != null) {
+ userVmSearchBuilder.and("hypervisorType", userVmSearchBuilder.entity().getHypervisorType(), Op.EQ);
+ }
+
+ if (vmHostName != null) {
+ userVmSearchBuilder.and("name", userVmSearchBuilder.entity().getHostName(), Op.EQ);
+ }
+
+ if (serviceOfferingId != null) {
+ userVmSearchBuilder.and("serviceOfferingId", userVmSearchBuilder.entity().getServiceOfferingId(), Op.EQ);
+ }
+ if (display != null) {
+ userVmSearchBuilder.and("display", userVmSearchBuilder.entity().isDisplayVm(), Op.EQ);
+ }
+
+ if (!isRootAdmin) {
+ userVmSearchBuilder.and("displayVm", userVmSearchBuilder.entity().isDisplayVm(), Op.EQ);
+ }
+
+ if (isHaEnabled != null) {
+ userVmSearchBuilder.and("haEnabled", userVmSearchBuilder.entity().isHaEnabled(), Op.EQ);
}
if (isoId != null) {
- sc.setParameters("isoId", isoId);
+ userVmSearchBuilder.and("isoId", userVmSearchBuilder.entity().getIsoId(), Op.EQ);
}
if (userId != null) {
- sc.setParameters("userId", userId);
+ userVmSearchBuilder.and("userId", userVmSearchBuilder.entity().getUserId(), Op.EQ);
}
- if (networkId != null) {
- sc.setParameters("networkId", networkId);
+ if (podId != null) {
+ userVmSearchBuilder.and("podId", userVmSearchBuilder.entity().getPodIdToDeployIn(), Op.EQ);
}
- if (vpcId != null && networkId == null) {
- sc.setParameters("vpcId", vpcId);
+ if (networkId != null || vpcId != null) {
+ SearchBuilder nicSearch = nicDao.createSearchBuilder();
+ nicSearch.and("networkId", nicSearch.entity().getNetworkId(), Op.EQ);
+ if (vpcId != null) {
+ SearchBuilder networkSearch = networkDao.createSearchBuilder();
+ networkSearch.and("vpcId", networkSearch.entity().getVpcId(), Op.EQ);
+ nicSearch.join("vpc", networkSearch, networkSearch.entity().getId(), nicSearch.entity().getNetworkId(), JoinBuilder.JoinType.INNER);
+ }
+ userVmSearchBuilder.join("nic", nicSearch, nicSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
}
- if (name != null) {
- sc.setParameters("name", name);
+ if (clusterId != null) {
+ userVmSearchBuilder.and().op("hostIdIn", userVmSearchBuilder.entity().getHostId(), Op.IN);
+ userVmSearchBuilder.or().op("lastHostIdIn", userVmSearchBuilder.entity().getLastHostId(), Op.IN);
+ userVmSearchBuilder.and(userVmSearchBuilder.entity().getState(), Op.EQ).values(VirtualMachine.State.Stopped);
+ userVmSearchBuilder.cp().cp();
+ }
+
+ if (groupId != null && groupId != -1) {
+ SearchBuilder instanceGroupSearch = instanceGroupVMMapDao.createSearchBuilder();
+ instanceGroupSearch.and("groupId", instanceGroupSearch.entity().getGroupId(), Op.EQ);
+ userVmSearchBuilder.join("instanceGroup", instanceGroupSearch, instanceGroupSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
+ }
+
+ if (affinityGroupId != null && affinityGroupId != -1) {
+ SearchBuilder affinityGroupSearch = affinityGroupVMMapDao.createSearchBuilder();
+ affinityGroupSearch.and("affinityGroupId", affinityGroupSearch.entity().getAffinityGroupId(), Op.EQ);
+ userVmSearchBuilder.join("affinityGroup", affinityGroupSearch, affinityGroupSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
+ }
+
+ if (securityGroupId != null && securityGroupId != -1) {
+ SearchBuilder securityGroupSearch = securityGroupVMMapDao.createSearchBuilder();
+ securityGroupSearch.and("securityGroupId", securityGroupSearch.entity().getSecurityGroupId(), Op.EQ);
+ userVmSearchBuilder.join("securityGroup", securityGroupSearch, securityGroupSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
+ }
+
+ if (storageId != null) {
+ SearchBuilder volumeSearch = volumeDao.createSearchBuilder();
+ if (pool.getPoolType().equals(Storage.StoragePoolType.DatastoreCluster)) {
+ volumeSearch.and("storagePoolId", volumeSearch.entity().getPoolId(), Op.IN);
+ } else {
+ volumeSearch.and("storagePoolId", volumeSearch.entity().getPoolId(), Op.EQ);
+ }
+ userVmSearchBuilder.join("volume", volumeSearch, volumeSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
+ }
+
+ if (tags != null && !tags.isEmpty()) {
+ SearchBuilder resourceTagSearch = resourceTagDao.createSearchBuilder();
+ resourceTagSearch.and("resourceType", resourceTagSearch.entity().getResourceType(), Op.EQ);
+ resourceTagSearch.and().op();
+ for (int count = 0; count < tags.size(); count++) {
+ if (count == 0) {
+ resourceTagSearch.op("tagKey" + String.valueOf(count), resourceTagSearch.entity().getKey(), Op.EQ);
+ } else {
+ resourceTagSearch.or().op("tagKey" + String.valueOf(count), resourceTagSearch.entity().getKey(), Op.EQ);
+ }
+ resourceTagSearch.and("tagValue" + String.valueOf(count), resourceTagSearch.entity().getValue(), Op.EQ);
+ resourceTagSearch.cp();
+ }
+ resourceTagSearch.cp();
+
+ userVmSearchBuilder.join("tags", resourceTagSearch, resourceTagSearch.entity().getResourceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
+ }
+
+ if (keyPairName != null) {
+ SearchBuilder vmDetailSearchKeys = userVmDetailsDao.createSearchBuilder();
+ SearchBuilder vmDetailSearchVmIds = userVmDetailsDao.createSearchBuilder();
+ vmDetailSearchKeys.and(vmDetailSearchKeys.entity().getName(), Op.EQ).values(SSH_PUBLIC_KEY);
+
+ SearchBuilder sshKeyPairSearch = sshKeyPairDao.createSearchBuilder();
+ sshKeyPairSearch.and("keyPairName", sshKeyPairSearch.entity().getName(), Op.EQ);
+
+ sshKeyPairSearch.join("keyPairToDetailValueJoin", vmDetailSearchKeys, vmDetailSearchKeys.entity().getValue(), sshKeyPairSearch.entity().getPublicKey(), JoinBuilder.JoinType.INNER);
+ userVmSearchBuilder.join("userVmToDetailJoin", vmDetailSearchVmIds, vmDetailSearchVmIds.entity().getResourceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
+ userVmSearchBuilder.join("userVmToKeyPairJoin", sshKeyPairSearch, sshKeyPairSearch.entity().getAccountId(), userVmSearchBuilder.entity().getAccountId(), JoinBuilder.JoinType.INNER);
+ }
+
+ if (keyword != null) {
+ userVmSearchBuilder.and().op("keywordDisplayName", userVmSearchBuilder.entity().getDisplayName(), Op.LIKE);
+ userVmSearchBuilder.or("keywordName", userVmSearchBuilder.entity().getHostName(), Op.LIKE);
+ userVmSearchBuilder.or("keywordState", userVmSearchBuilder.entity().getState(), Op.EQ);
+ if (isRootAdmin) {
+ userVmSearchBuilder.or("keywordInstanceName", userVmSearchBuilder.entity().getInstanceName(), Op.LIKE );
+ }
+ userVmSearchBuilder.cp();
+ }
+
+ if (backupOfferingId != null) {
+ SearchBuilder backupOfferingSearch = backupOfferingDao.createSearchBuilder();
+ backupOfferingSearch.and("backupOfferingId", backupOfferingSearch.entity().getId(), Op.EQ);
+ userVmSearchBuilder.join("backupOffering", backupOfferingSearch, backupOfferingSearch.entity().getId(), userVmSearchBuilder.entity().getBackupOfferingId(), JoinBuilder.JoinType.INNER);
+ }
+
+ if (autoScaleVmGroupId != null) {
+ SearchBuilder autoScaleMapSearch = autoScaleVmGroupVmMapDao.createSearchBuilder();
+ autoScaleMapSearch.and("autoScaleVmGroupId", autoScaleMapSearch.entity().getVmGroupId(), Op.EQ);
+ userVmSearchBuilder.join("autoScaleVmGroup", autoScaleMapSearch, autoScaleMapSearch.entity().getInstanceId(), userVmSearchBuilder.entity().getId(), JoinBuilder.JoinType.INNER);
+ }
+
+ Boolean isVnf = cmd.getVnf();
+ if (isVnf != null) {
+ SearchBuilder templateSearch = _templateDao.createSearchBuilder();
+ templateSearch.and("templateTypeEQ", templateSearch.entity().getTemplateType(), Op.EQ);
+ templateSearch.and("templateTypeNEQ", templateSearch.entity().getTemplateType(), Op.NEQ);
+
+ userVmSearchBuilder.join("vmTemplate", templateSearch, templateSearch.entity().getId(), userVmSearchBuilder.entity().getTemplateId(), JoinBuilder.JoinType.INNER);
+ }
+
+ SearchCriteria userVmSearchCriteria = userVmSearchBuilder.create();
+ accountMgr.buildACLSearchCriteria(userVmSearchCriteria, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+
+ if (serviceOfferingId != null) {
+ userVmSearchCriteria.setParameters("serviceOfferingId", serviceOfferingId);
}
if (state != null) {
if (state.equalsIgnoreCase("present")) {
- sc.setParameters("stateNIN", "Destroyed", "Expunging");
+ userVmSearchCriteria.setParameters("stateNIN", "Destroyed", "Expunging");
} else {
- sc.setParameters("stateEQ", state);
+ userVmSearchCriteria.setParameters("stateEQ", state);
}
}
if (hypervisor != null) {
- sc.setParameters("hypervisorType", hypervisor);
+ userVmSearchCriteria.setParameters("hypervisorType", hypervisor);
}
// Don't show Destroyed and Expunging vms to the end user if the AllowUserViewDestroyedVM flag is not set.
if (!isAdmin && !AllowUserViewDestroyedVM.valueIn(caller.getAccountId())) {
- sc.setParameters("stateNIN", "Destroyed", "Expunging");
+ userVmSearchCriteria.setParameters("stateNIN", "Destroyed", "Expunging");
}
if (zoneId != null) {
- sc.setParameters("dataCenterId", zoneId);
+ userVmSearchCriteria.setParameters("dataCenterId", zoneId);
}
- if (affinityGroupId != null) {
- sc.setParameters("affinityGroupId", affinityGroupId);
+ if (templateId != null) {
+ userVmSearchCriteria.setParameters("templateId", templateId);
+ }
+
+ if (display != null) {
+ userVmSearchCriteria.setParameters("display", display);
+ }
+
+ if (isHaEnabled != null) {
+ userVmSearchCriteria.setParameters("haEnabled", isHaEnabled);
+ }
+
+ if (isoId != null) {
+ userVmSearchCriteria.setParameters("isoId", isoId);
+ }
+
+ if (ids != null && !ids.isEmpty()) {
+ userVmSearchCriteria.setParameters("idIN", ids.toArray());
+ }
+
+ if (vmHostName != null) {
+ userVmSearchCriteria.setParameters("name", vmHostName);
+ }
+
+ if (groupId != null && groupId != -1) {
+ userVmSearchCriteria.setJoinParameters("instanceGroup","groupId", groupId);
+ }
+
+ if (affinityGroupId != null && affinityGroupId != -1) {
+ userVmSearchCriteria.setJoinParameters("affinityGroup", "affinityGroupId", affinityGroupId);
+ }
+
+ if (securityGroupId != null && securityGroupId != -1) {
+ userVmSearchCriteria.setJoinParameters("securityGroup","securityGroupId", securityGroupId);
+ }
+
+ if (keyword != null) {
+ String keywordMatch = "%" + keyword + "%";
+ userVmSearchCriteria.setParameters("keywordDisplayName", keywordMatch);
+ userVmSearchCriteria.setParameters("keywordName", keywordMatch);
+ userVmSearchCriteria.setParameters("keywordState", keyword);
+ if (isRootAdmin) {
+ userVmSearchCriteria.setParameters("keywordInstanceName", keywordMatch);
+ }
+ }
+
+ if (tags != null && !tags.isEmpty()) {
+ int count = 0;
+ userVmSearchCriteria.setJoinParameters("tags","resourceType", ResourceObjectType.UserVm);
+ for (Map.Entry entry : tags.entrySet()) {
+ userVmSearchCriteria.setJoinParameters("tags", "tagKey" + String.valueOf(count), entry.getKey());
+ userVmSearchCriteria.setJoinParameters("tags", "tagValue" + String.valueOf(count), entry.getValue());
+ count++;
+ }
}
if (keyPairName != null) {
- sc.setParameters("keyPairName", keyPairName);
+ userVmSearchCriteria.setJoinParameters("userVmToKeyPairJoin", "keyPairName", keyPairName);
}
- if (_accountMgr.isRootAdmin(caller.getId())) {
- if (pod != null) {
- sc.setParameters("podId", pod);
+ if (networkId != null) {
+ userVmSearchCriteria.setJoinParameters("nic", "networkId", networkId);
+ }
+ if (vpcId != null) {
+ userVmSearchCriteria.getJoin("nic").setJoinParameters("vpc", "vpcId", vpcId);
+ }
+
+ if (userId != null) {
+ userVmSearchCriteria.setParameters("userId", userId);
+ }
+
+ if (backupOfferingId != null) {
+ userVmSearchCriteria.setJoinParameters("backupOffering", "backupOfferingId", backupOfferingId);
+ }
+
+ if (autoScaleVmGroupId != null) {
+ userVmSearchCriteria.setJoinParameters("autoScaleVmGroup", "autoScaleVmGroupId", autoScaleVmGroupId);
+ }
+
+ if (isVnf != null) {
+ if (isVnf) {
+ userVmSearchCriteria.setJoinParameters("vmTemplate", "templateTypeEQ", TemplateType.VNF);
+ } else {
+ userVmSearchCriteria.setJoinParameters("vmTemplate", "templateTypeNEQ", TemplateType.VNF);
+ }
+ }
+
+ if (isRootAdmin) {
+ if (podId != null) {
+ userVmSearchCriteria.setParameters("podId", podId);
if (state == null) {
- sc.setParameters("stateNEQ", "Destroyed");
+ userVmSearchCriteria.setParameters("stateNEQ", "Destroyed");
}
}
if (clusterId != null) {
- sc.setParameters("clusterId", clusterId);
- List hosts = _hostJoinDao.findByClusterId((Long)clusterId, Host.Type.Routing);
+ List hosts = hostJoinDao.findByClusterId(clusterId, Host.Type.Routing);
+ if (CollectionUtils.isEmpty(hosts)) {
+ // cluster has no hosts, so we cannot find VMs, cancel search.
+ return new Pair<>(new ArrayList<>(), 0);
+ }
List hostIds = hosts.stream().map(HostJoinVO::getId).collect(Collectors.toList());
- sc.setParameters("clusterHostId", hostIds.toArray());
- sc.setParameters("clusterLastHostId", hostIds.toArray());
+ userVmSearchCriteria.setParameters("hostIdIn", hostIds.toArray());
+ userVmSearchCriteria.setParameters("lastHostIdIn", hostIds.toArray());
}
if (hostId != null) {
- sc.setParameters("hostIdEQ", hostId);
+ userVmSearchCriteria.setParameters("hostId", hostId);
}
- if (storageId != null) {
- StoragePoolVO poolVO = _storagePoolDao.findById((Long) storageId);
- if (poolVO.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
- List childDatastores = _storagePoolDao.listChildStoragePoolsInDatastoreCluster((Long) storageId);
+ if (storageId != null && pool != null) {
+ if (pool.getPoolType().equals(Storage.StoragePoolType.DatastoreCluster)) {
+ List childDatastores = storagePoolDao.listChildStoragePoolsInDatastoreCluster(storageId);
List childDatastoreIds = childDatastores.stream().map(mo -> mo.getId()).collect(Collectors.toList());
- sc.setParameters("poolId", childDatastoreIds.toArray());
+ userVmSearchCriteria.setJoinParameters("volume", "storagePoolId", childDatastoreIds.toArray());
} else {
- sc.setParameters("poolId", storageId);
+ userVmSearchCriteria.setJoinParameters("volume", "storagePoolId", storageId);
}
}
+ } else {
+ userVmSearchCriteria.setParameters("displayVm", 1);
}
- if (!isRootAdmin) {
- sc.setParameters("displayVm", 1);
- }
- // search vm details by ids
- Pair, Integer> uniqueVmPair = _userVmJoinDao.searchAndDistinctCount(sc, searchFilter);
+ Pair, Integer> uniqueVmPair = userVmDao.searchAndDistinctCount(userVmSearchCriteria, searchFilter, new String[]{"vm_instance.id"});
Integer count = uniqueVmPair.second();
- if (count.intValue() == 0) {
- // handle empty result cases
- return uniqueVmPair;
- }
- List uniqueVms = uniqueVmPair.first();
- Long[] vmIds = new Long[uniqueVms.size()];
- int i = 0;
- for (UserVmJoinVO v : uniqueVms) {
- vmIds[i++] = v.getId();
- }
- List vms = _userVmJoinDao.searchByIds(vmIds);
- return new Pair<>(vms, count);
+
+ List vmIds = uniqueVmPair.first().stream().map(VMInstanceVO::getId).collect(Collectors.toList());
+ return new Pair<>(vmIds, count);
}
@Override
@@ -1363,16 +1504,16 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Map tags = cmd.getTags();
if (instanceId != null) {
- UserVmVO userVM = _userVmDao.findById(instanceId);
+ UserVmVO userVM = userVmDao.findById(instanceId);
if (userVM == null) {
throw new InvalidParameterValueException("Unable to list network groups for virtual machine instance " + instanceId + "; instance not found.");
}
- _accountMgr.checkAccess(caller, null, true, userVM);
+ accountMgr.checkAccess(caller, null, true, userVM);
return listSecurityGroupRulesByVM(instanceId.longValue(), cmd.getStartIndex(), cmd.getPageSizeVal());
}
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
+ accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -1381,13 +1522,13 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
SearchBuilder sb = _securityGroupJoinDao.createSearchBuilder();
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct
// ids
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
SearchCriteria sc = sb.create();
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (id != null) {
sc.setParameters("id", id);
@@ -1435,7 +1576,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private Pair, Integer> listSecurityGroupRulesByVM(long vmId, long pageInd, long pageSize) {
Filter sf = new Filter(SecurityGroupVMMapVO.class, null, true, pageInd, pageSize);
- Pair, Integer> sgVmMappingPair = _securityGroupVMMapDao.listByInstanceId(vmId, sf);
+ Pair, Integer> sgVmMappingPair = securityGroupVMMapDao.listByInstanceId(vmId, sf);
Integer count = sgVmMappingPair.second();
if (count.intValue() == 0) {
// handle empty result cases
@@ -1499,7 +1640,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List permittedAccounts = new ArrayList();
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
+ accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -1511,7 +1652,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// number of
// records with
// pagination
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("name", sb.entity().getInstanceName(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
@@ -1559,7 +1700,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
}
SearchCriteria sc = sb.create();
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (keyword != null) {
SearchCriteria ssc = _routerJoinDao.createSearchCriteria();
@@ -1674,17 +1815,17 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct
// ids
- if (_accountMgr.isAdmin(caller.getId())) {
+ if (accountMgr.isAdmin(caller.getId())) {
if (domainId != null) {
DomainVO domain = _domainDao.findById(domainId);
if (domain == null) {
throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist in the system");
}
- _accountMgr.checkAccess(caller, domain);
+ accountMgr.checkAccess(caller, domain);
if (accountName != null) {
- Account owner = _accountMgr.getActiveAccountByName(accountName, domainId);
+ Account owner = accountMgr.getActiveAccountByName(accountName, domainId);
if (owner == null) {
throw new InvalidParameterValueException("Unable to find account " + accountName + " in domain " + domainId);
}
@@ -1725,10 +1866,10 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
userId = user.getId();
}
- if (domainId == null && accountId == null && (_accountMgr.isNormalUser(caller.getId()) || !listAll)) {
+ if (domainId == null && accountId == null && (accountMgr.isNormalUser(caller.getId()) || !listAll)) {
accountId = caller.getId();
userId = user.getId();
- } else if (_accountMgr.isDomainAdmin(caller.getId()) || (isRecursive && !listAll)) {
+ } else if (accountMgr.isDomainAdmin(caller.getId()) || (isRecursive && !listAll)) {
DomainVO domain = _domainDao.findById(caller.getDomainId());
path = domain.getPath();
}
@@ -1839,14 +1980,14 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List permittedAccounts = new ArrayList();
Ternary domainIdRecursiveListProject = new Ternary(domainId, isRecursive, null);
- _accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, true);
+ accountMgr.buildACLSearchParameters(caller, id, accountName, projectId, permittedAccounts, domainIdRecursiveListProject, listAll, true);
domainId = domainIdRecursiveListProject.first();
isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
Filter searchFilter = new Filter(ProjectInvitationJoinVO.class, "id", true, startIndex, pageSizeVal);
SearchBuilder sb = _projectInvitationJoinDao.createSearchBuilder();
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
ProjectInvitation invitation = projectInvitationDao.findByUserIdProjectId(callingUser.getId(), callingUser.getAccountId(), projectId == null ? -1 : projectId);
sb.and("projectId", sb.entity().getProjectId(), SearchCriteria.Op.EQ);
sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
@@ -1854,7 +1995,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
SearchCriteria sc = sb.create();
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (projectId != null) {
sc.setParameters("projectId", projectId);
@@ -1917,7 +2058,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// verify permissions - only accounts belonging to the project can list
// project's account
- if (!_accountMgr.isAdmin(caller.getId()) && _projectAccountDao.findByProjectIdUserId(projectId, callingUser.getAccountId(), callingUser.getId()) == null &&
+ if (!accountMgr.isAdmin(caller.getId()) && _projectAccountDao.findByProjectIdUserId(projectId, callingUser.getAccountId(), callingUser.getId()) == null &&
_projectAccountDao.findByProjectIdAccountId(projectId, caller.getAccountId()) == null) {
throw new PermissionDeniedException("Account " + caller + " is not authorized to list users of the project id=" + projectId);
}
@@ -1973,7 +2114,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
public Pair, Integer> searchForServersInternal(ListHostsCmd cmd) {
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
+ Long zoneId = accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Object name = cmd.getHostName();
Object type = cmd.getType();
Object state = cmd.getState();
@@ -1991,7 +2132,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Filter searchFilter = new Filter(HostJoinVO.class, "id", Boolean.TRUE, startIndex, pageSize);
- SearchBuilder sb = _hostJoinDao.createSearchBuilder();
+ SearchBuilder sb = hostJoinDao.createSearchBuilder();
sb.select(null, Func.DISTINCT, sb.entity().getId()); // select distinct
// ids
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
@@ -2021,7 +2162,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
SearchCriteria sc = sb.create();
if (keyword != null) {
- SearchCriteria ssc = _hostJoinDao.createSearchCriteria();
+ SearchCriteria ssc = hostJoinDao.createSearchCriteria();
ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("status", SearchCriteria.Op.LIKE, "%" + keyword + "%");
ssc.addOr("type", SearchCriteria.Op.LIKE, "%" + keyword + "%");
@@ -2072,7 +2213,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sc.setParameters("hypervisor_type", hypervisorType);
}
// search host details by ids
- Pair, Integer> uniqueHostPair = _hostJoinDao.searchAndCount(sc, searchFilter);
+ Pair, Integer> uniqueHostPair = hostJoinDao.searchAndCount(sc, searchFilter);
Integer count = uniqueHostPair.second();
if (count.intValue() == 0) {
// handle empty result cases
@@ -2084,7 +2225,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
for (HostJoinVO v : uniqueHosts) {
hostIds[i++] = v.getId();
}
- List hosts = _hostJoinDao.searchByIds(hostIds);
+ List hosts = hostJoinDao.searchByIds(hostIds);
return new Pair, Integer>(hosts, count);
}
@@ -2101,7 +2242,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
ResponseView respView = cmd.getResponseView();
Account account = CallContext.current().getCallingAccount();
- if (_accountMgr.isRootAdmin(account.getAccountId())) {
+ if (accountMgr.isRootAdmin(account.getAccountId())) {
respView = ResponseView.Full;
}
@@ -2160,7 +2301,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List ids = getIdsListFromCmd(cmd.getId(), cmd.getIds());
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
+ accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -2175,7 +2316,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// number of
// records with
// pagination
- _accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ);
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
@@ -2186,7 +2327,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("podId", sb.entity().getPodId(), SearchCriteria.Op.EQ);
if (storageId != null) {
- StoragePoolVO poolVO = _storagePoolDao.findByUuid(storageId);
+ StoragePoolVO poolVO = storagePoolDao.findByUuid(storageId);
if (poolVO.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
sb.and("storageId", sb.entity().getPoolUuid(), SearchCriteria.Op.IN);
} else {
@@ -2210,7 +2351,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// now set the SC criteria...
SearchCriteria sc = sb.create();
- _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
+ accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
if (keyword != null) {
SearchCriteria ssc = _volumeJoinDao.createSearchCriteria();
@@ -2269,9 +2410,9 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
}
if (storageId != null) {
- StoragePoolVO poolVO = _storagePoolDao.findByUuid(storageId);
+ StoragePoolVO poolVO = storagePoolDao.findByUuid(storageId);
if (poolVO.getPoolType() == Storage.StoragePoolType.DatastoreCluster) {
- List childDatastores = _storagePoolDao.listChildStoragePoolsInDatastoreCluster(poolVO.getId());
+ List childDatastores = storagePoolDao.listChildStoragePoolsInDatastoreCluster(poolVO.getId());
List childDatastoreIds = childDatastores.stream().map(mo -> mo.getUuid()).collect(Collectors.toList());
sc.setParameters("storageId", childDatastoreIds.toArray());
} else {
@@ -2285,7 +2426,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
if (state != null) {
sc.setParameters("state", state);
- } else if (!_accountMgr.isAdmin(caller.getId())) {
+ } else if (!accountMgr.isAdmin(caller.getId())) {
sc.setParameters("stateNEQ", Volume.State.Expunged);
}
@@ -2307,7 +2448,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
}
private boolean shouldListSystemVms(ListVolumesCmd cmd, Long callerId) {
- return Boolean.TRUE.equals(cmd.getListSystemVms()) && _accountMgr.isRootAdmin(callerId);
+ return Boolean.TRUE.equals(cmd.getListSystemVms()) && accountMgr.isRootAdmin(callerId);
}
@Override
@@ -2337,7 +2478,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
if (domain == null) {
throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
}
- _accountMgr.checkAccess(caller, domain);
+ accountMgr.checkAccess(caller, domain);
} else {
if (caller.getType() != Account.Type.ADMIN) {
domainId = caller.getDomainId();
@@ -2414,7 +2555,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
String accountName = cmd.getSearchName();
boolean isRecursive = cmd.isRecursive();
boolean listAll = cmd.listAll();
- boolean callerIsAdmin = _accountMgr.isAdmin(caller.getId());
+ boolean callerIsAdmin = accountMgr.isAdmin(caller.getId());
Account account;
Domain domain = null;
@@ -2426,7 +2567,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
throw new InvalidParameterValueException("Domain id=" + domainId + " doesn't exist");
}
// ... and check access rights.
- _accountMgr.checkAccess(caller, domain);
+ accountMgr.checkAccess(caller, domain);
}
// if no "id" specified...
@@ -2449,7 +2590,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Unable to find account by name " + accountName + " in domain " + domainId);
}
- _accountMgr.checkAccess(caller, null, true, account);
+ accountMgr.checkAccess(caller, null, true, account);
} else {
// if they specified an "id"...
if (domainId == null) {
@@ -2460,7 +2601,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
throw new InvalidParameterValueException("Unable to find account by id " + accountId + (domainId == null ? "" : " in domain " + domainId));
}
- _accountMgr.checkAccess(caller, null, true, account);
+ accountMgr.checkAccess(caller, null, true, account);
}
Filter searchFilter = new Filter(AccountJoinVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
@@ -2556,7 +2697,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List permittedAccounts = new ArrayList();
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), null, permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
+ accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(), null, permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Long domainId = domainIdRecursiveListProject.first();
Boolean isRecursive = domainIdRecursiveListProject.second();
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
@@ -2640,7 +2781,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Map caps = driver.getCapabilities();
if (Storage.StoragePoolType.NetworkFilesystem.toString().equals(poolResponse.getType()) &&
HypervisorType.VMware.toString().equals(poolResponse.getHypervisor())) {
- StoragePoolVO pool = _storagePoolDao.findPoolByUUID(poolResponse.getId());
+ StoragePoolVO pool = storagePoolDao.findPoolByUUID(poolResponse.getId());
StoragePoolDetailVO detail = _storagePoolDetailsDao.findDetail(pool.getId(), Storage.Capability.HARDWARE_ACCELERATION.toString());
if (detail != null) {
caps.put(Storage.Capability.HARDWARE_ACCELERATION.toString(), detail.getValue());
@@ -2659,7 +2800,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
ScopeType scopeType = ScopeType.validateAndGetScopeType(cmd.getScope());
StoragePoolStatus status = StoragePoolStatus.validateAndGetStatus(cmd.getStatus());
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
+ Long zoneId = accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Long id = cmd.getId();
String name = cmd.getStoragePoolName();
String path = cmd.getPath();
@@ -2667,6 +2808,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Long cluster = cmd.getClusterId();
String address = cmd.getIpAddress();
String keyword = cmd.getKeyword();
+
Long startIndex = cmd.getStartIndex();
Long pageSize = cmd.getPageSizeVal();
@@ -2786,7 +2928,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private Pair, Integer> searchForImageStoresInternal(ListImageStoresCmd cmd) {
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
+ Long zoneId = accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Object id = cmd.getId();
Object name = cmd.getStoreName();
String provider = cmd.getProvider();
@@ -2870,7 +3012,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
private Pair, Integer> searchForCacheStoresInternal(ListSecondaryStagingStoresCmd cmd) {
- Long zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
+ Long zoneId = accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), cmd.getZoneId());
Object id = cmd.getId();
Object name = cmd.getStoreName();
String provider = cmd.getProvider();
@@ -2967,7 +3109,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Object id = cmd.getId();
Object keyword = cmd.getKeyword();
Long domainId = cmd.getDomainId();
- Boolean isRootAdmin = _accountMgr.isRootAdmin(account.getAccountId());
+ Boolean isRootAdmin = accountMgr.isRootAdmin(account.getAccountId());
Boolean isRecursive = cmd.isRecursive();
Long zoneId = cmd.getZoneId();
Long volumeId = cmd.getVolumeId();
@@ -2977,7 +3119,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// if a domainId is provided, we just return the disk offering
// associated with this domain
if (domainId != null) {
- if (_accountMgr.isRootAdmin(account.getId()) || isPermissible(account.getDomainId(), domainId)) {
+ if (accountMgr.isRootAdmin(account.getId()) || isPermissible(account.getDomainId(), domainId)) {
// check if the user's domain == do's domain || user's domain is
// a child of so's domain for non-root users
sc.addAnd("domainId", Op.FIND_IN_SET, String.valueOf(domainId));
@@ -2992,7 +3134,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// For non-root users, only return all offerings for the user's domain,
// and everything above till root
- if ((_accountMgr.isNormalUser(account.getId()) || _accountMgr.isDomainAdmin(account.getId())) || account.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) {
+ if ((accountMgr.isNormalUser(account.getId()) || accountMgr.isDomainAdmin(account.getId())) || account.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) {
if (isRecursive) { // domain + all sub-domains
if (account.getType() == Account.Type.NORMAL) {
throw new InvalidParameterValueException("Only ROOT admins and Domain admins can list disk offerings with isrecursive=true");
@@ -3154,14 +3296,14 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Boolean encryptRoot = cmd.getEncryptRoot();
SearchCriteria sc = _srvOfferingJoinDao.createSearchCriteria();
- if (!_accountMgr.isRootAdmin(caller.getId()) && isSystem) {
+ if (!accountMgr.isRootAdmin(caller.getId()) && isSystem) {
throw new InvalidParameterValueException("Only ROOT admins can access system's offering");
}
// Keeping this logic consistent with domain specific zones
// if a domainId is provided, we just return the so associated with this
// domain
- if (domainId != null && !_accountMgr.isRootAdmin(caller.getId())) {
+ if (domainId != null && !accountMgr.isRootAdmin(caller.getId())) {
// check if the user's domain == so's domain || user's domain is a
// child of so's domain
if (!isPermissible(caller.getDomainId(), domainId)) {
@@ -3177,7 +3319,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
throw ex;
}
- _accountMgr.checkAccess(caller, null, true, vmInstance);
+ accountMgr.checkAccess(caller, null, true, vmInstance);
currentVmOffering = _srvOfferingDao.findByIdIncludingRemoved(vmInstance.getId(), vmInstance.getServiceOfferingId());
if (! currentVmOffering.isDynamic()) {
@@ -3202,8 +3344,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Integer vmMemory = currentVmOffering.getRamSize();
Integer vmSpeed = currentVmOffering.getSpeed();
if ((vmCpu == null || vmMemory == null || vmSpeed == null) && VirtualMachine.Type.User.equals(vmInstance.getType())) {
- UserVmVO userVmVO = _userVmDao.findById(vmId);
- _userVmDao.loadDetails(userVmVO);
+ UserVmVO userVmVO = userVmDao.findById(vmId);
+ userVmDao.loadDetails(userVmVO);
Map details = userVmVO.getDetails();
vmCpu = NumbersUtil.parseInt(details.get(ApiConstants.CPU_NUMBER), 0);
if (vmSpeed == null) {
@@ -3225,7 +3367,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
}
// boolean includePublicOfferings = false;
- if ((_accountMgr.isNormalUser(caller.getId()) || _accountMgr.isDomainAdmin(caller.getId())) || caller.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) {
+ if ((accountMgr.isNormalUser(caller.getId()) || accountMgr.isDomainAdmin(caller.getId())) || caller.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) {
// For non-root users.
if (isSystem) {
throw new InvalidParameterValueException("Only root admins can access system's offering");
@@ -3411,7 +3553,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
SearchBuilder sb = _dcJoinDao.createSearchBuilder();
if (resourceTags != null && !resourceTags.isEmpty()) {
- SearchBuilder tagSearch = _resourceTagDao.createSearchBuilder();
+ SearchBuilder tagSearch = resourceTagDao.createSearchBuilder();
for (int count = 0; count < resourceTags.size(); count++) {
tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
@@ -3455,7 +3597,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
// only list zones associated // with this domain, private zone
sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId);
- if (_accountMgr.isNormalUser(account.getId())) {
+ if (accountMgr.isNormalUser(account.getId())) {
// accountId == null (zones dedicated to a domain) or
// accountId = caller
SearchCriteria sdc = _dcJoinDao.createSearchCriteria();
@@ -3465,7 +3607,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sc.addAnd("accountId", SearchCriteria.Op.SC, sdc);
}
- } else if (_accountMgr.isNormalUser(account.getId())) {
+ } else if (accountMgr.isNormalUser(account.getId())) {
// it was decided to return all zones for the user's domain, and
// everything above till root
// list all zones belonging to this domain, and all of its
@@ -3510,7 +3652,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sdc.addAnd("id", SearchCriteria.Op.NIN, dedicatedZoneIds.toArray(new Object[dedicatedZoneIds.size()]));
}
- } else if (_accountMgr.isDomainAdmin(account.getId()) || account.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) {
+ } else if (accountMgr.isDomainAdmin(account.getId()) || account.getType() == Account.Type.RESOURCE_DOMAIN_ADMIN) {
// it was decided to return all zones for the domain admin, and
// everything above till root, as well as zones till the domain
// leaf
@@ -3658,23 +3800,34 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List permittedAccountIds = new ArrayList();
Ternary domainIdRecursiveListProject = new Ternary(cmd.getDomainId(), cmd.isRecursive(), null);
- _accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, false);
+ accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccountIds, domainIdRecursiveListProject, listAll, false);
ListProjectResourcesCriteria listProjectResourcesCriteria = domainIdRecursiveListProject.third();
List permittedAccounts = new ArrayList();
for (Long accountId : permittedAccountIds) {
- permittedAccounts.add(_accountMgr.getAccount(accountId));
+ permittedAccounts.add(accountMgr.getAccount(accountId));
}
boolean showDomr = ((templateFilter != TemplateFilter.selfexecutable) && (templateFilter != TemplateFilter.featured));
HypervisorType hypervisorType = HypervisorType.getType(cmd.getHypervisor());
+ String templateType = cmd.getTemplateType();
+ if (cmd instanceof ListVnfTemplatesCmd) {
+ if (templateType == null) {
+ templateType = TemplateType.VNF.name();
+ } else if (!TemplateType.VNF.name().equals(templateType)) {
+ throw new InvalidParameterValueException("Template type must be VNF when list VNF templates");
+ }
+ }
+ Boolean isVnf = cmd.getVnf();
+
return searchForTemplatesInternal(id, cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType,
- showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags, showRemovedTmpl, cmd.getIds(), parentTemplateId, cmd.getShowUnique());
+ showDomr, cmd.listInReadyState(), permittedAccounts, caller, listProjectResourcesCriteria, tags, showRemovedTmpl, cmd.getIds(), parentTemplateId, cmd.getShowUnique(), templateType, isVnf);
}
private Pair, Integer> searchForTemplatesInternal(Long templateId, String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Long pageSize,
Long startIndex, Long zoneId, HypervisorType hyperType, boolean showDomr, boolean onlyReady, List