Merge branch '4.19' into 4.20

This commit is contained in:
Daan Hoogland 2025-02-01 17:51:50 +01:00
commit 085bd3bda5
10 changed files with 227 additions and 130 deletions

View File

@ -19,6 +19,7 @@ package org.apache.cloudstack.api.command.user.firewall;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.cloudstack.acl.RoleType; import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand; import org.apache.cloudstack.api.APICommand;
@ -40,6 +41,7 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.IpAddress; import com.cloud.network.IpAddress;
import com.cloud.network.rules.FirewallRule; import com.cloud.network.rules.FirewallRule;
import com.cloud.user.Account; import com.cloud.user.Account;
import com.cloud.utils.StringUtils;
import com.cloud.utils.net.NetUtils; import com.cloud.utils.net.NetUtils;
@APICommand(name = "createFirewallRule", description = "Creates a firewall rule for a given IP address", responseObject = FirewallResponse.class, entityType = {FirewallRule.class}, @APICommand(name = "createFirewallRule", description = "Creates a firewall rule for a given IP address", responseObject = FirewallResponse.class, entityType = {FirewallRule.class},
@ -125,14 +127,13 @@ public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements Firewal
@Override @Override
public List<String> getSourceCidrList() { public List<String> getSourceCidrList() {
if (cidrlist != null) { if (CollectionUtils.isNotEmpty(cidrlist) && !(cidrlist.size() == 1 && StringUtils.isBlank(cidrlist.get(0)))) {
return cidrlist; return cidrlist;
} else { } else {
List<String> oneCidrList = new ArrayList<String>(); List<String> oneCidrList = new ArrayList<>();
oneCidrList.add(NetUtils.ALL_IP4_CIDRS); oneCidrList.add(NetUtils.ALL_IP4_CIDRS);
return oneCidrList; return oneCidrList;
} }
} }
// /////////////////////////////////////////////////// // ///////////////////////////////////////////////////

View File

@ -0,0 +1,91 @@
// 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.api.command.user.firewall;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.test.util.ReflectionTestUtils;
import com.cloud.utils.net.NetUtils;
@RunWith(MockitoJUnitRunner.class)
public class CreateFirewallRuleCmdTest {
private void validateAllIp4Cidr(final CreateFirewallRuleCmd cmd) {
Assert.assertTrue(CollectionUtils.isNotEmpty(cmd.getSourceCidrList()));
Assert.assertEquals(1, cmd.getSourceCidrList().size());
Assert.assertEquals(NetUtils.ALL_IP4_CIDRS, cmd.getSourceCidrList().get(0));
}
@Test
public void testGetSourceCidrList_Null() {
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
ReflectionTestUtils.setField(cmd, "cidrlist", null);
validateAllIp4Cidr(cmd);
}
@Test
public void testGetSourceCidrList_Empty() {
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
ReflectionTestUtils.setField(cmd, "cidrlist", new ArrayList<>());
validateAllIp4Cidr(cmd);
}
@Test
public void testGetSourceCidrList_NullFirstElement() {
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
List<String> list = new ArrayList<>();
list.add(null);
ReflectionTestUtils.setField(cmd, "cidrlist", list);
validateAllIp4Cidr(cmd);
}
@Test
public void testGetSourceCidrList_EmptyFirstElement() {
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
ReflectionTestUtils.setField(cmd, "cidrlist", Collections.singletonList(" "));
validateAllIp4Cidr(cmd);
}
@Test
public void testGetSourceCidrList_Valid() {
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
String cidr = "10.1.1.1/22";
ReflectionTestUtils.setField(cmd, "cidrlist", Collections.singletonList(cidr));
Assert.assertTrue(CollectionUtils.isNotEmpty(cmd.getSourceCidrList()));
Assert.assertEquals(1, cmd.getSourceCidrList().size());
Assert.assertEquals(cidr, cmd.getSourceCidrList().get(0));
}
@Test
public void testGetSourceCidrList_EmptyFirstElementButMore() {
final CreateFirewallRuleCmd cmd = new CreateFirewallRuleCmd();
String cidr = "10.1.1.1/22";
ReflectionTestUtils.setField(cmd, "cidrlist", Arrays.asList(" ", cidr));
Assert.assertTrue(CollectionUtils.isNotEmpty(cmd.getSourceCidrList()));
Assert.assertEquals(2, cmd.getSourceCidrList().size());
Assert.assertEquals(cidr, cmd.getSourceCidrList().get(1));
}
}

View File

@ -82,6 +82,9 @@ public interface NetworkOrchestrationService {
ConfigKey<Integer> NetworkLockTimeout = new ConfigKey<Integer>(Integer.class, NetworkLockTimeoutCK, "Network", "600", ConfigKey<Integer> NetworkLockTimeout = new ConfigKey<Integer>(Integer.class, NetworkLockTimeoutCK, "Network", "600",
"Lock wait timeout (seconds) while implementing network", true, Scope.Global, null); "Lock wait timeout (seconds) while implementing network", true, Scope.Global, null);
ConfigKey<String> DeniedRoutes = new ConfigKey<String>(String.class, "denied.routes", "Network", "",
"Routes that are denied, can not be used for Static Routes creation for the VPC Private Gateway", true, ConfigKey.Scope.Zone, null);
ConfigKey<String> GuestDomainSuffix = new ConfigKey<String>(String.class, GuestDomainSuffixCK, "Network", "cloud.internal", ConfigKey<String> GuestDomainSuffix = new ConfigKey<String>(String.class, GuestDomainSuffixCK, "Network", "cloud.internal",
"Default domain name for vms inside virtualized networks fronted by router", true, ConfigKey.Scope.Zone, null); "Default domain name for vms inside virtualized networks fronted by router", true, ConfigKey.Scope.Zone, null);

View File

@ -4872,7 +4872,7 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
@Override @Override
public ConfigKey<?>[] getConfigKeys() { public ConfigKey<?>[] getConfigKeys() {
return new ConfigKey<?>[]{NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, return new ConfigKey<?>[]{NetworkGcWait, NetworkGcInterval, NetworkLockTimeout, DeniedRoutes,
GuestDomainSuffix, NetworkThrottlingRate, MinVRVersion, GuestDomainSuffix, NetworkThrottlingRate, MinVRVersion,
PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RollingRestartEnabled, PromiscuousMode, MacAddressChanges, ForgedTransmits, MacLearning, RollingRestartEnabled,
TUNGSTEN_ENABLED, NSX_ENABLED }; TUNGSTEN_ENABLED, NSX_ENABLED };

View File

@ -61,6 +61,7 @@ import com.cloud.org.Managed;
import com.cloud.resource.ResourceState; import com.cloud.resource.ResourceState;
import com.cloud.utils.DateUtil; import com.cloud.utils.DateUtil;
import com.cloud.utils.Pair; import com.cloud.utils.Pair;
import com.cloud.utils.StringUtils;
import com.cloud.utils.db.Attribute; import com.cloud.utils.db.Attribute;
import com.cloud.utils.db.DB; import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter; import com.cloud.utils.db.Filter;
@ -80,13 +81,13 @@ import com.cloud.utils.exception.CloudRuntimeException;
@TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1) @TableGenerator(name = "host_req_sq", table = "op_host", pkColumnName = "id", valueColumnName = "sequence", allocationSize = 1)
public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao { public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao { //FIXME: , ExternalIdDao {
private static final String LIST_HOST_IDS_BY_COMPUTETAGS = "SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count " private static final String LIST_HOST_IDS_BY_HOST_TAGS = "SELECT filtered.host_id, COUNT(filtered.tag) AS tag_count "
+ "FROM (SELECT host_id, tag, is_tag_a_rule FROM host_tags GROUP BY host_id,tag) AS filtered " + "FROM (SELECT host_id, tag, is_tag_a_rule FROM host_tags GROUP BY host_id,tag,is_tag_a_rule) AS filtered "
+ "WHERE tag IN(%s) AND is_tag_a_rule = 0 " + "WHERE tag IN (%s) AND (is_tag_a_rule = 0 OR is_tag_a_rule IS NULL) "
+ "GROUP BY host_id " + "GROUP BY host_id "
+ "HAVING tag_count = %s "; + "HAVING tag_count = %s ";
private static final String SEPARATOR = ","; private static final String SEPARATOR = ",";
private static final String LIST_CLUSTERID_FOR_HOST_TAG = "select distinct cluster_id from host join ( %s ) AS selected_hosts ON host.id = selected_hosts.host_id"; private static final String LIST_CLUSTER_IDS_FOR_HOST_TAGS = "select distinct cluster_id from host join ( %s ) AS selected_hosts ON host.id = selected_hosts.host_id";
private static final String GET_HOSTS_OF_ACTIVE_VMS = "select h.id " + private static final String GET_HOSTS_OF_ACTIVE_VMS = "select h.id " +
"from vm_instance vm " + "from vm_instance vm " +
"join host h on (vm.host_id=h.id) " + "join host h on (vm.host_id=h.id) " +
@ -625,9 +626,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
sb.append(" "); sb.append(" ");
} }
if (logger.isTraceEnabled()) { logger.trace("Following hosts got reset: {}", sb);
logger.trace("Following hosts got reset: " + sb.toString());
}
} }
/* /*
@ -637,8 +636,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
SearchCriteria<Long> sc = ClustersOwnedByMSSearch.create(); SearchCriteria<Long> sc = ClustersOwnedByMSSearch.create();
sc.setParameters("server", managementServerId); sc.setParameters("server", managementServerId);
List<Long> clusters = customSearch(sc, null); return customSearch(sc, null);
return clusters;
} }
/* /*
@ -648,13 +646,11 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
SearchCriteria<Long> sc = ClustersForHostsNotOwnedByAnyMSSearch.create(); SearchCriteria<Long> sc = ClustersForHostsNotOwnedByAnyMSSearch.create();
sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed); sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed);
List<Long> clusters = customSearch(sc, null); return customSearch(sc, null);
return clusters;
} }
/** /**
* This determines if hosts belonging to cluster(@clusterId) are up for grabs * This determines if hosts belonging to cluster(@clusterId) are up for grabs
*
* This is used for handling following cases: * This is used for handling following cases:
* 1. First host added in cluster * 1. First host added in cluster
* 2. During MS restart all hosts in a cluster are without any MS * 2. During MS restart all hosts in a cluster are without any MS
@ -664,9 +660,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
sc.setParameters("cluster", clusterId); sc.setParameters("cluster", clusterId);
List<HostVO> hosts = search(sc, null); List<HostVO> hosts = search(sc, null);
boolean ownCluster = (hosts == null || hosts.size() == 0); return (hosts == null || hosts.isEmpty());
return ownCluster;
} }
@Override @Override
@ -683,14 +677,14 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
logger.debug("Completed resetting hosts suitable for reconnect"); logger.debug("Completed resetting hosts suitable for reconnect");
} }
List<HostVO> assignedHosts = new ArrayList<HostVO>(); List<HostVO> assignedHosts = new ArrayList<>();
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("Acquiring hosts for clusters already owned by this management server"); logger.debug("Acquiring hosts for clusters already owned by this management server");
} }
List<Long> clusters = findClustersOwnedByManagementServer(managementServerId); List<Long> clusters = findClustersOwnedByManagementServer(managementServerId);
txn.start(); txn.start();
if (clusters.size() > 0) { if (!clusters.isEmpty()) {
// handle clusters already owned by @managementServerId // handle clusters already owned by @managementServerId
SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create(); SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
sc.setParameters("lastPinged", lastPingSecondsAfter); sc.setParameters("lastPinged", lastPingSecondsAfter);
@ -705,13 +699,9 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
sb.append(host.getId()); sb.append(host.getId());
sb.append(" "); sb.append(" ");
} }
if (logger.isTraceEnabled()) { logger.trace("Following hosts got acquired for clusters already owned: {}", sb);
logger.trace("Following hosts got acquired for clusters already owned: " + sb.toString());
}
}
if (logger.isDebugEnabled()) {
logger.debug("Completed acquiring hosts for clusters already owned by this management server");
} }
logger.debug("Completed acquiring hosts for clusters already owned by this management server");
if (assignedHosts.size() < limit) { if (assignedHosts.size() < limit) {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
@ -723,7 +713,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
if (clusters.size() > limit) { if (clusters.size() > limit) {
updatedClusters = clusters.subList(0, limit.intValue()); updatedClusters = clusters.subList(0, limit.intValue());
} }
if (updatedClusters.size() > 0) { if (!updatedClusters.isEmpty()) {
SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create(); SearchCriteria<HostVO> sc = UnmanagedDirectConnectSearch.create();
sc.setParameters("lastPinged", lastPingSecondsAfter); sc.setParameters("lastPinged", lastPingSecondsAfter);
sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed); sc.setJoinParameters("ClusterManagedSearch", "managed", Managed.ManagedState.Managed);
@ -731,10 +721,10 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
List<HostVO> unmanagedHosts = lockRows(sc, null, true); List<HostVO> unmanagedHosts = lockRows(sc, null, true);
// group hosts based on cluster // group hosts based on cluster
Map<Long, List<HostVO>> hostMap = new HashMap<Long, List<HostVO>>(); Map<Long, List<HostVO>> hostMap = new HashMap<>();
for (HostVO host : unmanagedHosts) { for (HostVO host : unmanagedHosts) {
if (hostMap.get(host.getClusterId()) == null) { if (hostMap.get(host.getClusterId()) == null) {
hostMap.put(host.getClusterId(), new ArrayList<HostVO>()); hostMap.put(host.getClusterId(), new ArrayList<>());
} }
hostMap.get(host.getClusterId()).add(host); hostMap.get(host.getClusterId()).add(host);
} }
@ -755,13 +745,9 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
break; break;
} }
} }
if (logger.isTraceEnabled()) { logger.trace("Following hosts got acquired from newly owned clusters: {}", sb);
logger.trace("Following hosts got acquired from newly owned clusters: " + sb.toString());
}
}
if (logger.isDebugEnabled()) {
logger.debug("Completed acquiring hosts for clusters not owned by any management server");
} }
logger.debug("Completed acquiring hosts for clusters not owned by any management server");
} }
txn.commit(); txn.commit();
@ -816,6 +802,15 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
@Override @Override
public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag) { public List<HostVO> listByHostTag(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTag) {
return listHostsWithOrWithoutHostTags(type, clusterId, podId, dcId, hostTag, true);
}
private List<HostVO> listHostsWithOrWithoutHostTags(Host.Type type, Long clusterId, Long podId, Long dcId, String hostTags, boolean withHostTags) {
if (StringUtils.isEmpty(hostTags)) {
logger.debug("Host tags not specified, to list hosts");
return new ArrayList<>();
}
SearchBuilder<HostVO> hostSearch = createSearchBuilder(); SearchBuilder<HostVO> hostSearch = createSearchBuilder();
HostVO entity = hostSearch.entity(); HostVO entity = hostSearch.entity();
hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ); hostSearch.and("type", entity.getType(), SearchCriteria.Op.EQ);
@ -826,7 +821,9 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
hostSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ); hostSearch.and("resourceState", entity.getResourceState(), SearchCriteria.Op.EQ);
SearchCriteria<HostVO> sc = hostSearch.create(); SearchCriteria<HostVO> sc = hostSearch.create();
sc.setParameters("type", type.toString()); if (type != null) {
sc.setParameters("type", type.toString());
}
if (podId != null) { if (podId != null) {
sc.setParameters("pod", podId); sc.setParameters("pod", podId);
} }
@ -839,27 +836,38 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
sc.setParameters("status", Status.Up.toString()); sc.setParameters("status", Status.Up.toString());
sc.setParameters("resourceState", ResourceState.Enabled.toString()); sc.setParameters("resourceState", ResourceState.Enabled.toString());
List<HostVO> tmpHosts = listBy(sc); List<HostVO> upAndEnabledHosts = listBy(sc);
List<HostVO> correctHostsByHostTags = new ArrayList(); if (CollectionUtils.isEmpty(upAndEnabledHosts)) {
List<Long> hostIdsByComputeOffTags = findHostByComputeOfferings(hostTag); return new ArrayList<>();
}
tmpHosts.forEach((host) -> { if(hostIdsByComputeOffTags.contains(host.getId())) correctHostsByHostTags.add(host);}); List<Long> hostIdsByHostTags = findHostIdsByHostTags(hostTags);
if (CollectionUtils.isEmpty(hostIdsByHostTags)) {
return withHostTags ? new ArrayList<>() : upAndEnabledHosts;
}
return correctHostsByHostTags; if (withHostTags) {
List<HostVO> upAndEnabledHostsWithHostTags = new ArrayList<>();
upAndEnabledHosts.forEach((host) -> { if (hostIdsByHostTags.contains(host.getId())) upAndEnabledHostsWithHostTags.add(host);});
return upAndEnabledHostsWithHostTags;
} else {
List<HostVO> upAndEnabledHostsWithoutHostTags = new ArrayList<>();
upAndEnabledHosts.forEach((host) -> { if (!hostIdsByHostTags.contains(host.getId())) upAndEnabledHostsWithoutHostTags.add(host);});
return upAndEnabledHostsWithoutHostTags;
}
} }
@Override @Override
public List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag) { public List<HostVO> listAllUpAndEnabledNonHAHosts(Type type, Long clusterId, Long podId, long dcId, String haTag) {
if (StringUtils.isNotEmpty(haTag)) {
return listHostsWithOrWithoutHostTags(type, clusterId, podId, dcId, haTag, false);
}
SearchBuilder<HostTagVO> hostTagSearch = _hostTagsDao.createSearchBuilder(); SearchBuilder<HostTagVO> hostTagSearch = _hostTagsDao.createSearchBuilder();
hostTagSearch.and(); hostTagSearch.and();
hostTagSearch.op("isTagARule", hostTagSearch.entity().getIsTagARule(), Op.EQ); hostTagSearch.op("isTagARule", hostTagSearch.entity().getIsTagARule(), Op.EQ);
hostTagSearch.or("tagDoesNotExist", hostTagSearch.entity().getIsTagARule(), Op.NULL); hostTagSearch.or("tagDoesNotExist", hostTagSearch.entity().getIsTagARule(), Op.NULL);
hostTagSearch.cp(); hostTagSearch.cp();
if (haTag != null && !haTag.isEmpty()) {
hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.NEQ);
hostTagSearch.or("tagNull", hostTagSearch.entity().getTag(), SearchCriteria.Op.NULL);
hostTagSearch.cp();
}
SearchBuilder<HostVO> hostSearch = createSearchBuilder(); SearchBuilder<HostVO> hostSearch = createSearchBuilder();
@ -870,18 +878,12 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
hostSearch.and("status", hostSearch.entity().getStatus(), SearchCriteria.Op.EQ); hostSearch.and("status", hostSearch.entity().getStatus(), SearchCriteria.Op.EQ);
hostSearch.and("resourceState", hostSearch.entity().getResourceState(), SearchCriteria.Op.EQ); hostSearch.and("resourceState", hostSearch.entity().getResourceState(), SearchCriteria.Op.EQ);
hostSearch.join("hostTagSearch", hostTagSearch, hostSearch.entity().getId(), hostTagSearch.entity().getHostId(), JoinBuilder.JoinType.LEFTOUTER); hostSearch.join("hostTagSearch", hostTagSearch, hostSearch.entity().getId(), hostTagSearch.entity().getHostId(), JoinBuilder.JoinType.LEFTOUTER);
SearchCriteria<HostVO> sc = hostSearch.create(); SearchCriteria<HostVO> sc = hostSearch.create();
sc.setJoinParameters("hostTagSearch", "isTagARule", false); sc.setJoinParameters("hostTagSearch", "isTagARule", false);
if (haTag != null && !haTag.isEmpty()) {
sc.setJoinParameters("hostTagSearch", "tag", haTag);
}
if (type != null) { if (type != null) {
sc.setParameters("type", type); sc.setParameters("type", type);
} }
@ -921,12 +923,12 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
@DB @DB
@Override @Override
public List<HostVO> findLostHosts(long timeout) { public List<HostVO> findLostHosts(long timeout) {
List<HostVO> result = new ArrayList<HostVO>(); List<HostVO> result = new ArrayList<>();
String sql = "select h.id from host h left join cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;"; String sql = "select h.id from host h left join cluster c on h.cluster_id=c.id where h.mgmt_server_id is not null and h.last_ping < ? and h.status in ('Up', 'Updating', 'Disconnected', 'Connecting') and h.type not in ('ExternalFirewall', 'ExternalLoadBalancer', 'TrafficMonitor', 'SecondaryStorage', 'LocalSecondaryStorage', 'L2Networking') and (h.cluster_id is null or c.managed_state = 'Managed') ;";
try (TransactionLegacy txn = TransactionLegacy.currentTxn(); try (TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = txn.prepareStatement(sql);) { PreparedStatement pstmt = txn.prepareStatement(sql)) {
pstmt.setLong(1, timeout); pstmt.setLong(1, timeout);
try (ResultSet rs = pstmt.executeQuery();) { try (ResultSet rs = pstmt.executeQuery()) {
while (rs.next()) { while (rs.next()) {
long id = rs.getLong(1); //ID column long id = rs.getLong(1); //ID column
result.add(findById(id)); result.add(findById(id));
@ -959,7 +961,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = host.getGpuGroupDetails(); HashMap<String, HashMap<String, VgpuTypesInfo>> groupDetails = host.getGpuGroupDetails();
if (groupDetails != null) { if (groupDetails != null) {
// Create/Update GPU group entries // Create/Update GPU group entries
_hostGpuGroupsDao.persist(host.getId(), new ArrayList<String>(groupDetails.keySet())); _hostGpuGroupsDao.persist(host.getId(), new ArrayList<>(groupDetails.keySet()));
// Create/Update VGPU types entries // Create/Update VGPU types entries
_vgpuTypesDao.persist(host.getId(), groupDetails); _vgpuTypesDao.persist(host.getId(), groupDetails);
} }
@ -1002,7 +1004,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
boolean persisted = super.update(hostId, host); boolean persisted = super.update(hostId, host);
if (!persisted) { if (!persisted) {
return persisted; return false;
} }
saveDetails(host); saveDetails(host);
@ -1011,7 +1013,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
txn.commit(); txn.commit();
return persisted; return true;
} }
@Override @Override
@ -1022,11 +1024,10 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
+ "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid " + "select h.data_center_id, h.type, count(*) as count from host as h INNER JOIN mshost as m ON h.mgmt_server_id=m.msid "
+ "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type"; + "where h.status='Up' and h.type='Routing' and m.last_update > ? " + "group by h.data_center_id, h.type) as t " + "ORDER by t.data_center_id, t.type";
ArrayList<RunningHostCountInfo> l = new ArrayList<RunningHostCountInfo>(); ArrayList<RunningHostCountInfo> l = new ArrayList<>();
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
; PreparedStatement pstmt;
PreparedStatement pstmt = null;
try { try {
pstmt = txn.prepareAutoCloseStatement(sql); pstmt = txn.prepareAutoCloseStatement(sql);
String gmtCutTime = DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime); String gmtCutTime = DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutTime);
@ -1050,9 +1051,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
@Override @Override
public long getNextSequence(long hostId) { public long getNextSequence(long hostId) {
if (logger.isTraceEnabled()) { logger.trace("getNextSequence(), hostId: {}", hostId);
logger.trace("getNextSequence(), hostId: " + hostId);
}
TableGenerator tg = _tgs.get("host_req_sq"); TableGenerator tg = _tgs.get("host_req_sq");
assert tg != null : "how can this be wrong!"; assert tg != null : "how can this be wrong!";
@ -1121,31 +1120,30 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
HostVO ho = findById(host.getId()); HostVO ho = findById(host.getId());
assert ho != null : "How how how? : " + host.getId(); assert ho != null : "How how how? : " + host.getId();
// TODO handle this if(debug){}else{log.debug} it makes no sense
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
String str = "Unable to update host for event:" + event +
StringBuilder str = new StringBuilder("Unable to update host for event:").append(event.toString()); ". Name=" + host.getName() +
str.append(". Name=").append(host.getName()); "; New=[status=" + newStatus + ":msid=" + (newStatus.lostConnection() ? "null" : host.getManagementServerId()) +
str.append("; New=[status=").append(newStatus.toString()).append(":msid=").append(newStatus.lostConnection() ? "null" : host.getManagementServerId()) ":lastpinged=" + host.getLastPinged() + "]" +
.append(":lastpinged=").append(host.getLastPinged()).append("]"); "; Old=[status=" + oldStatus.toString() + ":msid=" + host.getManagementServerId() + ":lastpinged=" + oldPingTime +
str.append("; Old=[status=").append(oldStatus.toString()).append(":msid=").append(host.getManagementServerId()).append(":lastpinged=").append(oldPingTime) "]" +
.append("]"); "; DB=[status=" + vo.getStatus().toString() + ":msid=" + vo.getManagementServerId() + ":lastpinged=" + vo.getLastPinged() +
str.append("; DB=[status=").append(vo.getStatus().toString()).append(":msid=").append(vo.getManagementServerId()).append(":lastpinged=").append(vo.getLastPinged()) ":old update count=" + oldUpdateCount + "]";
.append(":old update count=").append(oldUpdateCount).append("]"); logger.debug(str);
logger.debug(str.toString());
} else { } else {
StringBuilder msg = new StringBuilder("Agent status update: ["); String msg = "Agent status update: [" + "id = " + host.getId() +
msg.append("id = " + host.getId()); "; name = " + host.getName() +
msg.append("; name = " + host.getName()); "; old status = " + oldStatus +
msg.append("; old status = " + oldStatus); "; event = " + event +
msg.append("; event = " + event); "; new status = " + newStatus +
msg.append("; new status = " + newStatus); "; old update count = " + oldUpdateCount +
msg.append("; old update count = " + oldUpdateCount); "; new update count = " + newUpdateCount + "]";
msg.append("; new update count = " + newUpdateCount + "]"); logger.debug(msg);
logger.debug(msg.toString());
} }
if (ho.getState() == newStatus) { if (ho.getState() == newStatus) {
logger.debug("Host " + ho.getName() + " state has already been updated to " + newStatus); logger.debug("Host {} state has already been updated to {}", ho.getName(), newStatus);
return true; return true;
} }
} }
@ -1171,25 +1169,24 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
int result = update(ub, sc, null); int result = update(ub, sc, null);
assert result <= 1 : "How can this update " + result + " rows? "; assert result <= 1 : "How can this update " + result + " rows? ";
// TODO handle this if(debug){}else{log.debug} it makes no sense
if (logger.isDebugEnabled() && result == 0) { if (logger.isDebugEnabled() && result == 0) {
HostVO ho = findById(host.getId()); HostVO ho = findById(host.getId());
assert ho != null : "How how how? : " + host.getId(); assert ho != null : "How how how? : " + host.getId();
StringBuilder str = new StringBuilder("Unable to update resource state: ["); String str = "Unable to update resource state: [" + "m = " + host.getId() +
str.append("m = " + host.getId()); "; name = " + host.getName() +
str.append("; name = " + host.getName()); "; old state = " + oldState +
str.append("; old state = " + oldState); "; event = " + event +
str.append("; event = " + event); "; new state = " + newState + "]";
str.append("; new state = " + newState + "]"); logger.debug(str);
logger.debug(str.toString());
} else { } else {
StringBuilder msg = new StringBuilder("Resource state update: ["); String msg = "Resource state update: [" + "id = " + host.getId() +
msg.append("id = " + host.getId()); "; name = " + host.getName() +
msg.append("; name = " + host.getName()); "; old state = " + oldState +
msg.append("; old state = " + oldState); "; event = " + event +
msg.append("; event = " + event); "; new state = " + newState + "]";
msg.append("; new state = " + newState + "]"); logger.debug(msg);
logger.debug(msg.toString());
} }
return result > 0; return result > 0;
@ -1364,7 +1361,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
Filter orderByFilter = new Filter(HostVO.class, "created", true, null, null); Filter orderByFilter = new Filter(HostVO.class, "created", true, null, null);
List<HostVO> hosts = search(sc, orderByFilter, null, false); List<HostVO> hosts = search(sc, orderByFilter, null, false);
if (hosts != null && hosts.size() > 0) { if (hosts != null && !hosts.isEmpty()) {
return hosts.get(0); return hosts.get(0);
} }
@ -1407,19 +1404,19 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
} }
@Override @Override
public List<Long> listClustersByHostTag(String computeOfferingTags) { public List<Long> listClustersByHostTag(String hostTags) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
String sql = this.LIST_CLUSTERID_FOR_HOST_TAG; String selectStmtToListClusterIdsByHostTags = LIST_CLUSTER_IDS_FOR_HOST_TAGS;
PreparedStatement pstmt = null; PreparedStatement pstmt;
List<Long> result = new ArrayList(); List<Long> result = new ArrayList<>();
List<String> tags = Arrays.asList(computeOfferingTags.split(this.SEPARATOR)); List<String> tags = Arrays.asList(hostTags.split(SEPARATOR));
String subselect = getHostIdsByComputeTags(tags); String selectStmtToListHostIdsByHostTags = getSelectStmtToListHostIdsByHostTags(tags);
sql = String.format(sql, subselect); selectStmtToListClusterIdsByHostTags = String.format(selectStmtToListClusterIdsByHostTags, selectStmtToListHostIdsByHostTags);
try { try {
pstmt = txn.prepareStatement(sql); pstmt = txn.prepareStatement(selectStmtToListClusterIdsByHostTags);
for(int i = 0; i < tags.size(); i++){ for (int i = 0; i < tags.size(); i++){
pstmt.setString(i+1, tags.get(i)); pstmt.setString(i+1, tags.get(i));
} }
@ -1430,20 +1427,20 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
pstmt.close(); pstmt.close();
return result; return result;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + sql, e); throw new CloudRuntimeException("DB Exception on: " + selectStmtToListClusterIdsByHostTags, e);
} }
} }
private List<Long> findHostByComputeOfferings(String computeOfferingTags){ private List<Long> findHostIdsByHostTags(String hostTags){
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; PreparedStatement pstmt;
List<Long> result = new ArrayList(); List<Long> result = new ArrayList<>();
List<String> tags = Arrays.asList(computeOfferingTags.split(this.SEPARATOR)); List<String> tags = Arrays.asList(hostTags.split(SEPARATOR));
String select = getHostIdsByComputeTags(tags); String selectStmtToListHostIdsByHostTags = getSelectStmtToListHostIdsByHostTags(tags);
try { try {
pstmt = txn.prepareStatement(select); pstmt = txn.prepareStatement(selectStmtToListHostIdsByHostTags);
for(int i = 0; i < tags.size(); i++){ for (int i = 0; i < tags.size(); i++){
pstmt.setString(i+1, tags.get(i)); pstmt.setString(i+1, tags.get(i));
} }
@ -1454,7 +1451,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
pstmt.close(); pstmt.close();
return result; return result;
} catch (SQLException e) { } catch (SQLException e) {
throw new CloudRuntimeException("DB Exception on: " + select, e); throw new CloudRuntimeException("DB Exception on: " + selectStmtToListHostIdsByHostTags, e);
} }
} }
@ -1504,16 +1501,16 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return result; return result;
} }
private String getHostIdsByComputeTags(List<String> offeringTags){ private String getSelectStmtToListHostIdsByHostTags(List<String> hostTags){
List<String> questionMarks = new ArrayList(); List<String> questionMarks = new ArrayList<>();
offeringTags.forEach((tag) -> { questionMarks.add("?"); }); hostTags.forEach((tag) -> questionMarks.add("?"));
return String.format(this.LIST_HOST_IDS_BY_COMPUTETAGS, String.join(",", questionMarks),questionMarks.size()); return String.format(LIST_HOST_IDS_BY_HOST_TAGS, String.join(SEPARATOR, questionMarks), questionMarks.size());
} }
@Override @Override
public List<HostVO> listHostsWithActiveVMs(long offeringId) { public List<HostVO> listHostsWithActiveVMs(long offeringId) {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();
PreparedStatement pstmt = null; PreparedStatement pstmt;
List<HostVO> result = new ArrayList<>(); List<HostVO> result = new ArrayList<>();
StringBuilder sql = new StringBuilder(GET_HOSTS_OF_ACTIVE_VMS); StringBuilder sql = new StringBuilder(GET_HOSTS_OF_ACTIVE_VMS);
try { try {
@ -1540,7 +1537,7 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
@Override @Override
public List<String> listOrderedHostsHypervisorVersionsInDatacenter(long datacenterId, HypervisorType hypervisorType) { public List<String> listOrderedHostsHypervisorVersionsInDatacenter(long datacenterId, HypervisorType hypervisorType) {
PreparedStatement pstmt = null; PreparedStatement pstmt;
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
try { try {
TransactionLegacy txn = TransactionLegacy.currentTxn(); TransactionLegacy txn = TransactionLegacy.currentTxn();

View File

@ -1774,6 +1774,10 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService, C
throwInvalidIdException("Network offering with specified id doesn't support adding multiple ip ranges", ntwkOff.getUuid(), NETWORK_OFFERING_ID); throwInvalidIdException("Network offering with specified id doesn't support adding multiple ip ranges", ntwkOff.getUuid(), NETWORK_OFFERING_ID);
} }
if (GuestType.Shared == ntwkOff.getGuestType() && !ntwkOff.isSpecifyVlan() && Objects.isNull(associatedNetworkId)) {
throw new CloudRuntimeException("Associated network must be provided when creating Shared networks when specifyVlan is false");
}
Pair<Integer, Integer> interfaceMTUs = validateMtuConfig(publicMtu, privateMtu, zone.getId()); Pair<Integer, Integer> interfaceMTUs = validateMtuConfig(publicMtu, privateMtu, zone.getId());
mtuCheckForVpcNetwork(vpcId, interfaceMTUs, publicMtu, privateMtu); mtuCheckForVpcNetwork(vpcId, interfaceMTUs, publicMtu, privateMtu);

View File

@ -2973,7 +2973,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
} }
// 2) CIDR should be outside of link-local cidr // 2) CIDR should be outside of link-local cidr
if (NetUtils.isNetworksOverlap(vpc.getCidr(), NetUtils.getLinkLocalCIDR())) { if (NetUtils.isNetworksOverlap(cidr, NetUtils.getLinkLocalCIDR())) {
throw new InvalidParameterValueException("CIDR should be outside of link local cidr " + NetUtils.getLinkLocalCIDR()); throw new InvalidParameterValueException("CIDR should be outside of link local cidr " + NetUtils.getLinkLocalCIDR());
} }
@ -3002,7 +3002,7 @@ public class VpcManagerImpl extends ManagerBase implements VpcManager, VpcProvis
} }
protected boolean isCidrDenylisted(final String cidr, final long zoneId) { protected boolean isCidrDenylisted(final String cidr, final long zoneId) {
final String routesStr = NetworkOrchestrationService.GuestDomainSuffix.valueIn(zoneId); final String routesStr = NetworkOrchestrationService.DeniedRoutes.valueIn(zoneId);
if (routesStr != null && !routesStr.isEmpty()) { if (routesStr != null && !routesStr.isEmpty()) {
final String[] cidrDenyList = routesStr.split(","); final String[] cidrDenyList = routesStr.split(",");

View File

@ -1924,7 +1924,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
final String haTag = _haMgr.getHaTag(); final String haTag = _haMgr.getHaTag();
SearchBuilder<HostTagVO> hostTagSearch = null; SearchBuilder<HostTagVO> hostTagSearch = null;
if (haHosts != null && haTag != null && !haTag.isEmpty()) { if (haHosts != null && StringUtils.isNotEmpty(haTag)) {
hostTagSearch = _hostTagsDao.createSearchBuilder(); hostTagSearch = _hostTagsDao.createSearchBuilder();
if ((Boolean)haHosts) { if ((Boolean)haHosts) {
hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.EQ); hostTagSearch.and().op("tag", hostTagSearch.entity().getTag(), SearchCriteria.Op.EQ);
@ -1985,7 +1985,7 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
sc.setParameters("resourceState", resourceState); sc.setParameters("resourceState", resourceState);
} }
if (haHosts != null && haTag != null && !haTag.isEmpty()) { if (haHosts != null && StringUtils.isNotEmpty(haTag)) {
sc.setJoinParameters("hostTagSearch", "tag", haTag); sc.setJoinParameters("hostTagSearch", "tag", haTag);
} }

View File

@ -219,8 +219,6 @@ public class FirstFitPlannerTest {
} }
private List<Long> initializeForClusterListBasedOnHostTag(ServiceOffering offering) { private List<Long> initializeForClusterListBasedOnHostTag(ServiceOffering offering) {
when(offering.getHostTag()).thenReturn("hosttag1"); when(offering.getHostTag()).thenReturn("hosttag1");
initializeForClusterThresholdDisabled(); initializeForClusterThresholdDisabled();
List<Long> matchingClusters = new ArrayList<>(); List<Long> matchingClusters = new ArrayList<>();

View File

@ -457,6 +457,9 @@ export default {
addRule () { addRule () {
if (this.loading) return if (this.loading) return
this.loading = true this.loading = true
if (this.newRule.cidrlist == null || this.newRule.cidrlist.trim?.() === '') {
delete this.newRule.cidrlist
}
api('createFirewallRule', { ...this.newRule }).then(response => { api('createFirewallRule', { ...this.newRule }).then(response => {
this.$pollJob({ this.$pollJob({
jobId: response.createfirewallruleresponse.jobid, jobId: response.createfirewallruleresponse.jobid,