Skip to content

Commit a32fc4e

Browse files
committed
Merge pull request apache#73 in CLOUD/cloudstack from 4.11.2-networkScopeSettings to 4.11.2-settings
* commit '4577fd9ea1afb6678aba0cf9f1a8ffe9ffd7e12f': CLSTACK-4602: Updating the integration test script CLSTACK-4602: Add network-scope settings and network.router.service.offering in 4.11.2
2 parents 3e21c77 + 4577fd9 commit a32fc4e

File tree

19 files changed

+1524
-460
lines changed

19 files changed

+1524
-460
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,25 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.config;
1818

19-
import java.util.ArrayList;
20-
import java.util.List;
21-
22-
import org.apache.cloudstack.api.response.DomainResponse;
23-
import org.apache.log4j.Logger;
24-
19+
import com.cloud.utils.Pair;
2520
import org.apache.cloudstack.api.APICommand;
2621
import org.apache.cloudstack.api.ApiConstants;
2722
import org.apache.cloudstack.api.BaseListCmd;
2823
import org.apache.cloudstack.api.Parameter;
2924
import org.apache.cloudstack.api.response.AccountResponse;
3025
import org.apache.cloudstack.api.response.ClusterResponse;
3126
import org.apache.cloudstack.api.response.ConfigurationResponse;
27+
import org.apache.cloudstack.api.response.DomainResponse;
3228
import org.apache.cloudstack.api.response.ImageStoreResponse;
3329
import org.apache.cloudstack.api.response.ListResponse;
30+
import org.apache.cloudstack.api.response.NetworkResponse;
3431
import org.apache.cloudstack.api.response.StoragePoolResponse;
3532
import org.apache.cloudstack.api.response.ZoneResponse;
3633
import org.apache.cloudstack.config.Configuration;
34+
import org.apache.log4j.Logger;
3735

38-
import com.cloud.utils.Pair;
36+
import java.util.ArrayList;
37+
import java.util.List;
3938

4039
@APICommand(name = "listConfigurations", description = "Lists all configurations.", responseObject = ConfigurationResponse.class,
4140
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -90,6 +89,12 @@ public class ListCfgsByCmd extends BaseListCmd {
9089
description = "the ID of the Image Store to update the parameter value for corresponding image store")
9190
private Long imageStoreId;
9291

92+
@Parameter(name = ApiConstants.NETWORK_ID,
93+
type = CommandType.UUID,
94+
entityType = NetworkResponse.class,
95+
description = "the ID of the Network to update the parameter value for corresponding network")
96+
private Long networkId;
97+
9398
// ///////////////////////////////////////////////////
9499
// ///////////////// Accessors ///////////////////////
95100
// ///////////////////////////////////////////////////
@@ -126,6 +131,10 @@ public Long getImageStoreId() {
126131
return imageStoreId;
127132
}
128133

134+
public Long getNetworkId() {
135+
return networkId;
136+
}
137+
129138
@Override
130139
public Long getPageSizeVal() {
131140
Long defaultPageSize = 500L;
@@ -172,9 +181,12 @@ public void execute() {
172181
if (getDomainId() != null) {
173182
cfgResponse.setScope("domain");
174183
}
175-
if (getImageStoreId() != null){
184+
if (getImageStoreId() != null) {
176185
cfgResponse.setScope("imagestore");
177186
}
187+
if (getNetworkId() != null) {
188+
cfgResponse.setScope("network");
189+
}
178190
configResponses.add(cfgResponse);
179191
}
180192

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.config;
1818

19+
import com.cloud.user.Account;
1920
import com.google.common.base.Strings;
2021
import org.apache.cloudstack.acl.RoleService;
21-
import org.apache.cloudstack.api.response.DomainResponse;
22-
import org.apache.log4j.Logger;
2322
import org.apache.cloudstack.api.APICommand;
2423
import org.apache.cloudstack.api.ApiArgValidator;
2524
import org.apache.cloudstack.api.ApiConstants;
@@ -30,12 +29,13 @@
3029
import org.apache.cloudstack.api.response.AccountResponse;
3130
import org.apache.cloudstack.api.response.ClusterResponse;
3231
import org.apache.cloudstack.api.response.ConfigurationResponse;
32+
import org.apache.cloudstack.api.response.DomainResponse;
3333
import org.apache.cloudstack.api.response.ImageStoreResponse;
34+
import org.apache.cloudstack.api.response.NetworkResponse;
3435
import org.apache.cloudstack.api.response.StoragePoolResponse;
3536
import org.apache.cloudstack.api.response.ZoneResponse;
3637
import org.apache.cloudstack.config.Configuration;
37-
38-
import com.cloud.user.Account;
38+
import org.apache.log4j.Logger;
3939

4040
@APICommand(name = "updateConfiguration", description = "Updates a configuration.", responseObject = ConfigurationResponse.class,
4141
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -90,6 +90,12 @@ public class UpdateCfgCmd extends BaseCmd {
9090
validations = ApiArgValidator.PositiveNumber)
9191
private Long imageStoreId;
9292

93+
@Parameter(name = ApiConstants.NETWORK_ID,
94+
type = CommandType.UUID,
95+
entityType = NetworkResponse.class,
96+
description = "the ID of the Network to update the parameter value for corresponding network")
97+
private Long networkId;
98+
9399
/////////////////////////////////////////////////////
94100
/////////////////// Accessors ///////////////////////
95101
/////////////////////////////////////////////////////
@@ -130,6 +136,10 @@ public Long getImageStoreId() {
130136
return imageStoreId;
131137
}
132138

139+
public Long getNetworkId() {
140+
return networkId;
141+
}
142+
133143
/////////////////////////////////////////////////////
134144
/////////////// API Implementation///////////////////
135145
/////////////////////////////////////////////////////
@@ -171,6 +181,9 @@ public void execute() {
171181
if (getDomainId() != null) {
172182
response.setScope("domain");
173183
}
184+
if (getNetworkId() != null) {
185+
response.setScope("network");
186+
}
174187
response.setValue(value);
175188
this.setResponseObject(response);
176189
} else {

api/src/org/apache/cloudstack/api/response/NetworkResponse.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.response;
1818

19-
import java.util.List;
20-
21-
import java.util.Set;
19+
import com.cloud.network.Network;
20+
import com.cloud.projects.ProjectAccount;
21+
import com.cloud.serializer.Param;
22+
import com.google.gson.annotations.SerializedName;
2223
import org.apache.cloudstack.acl.RoleType;
2324
import org.apache.cloudstack.api.ApiConstants;
2425
import org.apache.cloudstack.api.BaseResponse;
2526
import org.apache.cloudstack.api.EntityReference;
2627

27-
import com.cloud.network.Network;
28-
import com.cloud.projects.ProjectAccount;
29-
import com.cloud.serializer.Param;
30-
import com.google.gson.annotations.SerializedName;
28+
import java.util.List;
29+
import java.util.Map;
30+
import java.util.Set;
3131

3232
@SuppressWarnings("unused")
3333
@EntityReference(value = {Network.class, ProjectAccount.class})
@@ -233,6 +233,10 @@ public class NetworkResponse extends BaseResponse implements ControlledEntityRes
233233
@Param(description = "If the network has redundant routers enabled", since = "4.11.1")
234234
private Boolean redundantRouter;
235235

236+
@SerializedName(ApiConstants.DETAILS)
237+
@Param(description = "details for the network")
238+
private Map<String, String> details;
239+
236240
public Boolean getDisplayNetwork() {
237241
return displayNetwork;
238242
}
@@ -449,4 +453,8 @@ public Boolean getRedundantRouter() {
449453
public void setRedundantRouter(Boolean redundantRouter) {
450454
this.redundantRouter = redundantRouter;
451455
}
456+
457+
public void setDetails(Map<String, String> details) {
458+
this.details = details;
459+
}
452460
}

engine/schema/src/com/cloud/network/dao/NetworkDetailVO.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
// under the License.
1717
package com.cloud.network.dao;
1818

19+
import org.apache.cloudstack.api.ResourceDetail;
20+
1921
import javax.persistence.Column;
2022
import javax.persistence.Entity;
2123
import javax.persistence.GeneratedValue;
2224
import javax.persistence.GenerationType;
2325
import javax.persistence.Id;
2426
import javax.persistence.Table;
2527

26-
import org.apache.cloudstack.api.ResourceDetail;
27-
2828
@Entity
2929
@Table(name = "network_details")
3030
public class NetworkDetailVO implements ResourceDetail {
@@ -70,6 +70,10 @@ public String getValue() {
7070
return value;
7171
}
7272

73+
public void setValue(String value) {
74+
this.value = value;
75+
}
76+
7377
@Override
7478
public long getResourceId() {
7579
return resourceId;

engine/schema/src/com/cloud/network/dao/NetworkDetailsDao.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,24 @@
1616
// under the License.
1717
package com.cloud.network.dao;
1818

19+
import com.cloud.utils.db.GenericDao;
1920
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
2021

21-
import com.cloud.utils.db.GenericDao;
22+
import java.util.List;
23+
import java.util.Map;
2224

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

25-
}
27+
Map<String, String> findDetails(long networkId);
28+
29+
void persist(long networkId, Map<String, String> details);
30+
31+
NetworkDetailVO findDetail(long networkId, String name);
32+
33+
List<NetworkDetailVO> listDetailsByName(String name);
34+
35+
void deleteDetails(long networkId);
36+
37+
void update(long networkId, Map<String, String> details);
38+
39+
}

engine/schema/src/com/cloud/network/dao/NetworkDetailsDaoImpl.java

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,102 @@
1717
package com.cloud.network.dao;
1818

1919

20+
import com.cloud.utils.db.QueryBuilder;
21+
import com.cloud.utils.db.SearchBuilder;
22+
import com.cloud.utils.db.SearchCriteria;
23+
import com.cloud.utils.db.SearchCriteria.Op;
24+
import com.cloud.utils.db.TransactionLegacy;
25+
import org.apache.cloudstack.framework.config.ConfigKey;
26+
import org.apache.cloudstack.framework.config.ConfigKey.Scope;
27+
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
28+
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
2029
import org.springframework.stereotype.Component;
2130

22-
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
31+
import java.util.HashMap;
32+
import java.util.List;
33+
import java.util.Map;
2334

2435
@Component
25-
public class NetworkDetailsDaoImpl extends ResourceDetailsDaoBase<NetworkDetailVO> implements NetworkDetailsDao {
36+
public class NetworkDetailsDaoImpl extends ResourceDetailsDaoBase<NetworkDetailVO> implements NetworkDetailsDao, ScopedConfigStorage {
37+
protected final SearchBuilder<NetworkDetailVO> networkSearch;
2638

2739
@Override
2840
public void addDetail(long resourceId, String key, String value, boolean display) {
2941
super.addDetail(new NetworkDetailVO(resourceId, key, value, display));
3042
}
3143

44+
protected NetworkDetailsDaoImpl() {
45+
networkSearch = createSearchBuilder();
46+
networkSearch.and("networkId", networkSearch.entity().getResourceId(), Op.EQ);
47+
networkSearch.done();
48+
}
49+
50+
@Override
51+
public Map<String, String> findDetails(long networkId) {
52+
QueryBuilder<NetworkDetailVO> sc = QueryBuilder.create(NetworkDetailVO.class);
53+
sc.and(sc.entity().getResourceId(), Op.EQ, networkId);
54+
List<NetworkDetailVO> results = sc.list();
55+
Map<String, String> details = new HashMap<String, String>(results.size());
56+
for (NetworkDetailVO r : results) {
57+
details.put(r.getName(), r.getValue());
58+
}
59+
return details;
60+
}
61+
62+
@Override
63+
public void persist(long networkId, Map<String, String> details) {
64+
TransactionLegacy txn = TransactionLegacy.currentTxn();
65+
txn.start();
66+
SearchCriteria<NetworkDetailVO> sc = networkSearch.create();
67+
sc.setParameters("networkId", networkId);
68+
expunge(sc);
69+
for (Map.Entry<String, String> detail : details.entrySet()) {
70+
NetworkDetailVO vo = new NetworkDetailVO(networkId, detail.getKey(), detail.getValue(), true);
71+
persist(vo);
72+
}
73+
txn.commit();
74+
}
75+
76+
@Override
77+
public NetworkDetailVO findDetail(long networkId, String name) {
78+
QueryBuilder<NetworkDetailVO> sc = QueryBuilder.create(NetworkDetailVO.class);
79+
sc.and(sc.entity().getResourceId(), Op.EQ, networkId);
80+
sc.and(sc.entity().getName(), Op.EQ, name);
81+
return sc.find();
82+
}
83+
84+
@Override
85+
public List<NetworkDetailVO> listDetailsByName(String name) {
86+
QueryBuilder<NetworkDetailVO> sc = QueryBuilder.create(NetworkDetailVO.class);
87+
sc.and(sc.entity().getName(), Op.EQ, name);
88+
return sc.list();
89+
}
90+
91+
@Override
92+
public void deleteDetails(long networkId) {
93+
SearchCriteria<NetworkDetailVO> sc = networkSearch.create();
94+
sc.setParameters("networkId", networkId);
95+
List<NetworkDetailVO> results = search(sc, null);
96+
for (NetworkDetailVO result : results) {
97+
remove(result.getId());
98+
}
99+
}
100+
101+
@Override
102+
public void update(long networkId, Map<String, String> details) {
103+
Map<String, String> oldDetails = findDetails(networkId);
104+
oldDetails.putAll(details);
105+
persist(networkId, oldDetails);
106+
}
107+
108+
@Override
109+
public Scope getScope() {
110+
return ConfigKey.Scope.Network;
111+
}
112+
113+
@Override
114+
public String getConfigValue(long id, ConfigKey<?> key) {
115+
NetworkDetailVO vo = findDetail(id, key.key());
116+
return vo == null ? null : vo.getValue();
117+
}
32118
}

framework/config/src/org/apache/cloudstack/framework/config/ConfigKey.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
// under the License.
1717
package org.apache.cloudstack.framework.config;
1818

19-
import java.sql.Date;
20-
19+
import com.cloud.utils.exception.CloudRuntimeException;
2120
import org.apache.cloudstack.framework.config.impl.ConfigDepotImpl;
2221
import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
2322

24-
import com.cloud.utils.exception.CloudRuntimeException;
23+
import java.sql.Date;
2524

2625
/**
2726
* ConfigKey supplants the original Config.java. It is just a class
@@ -31,7 +30,7 @@
3130
public class ConfigKey<T> {
3231

3332
public static enum Scope {
34-
Global, Zone, Cluster, StoragePool, Account, ManagementServer, ImageStore, Domain
33+
Global, Zone, Cluster, StoragePool, Account, ManagementServer, ImageStore, Domain, Network
3534
}
3635

3736
private final String _category;

0 commit comments

Comments
 (0)