Search in sources :

Example 6 with ExternalResource

use of org.apache.flink.api.common.resources.ExternalResource in project flink by apache.

the class SlotManagerUtilsTest method testGenerateDefaultSlotConsistentWithTaskExecutorResourceUtils.

@Test
public void testGenerateDefaultSlotConsistentWithTaskExecutorResourceUtils() {
    final int numSlots = 5;
    final TaskExecutorResourceSpec taskExecutorResourceSpec = new TaskExecutorResourceSpec(new CPUResource(1.0), MemorySize.parse("1m"), MemorySize.parse("2m"), MemorySize.parse("3m"), MemorySize.parse("4m"), Collections.singleton(new ExternalResource(EXTERNAL_RESOURCE_NAME, numSlots)));
    final ResourceProfile resourceProfileFromTaskExecutorResourceUtils = TaskExecutorResourceUtils.generateDefaultSlotResourceProfile(taskExecutorResourceSpec, numSlots);
    final ResourceProfile totalResourceProfile = TaskExecutorResourceUtils.generateTotalAvailableResourceProfile(taskExecutorResourceSpec);
    final WorkerResourceSpec workerResourceSpec = WorkerResourceSpec.fromTotalResourceProfile(totalResourceProfile, numSlots);
    assertThat(SlotManagerUtils.generateDefaultSlotResourceProfile(totalResourceProfile, numSlots), is(resourceProfileFromTaskExecutorResourceUtils));
    assertThat(SlotManagerUtils.generateDefaultSlotResourceProfile(workerResourceSpec, numSlots), is(resourceProfileFromTaskExecutorResourceUtils));
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) TaskExecutorResourceSpec(org.apache.flink.runtime.taskexecutor.TaskExecutorResourceSpec) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) CPUResource(org.apache.flink.api.common.resources.CPUResource) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 7 with ExternalResource

use of org.apache.flink.api.common.resources.ExternalResource in project flink by apache.

the class ResourceSpecTest method testSubtract.

@Test
public void testSubtract() {
    final ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1)).build();
    final ResourceSpec rs2 = ResourceSpec.newBuilder(0.2, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.5)).build();
    final ResourceSpec subtracted = rs1.subtract(rs2);
    assertEquals(new CPUResource(0.8), subtracted.getCpuCores());
    assertEquals(0, subtracted.getTaskHeapMemory().getMebiBytes());
    assertEquals(new ExternalResource(EXTERNAL_RESOURCE_NAME, 0.6), subtracted.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
}
Also used : CPUResource(org.apache.flink.api.common.resources.CPUResource) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 8 with ExternalResource

use of org.apache.flink.api.common.resources.ExternalResource in project flink by apache.

the class ResourceSpecTest method testMerge.

@Test
public void testMerge() throws Exception {
    ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1)).build();
    ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).build();
    ResourceSpec rs3 = rs1.merge(rs2);
    assertEquals(new CPUResource(2.0), rs3.getCpuCores());
    assertEquals(200, rs3.getTaskHeapMemory().getMebiBytes());
    assertEquals(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1), rs3.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
    ResourceSpec rs4 = rs1.merge(rs3);
    assertEquals(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2), rs4.getExtendedResource(EXTERNAL_RESOURCE_NAME).get());
}
Also used : CPUResource(org.apache.flink.api.common.resources.CPUResource) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 9 with ExternalResource

use of org.apache.flink.api.common.resources.ExternalResource in project flink by apache.

the class KubernetesUtils method getResourceRequirements.

/**
 * Get resource requirements from memory and cpu.
 *
 * @param resourceRequirements resource requirements in pod template
 * @param mem Memory in mb.
 * @param memoryLimitFactor limit factor for the memory, used to set the limit resources.
 * @param cpu cpu.
 * @param cpuLimitFactor limit factor for the cpu, used to set the limit resources.
 * @param externalResources external resources
 * @param externalResourceConfigKeys config keys of external resources
 * @return KubernetesResource requirements.
 */
public static ResourceRequirements getResourceRequirements(ResourceRequirements resourceRequirements, int mem, double memoryLimitFactor, double cpu, double cpuLimitFactor, Map<String, ExternalResource> externalResources, Map<String, String> externalResourceConfigKeys) {
    final Quantity cpuQuantity = new Quantity(String.valueOf(cpu));
    final Quantity cpuLimitQuantity = new Quantity(String.valueOf(cpu * cpuLimitFactor));
    final Quantity memQuantity = new Quantity(mem + Constants.RESOURCE_UNIT_MB);
    final Quantity memQuantityLimit = new Quantity(((int) (mem * memoryLimitFactor)) + Constants.RESOURCE_UNIT_MB);
    ResourceRequirementsBuilder resourceRequirementsBuilder = new ResourceRequirementsBuilder(resourceRequirements).addToRequests(Constants.RESOURCE_NAME_MEMORY, memQuantity).addToRequests(Constants.RESOURCE_NAME_CPU, cpuQuantity).addToLimits(Constants.RESOURCE_NAME_MEMORY, memQuantityLimit).addToLimits(Constants.RESOURCE_NAME_CPU, cpuLimitQuantity);
    // Add the external resources to resource requirement.
    for (Map.Entry<String, ExternalResource> externalResource : externalResources.entrySet()) {
        final String configKey = externalResourceConfigKeys.get(externalResource.getKey());
        if (!StringUtils.isNullOrWhitespaceOnly(configKey)) {
            final Quantity resourceQuantity = new Quantity(String.valueOf(externalResource.getValue().getValue().longValue()));
            resourceRequirementsBuilder.addToRequests(configKey, resourceQuantity).addToLimits(configKey, resourceQuantity);
            LOG.info("Request external resource {} with config key {}.", resourceQuantity.getAmount(), configKey);
        }
    }
    return resourceRequirementsBuilder.build();
}
Also used : ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) KubernetesConfigMap(org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap) Map(java.util.Map) HashMap(java.util.HashMap) ExternalResource(org.apache.flink.api.common.resources.ExternalResource)

Example 10 with ExternalResource

use of org.apache.flink.api.common.resources.ExternalResource in project flink by apache.

the class SlotSharingGroupUtilsTest method testCovertToResourceSpec.

@Test
public void testCovertToResourceSpec() {
    final ExternalResource gpu = new ExternalResource("gpu", 1);
    final ResourceSpec resourceSpec = ResourceSpec.newBuilder(1.0, 100).setManagedMemoryMB(200).setTaskOffHeapMemoryMB(300).setExtendedResource(gpu).build();
    final SlotSharingGroup slotSharingGroup1 = SlotSharingGroup.newBuilder("ssg").setCpuCores(resourceSpec.getCpuCores().getValue().doubleValue()).setTaskHeapMemory(resourceSpec.getTaskHeapMemory()).setTaskOffHeapMemory(resourceSpec.getTaskOffHeapMemory()).setManagedMemory(resourceSpec.getManagedMemory()).setExternalResource(gpu.getName(), gpu.getValue().doubleValue()).build();
    final SlotSharingGroup slotSharingGroup2 = SlotSharingGroup.newBuilder("ssg").build();
    assertThat(SlotSharingGroupUtils.extractResourceSpec(slotSharingGroup1), is(resourceSpec));
    assertThat(SlotSharingGroupUtils.extractResourceSpec(slotSharingGroup2), is(ResourceSpec.UNKNOWN));
}
Also used : ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) SlotSharingGroup(org.apache.flink.api.common.operators.SlotSharingGroup) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Aggregations

ExternalResource (org.apache.flink.api.common.resources.ExternalResource)19 Test (org.junit.Test)16 CPUResource (org.apache.flink.api.common.resources.CPUResource)6 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)5 ResourceSpec (org.apache.flink.api.common.operators.ResourceSpec)4 WorkerResourceSpec (org.apache.flink.runtime.resourcemanager.WorkerResourceSpec)4 Configuration (org.apache.flink.configuration.Configuration)3 HashMap (java.util.HashMap)2 TaskExecutorProcessSpec (org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec)2 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 ResourceRequirementsBuilder (io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder)1 Map (java.util.Map)1 SlotSharingGroup (org.apache.flink.api.common.operators.SlotSharingGroup)1 MemorySize (org.apache.flink.configuration.MemorySize)1 KubernetesConfigMap (org.apache.flink.kubernetes.kubeclient.resources.KubernetesConfigMap)1 TaskExecutorResourceSpec (org.apache.flink.runtime.taskexecutor.TaskExecutorResourceSpec)1