Skip to content

Commit 6adf4d3

Browse files
Return details of the storage pool in the response including url, and update capacityBytes and capacityIops if applicable while creating storage pool
1 parent f13cf59 commit 6adf4d3

File tree

9 files changed

+152
-4
lines changed

9 files changed

+152
-4
lines changed

api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ public class StoragePoolResponse extends BaseResponseWithAnnotations {
145145
@Param(description = "whether this pool is managed or not")
146146
private Boolean managed;
147147

148+
@SerializedName(ApiConstants.DETAILS)
149+
@Param(description = "additional key/value details of the storage pool", since = "4.19.3")
150+
private Map<String, String> details;
151+
148152
public Map<String, String> getCaps() {
149153
return caps;
150154
}
@@ -395,4 +399,12 @@ public Boolean getManaged() {
395399
public void setManaged(Boolean managed) {
396400
this.managed = managed;
397401
}
402+
403+
public Map<String, String> getDetails() {
404+
return details;
405+
}
406+
407+
public void setDetails(Map<String, String> details) {
408+
this.details = details;
409+
}
398410
}

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import javax.inject.Inject;
3535

3636
import com.cloud.upgrade.dao.Upgrade41910to41920;
37+
import com.cloud.upgrade.dao.Upgrade41920to41930;
3738
import com.cloud.utils.FileUtil;
3839
import org.apache.cloudstack.utils.CloudStackVersion;
3940
import org.apache.commons.lang3.StringUtils;
@@ -229,6 +230,7 @@ public DatabaseUpgradeChecker() {
229230
.next("4.18.1.0", new Upgrade41810to41900())
230231
.next("4.19.0.0", new Upgrade41900to41910())
231232
.next("4.19.1.0", new Upgrade41910to41920())
233+
.next("4.19.2.0", new Upgrade41920to41930())
232234
.build();
233235
}
234236

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 com.cloud.upgrade.dao;
18+
19+
import com.cloud.utils.exception.CloudRuntimeException;
20+
21+
import java.io.InputStream;
22+
import java.sql.Connection;
23+
24+
public class Upgrade41920to41930 implements DbUpgrade {
25+
26+
@Override
27+
public String[] getUpgradableVersionRange() {
28+
return new String[]{"4.19.2.0", "4.19.3.0"};
29+
}
30+
31+
@Override
32+
public String getUpgradedVersion() {
33+
return "4.19.3.0";
34+
}
35+
36+
@Override
37+
public boolean supportsRollingUpgrade() {
38+
return false;
39+
}
40+
41+
@Override
42+
public InputStream[] getPrepareScripts() {
43+
final String scriptFile = "META-INF/db/schema-41920to41930.sql";
44+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
45+
if (script == null) {
46+
throw new CloudRuntimeException("Unable to find " + scriptFile);
47+
}
48+
49+
return new InputStream[]{script};
50+
}
51+
52+
@Override
53+
public void performDataMigration(Connection conn) {
54+
}
55+
56+
@Override
57+
public InputStream[] getCleanupScripts() {
58+
final String scriptFile = "META-INF/db/schema-41920to41930-cleanup.sql";
59+
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);
60+
if (script == null) {
61+
throw new CloudRuntimeException("Unable to find " + scriptFile);
62+
}
63+
64+
return new InputStream[]{script};
65+
}
66+
}

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,11 @@ public StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details, Li
303303
pool = super.persist(pool);
304304
if (details != null) {
305305
for (Map.Entry<String, String> detail : details.entrySet()) {
306-
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue(), true);
306+
boolean display = true;
307+
if (detail.getKey().toLowerCase().contains("password")) {
308+
display = false;
309+
}
310+
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue(), display);
307311
_detailsDao.persist(vo);
308312
}
309313
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
--;
19+
-- Schema upgrade cleanup from 4.19.2.0 to 4.19.3.0
20+
--;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
--;
19+
-- Schema upgrade from 4.19.2.0 to 4.19.3.0
20+
--;
21+
22+
-- Updated display to false for password detail of the storage pool details
23+
UPDATE `cloud`.`storage_pool_details` SET display = 0 WHERE name LIKE '%password%';

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,32 @@ public DataStore initialize(Map<String, Object> dsInfos) {
134134

135135
PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();
136136

137-
String tags = (String)dsInfos.get("tags");
137+
if (dsInfos.get("capacityBytes") != null) {
138+
Long capacityBytes = (Long)dsInfos.get("capacityBytes");
139+
if (capacityBytes <= 0) {
140+
throw new IllegalArgumentException("'capacityBytes' must be greater than 0.");
141+
}
142+
parameters.setCapacityBytes(capacityBytes);
143+
}
144+
145+
if (dsInfos.get("capacityIops") != null) {
146+
Long capacityIops = (Long)dsInfos.get("capacityIops");
147+
if (capacityIops <= 0) {
148+
throw new IllegalArgumentException("'capacityIops' must be greater than 0.");
149+
}
150+
parameters.setCapacityIops(capacityIops);
151+
}
152+
138153
Map<String, String> details = (Map<String, String>)dsInfos.get("details");
154+
parameters.setDetails(details);
139155

156+
String tags = (String)dsInfos.get("tags");
140157
parameters.setTags(tags);
141158
parameters.setIsTagARule((Boolean)dsInfos.get("isTagARule"));
142-
parameters.setDetails(details);
143159

144160
String scheme = dsInfos.get("scheme").toString();
145161
String storageHost = dsInfos.get("host").toString();
146162
String hostPath = dsInfos.get("hostPath").toString();
147-
String uri = String.format("%s://%s%s", scheme, storageHost, hostPath);
148163

149164
Object localStorage = dsInfos.get("localStorage");
150165
if (localStorage != null) {

server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.cloud.api.ApiDBUtils;
2020
import com.cloud.api.query.vo.StoragePoolJoinVO;
2121
import com.cloud.capacity.CapacityManager;
22+
import com.cloud.server.ResourceTag;
2223
import com.cloud.storage.DataStoreRole;
2324
import com.cloud.storage.ScopeType;
2425
import com.cloud.storage.Storage;
@@ -172,6 +173,8 @@ public StoragePoolResponse newStoragePoolResponse(StoragePoolJoinVO pool, boolea
172173
poolResponse.setIsTagARule(pool.getIsTagARule());
173174
poolResponse.setOverProvisionFactor(Double.toString(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())));
174175
poolResponse.setManaged(storagePool.isManaged());
176+
Map<String, String> details = ApiDBUtils.getResourceDetails(pool.getId(), ResourceTag.ResourceObjectType.Storage);
177+
poolResponse.setDetails(details);
175178

176179
// set async job
177180
if (pool.getJobId() != null) {

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,9 @@ public PrimaryDataStoreInfo createPool(CreateStoragePoolCmd cmd) throws Resource
992992

993993
Map<String, String> details = extractApiParamAsMap(cmd.getDetails());
994994
checkNFSMountOptionsForCreate(details, hypervisorType, uriParams.get("scheme"));
995+
if (StringUtils.isNotBlank(cmd.getUrl())) {
996+
details.put("url", cmd.getUrl());
997+
}
995998

996999
DataCenterVO zone = _dcDao.findById(cmd.getZoneId());
9971000
if (zone == null) {

0 commit comments

Comments
 (0)