Search in sources :

Example 11 with CPUResource

use of org.apache.flink.api.common.resources.CPUResource 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 12 with CPUResource

use of org.apache.flink.api.common.resources.CPUResource 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 13 with CPUResource

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

the class KubernetesWorkerResourceSpecFactoryTest method testGetCpuCoresKubernetesOption.

@Test
public void testGetCpuCoresKubernetesOption() {
    final Configuration configuration = new Configuration();
    configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU, 2.0);
    configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU_LIMIT_FACTOR, 1.5);
    configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 3);
    assertThat(KubernetesWorkerResourceSpecFactory.getDefaultCpus(configuration), is(new CPUResource(2.0)));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) CPUResource(org.apache.flink.api.common.resources.CPUResource) Test(org.junit.Test)

Example 14 with CPUResource

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

the class KubernetesWorkerResourceSpecFactoryTest method testGetCpuCoresCommonOption.

@Test
public void testGetCpuCoresCommonOption() {
    final Configuration configuration = new Configuration();
    configuration.setDouble(TaskManagerOptions.CPU_CORES, 1.0);
    configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU, 2.0);
    configuration.setDouble(KubernetesConfigOptions.TASK_MANAGER_CPU_LIMIT_FACTOR, 1.5);
    configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 3);
    assertThat(KubernetesWorkerResourceSpecFactory.getDefaultCpus(configuration), is(new CPUResource(1.0)));
}
Also used : Configuration(org.apache.flink.configuration.Configuration) CPUResource(org.apache.flink.api.common.resources.CPUResource) Test(org.junit.Test)

Example 15 with CPUResource

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

the class TaskExecutorProcessUtilsTest method testGenerateDynamicConfigurations.

@Test
public void testGenerateDynamicConfigurations() {
    String dynamicConfigsStr = TaskExecutorProcessUtils.generateDynamicConfigsStr(TM_RESOURCE_SPEC);
    Map<String, String> configs = ConfigurationUtils.parseTmResourceDynamicConfigs(dynamicConfigsStr);
    assertThat(new CPUResource(Double.valueOf(configs.get(TaskManagerOptions.CPU_CORES.key()))), is(TM_RESOURCE_SPEC.getCpuCores()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.FRAMEWORK_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getFrameworkHeapSize()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.FRAMEWORK_OFF_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getFrameworkOffHeapMemorySize()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.TASK_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getTaskHeapSize()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.TASK_OFF_HEAP_MEMORY.key())), is(TM_RESOURCE_SPEC.getTaskOffHeapSize()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.NETWORK_MEMORY_MAX.key())), is(TM_RESOURCE_SPEC.getNetworkMemSize()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.NETWORK_MEMORY_MIN.key())), is(TM_RESOURCE_SPEC.getNetworkMemSize()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.MANAGED_MEMORY_SIZE.key())), is(TM_RESOURCE_SPEC.getManagedMemorySize()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.JVM_METASPACE.key())), is(TM_RESOURCE_SPEC.getJvmMetaspaceAndOverhead().getMetaspace()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.JVM_OVERHEAD_MIN.key())), is(TM_RESOURCE_SPEC.getJvmMetaspaceAndOverhead().getOverhead()));
    assertThat(MemorySize.parse(configs.get(TaskManagerOptions.JVM_OVERHEAD_MAX.key())), is(TM_RESOURCE_SPEC.getJvmMetaspaceAndOverhead().getOverhead()));
    assertThat(Integer.valueOf(configs.get(TaskManagerOptions.NUM_TASK_SLOTS.key())), is(TM_RESOURCE_SPEC.getNumSlots()));
    assertThat(configs.get(ExternalResourceOptions.EXTERNAL_RESOURCE_LIST.key()), is('"' + String.join(";", TM_RESOURCE_SPEC.getExtendedResources().keySet()) + '"'));
    assertThat(configs.get(ExternalResourceOptions.getAmountConfigOptionForResource(EXTERNAL_RESOURCE_NAME_1)), is(String.valueOf(TM_RESOURCE_SPEC.getExtendedResources().get(EXTERNAL_RESOURCE_NAME_1).getValue().longValue())));
    assertThat(configs.get(ExternalResourceOptions.getAmountConfigOptionForResource(EXTERNAL_RESOURCE_NAME_2)), is(String.valueOf(TM_RESOURCE_SPEC.getExtendedResources().get(EXTERNAL_RESOURCE_NAME_2).getValue().longValue())));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) CPUResource(org.apache.flink.api.common.resources.CPUResource) Test(org.junit.Test)

Aggregations

CPUResource (org.apache.flink.api.common.resources.CPUResource)19 Test (org.junit.Test)19 Configuration (org.apache.flink.configuration.Configuration)10 ExternalResource (org.apache.flink.api.common.resources.ExternalResource)6 TaskExecutorProcessSpec (org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec)3 ArrayList (java.util.ArrayList)2 MemorySize (org.apache.flink.configuration.MemorySize)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 CompletableFuture (java.util.concurrent.CompletableFuture)1 ResourceSpec (org.apache.flink.api.common.operators.ResourceSpec)1 GlobalConfiguration (org.apache.flink.configuration.GlobalConfiguration)1 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)1 WorkerResourceSpec (org.apache.flink.runtime.resourcemanager.WorkerResourceSpec)1 TaskExecutorResourceSpec (org.apache.flink.runtime.taskexecutor.TaskExecutorResourceSpec)1 Container (org.apache.hadoop.yarn.api.records.Container)1 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)1 ContainerStatus (org.apache.hadoop.yarn.api.records.ContainerStatus)1 Priority (org.apache.hadoop.yarn.api.records.Priority)1 Resource (org.apache.hadoop.yarn.api.records.Resource)1 AMRMClient (org.apache.hadoop.yarn.client.api.AMRMClient)1