|
|
@@ -0,0 +1,52 @@
|
|
|
+package nju.seec.SEECdemo.logic.api.k8s.util;
|
|
|
+
|
|
|
+import io.kubernetes.client.custom.Quantity;
|
|
|
+import lombok.Data;
|
|
|
+import lombok.NoArgsConstructor;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+
|
|
|
+@Data
|
|
|
+@NoArgsConstructor
|
|
|
+public class StorageQuantity {
|
|
|
+
|
|
|
+ private BigDecimal quantity;
|
|
|
+
|
|
|
+ //存储的默认单位为MB
|
|
|
+ private Unit unit = Unit.MB;
|
|
|
+
|
|
|
+ //存储单位
|
|
|
+ public enum Unit{
|
|
|
+ KB("Ki"),
|
|
|
+ MB("Mi"),
|
|
|
+ GB("Gi");
|
|
|
+
|
|
|
+ private String code;
|
|
|
+
|
|
|
+ Unit(String code) {
|
|
|
+ this.code = code;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static final StorageQuantity EMPTY = new StorageQuantity(0);
|
|
|
+
|
|
|
+ public StorageQuantity(int quantity){
|
|
|
+ this.quantity = BigDecimal.valueOf(quantity);
|
|
|
+ }
|
|
|
+
|
|
|
+ public StorageQuantity(int quantity, Unit unit) {
|
|
|
+ this.quantity = BigDecimal.valueOf(quantity);
|
|
|
+ this.unit = unit;
|
|
|
+ }
|
|
|
+
|
|
|
+ public StorageQuantity(Quantity quantity) {
|
|
|
+ this.quantity = quantity.getNumber();
|
|
|
+ //@todo 检验到底是啥单位
|
|
|
+ }
|
|
|
+
|
|
|
+ public Quantity toQuantity(){
|
|
|
+ return new Quantity(quantity, Quantity.Format.DECIMAL_SI);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|