Skip to content

Commit d8c7e34

Browse files
sureshanapartinvazquezdavidjumaniDaanHoogland
authored
Improve global settings UI to be more intuitive/logical (#5797)
Co-authored-by: Suresh Kumar Anaparti <suresh.anaparti@shapeblue.com> Co-authored-by: nvazquez <nicovazquez90@gmail.com> Co-authored-by: davidjumani <dj.davidjumani1994@gmail.com> Co-authored-by: dahn <daan.hoogland@gmail.com> Co-authored-by: dahn <daan@onecht.net>
1 parent 3b6ce97 commit d8c7e34

File tree

81 files changed

+3240
-163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3240
-163
lines changed

api/src/main/java/com/cloud/server/ManagementService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.cloud.user.UserData;
2424
import org.apache.cloudstack.api.command.admin.cluster.ListClustersCmd;
25+
import org.apache.cloudstack.api.command.admin.config.ListCfgGroupsByCmd;
2526
import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
2627
import org.apache.cloudstack.api.command.admin.config.UpdateHypervisorCapabilitiesCmd;
2728
import org.apache.cloudstack.api.command.admin.guest.AddGuestOsCmd;
@@ -63,6 +64,7 @@
6364
import org.apache.cloudstack.api.command.user.vm.GetVMPasswordCmd;
6465
import org.apache.cloudstack.api.command.user.vmgroup.UpdateVMGroupCmd;
6566
import org.apache.cloudstack.config.Configuration;
67+
import org.apache.cloudstack.config.ConfigurationGroup;
6668

6769
import com.cloud.alert.Alert;
6870
import com.cloud.capacity.Capacity;
@@ -102,6 +104,13 @@ public interface ManagementService {
102104
*/
103105
Pair<List<? extends Configuration>, Integer> searchForConfigurations(ListCfgsByCmd c);
104106

107+
/**
108+
* returns the the configuration groups
109+
*
110+
* @return list of configuration groups
111+
*/
112+
Pair<List<? extends ConfigurationGroup>, Integer> listConfigurationGroups(ListCfgGroupsByCmd cmd);
113+
105114
/**
106115
* Searches for Clusters by the specified search criteria
107116
*

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public class ApiConstants {
118118
public static final String MAX_IOPS = "maxiops";
119119
public static final String HYPERVISOR_SNAPSHOT_RESERVE = "hypervisorsnapshotreserve";
120120
public static final String DATADISK_OFFERING_LIST = "datadiskofferinglist";
121+
public static final String DEFAULT_VALUE = "defaultvalue";
121122
public static final String DESCRIPTION = "description";
122123
public static final String DESTINATION = "destination";
123124
public static final String DESTINATION_ZONE_ID = "destzoneid";
@@ -187,6 +188,7 @@ public class ApiConstants {
187188
public static final String GATEWAY = "gateway";
188189
public static final String IP6_GATEWAY = "ip6gateway";
189190
public static final String GROUP = "group";
191+
public static final String SUBGROUP = "subgroup";
190192
public static final String GROUP_ID = "groupid";
191193
public static final String GSLB_LB_METHOD = "gslblbmethod";
192194
public static final String GSLB_SERVICE_DOMAIN_NAME = "gslbdomainname";
@@ -301,6 +303,7 @@ public class ApiConstants {
301303
public static final String IS_DEFAULT_USE = "defaultuse";
302304
public static final String OLD_FORMAT = "oldformat";
303305
public static final String OP = "op";
306+
public static final String OPTIONS = "options";
304307
public static final String OS_CATEGORY_ID = "oscategoryid";
305308
public static final String OS_CATEGORY_NAME = "oscategoryname";
306309
public static final String OS_ID = "osid";
@@ -312,6 +315,7 @@ public class ApiConstants {
312315
public static final String OUTPUT = "output";
313316
public static final String PROPERTIES = "properties";
314317
public static final String PARAMS = "params";
318+
public static final String PARENT = "parent";
315319
public static final String PARENT_ID = "parentid";
316320
public static final String PARENT_DOMAIN_ID = "parentdomainid";
317321
public static final String PARENT_TEMPLATE_ID = "parenttemplateid";
@@ -333,6 +337,7 @@ public class ApiConstants {
333337
public static final String POSITION = "position";
334338
public static final String POST_URL = "postURL";
335339
public static final String POWER_STATE = "powerstate";
340+
public static final String PRECEDENCE = "precedence";
336341
public static final String PRIVATE_INTERFACE = "privateinterface";
337342
public static final String PRIVATE_IP = "privateip";
338343
public static final String PRIVATE_PORT = "privateport";

api/src/main/java/org/apache/cloudstack/api/ResponseGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import org.apache.cloudstack.api.response.CapacityResponse;
4141
import org.apache.cloudstack.api.response.ClusterResponse;
4242
import org.apache.cloudstack.api.response.ConditionResponse;
43+
import org.apache.cloudstack.api.response.ConfigurationGroupResponse;
4344
import org.apache.cloudstack.api.response.ConfigurationResponse;
4445
import org.apache.cloudstack.api.response.CounterResponse;
4546
import org.apache.cloudstack.api.response.CreateCmdResponse;
@@ -133,6 +134,7 @@
133134
import org.apache.cloudstack.backup.BackupOffering;
134135
import org.apache.cloudstack.backup.BackupSchedule;
135136
import org.apache.cloudstack.config.Configuration;
137+
import org.apache.cloudstack.config.ConfigurationGroup;
136138
import org.apache.cloudstack.direct.download.DirectDownloadCertificate;
137139
import org.apache.cloudstack.direct.download.DirectDownloadCertificateHostMap;
138140
import org.apache.cloudstack.direct.download.DirectDownloadManager;
@@ -244,6 +246,8 @@ public interface ResponseGenerator {
244246

245247
ConfigurationResponse createConfigurationResponse(Configuration cfg);
246248

249+
ConfigurationGroupResponse createConfigurationGroupResponse(ConfigurationGroup cfgGroup);
250+
247251
SnapshotResponse createSnapshotResponse(Snapshot snapshot);
248252

249253
SnapshotPolicyResponse createSnapshotPolicyResponse(SnapshotPolicy policy);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.config;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.BaseCmd;
25+
import org.apache.cloudstack.api.BaseListCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.response.ConfigurationGroupResponse;
28+
import org.apache.cloudstack.api.response.ListResponse;
29+
import org.apache.cloudstack.config.ConfigurationGroup;
30+
import org.apache.log4j.Logger;
31+
32+
import com.cloud.utils.Pair;
33+
34+
@APICommand(name = ListCfgGroupsByCmd.APINAME, description = "Lists all configuration groups (primarily used for UI).", responseObject = ConfigurationGroupResponse.class,
35+
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, since = "4.18.0")
36+
public class ListCfgGroupsByCmd extends BaseListCmd {
37+
public static final Logger s_logger = Logger.getLogger(ListCfgGroupsByCmd.class.getName());
38+
39+
public static final String APINAME = "listConfigurationGroups";
40+
41+
// ///////////////////////////////////////////////////
42+
// ////////////// API parameters /////////////////////
43+
// ///////////////////////////////////////////////////
44+
45+
@Parameter(name = ApiConstants.GROUP, type = CommandType.STRING, description = "lists configuration group by group name")
46+
private String groupName;
47+
48+
// ///////////////////////////////////////////////////
49+
// ///////////////// Accessors ///////////////////////
50+
// ///////////////////////////////////////////////////
51+
52+
public String getGroupName() {
53+
return groupName;
54+
}
55+
56+
// ///////////////////////////////////////////////////
57+
// ///////////// API Implementation///////////////////
58+
// ///////////////////////////////////////////////////
59+
60+
@Override
61+
public String getCommandName() {
62+
return APINAME.toLowerCase() + BaseCmd.RESPONSE_SUFFIX;
63+
}
64+
65+
@Override
66+
public void execute() {
67+
Pair<List<? extends ConfigurationGroup>, Integer> result = _mgr.listConfigurationGroups(this);
68+
ListResponse<ConfigurationGroupResponse> response = new ListResponse<>();
69+
List<ConfigurationGroupResponse> configGroupResponses = new ArrayList<>();
70+
for (ConfigurationGroup cfgGroup : result.first()) {
71+
ConfigurationGroupResponse cfgGroupResponse = _responseGenerator.createConfigurationGroupResponse(cfgGroup);
72+
configGroupResponses.add(cfgGroupResponse);
73+
}
74+
75+
response.setResponses(configGroupResponses, result.second());
76+
response.setResponseName(getCommandName());
77+
setResponseObject(response);
78+
}
79+
}

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

Lines changed: 96 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121

22+
import org.apache.cloudstack.api.ApiErrorCode;
23+
import org.apache.cloudstack.api.ServerApiException;
2224
import org.apache.cloudstack.api.response.DomainResponse;
25+
import org.apache.commons.lang3.StringUtils;
2326
import org.apache.log4j.Logger;
2427

2528
import org.apache.cloudstack.api.APICommand;
@@ -35,7 +38,9 @@
3538
import org.apache.cloudstack.api.response.ZoneResponse;
3639
import org.apache.cloudstack.config.Configuration;
3740

41+
import com.cloud.exception.InvalidParameterValueException;
3842
import com.cloud.utils.Pair;
43+
import com.cloud.utils.exception.CloudRuntimeException;
3944

4045
@APICommand(name = "listConfigurations", description = "Lists all configurations.", responseObject = ConfigurationResponse.class,
4146
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
@@ -89,6 +94,15 @@ public class ListCfgsByCmd extends BaseListCmd {
8994
description = "the ID of the Image Store to update the parameter value for corresponding image store")
9095
private Long imageStoreId;
9196

97+
@Parameter(name = ApiConstants.GROUP, type = CommandType.STRING, description = "lists configuration by group name (primarily used for UI)", since = "4.18.0")
98+
private String groupName;
99+
100+
@Parameter(name = ApiConstants.SUBGROUP, type = CommandType.STRING, description = "lists configuration by subgroup name (primarily used for UI)", since = "4.18.0")
101+
private String subGroupName;
102+
103+
@Parameter(name = ApiConstants.PARENT, type = CommandType.STRING, description = "lists configuration by parent name (primarily used for UI)", since = "4.18.0")
104+
private String parentName;
105+
92106
// ///////////////////////////////////////////////////
93107
// ///////////////// Accessors ///////////////////////
94108
// ///////////////////////////////////////////////////
@@ -125,6 +139,26 @@ public Long getImageStoreId() {
125139
return imageStoreId;
126140
}
127141

142+
public String getGroupName() {
143+
return groupName;
144+
}
145+
146+
public String getSubGroupName() {
147+
return subGroupName;
148+
}
149+
150+
public String getParentName() {
151+
return parentName;
152+
}
153+
154+
@Override
155+
public Integer getPageSize() {
156+
if (StringUtils.isNotEmpty(getGroupName())) {
157+
return Integer.valueOf(s_pageSizeUnlimited.intValue());
158+
}
159+
return super.getPageSize();
160+
}
161+
128162
@Override
129163
public Long getPageSizeVal() {
130164
Long defaultPageSize = 500L;
@@ -143,37 +177,74 @@ public Long getPageSizeVal() {
143177
// ///////////// API Implementation///////////////////
144178
// ///////////////////////////////////////////////////
145179

180+
private void setScope(ConfigurationResponse cfgResponse) {
181+
if (!matchesConfigurationGroup(cfgResponse)) {
182+
return;
183+
}
184+
cfgResponse.setObjectName("configuration");
185+
if (getZoneId() != null) {
186+
cfgResponse.setScope("zone");
187+
}
188+
if (getClusterId() != null) {
189+
cfgResponse.setScope("cluster");
190+
}
191+
if (getStoragepoolId() != null) {
192+
cfgResponse.setScope("storagepool");
193+
}
194+
if (getAccountId() != null) {
195+
cfgResponse.setScope("account");
196+
}
197+
if (getDomainId() != null) {
198+
cfgResponse.setScope("domain");
199+
}
200+
if (getImageStoreId() != null){
201+
cfgResponse.setScope("imagestore");
202+
}
203+
}
204+
146205
@Override
147206
public void execute() {
148-
Pair<List<? extends Configuration>, Integer> result = _mgr.searchForConfigurations(this);
149-
ListResponse<ConfigurationResponse> response = new ListResponse<ConfigurationResponse>();
150-
List<ConfigurationResponse> configResponses = new ArrayList<ConfigurationResponse>();
151-
for (Configuration cfg : result.first()) {
152-
ConfigurationResponse cfgResponse = _responseGenerator.createConfigurationResponse(cfg);
153-
cfgResponse.setObjectName("configuration");
154-
if (getZoneId() != null) {
155-
cfgResponse.setScope("zone");
156-
}
157-
if (getClusterId() != null) {
158-
cfgResponse.setScope("cluster");
207+
validateParameters();
208+
try {
209+
Pair<List<? extends Configuration>, Integer> result = _mgr.searchForConfigurations(this);
210+
ListResponse<ConfigurationResponse> response = new ListResponse<>();
211+
List<ConfigurationResponse> configResponses = new ArrayList<>();
212+
for (Configuration cfg : result.first()) {
213+
ConfigurationResponse cfgResponse = _responseGenerator.createConfigurationResponse(cfg);
214+
setScope(cfgResponse);
215+
configResponses.add(cfgResponse);
159216
}
160-
if (getStoragepoolId() != null) {
161-
cfgResponse.setScope("storagepool");
162-
}
163-
if (getAccountId() != null) {
164-
cfgResponse.setScope("account");
217+
218+
if (StringUtils.isNotEmpty(getGroupName())) {
219+
response.setResponses(configResponses, configResponses.size());
220+
} else {
221+
response.setResponses(configResponses, result.second());
165222
}
166-
if (getDomainId() != null) {
167-
cfgResponse.setScope("domain");
223+
response.setResponseName(getCommandName());
224+
setResponseObject(response);
225+
} catch (InvalidParameterValueException e) {
226+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
227+
} catch (CloudRuntimeException e) {
228+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
229+
}
230+
}
231+
232+
private void validateParameters() {
233+
if (StringUtils.isNotEmpty(getSubGroupName()) && StringUtils.isEmpty(getGroupName())) {
234+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Configuration group name must be specified with the subgroup name");
235+
}
236+
}
237+
238+
private boolean matchesConfigurationGroup(ConfigurationResponse cfgResponse) {
239+
if (StringUtils.isNotEmpty(getGroupName())) {
240+
if (!(getGroupName().equalsIgnoreCase(cfgResponse.getGroup()))) {
241+
return false;
168242
}
169-
if (getImageStoreId() != null){
170-
cfgResponse.setScope("imagestore");
243+
if (StringUtils.isNotEmpty(getSubGroupName()) &&
244+
!getSubGroupName().equalsIgnoreCase(cfgResponse.getSubGroup())) {
245+
return false;
171246
}
172-
configResponses.add(cfgResponse);
173247
}
174-
175-
response.setResponses(configResponses, result.second());
176-
response.setResponseName(getCommandName());
177-
setResponseObject(response);
248+
return true;
178249
}
179250
}

0 commit comments

Comments
 (0)