下面列出了io.fabric8.kubernetes.api.model.Quantity#getAmount ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Parse a K8S-style representation of a disk size, such as {@code 100Gi},
* into the equivalent number of bytes represented as a long.
*
* @param size The String representation of the volume size.
* @return The equivalent number of bytes.
*/
public static long parseMemory(Quantity size) {
String amount = size.getAmount();
String format = size.getFormat();
if (format != null) {
return parseMemory(amount + format);
} else {
return parseMemory(amount);
}
}
/**
* Returns the RAM limit in bytes, if it is present in given container otherwise 0 will be
* returned.
*/
public static long getRamLimit(Container container) {
final ResourceRequirements resources = container.getResources();
final Quantity quantity;
if (resources != null
&& resources.getLimits() != null
&& (quantity = resources.getLimits().get("memory")) != null
&& quantity.getAmount() != null) {
return Quantity.getAmountInBytes(quantity).longValue();
}
return 0;
}
/**
* Returns the RAM request in bytes, if it is present in given container otherwise 0 will be
* returned.
*/
public static long getRamRequest(Container container) {
final ResourceRequirements resources = container.getResources();
final Quantity quantity;
if (resources != null
&& resources.getRequests() != null
&& (quantity = resources.getRequests().get("memory")) != null
&& quantity.getAmount() != null) {
return Quantity.getAmountInBytes(quantity).longValue();
}
return 0;
}
/**
* Returns the CPU limit in cores, if it is present in given container otherwise 0 will be
* returned.
*/
public static float getCpuLimit(Container container) {
final ResourceRequirements resources = container.getResources();
final Quantity quantity;
if (resources != null
&& resources.getLimits() != null
&& (quantity = resources.getLimits().get("cpu")) != null
&& quantity.getAmount() != null) {
return KubernetesSize.toCores(quantity.getAmount());
}
return 0;
}
/**
* Returns the CPU request in bytes, if it is present in given container otherwise 0 will be
* returned.
*/
public static float getCpuRequest(Container container) {
final ResourceRequirements resources = container.getResources();
final Quantity quantity;
if (resources != null
&& resources.getRequests() != null
&& (quantity = resources.getRequests().get("cpu")) != null
&& quantity.getAmount() != null) {
return KubernetesSize.toCores(quantity.getAmount());
}
return 0;
}