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 @@
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 @@
return clusterId;
}

public Map getDetails() {
public Map<String, ? extends Map<String, String>> getDetails() {

Check failure on line 103 in api/src/main/java/org/apache/cloudstack/api/command/admin/storage/CreateStoragePoolCmd.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove usage of generic wildcard type.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxqByWl1v1LY0xCirI&open=AaGxqByWl1v1LY0xCirI&pullRequest=14560
return details;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
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 @@
return ApiCommandResourceType.StoragePool;
}

public Map<String,String> getDetails() {
public Map<String, ? extends Map<String, String>> getDetails() {

Check failure on line 134 in api/src/main/java/org/apache/cloudstack/api/command/admin/storage/UpdateStoragePoolCmd.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove usage of generic wildcard type.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxqBqql1v1LY0xCirH&open=AaGxqBqql1v1LY0xCirH&pullRequest=14560
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
55 changes: 23 additions & 32 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -143,8 +142,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 +669,16 @@

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");

Check failure on line 673 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "details" 6 times.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxqB49l1v1LY0xCirJ&open=AaGxqB49l1v1LY0xCirJ&pullRequest=14560
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 +1031,11 @@
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 +1415,8 @@

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 +1432,9 @@

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 +1465,10 @@
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,16 +1564,16 @@
@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());

Check failure on line 1576 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Fix this access that will throw a NullPointerException when executed.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxqB49l1v1LY0xCirK&open=AaGxqB49l1v1LY0xCirK&pullRequest=14560
details_added = true;
}
return new Pair<>(details, details_added);
Expand Down Expand Up @@ -4483,7 +4474,7 @@

@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