Skip to content
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 @@ -30,7 +30,6 @@
import com.cloud.user.Account;
import org.apache.commons.collections.MapUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -49,7 +48,7 @@ public class AddSecondaryStorageCmd extends BaseCmd {
protected Long zoneId;

@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "Details in key/value pairs using format details[i].keyname=keyvalue. Example: details[0].copytemplatesfromothersecondarystorages=true")
protected Map details;
protected Map<String, ? extends Map<String, String>> details;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
Expand All @@ -66,12 +65,8 @@ public Long getZoneId() {
public Map<String, String> getDetails() {
Map<String, String> detailsMap = new HashMap<>();
if (MapUtils.isNotEmpty(details)) {
Collection<?> props = details.values();
for (Object prop : props) {
HashMap<String, String> detail = (HashMap<String, String>) prop;
for (Map.Entry<String, String> entry: detail.entrySet()) {
detailsMap.put(entry.getKey(),entry.getValue());
}
for (Map<String, String> detail : details.values()) {
detailsMap.putAll(detail);
}
}
return detailsMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
// under the License.
package org.apache.cloudstack.api.command.admin.storage;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;


Expand Down Expand Up @@ -57,7 +55,7 @@ public class AddImageStoreCmd extends BaseCmd {
@Parameter(name = ApiConstants.DETAILS,
type = CommandType.MAP,
description = "The details for the image store. Example: details[0].key=accesskey&details[0].value=s389ddssaa&details[1].key=secretkey&details[1].value=8dshfsss")
private Map details;
private Map<String, ? extends Map<String, String>> details;

/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
Expand All @@ -78,11 +76,8 @@ public Long getZoneId() {
public Map<String, String> getDetails() {
Map<String, String> detailsMap = null;
if (details != null && !details.isEmpty()) {
detailsMap = new HashMap<String, String>();
Collection<?> props = details.values();
Iterator<?> iter = props.iterator();
while (iter.hasNext()) {
HashMap<String, String> detail = (HashMap<String, String>)iter.next();
detailsMap = new HashMap<>();
for (Map<String, String> detail : details.values()) {
String key = detail.get("key");
String value = detail.get("value");
detailsMap.put(key, value);
Expand All @@ -107,7 +102,7 @@ public void setProviderName(String providerName) {
this.providerName = providerName;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public final class AddImageStoreS3CMD extends BaseCmd implements ClientOptions {
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
ResourceAllocationException, NetworkRuleConflictException {

Map<String, String> dm = new HashMap();
Map<String, String> dm = new HashMap<>();

dm.put(ApiConstants.S3_ACCESS_KEY, getAccessKey());
dm.put(ApiConstants.SECRET_KEY, getSecretKey());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CreateStoragePoolCmd extends BaseCmd {
private Long clusterId;

@Parameter(name = ApiConstants.DETAILS, type = CommandType.MAP, description = "The details for the storage pool")
private Map details;
private Map<String, ? extends Map<String, String>> details;

@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "The name for the storage pool")
private String storagePoolName;
Expand Down Expand Up @@ -100,7 +100,7 @@ public Long getClusterId() {
return clusterId;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class UpdateStoragePoolCmd extends BaseCmd {
required = false,
description = "the details for the storage pool",
since = "4.19.0")
private Map details;
private Map<String, ? extends Map<String, String>> details;

@Parameter(name = ApiConstants.URL,
type = CommandType.STRING,
Expand Down Expand Up @@ -131,13 +131,10 @@ public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.StoragePool;
}

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

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

public String getUrl() {
return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public long getEntityOwnerId() {

@Override
public void execute() {
Map<String, String> dm = new HashMap<String, String>();
Map<String, String> dm = new HashMap<>();
dm.put(ApiConstants.ACCOUNT, getAccount());
dm.put(ApiConstants.USERNAME, getUsername());
dm.put(ApiConstants.KEY, getKey());
Expand Down
54 changes: 23 additions & 31 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@
import org.apache.cloudstack.storage.object.ObjectStore;
import org.apache.cloudstack.storage.object.ObjectStoreEntity;
import org.apache.cloudstack.storage.to.VolumeObjectTO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.BooleanUtils;
Expand Down Expand Up @@ -670,14 +670,16 @@ protected DataStore createLocalStorage(Map<String, Object> poolInfos) throws Con

long capacityBytes = poolInfos.get("capacityBytes") != null ? Long.parseLong(poolInfos.get("capacityBytes").toString()) : 0;

@SuppressWarnings("unchecked") // the local storage configuration is parsed into untyped maps
Map<String, String> poolDetails = (Map<String, String>) poolInfos.get("details");
StoragePoolInfo pInfo = new StoragePoolInfo(poolInfos.get("uuid").toString(),
host.getPrivateIpAddress(),
hostPath,
hostPath,
StoragePoolType.Filesystem,
capacityBytes,
0,
(Map<String,String>)poolInfos.get("details"),
poolDetails,
poolInfos.get("name").toString());

return createLocalStorage(host, pInfo);
Expand Down Expand Up @@ -1030,18 +1032,11 @@ protected Map<String,String> extractUriParamsAsMap(String url) {
return uriParams;
}

private Map<String, String> extractApiParamAsMap(Map ds) {
private Map<String, String> extractApiParamAsMap(Map<String, ? extends Map<String, String>> ds) {
Map<String, String> details = new HashMap<>();
if (ds != null) {
Collection detailsCollection = ds.values();
Iterator it = detailsCollection.iterator();
while (it.hasNext()) {
HashMap d = (HashMap)it.next();
Iterator it2 = d.entrySet().iterator();
while (it2.hasNext()) {
Map.Entry entry = (Map.Entry)it2.next();
details.put((String)entry.getKey(), (String)entry.getValue());
}
for (Map<String, String> d : ds.values()) {
details.putAll(d);
}
}
return details;
Expand Down Expand Up @@ -1421,9 +1416,8 @@ protected void checkIfStorageAccessGroupsExistsOnZone(long zoneId, List<String>

String storageAccessGroupsOnZone = zoneVO.getStorageAccessGroups();
List<String> zoneTagsList = parseTags(storageAccessGroupsOnZone);
List<String> newTags = storageAccessGroups;

List<String> existingTagsOnZone = (List<String>) CollectionUtils.intersection(newTags, zoneTagsList);
List<String> existingTagsOnZone = new ArrayList<>(CollectionUtils.intersection(storageAccessGroups, zoneTagsList));

if (CollectionUtils.isNotEmpty(existingTagsOnZone)) {
throw new CloudRuntimeException(String.format("access groups already exist on the zone: %s", existingTagsOnZone));
Expand All @@ -1439,10 +1433,9 @@ protected void checkIfStorageAccessGroupsExistsOnPod(long podId, List<String> st

List<String> podTagsList = parseTags(storageAccessGroupsOnPod);
List<String> zoneTagsList = parseTags(storageAccessGroupsOnZone);
List<String> newTags = storageAccessGroups;

List<String> existingTagsOnPod = (List<String>) CollectionUtils.intersection(newTags, podTagsList);
List<String> existingTagsOnZone = (List<String>) CollectionUtils.intersection(newTags, zoneTagsList);
List<String> existingTagsOnPod = new ArrayList<>(CollectionUtils.intersection(storageAccessGroups, podTagsList));
List<String> existingTagsOnZone = new ArrayList<>(CollectionUtils.intersection(storageAccessGroups, zoneTagsList));

if (CollectionUtils.isNotEmpty(existingTagsOnPod) || CollectionUtils.isNotEmpty(existingTagsOnZone)) {
String message = "access groups already exist ";
Expand Down Expand Up @@ -1473,11 +1466,10 @@ protected void checkIfStorageAccessGroupsExistsOnCluster(long clusterId, List<St
List<String> podTagsList = parseTags(storageAccessGroupsOnPod);
List<String> zoneTagsList = parseTags(storageAccessGroupsOnZone);
List<String> clusterTagsList = parseTags(storageAccessGroupsOnCluster);
List<String> newTags = storageAccessGroups;

List<String> existingTagsOnCluster = (List<String>) CollectionUtils.intersection(newTags, clusterTagsList);
List<String> existingTagsOnPod = (List<String>) CollectionUtils.intersection(newTags, podTagsList);
List<String> existingTagsOnZone = (List<String>) CollectionUtils.intersection(newTags, zoneTagsList);
List<String> existingTagsOnCluster = new ArrayList<>(CollectionUtils.intersection(storageAccessGroups, clusterTagsList));
List<String> existingTagsOnPod = new ArrayList<>(CollectionUtils.intersection(storageAccessGroups, podTagsList));
List<String> existingTagsOnZone = new ArrayList<>(CollectionUtils.intersection(storageAccessGroups, zoneTagsList));

if (CollectionUtils.isNotEmpty(existingTagsOnCluster) || CollectionUtils.isNotEmpty(existingTagsOnPod) || CollectionUtils.isNotEmpty(existingTagsOnZone)) {
String message = "access groups already exist ";
Expand Down Expand Up @@ -1573,14 +1565,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
@Override
public Pair<Map<String, String>, Boolean> getStoragePoolNFSMountOpts(StoragePool pool, Map<String, String> details) {
boolean details_added = false;
if (!pool.getPoolType().equals(Storage.StoragePoolType.NetworkFilesystem)) {
return new Pair<>(details, details_added);
}

StoragePoolDetailVO nfsMountOpts = _storagePoolDetailsDao.findDetail(pool.getId(), ApiConstants.NFS_MOUNT_OPTIONS);
if (nfsMountOpts != null) {
if (details == null) {
details = new HashMap<>();
if (pool.getPoolType().equals(Storage.StoragePoolType.NetworkFilesystem)) {
StoragePoolDetailVO nfsMountOpts = _storagePoolDetailsDao.findDetail(pool.getId(), ApiConstants.NFS_MOUNT_OPTIONS);
if (nfsMountOpts != null) {
if (details == null) {
details = new HashMap<>();
}
details.put(ApiConstants.NFS_MOUNT_OPTIONS, nfsMountOpts.getValue());
details_added = true;
}
details.put(ApiConstants.NFS_MOUNT_OPTIONS, nfsMountOpts.getValue());
details_added = true;
Expand Down Expand Up @@ -4483,7 +4475,7 @@ private void setVolumeObjectTOThrottling(VolumeObjectTO volumeTO, final ServiceO

@Override
@ActionEvent(eventType = EventTypes.EVENT_OBJECT_STORE_CREATE, eventDescription = "creating object storage")
public ObjectStore discoverObjectStore(String name, String url, Long size, String providerName, Map details)
public ObjectStore discoverObjectStore(String name, String url, Long size, String providerName, Map<String, String> details)
throws IllegalArgumentException, InvalidParameterValueException {
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(providerName);

Expand Down
Loading