Skip to content

Commit fe8d81e

Browse files
author
Jessica Wang
committed
bug 9765: This is NOT an UI bug. This is a server-side bug. UI calls DeployVM API with ServiceOfferingID parameter (NOT ServiceOfferingDescription parameter). Then, server-side gets ServiceOfferingDescription by ServiceOfferingID and send it to DomR WITHTOUT escaping it first. DomR doesn't support full range of unicode character set. Therefore, DomR fails to accept metadata that has non-ascii code (error: "vm_data failed"). This check-in will send Unicode-escaped string of metadata "service-offering", "availability-zone" and "local-hostname" to DomR. Data Consumer of VM-data service needs to unescape the content accordingly.
1 parent feb226b commit fe8d81e

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
import com.cloud.utils.NumbersUtil;
153153
import com.cloud.utils.Pair;
154154
import com.cloud.utils.PasswordGenerator;
155+
import com.cloud.utils.StringUtils;
155156
import com.cloud.utils.component.ComponentLocator;
156157
import com.cloud.utils.component.Inject;
157158
import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -598,10 +599,10 @@ private VmDataCommand generateVmDataCommand(DomainRouterVO router, String vmPriv
598599
cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
599600

600601
cmd.addVmData("userdata", "user-data", userData);
601-
cmd.addVmData("metadata", "service-offering", serviceOffering);
602-
cmd.addVmData("metadata", "availability-zone", zoneName);
602+
cmd.addVmData("metadata", "service-offering", StringUtils.unicodeEscape(serviceOffering));
603+
cmd.addVmData("metadata", "availability-zone", StringUtils.unicodeEscape(zoneName));
603604
cmd.addVmData("metadata", "local-ipv4", guestIpAddress);
604-
cmd.addVmData("metadata", "local-hostname", vmName);
605+
cmd.addVmData("metadata", "local-hostname", StringUtils.unicodeEscape(vmName));
605606
cmd.addVmData("metadata", "public-ipv4", router.getPublicIpAddress());
606607
cmd.addVmData("metadata", "public-hostname", router.getPublicIpAddress());
607608
cmd.addVmData("metadata", "instance-id", vmInstanceName);

utils/src/com/cloud/utils/StringUtils.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424

2525
// StringUtils exists in Apache Commons Lang, but rather than import the entire JAR to our system, for now
2626
// just implement the method needed
27-
public class StringUtils {
27+
public class StringUtils {
28+
private static final char[] hexChar = {
29+
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
30+
};
31+
2832
public static String join(Iterable<? extends Object> iterable, String delim) {
2933
StringBuilder sb = new StringBuilder();
3034
if (iterable != null) {
@@ -97,4 +101,22 @@ public static String getExceptionStackInfo(Throwable e) {
97101

98102
return sb.toString();
99103
}
104+
105+
public static String unicodeEscape(String s) {
106+
StringBuilder sb = new StringBuilder();
107+
for (int i = 0; i < s.length(); i++) {
108+
char c = s.charAt(i);
109+
if ((c >> 7) > 0) {
110+
sb.append("\\u");
111+
sb.append(hexChar[(c >> 12) & 0xF]); // append the hex character for the left-most 4-bits
112+
sb.append(hexChar[(c >> 8) & 0xF]); // hex for the second group of 4-bits from the left
113+
sb.append(hexChar[(c >> 4) & 0xF]); // hex for the third group
114+
sb.append(hexChar[c & 0xF]); // hex for the last group, e.g., the right most 4-bits
115+
}
116+
else {
117+
sb.append(c);
118+
}
119+
}
120+
return sb.toString();
121+
}
100122
}

0 commit comments

Comments
 (0)