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 15 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 @@ -34,6 +34,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 @@ -105,6 +106,12 @@ public class ListCfgsByCmd extends BaseListCmd {
@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 update the parameter value for corresponding network")
private Long networkId;

// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
Expand Down Expand Up @@ -161,6 +168,10 @@ public Integer getPageSize() {
return super.getPageSize();
}

public Long getNetworkId() {
return networkId;
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -86,6 +87,12 @@ public class ResetCfgCmd extends BaseCmd {
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 update the parameter value for corresponding network")
private Long networkId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -118,6 +125,10 @@ public Long getImageStoreId() {
return imageStoreId;
}

public Long getNetworkId() {
return networkId;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -151,6 +162,9 @@ public void execute() {
if (getImageStoreId() != null) {
response.setScope(ConfigKey.Scope.ImageStore.name());
}
if (getNetworkId() != null) {
response.setScope(ConfigKey.Scope.Network.name());
}
response.setValue(cfg.second());
this.setResponseObject(response);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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 @@ -90,6 +91,12 @@ public class UpdateCfgCmd extends BaseCmd {
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")
private Long networkId;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -130,6 +137,10 @@ public Long getImageStoreId() {
return imageStoreId;
}

public Long getNetworkId() {
return networkId;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -195,6 +206,9 @@ public ConfigurationResponse setResponseScopes(ConfigurationResponse response) {
if (getDomainId() != null) {
response.setScope("domain");
}
if (getNetworkId() != null) {
response.setScope("network");
}
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,26 @@
// 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);

Map<String, String> findDetails(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,32 @@

import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;

import java.util.HashMap;
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 +58,74 @@ public boolean isNetworkUsageHidden(long networkId) {
NetworkDetailVO networkDetail = findDetail(networkId, Network.hideIpAddressUsage);
return networkDetail != null && "true".equals(networkDetail.getValue());
}

@Override
public Map<String, String> findDetails(long networkId) {
QueryBuilder<NetworkDetailVO> sc = QueryBuilder.create(NetworkDetailVO.class);
sc.and(sc.entity().getResourceId(), Op.EQ, networkId);
List<NetworkDetailVO> results = sc.list();
Map<String, String> details = new HashMap<String, String>(results.size());
for (NetworkDetailVO r : results) {
details.put(r.getName(), r.getValue());
}
return details;
}

@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);
for (Map.Entry<String, String> detail : details.entrySet()) {
NetworkDetailVO vo = new NetworkDetailVO(networkId, detail.getKey(), detail.getValue(), true);
persist(vo);
}
txn.commit();
}
}

@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();
}

@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();
}

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

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

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

@Override
public String getConfigValue(long id, ConfigKey<?> key) {
NetworkDetailVO vo = findDetail(id, key.key());
return vo == null ? null : vo.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ConfigKey<T> {
public static final String CATEGORY_ALERT = "Alert";

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 @@ -101,9 +101,10 @@ protected void createEmptyScopeLevelMappings() {
_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.ImageStore, new HashSet<>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.Domain, new HashSet<ConfigKey<?>>());
_scopeLevelConfigsMap.put(ConfigKey.Scope.ManagementServer, new HashSet<ConfigKey<?>>());
_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 @@ -142,6 +142,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 @@ -410,6 +411,7 @@ public class ApiDBUtils {
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 @@ -604,6 +606,8 @@ public class ApiDBUtils {
@Inject
private NetworkDomainDao networkDomainDao;
@Inject
private NetworkDetailsDao networkDetailsDao;
@Inject
private HighAvailabilityManager haMgr;
@Inject
private VpcManager vpcMgr;
Expand Down Expand Up @@ -793,6 +797,7 @@ void init() {
s_domainDetailsDao = domainDetailsDao;
s_accountDetailsDao = accountDetailsDao;
s_networkDomainDao = networkDomainDao;
s_networkDetailsDao = networkDetailsDao;
s_haMgr = haMgr;
s_vpcMgr = vpcMgr;
s_taggedResourceService = taggedResourceService;
Expand Down Expand Up @@ -1480,6 +1485,11 @@ public static Map<String, String> getAccountDetails(long accountId) {
return details.isEmpty() ? null : details;
}

public static Map<String, String> getNetworkDetails(long networkId) {
Map<String, String> details = s_networkDetailsDao.findDetails(networkId);
return details.isEmpty() ? null : details;
}

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 @@ -2648,6 +2648,7 @@ public NetworkResponse createNetworkResponse(ResponseView view, Network network)
}
response.setBytesReceived(bytesReceived);
response.setBytesSent(bytesSent);
response.setDetails(ApiDBUtils.getNetworkDetails(network.getId()));

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