Java Code Examples for io.fabric8.kubernetes.api.model.Quantity#getAmount()

The following examples show how to use io.fabric8.kubernetes.api.model.Quantity#getAmount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageUtils.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: Containers.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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;
}