Skip to content

Commit 5a23293

Browse files
committed
wip
Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
1 parent 69c06cb commit 5a23293

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

api/src/main/java/org/apache/cloudstack/context/CallContext.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Map;
2121
import java.util.Stack;
2222
import java.util.UUID;
23+
import java.util.stream.Collectors;
2324

2425
import org.apache.cloudstack.api.ApiCommandResourceType;
2526
import org.apache.cloudstack.managed.threadlocal.ManagedThreadLocal;
@@ -417,6 +418,12 @@ public Map<Object, Object> getContextParameters() {
417418
return context;
418419
}
419420

421+
public Map<String, Object> getContextStringKeyParameters() {
422+
return context.entrySet().stream()
423+
.filter(entry -> entry.getKey() instanceof String)
424+
.collect(Collectors.toMap(entry -> (String) entry.getKey(), Map.Entry::getValue));
425+
}
426+
420427
public void putContextParameters(Map<Object, Object> details){
421428
if (details == null) return;
422429
for(Map.Entry<Object,Object>entry : details.entrySet()){

api/src/main/java/org/apache/cloudstack/context/ErrorMessageResolver.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.cloudstack.api.InternalIdentity;
3131
import org.apache.cloudstack.api.response.ExceptionResponse;
3232
import org.apache.commons.collections.MapUtils;
33+
import org.apache.commons.lang3.ObjectUtils;
3334
import org.apache.commons.lang3.StringUtils;
3435
import org.apache.logging.log4j.LogManager;
3536
import org.apache.logging.log4j.Logger;
@@ -47,6 +48,7 @@ public final class ErrorMessageResolver {
4748

4849
private static final String ERROR_MESSAGES_FILENAME = "error-messages.json";
4950
private static final String ERROR_KEY_ADMIN_SUFFIX = ".admin";
51+
private static final boolean INCLUDE_METADATA_ID_IN_MESSAGE = false;
5052

5153
private static final ObjectMapper MAPPER = new ObjectMapper();
5254

@@ -127,12 +129,16 @@ private static String getMetadataObjectStringValue(Object obj) {
127129
StringBuilder sb = new StringBuilder();
128130
sb.append("'").append(name).append("'");
129131

132+
if (!CallContext.current().isCallingAccountRootAdmin()) {
133+
return sb.toString();
134+
}
135+
130136
Long id = null;
131-
if (CallContext.current().isCallingAccountRootAdmin() && obj instanceof InternalIdentity) {
137+
if (INCLUDE_METADATA_ID_IN_MESSAGE && obj instanceof InternalIdentity) {
132138
id = ((InternalIdentity) obj).getId();
133139
}
134140

135-
if (id == null && uuid == null) {
141+
if (ObjectUtils.allNull(id, uuid)) {
136142
return sb.toString();
137143
}
138144
sb.append(" (");
@@ -225,7 +231,11 @@ private static synchronized void reloadIfRequired() {
225231
}
226232

227233
private static String expand(String template, Map<String, String> metadata) {
228-
if (metadata == null || metadata.isEmpty()) {
234+
Map<String, Object> allMetadata = CallContext.current().getContextStringKeyParameters();
235+
if (MapUtils.isNotEmpty(allMetadata)) {
236+
allMetadata.putAll(metadata);
237+
}
238+
if (MapUtils.isEmpty(allMetadata)) {
229239
return template;
230240
}
231241
String result = template;

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6264,15 +6264,16 @@ public String finalizeUserData(String userData, Long userDataId, VirtualMachineT
62646264
}
62656265

62666266
private void verifyServiceOffering(BaseDeployVMCmd cmd, ServiceOffering serviceOffering) {
6267+
CallContext.current().putContextParameter("serviceOffering", serviceOffering);
62676268
if (ServiceOffering.State.Inactive.equals(serviceOffering.getState())) {
62686269
throw new InvalidParameterValueException("vm.deploy.serviceoffering.inactive",
6269-
Map.of("serviceOffering", serviceOffering));
6270+
Collections.emptyMap());
62706271
}
62716272

62726273
Long overrideDiskOfferingId = cmd.getOverrideDiskOfferingId();
62736274
if (serviceOffering.getDiskOfferingStrictness() && overrideDiskOfferingId != null) {
62746275
throw new InvalidParameterValueException("vm.deploy.serviceoffering.override.not.allowed",
6275-
Map.of("serviceOffering", serviceOffering));
6276+
Collections.emptyMap());
62766277
}
62776278

62786279
if (!serviceOffering.isDynamic()) {

ui/public/locales/hi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,5 +460,6 @@
460460
"label.yourinstance": "आपका उदाहरण",
461461
"label.zone": "ज़ोन",
462462
"label.zoneid": "ज़ोन",
463-
"label.zonename": "ज़ोन नाम"
463+
"label.zonename": "ज़ोन नाम",
464+
"vm.deploy.serviceoffering.inactive": "इंस्टेंस डिप्लॉय नहीं किया जा सका क्योंकि दी गई सर्विस ऑफ़रिंग {{serviceOffering}} इनएक्टिव है।"
464465
}

0 commit comments

Comments
 (0)