Skip to content

Commit fb82ca3

Browse files
committed
config: fix ManagementServer scope
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 00d1dbc commit fb82ca3

File tree

13 files changed

+275
-8
lines changed

13 files changed

+275
-8
lines changed

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,24 @@
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;
24-
import org.apache.cloudstack.api.response.DomainResponse;
25-
import org.apache.commons.lang3.StringUtils;
26-
2722
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiArgValidator;
2824
import org.apache.cloudstack.api.ApiConstants;
25+
import org.apache.cloudstack.api.ApiErrorCode;
2926
import org.apache.cloudstack.api.BaseListCmd;
3027
import org.apache.cloudstack.api.Parameter;
28+
import org.apache.cloudstack.api.ServerApiException;
3129
import org.apache.cloudstack.api.response.AccountResponse;
3230
import org.apache.cloudstack.api.response.ClusterResponse;
3331
import org.apache.cloudstack.api.response.ConfigurationResponse;
32+
import org.apache.cloudstack.api.response.DomainResponse;
3433
import org.apache.cloudstack.api.response.ImageStoreResponse;
3534
import org.apache.cloudstack.api.response.ListResponse;
35+
import org.apache.cloudstack.api.response.ManagementServerResponse;
3636
import org.apache.cloudstack.api.response.StoragePoolResponse;
3737
import org.apache.cloudstack.api.response.ZoneResponse;
3838
import org.apache.cloudstack.config.Configuration;
39+
import org.apache.commons.lang3.StringUtils;
3940

4041
import com.cloud.exception.InvalidParameterValueException;
4142
import com.cloud.utils.Pair;
@@ -94,6 +95,13 @@ public class ListCfgsByCmd extends BaseListCmd {
9495
description = "The ID of the Image Store to update the parameter value for corresponding image store")
9596
private Long imageStoreId;
9697

98+
@Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID,
99+
type = CommandType.UUID,
100+
entityType = ManagementServerResponse.class,
101+
description = "the ID of the Management Server to update the parameter value for corresponding management server",
102+
since = "4.23.0")
103+
private Long managementServerId;
104+
97105
@Parameter(name = ApiConstants.GROUP, type = CommandType.STRING, description = "Lists configuration by group name (primarily used for UI)", since = "4.18.0")
98106
private String groupName;
99107

@@ -139,6 +147,10 @@ public Long getImageStoreId() {
139147
return imageStoreId;
140148
}
141149

150+
public Long getManagementServerId() {
151+
return managementServerId;
152+
}
153+
142154
public String getGroupName() {
143155
return groupName;
144156
}
@@ -200,6 +212,9 @@ private void setScope(ConfigurationResponse cfgResponse) {
200212
if (getImageStoreId() != null){
201213
cfgResponse.setScope("imagestore");
202214
}
215+
if (getManagementServerId() != null){
216+
cfgResponse.setScope("managementserver");
217+
}
203218
}
204219

205220
@Override

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.cloudstack.api.Parameter;
2525
import org.apache.cloudstack.api.ServerApiException;
2626
import org.apache.cloudstack.api.response.ImageStoreResponse;
27+
import org.apache.cloudstack.api.response.ManagementServerResponse;
2728
import org.apache.cloudstack.framework.config.ConfigKey;
2829

2930
import org.apache.cloudstack.api.response.AccountResponse;
@@ -84,6 +85,13 @@ public class ResetCfgCmd extends BaseCmd {
8485
description = "The ID of the Image Store to reset the parameter value for corresponding image store")
8586
private Long imageStoreId;
8687

88+
@Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID,
89+
type = CommandType.UUID,
90+
entityType = ManagementServerResponse.class,
91+
description = "the ID of the Management Server to update the parameter value for corresponding management server",
92+
since = "4.23.0")
93+
private Long managementServerId;
94+
8795
/////////////////////////////////////////////////////
8896
/////////////////// Accessors ///////////////////////
8997
/////////////////////////////////////////////////////
@@ -116,6 +124,10 @@ public Long getImageStoreId() {
116124
return imageStoreId;
117125
}
118126

127+
public Long getManagementServerId() {
128+
return managementServerId;
129+
}
130+
119131
/////////////////////////////////////////////////////
120132
/////////////// API Implementation///////////////////
121133
/////////////////////////////////////////////////////
@@ -149,6 +161,9 @@ public void execute() {
149161
if (getImageStoreId() != null) {
150162
response.setScope(ConfigKey.Scope.ImageStore.name());
151163
}
164+
if (getManagementServerId() != null) {
165+
response.setScope(ConfigKey.Scope.ManagementServer.name());
166+
}
152167
response.setValue(cfg.second());
153168
this.setResponseObject(response);
154169
} else {

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.cloudstack.api.response.ClusterResponse;
3131
import org.apache.cloudstack.api.response.ConfigurationResponse;
3232
import org.apache.cloudstack.api.response.ImageStoreResponse;
33+
import org.apache.cloudstack.api.response.ManagementServerResponse;
3334
import org.apache.cloudstack.api.response.StoragePoolResponse;
3435
import org.apache.cloudstack.api.response.ZoneResponse;
3536
import org.apache.cloudstack.config.Configuration;
@@ -88,6 +89,13 @@ public class UpdateCfgCmd extends BaseCmd {
8889
validations = ApiArgValidator.PositiveNumber)
8990
private Long imageStoreId;
9091

92+
@Parameter(name = ApiConstants.MANAGEMENT_SERVER_ID,
93+
type = CommandType.UUID,
94+
entityType = ManagementServerResponse.class,
95+
description = "the ID of the Management Server to update the parameter value for corresponding management server",
96+
since = "4.23.0")
97+
private Long managementServerId;
98+
9199
/////////////////////////////////////////////////////
92100
/////////////////// Accessors ///////////////////////
93101
/////////////////////////////////////////////////////
@@ -112,7 +120,7 @@ public Long getClusterId() {
112120
return clusterId;
113121
}
114122

115-
public Long getStoragepoolId() {
123+
public Long getStoragePoolId() {
116124
return storagePoolId;
117125
}
118126

@@ -128,6 +136,10 @@ public Long getImageStoreId() {
128136
return imageStoreId;
129137
}
130138

139+
public Long getManagementServerId() {
140+
return managementServerId;
141+
}
142+
131143
/////////////////////////////////////////////////////
132144
/////////////// API Implementation///////////////////
133145
/////////////////////////////////////////////////////
@@ -182,7 +194,7 @@ public ConfigurationResponse setResponseScopes(ConfigurationResponse response) {
182194
if (getClusterId() != null) {
183195
response.setScope("cluster");
184196
}
185-
if (getStoragepoolId() != null) {
197+
if (getStoragePoolId() != null) {
186198
response.setScope("storagepool");
187199
}
188200
if (getAccountId() != null) {

engine/schema/src/main/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
<bean id="loadBalancerVMMapDaoImpl" class="com.cloud.network.dao.LoadBalancerVMMapDaoImpl" />
117117
<bean id="loadBalancerCertMapDaoImpl" class="com.cloud.network.dao.LoadBalancerCertMapDaoImpl" />
118118
<bean id="managementServerHostDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostDaoImpl" />
119+
<bean id="managementServerHostDetailsDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostDetailsDaoImpl" />
119120
<bean id="managementServerHostPeerDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostPeerDaoImpl" />
120121
<bean id="managementServerHostPeerJoinDaoImpl" class="com.cloud.cluster.dao.ManagementServerHostPeerJoinDaoImpl" />
121122
<bean id="managementServerStatusDaoImpl" class="com.cloud.cluster.dao.ManagementServerStatusDaoImpl" />

engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.vpc_offerings','conserve_mode', 'tin
118118
--- Disable/enable NICs
119119
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.nics','enabled', 'TINYINT(1) NOT NULL DEFAULT 1 COMMENT ''Indicates whether the NIC is enabled or not'' ');
120120

121+
-- Add management_server_details table to allow ManagementServer scope configs
122+
CREATE TABLE IF NOT EXISTS `management_server_details` (
123+
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
124+
`management_server_id` bigint unsigned NOT NULL COMMENT 'management server the detail is related to',
125+
`name` varchar(255) NOT NULL COMMENT 'name of the detail',
126+
`value` varchar(255) NOT NULL,
127+
`display` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'True if the detail can be displayed to the end user',
128+
PRIMARY KEY (`id`),
129+
CONSTRAINT `fk_management_server_details__management_server_id` FOREIGN KEY `fk_management_server_details__management_server_id`(`management_server_id`) REFERENCES `mshost`(`id`) ON DELETE CASCADE,
130+
KEY `i_management_server_details__name__value` (`name`(128),`value`(128))
131+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
132+
121133
-- Add checkpoint tracking fields to backups table for incremental backup support
122134
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'from_checkpoint_id', 'VARCHAR(255) DEFAULT NULL COMMENT "Previous active checkpoint id for incremental backups"');
123135
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'to_checkpoint_id', 'VARCHAR(255) DEFAULT NULL COMMENT "New checkpoint id created for the next incremental backup"');

framework/cluster/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
<artifactId>cloud-api</artifactId>
4949
<version>${project.version}</version>
5050
</dependency>
51+
<dependency>
52+
<groupId>org.apache.cloudstack</groupId>
53+
<artifactId>cloud-engine-schema</artifactId>
54+
<version>${project.version}</version>
55+
<scope>compile</scope>
56+
</dependency>
5157
</dependencies>
5258

5359
</project>
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
18+
package com.cloud.cluster;
19+
20+
import javax.persistence.Column;
21+
import javax.persistence.Entity;
22+
import javax.persistence.GeneratedValue;
23+
import javax.persistence.GenerationType;
24+
import javax.persistence.Id;
25+
import javax.persistence.Table;
26+
27+
import org.apache.cloudstack.api.ResourceDetail;
28+
29+
@Entity
30+
@Table(name = "management_server_details")
31+
public class ManagementServerHostDetailVO implements ResourceDetail {
32+
@Id
33+
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@Column(name = "id")
35+
long id;
36+
37+
@Column(name = "management_server_id")
38+
long resourceId;
39+
40+
@Column(name = "name")
41+
String name;
42+
43+
@Column(name = "value")
44+
String value;
45+
46+
@Column(name = "display")
47+
private boolean display = true;
48+
49+
public ManagementServerHostDetailVO(long poolId, String name, String value, boolean display) {
50+
this.resourceId = poolId;
51+
this.name = name;
52+
this.value = value;
53+
this.display = display;
54+
}
55+
56+
public ManagementServerHostDetailVO() {
57+
}
58+
59+
@Override
60+
public long getId() {
61+
return id;
62+
}
63+
64+
@Override
65+
public long getResourceId() {
66+
return resourceId;
67+
}
68+
69+
@Override
70+
public String getName() {
71+
return name;
72+
}
73+
74+
public void setValue(String value) {
75+
this.value = value;
76+
}
77+
78+
@Override
79+
public String getValue() {
80+
return value;
81+
}
82+
83+
@Override
84+
public boolean isDisplay() {
85+
return display;
86+
}
87+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
18+
package com.cloud.cluster.dao;
19+
20+
import org.apache.cloudstack.resourcedetail.ResourceDetailsDao;
21+
22+
import com.cloud.cluster.ManagementServerHostDetailVO;
23+
import com.cloud.utils.db.GenericDao;
24+
25+
public interface ManagementServerHostDetailsDao extends GenericDao<ManagementServerHostDetailVO, Long>, ResourceDetailsDao<ManagementServerHostDetailVO> {
26+
}
27+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
18+
package com.cloud.cluster.dao;
19+
20+
import org.apache.cloudstack.framework.config.ConfigKey;
21+
import org.apache.cloudstack.framework.config.ScopedConfigStorage;
22+
import org.apache.cloudstack.resourcedetail.ResourceDetailsDaoBase;
23+
24+
import com.cloud.cluster.ManagementServerHostDetailVO;
25+
26+
public class ManagementServerHostDetailsDaoImpl extends ResourceDetailsDaoBase<ManagementServerHostDetailVO> implements ManagementServerHostDetailsDao, ScopedConfigStorage {
27+
28+
public ManagementServerHostDetailsDaoImpl() {
29+
}
30+
31+
@Override
32+
public ConfigKey.Scope getScope() {
33+
return ConfigKey.Scope.ManagementServer;
34+
}
35+
36+
@Override
37+
public String getConfigValue(long id, String key) {
38+
ManagementServerHostDetailVO vo = findDetail(id, key);
39+
return vo == null ? null : vo.getValue();
40+
}
41+
42+
@Override
43+
public void addDetail(long resourceId, String key, String value, boolean display) {
44+
super.addDetail(new ManagementServerHostDetailVO(resourceId, key, value, display));
45+
}
46+
}

0 commit comments

Comments
 (0)