mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Search for resource type efficiently (#6242)
Co-authored-by: Rakesh Venkatesh <rakeshv@apache.org>
This commit is contained in:
parent
4418574478
commit
aad03530af
@ -20,6 +20,10 @@ import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ResourceTag extends ControlledEntity, Identity, InternalIdentity {
|
||||
|
||||
// FIXME - extract enum to another interface as its used both by resourceTags and resourceMetaData code
|
||||
@ -80,6 +84,7 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit
|
||||
private final boolean resourceTagsSupport;
|
||||
private final boolean metadataSupport;
|
||||
private boolean resourceIconSupport;
|
||||
private static final Map<String, ResourceObjectType> resourceObjectTypeMap = new HashMap<>();
|
||||
|
||||
public boolean resourceTagsSupport() {
|
||||
return resourceTagsSupport;
|
||||
@ -92,6 +97,16 @@ public interface ResourceTag extends ControlledEntity, Identity, InternalIdentit
|
||||
public boolean resourceIconSupport() {
|
||||
return resourceIconSupport;
|
||||
}
|
||||
|
||||
static {
|
||||
for (var value : ResourceObjectType.values()) {
|
||||
resourceObjectTypeMap.put(value.toString().toLowerCase(Locale.ROOT), value);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResourceObjectType getResourceObjectType(String type) {
|
||||
return resourceObjectTypeMap.getOrDefault(type.toLowerCase(Locale.ROOT), null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -72,6 +72,7 @@ import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.UserVmVO;
|
||||
import com.cloud.vm.snapshot.VMSnapshotVO;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ResourceManagerUtilImpl implements ResourceManagerUtil {
|
||||
public static final Map<ResourceTag.ResourceObjectType, Class<?>> s_typeMap = new HashMap<>();
|
||||
@ -159,13 +160,8 @@ public class ResourceManagerUtilImpl implements ResourceManagerUtil {
|
||||
|
||||
@Override
|
||||
public ResourceTag.ResourceObjectType getResourceType(String resourceTypeStr) {
|
||||
|
||||
for (ResourceTag.ResourceObjectType type : ResourceTag.ResourceObjectType.values()) {
|
||||
if (type.toString().equalsIgnoreCase(resourceTypeStr)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
throw new InvalidParameterValueException("Invalid resource type: " + resourceTypeStr);
|
||||
return Optional.ofNullable(ResourceTag.ResourceObjectType.getResourceObjectType(resourceTypeStr))
|
||||
.orElseThrow(() -> new InvalidParameterValueException("Invalid resource type " + resourceTypeStr));
|
||||
}
|
||||
|
||||
public void checkResourceAccessible(Long accountId, Long domainId, String exceptionMessage) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user