Skip to content

Storage pool response improvements #10740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 4.19
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,24 @@
@Param(description = "the name of the cluster for the storage pool")
private String clusterName;

@SerializedName(ApiConstants.CAPACITY_BYTES)
@Param(description = "bytes CloudStack can provision from this storage pool", since = "4.19.3")
private Long capacityBytes;

@Deprecated(since = "4.19.3")
@SerializedName("disksizetotal")
@Param(description = "the total disk size of the storage pool")
private Long diskSizeTotal;

@SerializedName("disksizeallocated")
@Param(description = "the host's currently allocated disk size")
@Param(description = "the pool's currently allocated disk size")
private Long diskSizeAllocated;

@SerializedName("disksizeused")
@Param(description = "the host's currently used disk size")
@Param(description = "the pool's currently used disk size")
private Long diskSizeUsed;

@SerializedName("capacityiops")
@SerializedName(ApiConstants.CAPACITY_IOPS)
@Param(description = "IOPS CloudStack can provision from this storage pool")
private Long capacityIops;

Expand Down Expand Up @@ -145,6 +150,10 @@
@Param(description = "whether this pool is managed or not")
private Boolean managed;

@SerializedName(ApiConstants.DETAILS)
@Param(description = "additional key/value details of the storage pool", since = "4.19.3")
private Map<String, String> details;

public Map<String, String> getCaps() {
return caps;
}
Expand Down Expand Up @@ -276,6 +285,14 @@
this.clusterName = clusterName;
}

public Long getCapacityBytes() {
return capacityBytes;
}

Check warning on line 290 in api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java#L288-L290

Added lines #L288 - L290 were not covered by tests

public void setCapacityBytes(Long capacityBytes) {
this.capacityBytes = capacityBytes;
}

Check warning on line 294 in api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java#L292-L294

Added lines #L292 - L294 were not covered by tests

public Long getDiskSizeTotal() {
return diskSizeTotal;
}
Expand Down Expand Up @@ -395,4 +412,12 @@
public void setManaged(Boolean managed) {
this.managed = managed;
}

public Map<String, String> getDetails() {
return details;
}

Check warning on line 418 in api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java#L416-L418

Added lines #L416 - L418 were not covered by tests

public void setDetails(Map<String, String> details) {
this.details = details;
}

Check warning on line 422 in api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java

View check run for this annotation

Codecov / codecov/patch

api/src/main/java/org/apache/cloudstack/api/response/StoragePoolResponse.java#L420-L422

Added lines #L420 - L422 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import com.cloud.storage.StoragePool;

public interface PrimaryDataStoreLifeCycle extends DataStoreLifeCycle {
public static final String CAPACITY_BYTES = "capacityBytes";
public static final String CAPACITY_IOPS = "capacityIops";
String CAPACITY_BYTES = "capacityBytes";
String CAPACITY_IOPS = "capacityIops";

void updateStoragePool(StoragePool storagePool, Map<String, String> details);
void enableStoragePool(DataStore store);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import javax.inject.Inject;

import com.cloud.upgrade.dao.Upgrade41910to41920;
import com.cloud.upgrade.dao.Upgrade41920to41930;
import com.cloud.utils.FileUtil;
import org.apache.cloudstack.utils.CloudStackVersion;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -229,6 +230,7 @@ public DatabaseUpgradeChecker() {
.next("4.18.1.0", new Upgrade41810to41900())
.next("4.19.0.0", new Upgrade41900to41910())
.next("4.19.1.0", new Upgrade41910to41920())
.next("4.19.2.0", new Upgrade41920to41930())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.upgrade.dao;

import com.cloud.utils.exception.CloudRuntimeException;

import java.io.InputStream;
import java.sql.Connection;

public class Upgrade41920to41930 implements DbUpgrade {

@Override
public String[] getUpgradableVersionRange() {
return new String[]{"4.19.2.0", "4.19.3.0"};
}

Check warning on line 29 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L27-L29

Added lines #L27 - L29 were not covered by tests

@Override
public String getUpgradedVersion() {
return "4.19.3.0";
}

@Override
public boolean supportsRollingUpgrade() {
return false;
}

Check warning on line 39 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L37-L39

Added lines #L37 - L39 were not covered by tests

@Override
public InputStream[] getPrepareScripts() {
final String scriptFile = "META-INF/db/schema-41920to41930.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);

Check warning on line 44 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L42-L44

Added lines #L42 - L44 were not covered by tests
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);

Check warning on line 46 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L46

Added line #L46 was not covered by tests
}

return new InputStream[]{script};
}

Check warning on line 50 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L49-L50

Added lines #L49 - L50 were not covered by tests

@Override
public void performDataMigration(Connection conn) {
}

Check warning on line 54 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L53-L54

Added lines #L53 - L54 were not covered by tests

@Override
public InputStream[] getCleanupScripts() {
final String scriptFile = "META-INF/db/schema-41920to41930-cleanup.sql";
final InputStream script = Thread.currentThread().getContextClassLoader().getResourceAsStream(scriptFile);

Check warning on line 59 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L57-L59

Added lines #L57 - L59 were not covered by tests
if (script == null) {
throw new CloudRuntimeException("Unable to find " + scriptFile);

Check warning on line 61 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L61

Added line #L61 was not covered by tests
}

return new InputStream[]{script};
}

Check warning on line 65 in engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade41920to41930.java#L64-L65

Added lines #L64 - L65 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@
pool = super.persist(pool);
if (details != null) {
for (Map.Entry<String, String> detail : details.entrySet()) {
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue(), true);
boolean display = true;

Check warning on line 306 in engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L306 was not covered by tests
if (detail.getKey().toLowerCase().contains("password") || detail.getKey().toLowerCase().contains("token")) {
display = false;

Check warning on line 308 in engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L308 was not covered by tests
}
StoragePoolDetailVO vo = new StoragePoolDetailVO(pool.getId(), detail.getKey(), detail.getValue(), display);

Check warning on line 310 in engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L310 was not covered by tests
_detailsDao.persist(vo);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

--;
-- Schema upgrade cleanup from 4.19.2.0 to 4.19.3.0
--;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- Licensed to the Apache Software Foundation (ASF) under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. The ASF licenses this file
-- to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License.

--;
-- Schema upgrade from 4.19.2.0 to 4.19.3.0
--;

-- Updated display to false for password/token detail of the storage pool details
UPDATE `cloud`.`storage_pool_details` SET display = 0 WHERE name LIKE '%password%';
UPDATE `cloud`.`storage_pool_details` SET display = 0 WHERE name LIKE '%token%';
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ public class PrimaryDataStoreHelper {
private AnnotationDao annotationDao;

public DataStore createPrimaryDataStore(PrimaryDataStoreParameters params) {
if(params == null)
{
if (params == null) {
throw new InvalidParameterValueException("createPrimaryDataStore: Input params is null, please check");
}
StoragePoolVO dataStoreVO = dataStoreDao.findPoolByUUID(params.getUuid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

import javax.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -125,7 +126,6 @@
Long clusterId = (Long)dsInfos.get("clusterId");
Long podId = (Long)dsInfos.get("podId");
Long zoneId = (Long)dsInfos.get("zoneId");
String url = (String)dsInfos.get("url");
String providerName = (String)dsInfos.get("providerName");
HypervisorType hypervisorType = (HypervisorType)dsInfos.get("hypervisorType");
if (clusterId != null && podId == null) {
Expand All @@ -134,17 +134,41 @@

PrimaryDataStoreParameters parameters = new PrimaryDataStoreParameters();

String tags = (String)dsInfos.get("tags");
Map<String, String> details = (Map<String, String>)dsInfos.get("details");

if (dsInfos.get("capacityBytes") != null) {
Long capacityBytes = (Long)dsInfos.get("capacityBytes");

Check warning on line 140 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L140 was not covered by tests
if (capacityBytes <= 0) {
throw new IllegalArgumentException("'capacityBytes' must be greater than 0.");

Check warning on line 142 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L142 was not covered by tests
}
if (details == null) {
details = new HashMap<>();

Check warning on line 145 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L145 was not covered by tests
}
details.put(PrimaryDataStoreLifeCycle.CAPACITY_BYTES, String.valueOf(capacityBytes));
parameters.setCapacityBytes(capacityBytes);

Check warning on line 148 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java#L147-L148

Added lines #L147 - L148 were not covered by tests
}

if (dsInfos.get("capacityIops") != null) {
Long capacityIops = (Long)dsInfos.get("capacityIops");

Check warning on line 152 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L152 was not covered by tests
if (capacityIops <= 0) {
throw new IllegalArgumentException("'capacityIops' must be greater than 0.");

Check warning on line 154 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L154 was not covered by tests
}
if (details == null) {
details = new HashMap<>();

Check warning on line 157 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L157 was not covered by tests
}
details.put(PrimaryDataStoreLifeCycle.CAPACITY_IOPS, String.valueOf(capacityIops));
parameters.setCapacityIops(capacityIops);

Check warning on line 160 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java#L159-L160

Added lines #L159 - L160 were not covered by tests
}

parameters.setDetails(details);

Check warning on line 163 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L163 was not covered by tests

String tags = (String)dsInfos.get("tags");

Check warning on line 165 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/lifecycle/CloudStackPrimaryDataStoreLifeCycleImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L165 was not covered by tests
parameters.setTags(tags);
parameters.setIsTagARule((Boolean)dsInfos.get("isTagARule"));
parameters.setDetails(details);

String scheme = dsInfos.get("scheme").toString();
String storageHost = dsInfos.get("host").toString();
String hostPath = dsInfos.get("hostPath").toString();
String uri = String.format("%s://%s%s", scheme, storageHost, hostPath);

Object localStorage = dsInfos.get("localStorage");
if (localStorage != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.cloud.api.ApiDBUtils;
import com.cloud.api.query.vo.StoragePoolJoinVO;
import com.cloud.capacity.CapacityManager;
import com.cloud.server.ResourceTag;
import com.cloud.storage.DataStoreRole;
import com.cloud.storage.ScopeType;
import com.cloud.storage.Storage;
Expand Down Expand Up @@ -140,6 +141,7 @@
}
}
}
poolResponse.setCapacityBytes(pool.getCapacityBytes());

Check warning on line 144 in server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L144 was not covered by tests
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
poolResponse.setDiskSizeAllocated(allocatedSize);
poolResponse.setCapacityIops(pool.getCapacityIops());
Expand Down Expand Up @@ -172,6 +174,8 @@
poolResponse.setIsTagARule(pool.getIsTagARule());
poolResponse.setOverProvisionFactor(Double.toString(CapacityManager.StorageOverprovisioningFactor.valueIn(pool.getId())));
poolResponse.setManaged(storagePool.isManaged());
Map<String, String> details = ApiDBUtils.getResourceDetails(pool.getId(), ResourceTag.ResourceObjectType.Storage);
poolResponse.setDetails(details);

Check warning on line 178 in server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java#L177-L178

Added lines #L177 - L178 were not covered by tests

// set async job
if (pool.getJobId() != null) {
Expand Down Expand Up @@ -228,6 +232,7 @@
}

long allocatedSize = pool.getUsedCapacity();
poolResponse.setCapacityBytes(pool.getCapacityBytes());

Check warning on line 235 in server/src/main/java/com/cloud/api/query/dao/StoragePoolJoinDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L235 was not covered by tests
poolResponse.setDiskSizeTotal(pool.getCapacityBytes());
poolResponse.setDiskSizeAllocated(allocatedSize);
poolResponse.setCapacityIops(pool.getCapacityIops());
Expand Down
Loading