mirror of https://github.com/apache/cloudstack.git
wip
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
parent
badada1e8e
commit
d535dbcd17
|
|
@ -20,6 +20,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.cloudstack.api.ApiCommandResourceType;
|
||||
import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal;
|
||||
|
|
@ -417,6 +418,12 @@ public class CallContext {
|
|||
return context;
|
||||
}
|
||||
|
||||
public Map<String, Object> getContextStringKeyParameters() {
|
||||
return context.entrySet().stream()
|
||||
.filter(entry -> entry.getKey() instanceof String)
|
||||
.collect(Collectors.toMap(entry -> (String) entry.getKey(), Map.Entry::getValue));
|
||||
}
|
||||
|
||||
public void putContextParameters(Map<Object, Object> details){
|
||||
if (details == null) return;
|
||||
for(Map.Entry<Object,Object>entry : details.entrySet()){
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.apache.cloudstack.api.Identity;
|
|||
import org.apache.cloudstack.api.InternalIdentity;
|
||||
import org.apache.cloudstack.api.response.ExceptionResponse;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
|
@ -47,6 +48,7 @@ public final class ErrorMessageResolver {
|
|||
|
||||
private static final String ERROR_MESSAGES_FILENAME = "error-messages.json";
|
||||
private static final String ERROR_KEY_ADMIN_SUFFIX = ".admin";
|
||||
private static final boolean INCLUDE_METADATA_ID_IN_MESSAGE = false;
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
|
|
@ -127,12 +129,16 @@ public final class ErrorMessageResolver {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("'").append(name).append("'");
|
||||
|
||||
if (!CallContext.current().isCallingAccountRootAdmin()) {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
Long id = null;
|
||||
if (CallContext.current().isCallingAccountRootAdmin() && obj instanceof InternalIdentity) {
|
||||
if (INCLUDE_METADATA_ID_IN_MESSAGE && obj instanceof InternalIdentity) {
|
||||
id = ((InternalIdentity) obj).getId();
|
||||
}
|
||||
|
||||
if (id == null && uuid == null) {
|
||||
if (ObjectUtils.allNull(id, uuid)) {
|
||||
return sb.toString();
|
||||
}
|
||||
sb.append(" (");
|
||||
|
|
@ -225,7 +231,11 @@ public final class ErrorMessageResolver {
|
|||
}
|
||||
|
||||
private static String expand(String template, Map<String, String> metadata) {
|
||||
if (metadata == null || metadata.isEmpty()) {
|
||||
Map<String, Object> allMetadata = CallContext.current().getContextStringKeyParameters();
|
||||
if (MapUtils.isNotEmpty(allMetadata)) {
|
||||
allMetadata.putAll(metadata);
|
||||
}
|
||||
if (MapUtils.isEmpty(allMetadata)) {
|
||||
return template;
|
||||
}
|
||||
String result = template;
|
||||
|
|
|
|||
|
|
@ -6322,15 +6322,16 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
|
|||
}
|
||||
|
||||
private void verifyServiceOffering(BaseDeployVMCmd cmd, ServiceOffering serviceOffering) {
|
||||
CallContext.current().putContextParameter("serviceOffering", serviceOffering);
|
||||
if (ServiceOffering.State.Inactive.equals(serviceOffering.getState())) {
|
||||
throw new InvalidParameterValueException("vm.deploy.serviceoffering.inactive",
|
||||
Map.of("serviceOffering", serviceOffering));
|
||||
Collections.emptyMap());
|
||||
}
|
||||
|
||||
Long overrideDiskOfferingId = cmd.getOverrideDiskOfferingId();
|
||||
if (serviceOffering.getDiskOfferingStrictness() && overrideDiskOfferingId != null) {
|
||||
throw new InvalidParameterValueException("vm.deploy.serviceoffering.override.not.allowed",
|
||||
Map.of("serviceOffering", serviceOffering));
|
||||
Collections.emptyMap());
|
||||
}
|
||||
|
||||
if (!serviceOffering.isDynamic()) {
|
||||
|
|
|
|||
|
|
@ -460,5 +460,6 @@
|
|||
"label.yourinstance": "आपका उदाहरण",
|
||||
"label.zone": "ज़ोन",
|
||||
"label.zoneid": "ज़ोन",
|
||||
"label.zonename": "ज़ोन नाम"
|
||||
"label.zonename": "ज़ोन नाम",
|
||||
"vm.deploy.serviceoffering.inactive": "इंस्टेंस डिप्लॉय नहीं किया जा सका क्योंकि दी गई सर्विस ऑफ़रिंग {{serviceOffering}} इनएक्टिव है।"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue