Skip to content

Support network-scope settings and add setting to override vr service offering #6918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3904cbe
Added a network-scope setting and the possibility to override the rou…
Nov 23, 2022
e74a970
As customer I want to have more VR resource per network (via network.…
Nov 23, 2022
ad7f53b
Remove hard coded scope names
soreana Dec 13, 2022
acb3cf9
Apply suggestions @stephankruggg code review.
soreana Dec 30, 2022
ad3210e
Add missing import statements.
Dec 30, 2022
af769d3
Revert unnecessary line changes.
Apr 3, 2023
3ce2647
Removed unused import.
Apr 3, 2023
1c0e3b2
Removed NetworkDetailsDao from ChildTestConfiguration.java
Apr 4, 2023
8fa372b
Added ui tab for network scope settings.
Apr 11, 2023
92c1e35
Added missing methods after rebase.
May 19, 2023
d63dcef
Remove tailing space.
May 22, 2023
11bd5bd
Apply suggestions from code review by @dahn (DaanHoogland)
soreana May 23, 2023
cdec929
Fix build issue.
Oct 16, 2023
2984d92
Fix conflict.
Oct 16, 2023
aec06ab
Fix end of file lint error.
Oct 16, 2023
8c47508
Update parameter descriptions and added since.
Oct 19, 2023
89eae58
Remove unnecessary ConfigKey<> from the initialization.
Oct 19, 2023
1c84b34
Replace findDetails with listDetailsKeyPair.
Oct 19, 2023
baf242e
Remove unused import.
Oct 19, 2023
bff1d5d
Added a network-scope setting and the possibility to override the rou…
Nov 23, 2022
67c437f
As customer I want to have more VR resource per network (via network.…
Nov 23, 2022
9bfd4e6
Remove hard coded scope names
soreana Dec 13, 2022
f95e7fe
Apply suggestions @stephankruggg code review.
soreana Dec 30, 2022
3b05ef6
Add missing import statements.
Dec 30, 2022
735783d
Revert unnecessary line changes.
Apr 3, 2023
6a110a8
Removed unused import.
Apr 3, 2023
b952128
Removed NetworkDetailsDao from ChildTestConfiguration.java
Apr 4, 2023
e002984
Added ui tab for network scope settings.
Apr 11, 2023
a6e74a7
Added missing methods after rebase.
May 19, 2023
d0e6575
Remove tailing space.
May 22, 2023
ea234b7
Apply suggestions from code review by @dahn (DaanHoogland)
soreana May 23, 2023
1593e36
Fix build issue.
Oct 16, 2023
28381fc
Fix conflict.
Oct 16, 2023
91734cf
Fix end of file lint error.
Oct 16, 2023
ae8b583
Update parameter descriptions and added since.
Oct 19, 2023
d956c24
Remove unnecessary ConfigKey<> from the initialization.
Oct 19, 2023
24d341d
Replace findDetails with listDetailsKeyPair.
Oct 19, 2023
bc3f204
Remove unused import.
Oct 19, 2023
aec9305
Merge branch 'main' into override-vr-service-offering
benj-n May 7, 2024
37bc54b
Fix build issue
benj-n May 8, 2024
8d98604
Merge branch 'override-vr-service-offering' of github.com:LeaseWeb/cl…
benj-n May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
Expand Down Expand Up @@ -103,6 +104,13 @@
@Parameter(name = ApiConstants.PARENT, type = CommandType.STRING, description = "lists configuration by parent name (primarily used for UI)", since = "4.18.0")
private String parentName;

@Parameter(name = ApiConstants.NETWORK_ID,
type = CommandType.UUID,
entityType = NetworkResponse.class,
description = "the ID of the Network to list the parameter value for corresponding network",
since = "4.18.0")
private Long networkId;

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
Expand Down Expand Up @@ -159,6 +167,10 @@
return super.getPageSize();
}

public Long getNetworkId() {
return networkId;
}

@Override
public Long getPageSizeVal() {
Long defaultPageSize = 500L;
Expand Down Expand Up @@ -200,6 +212,9 @@
if (getImageStoreId() != null){
cfgResponse.setScope("imagestore");
}
if (getNetworkId() != null) {
cfgResponse.setScope("network");

Check warning on line 216 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/ListCfgsByCmd.java#L216

Added line #L216 was not covered by tests
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.DomainResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
Expand Down Expand Up @@ -84,6 +85,13 @@
description = "the ID of the Image Store to reset the parameter value for corresponding image store")
private Long imageStoreId;

@Parameter(name = ApiConstants.NETWORK_ID,
type = CommandType.UUID,
entityType = NetworkResponse.class,
description = "the ID of the Network to reset the parameter value for corresponding network",
since = "4.18.0")
private Long networkId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -116,6 +124,10 @@
return imageStoreId;
}

public Long getNetworkId() {
return networkId;
}

Check warning on line 129 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java#L127-L129

Added lines #L127 - L129 were not covered by tests

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -149,6 +161,9 @@
if (getImageStoreId() != null) {
response.setScope(ConfigKey.Scope.ImageStore.name());
}
if (getNetworkId() != null) {
response.setScope(ConfigKey.Scope.Network.name());

Check warning on line 165 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/ResetCfgCmd.java#L165

Added line #L165 was not covered by tests
}
response.setValue(cfg.second());
this.setResponseObject(response);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.cloudstack.api.response.ClusterResponse;
import org.apache.cloudstack.api.response.ConfigurationResponse;
import org.apache.cloudstack.api.response.ImageStoreResponse;
import org.apache.cloudstack.api.response.NetworkResponse;
import org.apache.cloudstack.api.response.StoragePoolResponse;
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
Expand Down Expand Up @@ -88,6 +89,13 @@
validations = ApiArgValidator.PositiveNumber)
private Long imageStoreId;

@Parameter(name = ApiConstants.NETWORK_ID,
type = CommandType.UUID,
entityType = NetworkResponse.class,
description = "the ID of the Network to update the parameter value for corresponding network",
since = "4.18.0")
private Long networkId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -128,6 +136,10 @@
return imageStoreId;
}

public Long getNetworkId() {
return networkId;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -193,6 +205,9 @@
if (getDomainId() != null) {
response.setScope("domain");
}
if (getNetworkId() != null) {
response.setScope("network");

Check warning on line 209 in api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/command/admin/config/UpdateCfgCmd.java#L209

Added line #L209 was not covered by tests
}
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,24 @@
// under the License.
package com.cloud.network.dao;

import java.util.Map;
import java.util.List;

import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;

import com.cloud.utils.db.GenericDao;

public interface NetworkDetailsDao extends GenericDao<NetworkDetailVO, Long>, ResourceDetailsDao<NetworkDetailVO> {

boolean isNetworkUsageHidden(long networkId);

void persist(long networkId, Map<String, String> details);

NetworkDetailVO findDetail(long networkId, String name);

List<NetworkDetailVO> listDetailsByName(String name);

void deleteDetails(long networkId);

void update(long networkId, Map<String, String> details);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,31 @@

import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;

import java.util.List;
import java.util.Map;

import org.apache.cloudstack.framework.config.ConfigKey;
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
import org.apache.cloudstack.framework.config.ScopedConfigStorage;

import com.cloud.utils.db.DB;
import com.cloud.utils.db.QueryBuilder;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.TransactionLegacy;
import com.cloud.utils.db.SearchCriteria.Op;
import com.cloud.network.Network;

@Component
public class NetworkDetailsDaoImpl extends ResourceDetailsDaoBase<NetworkDetailVO> implements NetworkDetailsDao {
@DB
public class NetworkDetailsDaoImpl extends ResourceDetailsDaoBase<NetworkDetailVO> implements NetworkDetailsDao, ScopedConfigStorage {
protected final SearchBuilder<NetworkDetailVO> networkSearch;

protected NetworkDetailsDaoImpl() {
networkSearch = createSearchBuilder();
networkSearch.and("networkId", networkSearch.entity().getResourceId(), Op.EQ);
networkSearch.done();
}

@Override
public void addDetail(long resourceId, String key, String value, boolean display) {
Expand All @@ -36,4 +57,62 @@
NetworkDetailVO networkDetail = findDetail(networkId, Network.hideIpAddressUsage);
return networkDetail != null && "true".equals(networkDetail.getValue());
}

@Override
public void persist(long networkId, Map<String, String> details) {
try(TransactionLegacy txn = TransactionLegacy.currentTxn()) {
txn.start();
SearchCriteria<NetworkDetailVO> sc = networkSearch.create();
sc.setParameters("networkId", networkId);
expunge(sc);

Check warning on line 67 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L62-L67

Added lines #L62 - L67 were not covered by tests
for (Map.Entry<String, String> detail : details.entrySet()) {
NetworkDetailVO vo = new NetworkDetailVO(networkId, detail.getKey(), detail.getValue(), true);
persist(vo);
}
txn.commit();

Check warning on line 72 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L69-L72

Added lines #L69 - L72 were not covered by tests
}
}

Check warning on line 74 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L74

Added line #L74 was not covered by tests

@Override
public NetworkDetailVO findDetail(long networkId, String name) {
QueryBuilder<NetworkDetailVO> sc = QueryBuilder.create(NetworkDetailVO.class);
sc.and(sc.entity().getResourceId(), Op.EQ, networkId);
sc.and(sc.entity().getName(), Op.EQ, name);
return sc.find();
}

Check warning on line 82 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L77-L82

Added lines #L77 - L82 were not covered by tests

@Override
public List<NetworkDetailVO> listDetailsByName(String name) {
QueryBuilder<NetworkDetailVO> sc = QueryBuilder.create(NetworkDetailVO.class);
sc.and(sc.entity().getName(), Op.EQ, name);
return sc.list();
}

Check warning on line 89 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L85-L89

Added lines #L85 - L89 were not covered by tests

@Override
public void deleteDetails(long networkId) {
SearchCriteria<NetworkDetailVO> sc = networkSearch.create();
sc.setParameters("networkId", networkId);
List<NetworkDetailVO> results = search(sc, null);

Check warning on line 95 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L92-L95

Added lines #L92 - L95 were not covered by tests
for (NetworkDetailVO result : results) {
remove(result.getId());
}
}

Check warning on line 99 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L97-L99

Added lines #L97 - L99 were not covered by tests

@Override
public void update(long networkId, Map<String, String> details) {
Map<String, String> oldDetails = listDetailsKeyPairs(networkId);
oldDetails.putAll(details);
persist(networkId, oldDetails);
}

Check warning on line 106 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L102-L106

Added lines #L102 - L106 were not covered by tests

@Override
public Scope getScope() {
return ConfigKey.Scope.Network;
}

Check warning on line 111 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L109-L111

Added lines #L109 - L111 were not covered by tests

@Override
public String getConfigValue(long id, ConfigKey<?> key) {
NetworkDetailVO vo = findDetail(id, key.key());

Check warning on line 115 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L114-L115

Added lines #L114 - L115 were not covered by tests
return vo == null ? null : vo.getValue();
}

Check warning on line 117 in engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/network/dao/NetworkDetailsDaoImpl.java#L117

Added line #L117 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ConfigKey<T> {
public static final String CATEGORY_NETWORK = "Network";

public enum Scope {
Global, Zone, Cluster, StoragePool, Account, ManagementServer, ImageStore, Domain
Global, Zone, Cluster, StoragePool, Account, ManagementServer, ImageStore, Domain, Network
}

public enum Kind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ public ConfigDepotImpl() {
* This map must contain all ConfigKey.Scope values, except the ConfigKey.Scope.Global.
*/
protected void createEmptyScopeLevelMappings() {
_scopeLevelConfigsMap = new HashMap<ConfigKey.Scope, Set<ConfigKey<?>>>();
_scopeLevelConfigsMap.put(ConfigKey.Scope.Zone, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.ImageStore, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Domain, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.ManagementServer, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap = new HashMap<>();
_scopeLevelConfigsMap.put(ConfigKey.Scope.Zone, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Cluster, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.StoragePool, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Account, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.ImageStore, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Domain, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.ManagementServer, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Network, new HashSet<>());
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions server/src/main/java/com/cloud/api/ApiDBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
import com.cloud.network.dao.LoadBalancerDao;
import com.cloud.network.dao.LoadBalancerVO;
import com.cloud.network.dao.NetworkDao;
import com.cloud.network.dao.NetworkDetailsDao;
import com.cloud.network.dao.NetworkDomainDao;
import com.cloud.network.dao.NetworkDomainVO;
import com.cloud.network.dao.NetworkRuleConfigDao;
Expand Down Expand Up @@ -426,6 +427,7 @@
static DomainDetailsDao s_domainDetailsDao;
static AccountDetailsDao s_accountDetailsDao;
static NetworkDomainDao s_networkDomainDao;
static NetworkDetailsDao s_networkDetailsDao;
static HighAvailabilityManager s_haMgr;
static VpcManager s_vpcMgr;
static TaggedResourceService s_taggedResourceService;
Expand Down Expand Up @@ -626,6 +628,8 @@
@Inject
private NetworkDomainDao networkDomainDao;
@Inject
private NetworkDetailsDao networkDetailsDao;
@Inject
private HighAvailabilityManager haMgr;
@Inject
private VpcManager vpcMgr;
Expand Down Expand Up @@ -826,6 +830,7 @@
s_domainDetailsDao = domainDetailsDao;
s_accountDetailsDao = accountDetailsDao;
s_networkDomainDao = networkDomainDao;
s_networkDetailsDao = networkDetailsDao;

Check warning on line 833 in server/src/main/java/com/cloud/api/ApiDBUtils.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/ApiDBUtils.java#L833

Added line #L833 was not covered by tests
s_haMgr = haMgr;
s_vpcMgr = vpcMgr;
s_taggedResourceService = taggedResourceService;
Expand Down Expand Up @@ -1510,6 +1515,11 @@
return details.isEmpty() ? null : details;
}

public static Map<String, String> getNetworkDetails(long networkId) {
Map<String, String> details = s_networkDetailsDao.listDetailsKeyPairs(networkId);

Check warning on line 1519 in server/src/main/java/com/cloud/api/ApiDBUtils.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/ApiDBUtils.java#L1518-L1519

Added lines #L1518 - L1519 were not covered by tests
return details.isEmpty() ? null : details;
}

Check warning on line 1521 in server/src/main/java/com/cloud/api/ApiDBUtils.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/ApiDBUtils.java#L1521

Added line #L1521 was not covered by tests

public static Map<Service, Set<Provider>> listNetworkOfferingServices(long networkOfferingId) {
return s_networkModel.getNetworkOfferingServiceProvidersMap(networkOfferingId);
}
Expand Down
1 change: 1 addition & 0 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2711,6 +2711,7 @@
}
response.setBytesReceived(bytesReceived);
response.setBytesSent(bytesSent);
response.setDetails(ApiDBUtils.getNetworkDetails(network.getId()));

Check warning on line 2714 in server/src/main/java/com/cloud/api/ApiResponseHelper.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/ApiResponseHelper.java#L2714

Added line #L2714 was not covered by tests

if (networkOfferingDao.isIpv6Supported(network.getNetworkOfferingId())) {
response.setInternetProtocol(networkOfferingDao.getNetworkOfferingInternetProtocol(network.getNetworkOfferingId(), NetUtils.InternetProtocol.IPv4).toString());
Expand Down
Loading
Loading