Search in sources :

Example 11 with ExternalResource

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

the class ResourceSpec method subtract.

/**
 * Subtracts another resource spec from this one.
 *
 * @param other The other resource spec to subtract.
 * @return The subtracted resource spec.
 */
public ResourceSpec subtract(final ResourceSpec other) {
    checkNotNull(other, "Cannot subtract null resources");
    if (this.equals(UNKNOWN) || other.equals(UNKNOWN)) {
        return UNKNOWN;
    }
    checkArgument(other.lessThanOrEqual(this), "Cannot subtract a larger ResourceSpec from this one.");
    Map<String, ExternalResource> resultExtendedResources = new HashMap<>(extendedResources);
    for (ExternalResource resource : other.extendedResources.values()) {
        resultExtendedResources.merge(resource.getName(), resource, (v1, v2) -> v1.subtract(v2));
    }
    return new ResourceSpec(this.cpuCores.subtract(other.cpuCores), this.taskHeapMemory.subtract(other.taskHeapMemory), this.taskOffHeapMemory.subtract(other.taskOffHeapMemory), this.managedMemory.subtract(other.managedMemory), resultExtendedResources);
}
Also used : HashMap(java.util.HashMap) ExternalResource(org.apache.flink.api.common.resources.ExternalResource)

Example 12 with ExternalResource

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

the class TaskExecutorProcessUtilsTest method testProcessSpecFromWorkerResourceSpec.

@Test
public void testProcessSpecFromWorkerResourceSpec() {
    final WorkerResourceSpec workerResourceSpec = new WorkerResourceSpec.Builder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(200).setNetworkMemoryMB(300).setManagedMemoryMB(400).setNumSlots(5).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME_1, 1)).build();
    final TaskExecutorProcessSpec taskExecutorProcessSpec = TaskExecutorProcessUtils.processSpecFromWorkerResourceSpec(new Configuration(), workerResourceSpec);
    assertEquals(workerResourceSpec.getCpuCores(), taskExecutorProcessSpec.getCpuCores());
    assertEquals(workerResourceSpec.getTaskHeapSize(), taskExecutorProcessSpec.getTaskHeapSize());
    assertEquals(workerResourceSpec.getTaskOffHeapSize(), taskExecutorProcessSpec.getTaskOffHeapSize());
    assertEquals(workerResourceSpec.getNetworkMemSize(), taskExecutorProcessSpec.getNetworkMemSize());
    assertEquals(workerResourceSpec.getManagedMemSize(), taskExecutorProcessSpec.getManagedMemorySize());
    assertEquals(workerResourceSpec.getNumSlots(), taskExecutorProcessSpec.getNumSlots());
    assertEquals(workerResourceSpec.getExtendedResources(), taskExecutorProcessSpec.getExtendedResources());
}
Also used : Configuration(org.apache.flink.configuration.Configuration) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 13 with ExternalResource

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

the class ResourceProfileTest method testAllFieldsNoLessThanProfile.

@Test
public void testAllFieldsNoLessThanProfile() {
    final ResourceProfile rp1 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).build();
    final ResourceProfile rp2 = ResourceProfile.newBuilder().setCpuCores(1.0).setTaskHeapMemoryMB(200).setTaskOffHeapMemoryMB(200).setManagedMemoryMB(200).build();
    final ResourceProfile rp3 = ResourceProfile.newBuilder().setCpuCores(2.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).build();
    final ResourceProfile rp4 = ResourceProfile.newBuilder().setCpuCores(2.0).setTaskHeapMemoryMB(200).setTaskOffHeapMemoryMB(200).setManagedMemoryMB(200).build();
    assertFalse(rp1.allFieldsNoLessThan(rp2));
    assertTrue(rp2.allFieldsNoLessThan(rp1));
    assertFalse(rp1.allFieldsNoLessThan(rp3));
    assertTrue(rp3.allFieldsNoLessThan(rp1));
    assertFalse(rp2.allFieldsNoLessThan(rp3));
    assertFalse(rp3.allFieldsNoLessThan(rp2));
    assertTrue(rp4.allFieldsNoLessThan(rp1));
    assertTrue(rp4.allFieldsNoLessThan(rp2));
    assertTrue(rp4.allFieldsNoLessThan(rp3));
    assertTrue(rp4.allFieldsNoLessThan(rp4));
    final ResourceProfile rp5 = ResourceProfile.newBuilder().setCpuCores(2.0).setTaskHeapMemoryMB(100).setTaskOffHeapMemoryMB(100).setManagedMemoryMB(100).setNetworkMemoryMB(100).build();
    assertFalse(rp4.allFieldsNoLessThan(rp5));
    ResourceSpec rs1 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 2.2)).build();
    ResourceSpec rs2 = ResourceSpec.newBuilder(1.0, 100).setExtendedResource(new ExternalResource(EXTERNAL_RESOURCE_NAME, 1.1)).build();
    assertFalse(rp1.allFieldsNoLessThan(ResourceProfile.fromResourceSpec(rs1)));
    assertTrue(ResourceProfile.fromResourceSpec(rs1).allFieldsNoLessThan(ResourceProfile.fromResourceSpec(rs2)));
    assertFalse(ResourceProfile.fromResourceSpec(rs2).allFieldsNoLessThan(ResourceProfile.fromResourceSpec(rs1)));
}
Also used : ResourceSpec(org.apache.flink.api.common.operators.ResourceSpec) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 14 with ExternalResource

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

the class ExternalResourceUtilsTest method testGetExternalResourcesCollection.

@Test
public void testGetExternalResourcesCollection() {
    final Configuration config = new Configuration();
    config.set(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST, Collections.singletonList(RESOURCE_NAME_1));
    config.setLong(ExternalResourceOptions.getAmountConfigOptionForResource(RESOURCE_NAME_1), RESOURCE_AMOUNT_1);
    final Collection<ExternalResource> externalResources = ExternalResourceUtils.getExternalResourcesCollection(config);
    assertThat(externalResources.size(), is(1));
    assertThat(externalResources, contains(new ExternalResource(RESOURCE_NAME_1, RESOURCE_AMOUNT_1)));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) ExternalResource(org.apache.flink.api.common.resources.ExternalResource) Test(org.junit.Test)

Example 15 with ExternalResource

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

the class TaskExecutorProcessSpecTest method testEquals.

@Test
public void testEquals() {
    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(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)));
    assertThat(spec1, is(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