Skip to content

Commit eae22d2

Browse files
Harikrishna PatnalaAbhinandan Prateek
authored andcommitted
CLOUDSTACK-741: Granular Global Parameters
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
1 parent 81e1ba3 commit eae22d2

17 files changed

Lines changed: 561 additions & 37 deletions

File tree

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
import org.apache.cloudstack.api.ApiConstants;
2424
import org.apache.cloudstack.api.BaseListCmd;
2525
import org.apache.cloudstack.api.Parameter;
26-
import org.apache.cloudstack.api.response.ConfigurationResponse;
27-
import org.apache.cloudstack.api.response.ListResponse;
26+
import org.apache.cloudstack.api.response.*;
2827
import org.apache.log4j.Logger;
2928

3029
import com.cloud.configuration.Configuration;
@@ -46,6 +45,13 @@ public class ListCfgsByCmd extends BaseListCmd {
4645
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "lists configuration by name")
4746
private String configName;
4847

48+
@Parameter(name=ApiConstants.SCOPE, type = CommandType.STRING, description = "scope(zone/cluster/pool/account) of the parameter that needs to be updated")
49+
private String scope;
50+
51+
@Parameter(name=ApiConstants.ID, type = CommandType.UUID, entityType = {ZoneResponse.class, ClusterResponse.class, StoragePoolResponse.class, AccountResponse.class}, description = "corresponding ID of the scope")
52+
private Long id;
53+
54+
4955
// ///////////////////////////////////////////////////
5056
// ///////////////// Accessors ///////////////////////
5157
// ///////////////////////////////////////////////////
@@ -58,6 +64,15 @@ public String getConfigName() {
5864
return configName;
5965
}
6066

67+
public String getScope() {
68+
return scope;
69+
}
70+
71+
public Long getId() {
72+
return id;
73+
}
74+
75+
6176
@Override
6277
public Long getPageSizeVal() {
6378
Long pageSizeVal = 500L;
@@ -85,6 +100,11 @@ public void execute() {
85100
for (Configuration cfg : result.first()) {
86101
ConfigurationResponse cfgResponse = _responseGenerator.createConfigurationResponse(cfg);
87102
cfgResponse.setObjectName("configuration");
103+
if (scope != null) {
104+
cfgResponse.setScope(scope);
105+
} else {
106+
cfgResponse.setScope("global");
107+
}
88108
configResponses.add(cfgResponse);
89109
}
90110

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.apache.cloudstack.api.BaseCmd;
2323
import org.apache.cloudstack.api.Parameter;
2424
import org.apache.cloudstack.api.ServerApiException;
25-
import org.apache.cloudstack.api.response.ConfigurationResponse;
25+
import org.apache.cloudstack.api.response.*;
2626
import org.apache.log4j.Logger;
2727

2828
import com.cloud.configuration.Configuration;
@@ -43,6 +43,12 @@ public class UpdateCfgCmd extends BaseCmd {
4343
@Parameter(name=ApiConstants.VALUE, type=CommandType.STRING, description="the value of the configuration", length=4095)
4444
private String value;
4545

46+
@Parameter(name=ApiConstants.SCOPE, type = CommandType.STRING, description = "scope(zone/cluster/pool/account) of the parameter that needs to be updated")
47+
private String scope;
48+
49+
@Parameter(name=ApiConstants.ID, type = CommandType.UUID, entityType = {ZoneResponse.class, ClusterResponse.class, StoragePoolResponse.class, AccountResponse.class}, description = "corresponding ID of the scope")
50+
private Long id;
51+
4652
/////////////////////////////////////////////////////
4753
/////////////////// Accessors ///////////////////////
4854
/////////////////////////////////////////////////////
@@ -55,6 +61,14 @@ public String getValue() {
5561
return value;
5662
}
5763

64+
public String getScope() {
65+
return scope;
66+
}
67+
68+
public Long getId() {
69+
return id;
70+
}
71+
5872
/////////////////////////////////////////////////////
5973
/////////////// API Implementation///////////////////
6074
/////////////////////////////////////////////////////
@@ -75,6 +89,12 @@ public void execute(){
7589
if (cfg != null) {
7690
ConfigurationResponse response = _responseGenerator.createConfigurationResponse(cfg);
7791
response.setResponseName(getCommandName());
92+
if (scope != null) {
93+
response.setScope(scope);
94+
response.setValue(value);
95+
} else {
96+
response.setScope("global");
97+
}
7898
this.setResponseObject(response);
7999
} else {
80100
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update config");

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ public class ConfigurationResponse extends BaseResponse {
3232
@SerializedName(ApiConstants.VALUE) @Param(description="the value of the configuration")
3333
private String value;
3434

35+
@SerializedName(ApiConstants.SCOPE) @Param(description="scope(zone/cluster/pool/account) of the parameter that needs to be updated")
36+
private String scope;
37+
3538
@SerializedName(ApiConstants.DESCRIPTION) @Param(description="the description of the configuration")
3639
private String description;
3740

41+
3842
public String getCategory() {
3943
return category;
4044
}
@@ -66,4 +70,12 @@ public String getDescription() {
6670
public void setDescription(String description) {
6771
this.description = description;
6872
}
73+
74+
public String getScope() {
75+
return scope;
76+
}
77+
78+
public void setScope(String scope) {
79+
this.scope = scope;
80+
}
6981
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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.test;
18+
19+
import com.cloud.configuration.Configuration;
20+
import com.cloud.configuration.ConfigurationService;
21+
import com.cloud.exception.InvalidParameterValueException;
22+
import com.cloud.resource.ResourceService;
23+
import com.cloud.server.ManagementService;
24+
import com.cloud.utils.Pair;
25+
import junit.framework.Assert;
26+
import junit.framework.TestCase;
27+
import org.apache.cloudstack.api.ResponseGenerator;
28+
import org.apache.cloudstack.api.ServerApiException;
29+
import org.apache.cloudstack.api.command.admin.config.ListCfgsByCmd;
30+
import org.apache.cloudstack.api.response.ConfigurationResponse;
31+
import org.apache.cloudstack.api.response.ListResponse;
32+
import org.junit.Before;
33+
import org.junit.Rule;
34+
import org.junit.Test;
35+
import org.junit.rules.ExpectedException;
36+
import org.mockito.Mockito;
37+
38+
import java.util.ArrayList;
39+
import java.util.List;
40+
41+
public class ListCfgCmdTest extends TestCase{
42+
43+
private ListCfgsByCmd listCfgsByCmd;
44+
private ManagementService mgr;
45+
private ResponseGenerator responseGenerator;
46+
47+
@Rule
48+
public ExpectedException expectedException = ExpectedException.none();
49+
50+
@Before
51+
public void setUp() {
52+
responseGenerator = Mockito.mock(ResponseGenerator.class);
53+
mgr = Mockito.mock(ManagementService.class);
54+
listCfgsByCmd = new ListCfgsByCmd();
55+
}
56+
57+
@Test
58+
public void testCreateSuccess() {
59+
60+
Configuration cfg = Mockito.mock(Configuration.class);
61+
listCfgsByCmd._mgr = mgr;
62+
listCfgsByCmd._responseGenerator = responseGenerator;
63+
64+
65+
66+
List<Configuration> configList = new ArrayList<Configuration>();
67+
configList.add(cfg);
68+
69+
Pair<List<? extends Configuration>, Integer> result = new Pair<List<? extends Configuration>, Integer>(configList, 1);
70+
71+
try {
72+
Mockito.when(
73+
mgr.searchForConfigurations(listCfgsByCmd))
74+
.thenReturn(result);
75+
}catch (Exception e){
76+
Assert.fail("Received exception when success expected " + e.getMessage());
77+
}
78+
ConfigurationResponse cfgResponse = new ConfigurationResponse();
79+
cfgResponse.setName("Test case");
80+
Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(cfgResponse);
81+
82+
listCfgsByCmd.execute();
83+
Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
84+
85+
ListResponse<ConfigurationResponse> actualResponse = (ListResponse<ConfigurationResponse>) listCfgsByCmd.getResponseObject();
86+
Assert.assertEquals(cfgResponse, actualResponse.getResponses().get(0));
87+
}
88+
89+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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.test;
18+
19+
import com.cloud.configuration.Configuration;
20+
import com.cloud.configuration.ConfigurationService;
21+
import com.cloud.exception.InvalidParameterValueException;
22+
import com.cloud.resource.ResourceService;
23+
import junit.framework.Assert;
24+
import junit.framework.TestCase;
25+
import org.apache.cloudstack.api.ResponseGenerator;
26+
import org.apache.cloudstack.api.ServerApiException;
27+
import org.apache.cloudstack.api.command.admin.config.UpdateCfgCmd;
28+
import org.apache.cloudstack.api.response.ConfigurationResponse;
29+
import org.junit.Before;
30+
import org.junit.Rule;
31+
import org.junit.Test;
32+
import org.junit.rules.ExpectedException;
33+
import org.mockito.Mockito;
34+
35+
public class UpdateCfgCmdTest extends TestCase{
36+
37+
private UpdateCfgCmd updateCfgCmd;
38+
private ConfigurationService configService;
39+
private ResponseGenerator responseGenerator;
40+
41+
@Rule
42+
public ExpectedException expectedException = ExpectedException.none();
43+
44+
@Before
45+
public void setUp() {
46+
responseGenerator = Mockito.mock(ResponseGenerator.class);
47+
configService = Mockito.mock(ConfigurationService.class);
48+
updateCfgCmd = new UpdateCfgCmd();
49+
}
50+
51+
@Test
52+
public void testExecuteForEmptyResult() {
53+
updateCfgCmd._configService = configService;
54+
55+
try {
56+
updateCfgCmd.execute();
57+
} catch (ServerApiException exception) {
58+
Assert.assertEquals("Failed to update config",
59+
exception.getDescription());
60+
}
61+
62+
}
63+
64+
@Test
65+
public void testExecuteForNullResult() {
66+
67+
updateCfgCmd._configService = configService;
68+
69+
try {
70+
Mockito.when(
71+
configService.updateConfiguration(updateCfgCmd))
72+
.thenReturn(null);
73+
} catch (InvalidParameterValueException e) {
74+
// TODO Auto-generated catch block
75+
e.printStackTrace();
76+
} catch (IllegalArgumentException e) {
77+
// TODO Auto-generated catch block
78+
e.printStackTrace();
79+
}
80+
try {
81+
updateCfgCmd.execute();
82+
} catch (ServerApiException exception) {
83+
Assert.assertEquals("Failed to update config",
84+
exception.getDescription());
85+
}
86+
87+
}
88+
89+
90+
@Test
91+
public void testCreateSuccess() {
92+
93+
Configuration cfg = Mockito.mock(Configuration.class);
94+
updateCfgCmd._configService = configService;
95+
updateCfgCmd._responseGenerator = responseGenerator;
96+
97+
try {
98+
Mockito.when(
99+
configService.updateConfiguration(updateCfgCmd))
100+
.thenReturn(cfg);
101+
}catch (Exception e){
102+
Assert.fail("Received exception when success expected " + e.getMessage());
103+
}
104+
105+
ConfigurationResponse response = new ConfigurationResponse();
106+
response.setName("Test case");
107+
Mockito.when(responseGenerator.createConfigurationResponse(cfg)).thenReturn(response);
108+
109+
updateCfgCmd.execute();
110+
Mockito.verify(responseGenerator).createConfigurationResponse(cfg);
111+
ConfigurationResponse actualResponse = (ConfigurationResponse) updateCfgCmd.getResponseObject();
112+
Assert.assertEquals(response, actualResponse);
113+
Assert.assertEquals("updateconfigurationresponse", response.getResponseName());
114+
}
115+
116+
}

engine/api/src/org/apache/cloudstack/storage/datastore/db/StoragePoolDetailsDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ public interface StoragePoolDetailsDao extends GenericDao<StoragePoolDetailVO, L
2525

2626
void update(long poolId, Map<String, String> details);
2727
Map<String, String> getDetails(long poolId);
28+
StoragePoolDetailVO findDetail(long poolId, String name);
2829
}

0 commit comments

Comments
 (0)