Search in sources :

Example 1 with ExternalResource

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

the class ResourceProfileTest method testGet.

@Test
public void testGet() {
    ResourceSpec rs = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.6)).build();
    ResourceProfile rp = ResourceProfile.fromResourceSpec(rs, MemorySize.ofMebiBytes(50));
    assertEquals(new CPUResource(1.0), rp.getCpuCores());
    assertEquals(150, rp.getTotalMemory().getMebiBytes());
    assertEquals(100, rp.getOperatorsMemory().getMebiBytes());
    assertEquals(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.6), rp.getExtendedResources().get(EXTERNAL_RESOURCE_NAME));
}
Also used : ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) CPUResource(org.apache.flink.api.common.resources.CPUResource) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 2 with ExternalResource

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

the class ResourceProfileTest method testEquals.

@Test
public void testEquals() {
    ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).build();
    ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).build();
    assertEquals(ResourceProfile.fromResourceSpec(rs1), ResourceProfile.fromResourceSpec(rs2));
    ResourceSpec rs3 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2)).build();
    ResourceSpec rs4 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1)).build();
    assertNotEquals(ResourceProfile.fromResourceSpec(rs3), ResourceProfile.fromResourceSpec(rs4));
    ResourceSpec rs5 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2)).build();
    MemorySize networkMemory = MemorySize.ofMebiBytes(100);
    assertEquals(ResourceProfile.fromResourceSpec(rs3, networkMemory), ResourceProfile.fromResourceSpec(rs5, networkMemory));
    final ResourceProfile rp1 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).setNetworkMemoryMB(100).build();
    final ResourceProfile rp2 = ResourceProfile.newBuilder().setCpuCores(1.1).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).setNetworkMemoryMB(100).build();
    final ResourceProfile rp3 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(110).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).setNetworkMemoryMB(100).build();
    final ResourceProfile rp4 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(110).setManagedMemoryMB(100).setNetworkMemoryMB(100).build();
    final ResourceProfile rp5 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(110).setNetworkMemoryMB(100).build();
    final ResourceProfile rp6 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(110).setNetworkMemoryMB(100).build();
    final ResourceProfile rp7 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).setNetworkMemoryMB(110).build();
    final ResourceProfile rp8 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).setNetworkMemoryMB(100).build();
    assertNotEquals(rp1, rp2);
    assertNotEquals(rp1, rp3);
    assertNotEquals(rp1, rp4);
    assertNotEquals(rp1, rp5);
    assertNotEquals(rp1, rp6);
    assertNotEquals(rp1, rp7);
    assertEquals(rp1, rp8);
}
Also used : MemorySize(org.apache.flink.configuration.MemorySize) ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 3 with ExternalResource

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

the class ResourceSpec method lessThanOrEqual.

/**
 * Checks the current resource less than or equal with the other resource by comparing all the
 * fields in the resource.
 *
 * @param other The resource to compare
 * @return True if current resource is less than or equal with the other resource, otherwise
 *     return false.
 */
public boolean lessThanOrEqual(final ResourceSpec other) {
    checkNotNull(other, "Cannot compare with null resources");
    if (this.equals(UNKNOWN) && other.equals(UNKNOWN)) {
        return true;
    } else if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) {
        throw new IllegalArgumentException("Cannot compare specified resources with UNKNOWN resources.");
    }
    int cmp1 = this.cpuCores.getValue().compareTo(other.getCpuCores().getValue());
    int cmp2 = this.taskHeapMemory.compareTo(other.taskHeapMemory);
    int cmp3 = this.taskOffHeapMemory.compareTo(other.taskOffHeapMemory);
    int cmp4 = this.managedMemory.compareTo(other.managedMemory);
    if (cmp1 <= 0 && cmp2 <= 0 && cmp3 <= 0 && cmp4 <= 0) {
        for (ExternalResource resource : extendedResources.values()) {
            if (!other.extendedResources.containsKey(resource.getName()) || other.extendedResources.get(resource.getName()).getValue().compareTo(resource.getValue()) < 0) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : ExternalResource(org.apache.flink.api.common.resources.ExternalResource)

Example 4 with ExternalResource

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

the class ExternalResourceUtilsTest method testRecognizeEmptyResourceList.

@Test
public void testRecognizeEmptyResourceList() {
    final Configuration config = new Configuration();
    config.setString(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST.key(), ExternalResourceOptions.NONE);
    config.setLong(ExternalResourceOptions.getAmountConfigOptionForResource(RESOURCE_NAME_1), RESOURCE_AMOUNT_1);
    final Collection<ExternalResource> externalResources = ExternalResourceUtils.getExternalResourcesCollection(config);
    assertThat(externalResources, is(empty()));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 5 with ExternalResource

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

the class TaskExecutorProcessSpecTest method testNotEquals.

@Test
public void testNotEquals() {
    TaskExecutorProcessSpec spec1 = new TaskExecutorProcessSpec(new CPUResource(1.0), MemorySize.parse("1m"), MemorySize.parse("2m"), MemorySize.parse("3m"), MemorySize.parse("4m"), MemorySize.parse("5m"), MemorySize.parse("6m"), MemorySize.parse("7m"), MemorySize.parse("8m"), Collections.singleton(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1)));
    TaskExecutorProcessSpec spec2 = new TaskExecutorProcessSpec(new CPUResource(0.0), MemorySize.ZERO, MemorySize.ZERO, MemorySize.ZERO, MemorySize.ZERO, MemorySize.ZERO, MemorySize.ZERO, MemorySize.ZERO, MemorySize.ZERO, Collections.emptyList());
    assertThat(spec1, not(spec2));
}
Also used : TaskExecutorProcessSpec(org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec) CPUResource(org.apache.flink.api.common.resources.CPUResource) 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