Java Code Examples for io.fabric8.kubernetes.api.model.ResourceRequirements#getLimits()

The following examples show how to use io.fabric8.kubernetes.api.model.ResourceRequirements#getLimits() . 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: 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 2
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 3
Source File: InitTaskManagerDecoratorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMainContainerResourceRequirements() {
	final ResourceRequirements resourceRequirements = this.resultMainContainer.getResources();

	final Map<String, Quantity> requests = resourceRequirements.getRequests();
	assertEquals(Double.toString(TASK_MANAGER_CPU), requests.get("cpu").getAmount());
	assertEquals(String.valueOf(TOTAL_PROCESS_MEMORY), requests.get("memory").getAmount());

	final Map<String, Quantity> limits = resourceRequirements.getLimits();
	assertEquals(Double.toString(TASK_MANAGER_CPU), limits.get("cpu").getAmount());
	assertEquals(String.valueOf(TOTAL_PROCESS_MEMORY), limits.get("memory").getAmount());
}
 
Example 4
Source File: InitTaskManagerDecoratorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testExternalResourceInResourceRequirements() {
	final ResourceRequirements resourceRequirements = this.resultMainContainer.getResources();

	final Map<String, Quantity> requests = resourceRequirements.getRequests();
	assertEquals(Long.toString(RESOURCE_AMOUNT), requests.get(RESOURCE_CONFIG_KEY).getAmount());

	final Map<String, Quantity> limits = resourceRequirements.getLimits();
	assertEquals(Long.toString(RESOURCE_AMOUNT), limits.get(RESOURCE_CONFIG_KEY).getAmount());
}
 
Example 5
Source File: InitJobManagerDecoratorTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testMainContainerResourceRequirements() {
	final ResourceRequirements resourceRequirements = this.resultMainContainer.getResources();

	final Map<String, Quantity> requests = resourceRequirements.getRequests();
	assertEquals(Double.toString(JOB_MANAGER_CPU), requests.get("cpu").getAmount());
	assertEquals(String.valueOf(JOB_MANAGER_MEMORY), requests.get("memory").getAmount());

	final Map<String, Quantity> limits = resourceRequirements.getLimits();
	assertEquals(Double.toString(JOB_MANAGER_CPU), limits.get("cpu").getAmount());
	assertEquals(String.valueOf(JOB_MANAGER_MEMORY), limits.get("memory").getAmount());
}