Skip to content

Commit

Permalink
fix memory specification unit for token 'Mi'
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Apr 19, 2024
1 parent b63db43 commit 8c598a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class Specification {

private static final Pattern p = Pattern.compile("(\\d+(\\.\\d)?)([mGM]?)");
private static final Pattern p = Pattern.compile("(\\d+(\\.\\d)?)(([mGM]|Mi)?)");

public static Specification parse(String val) {
Matcher m = p.matcher(val);
Expand Down Expand Up @@ -72,7 +72,7 @@ public int normalizeMemory() {
*/
public int normalizeMemory(Optional<Integer> proportion) {
float result = 0;
if ("M".equals(this.getUnit())) {
if ("Mi".equals(this.getUnit()) || "M".equals(this.getUnit())) {
result = this.getVal();
} else if ("G".equals(this.getUnit())) {
result = this.getVal() * 1024;
Expand Down Expand Up @@ -103,7 +103,7 @@ public int normalizeCPU() {
} else {
throw new IllegalStateException("invalid cpu unit:" + this.getUnit());
}
return (int)result;
return (int) result;
}

public boolean memoryBigThan(Specification spec) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.qlangtech.tis.coredefine.module.action;

import junit.framework.TestCase;
import org.apache.commons.lang.StringUtils;

import java.util.Optional;

Expand All @@ -39,5 +40,16 @@ public void testNormalizeMemory() {
assertEquals("G", mem.getUnit());
assertEquals(1024, mem.normalizeMemory());
assertEquals(512, mem.normalizeMemory(Optional.of(50)));

mem = Specification.parse("1500Mi");
assertEquals("Mi", mem.getUnit());
assertEquals(1500, mem.normalizeMemory());
assertEquals(750, mem.normalizeMemory(Optional.of(50)));

Specification cpu = Specification.parse("1500");

assertTrue(StringUtils.isEmpty( cpu.getUnit() ));
assertEquals(1500*1024, cpu.normalizeCPU());

}
}
2 changes: 1 addition & 1 deletion tis-console.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ spec:
mountPath: /opt/app/tis-uber/tis-assemble/conf/tis-web-config/
- name: tis-console-pvc
mountPath: "/opt/data"
image: registry.cn-hangzhou.aliyuncs.com/tis/tis-console:4.0.0.32
image: registry.cn-hangzhou.aliyuncs.com/tis/tis-console:4.0.0.35
# command: [ "/bin/sh", "-c", "sleep 1000000" ]
ports:
- name: tis-8080
Expand Down

0 comments on commit 8c598a4

Please sign in to comment.