Search in sources :

Example 6 with CPUResource

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

Example 7 with CPUResource

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

the class YarnResourceManagerDriverTest method testStartWorkerVariousSpec.

@Test
public void testStartWorkerVariousSpec() throws Exception {
    final TaskExecutorProcessSpec taskExecutorProcessSpec1 = new TaskExecutorProcessSpec(new CPUResource(1), MemorySize.ZERO, MemorySize.ZERO, MemorySize.ofMebiBytes(50), MemorySize.ofMebiBytes(50), MemorySize.ofMebiBytes(50), MemorySize.ofMebiBytes(50), MemorySize.ZERO, MemorySize.ZERO, Collections.emptyList());
    final TaskExecutorProcessSpec taskExecutorProcessSpec2 = new TaskExecutorProcessSpec(new CPUResource(2), MemorySize.ZERO, MemorySize.ZERO, MemorySize.ofMebiBytes(500), MemorySize.ofMebiBytes(500), MemorySize.ofMebiBytes(500), MemorySize.ofMebiBytes(500), MemorySize.ZERO, MemorySize.ZERO, Collections.emptyList());
    new Context() {

        {
            final String startCommand1 = TaskManagerOptions.TASK_HEAP_MEMORY.key() + "=" + (50L << 20);
            final String startCommand2 = TaskManagerOptions.TASK_HEAP_MEMORY.key() + "=" + (100L << 20);
            final CompletableFuture<Void> startContainerAsyncCommandFuture1 = new CompletableFuture<>();
            final CompletableFuture<Void> startContainerAsyncCommandFuture2 = new CompletableFuture<>();
            prepareForTestStartTaskExecutorProcessVariousSpec(startCommand1, startCommand2, startContainerAsyncCommandFuture1, startContainerAsyncCommandFuture2, taskExecutorProcessSpec1);
            testingYarnAMRMClientAsyncBuilder.setGetMatchingRequestsFunction(tuple -> {
                final Priority priority = tuple.f0;
                final List<AMRMClient.ContainerRequest> matchingRequests = new ArrayList<>();
                for (CompletableFuture<AMRMClient.ContainerRequest> addContainerRequestFuture : addContainerRequestFutures) {
                    final AMRMClient.ContainerRequest request = addContainerRequestFuture.getNow(null);
                    if (request != null && priority.equals(request.getPriority())) {
                        assertThat(tuple.f2, is(request.getCapability()));
                        matchingRequests.add(request);
                    }
                }
                return Collections.singletonList(matchingRequests);
            });
            runTest(() -> {
                final Resource containerResource1 = ((YarnResourceManagerDriver) getDriver()).getContainerResource(taskExecutorProcessSpec1).get();
                final Resource containerResource2 = ((YarnResourceManagerDriver) getDriver()).getContainerResource(taskExecutorProcessSpec2).get();
                // Make sure two worker resource spec will be normalized to different
                // container resources
                assertNotEquals(containerResource1, containerResource2);
                runInMainThread(() -> getDriver().requestResource(taskExecutorProcessSpec1));
                runInMainThread(() -> getDriver().requestResource(taskExecutorProcessSpec2));
                // Verify both containers requested
                verifyFutureCompleted(addContainerRequestFutures.get(0));
                verifyFutureCompleted(addContainerRequestFutures.get(1));
                // Mock that container 1 is allocated
                Container container1 = createTestingContainerWithResource(containerResource1);
                resourceManagerClientCallbackHandler.onContainersAllocated(Collections.singletonList(container1));
                // Verify that only worker with spec1 is started.
                verifyFutureCompleted(startContainerAsyncCommandFuture1);
                assertFalse(startContainerAsyncCommandFuture2.isDone());
                // Mock that container 1 is completed, while the worker is still pending
                ContainerStatus testingContainerStatus = createTestingContainerCompletedStatus(container1.getId());
                resourceManagerClientCallbackHandler.onContainersCompleted(Collections.singletonList(testingContainerStatus));
                // Verify that only container 1 is requested again
                verifyFutureCompleted(addContainerRequestFutures.get(2));
                assertThat(addContainerRequestFutures.get(2).get().getCapability(), is(containerResource1));
                assertFalse(addContainerRequestFutures.get(3).isDone());
            });
        }
    };
}
Also used : ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) AMRMClient(org.apache.hadoop.yarn.client.api.AMRMClient) TaskExecutorProcessSpec(org.apache.flink.runtime.clusterframework.TaskExecutorProcessSpec) Priority(org.apache.hadoop.yarn.api.records.Priority) ArrayList(java.util.ArrayList) Resource(org.apache.hadoop.yarn.api.records.Resource) CPUResource(org.apache.flink.api.common.resources.CPUResource) Matchers.containsString(org.hamcrest.Matchers.containsString) CompletableFuture(java.util.concurrent.CompletableFuture) Container(org.apache.hadoop.yarn.api.records.Container) ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) CPUResource(org.apache.flink.api.common.resources.CPUResource) Test(org.junit.Test)

Example 8 with CPUResource

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

the class YarnWorkerResourceSpecFactoryTest method testGetCpuCoresYarnOption.

@Test
public void testGetCpuCoresYarnOption() {
    final Configuration configuration = new Configuration();
    configuration.setInteger(YarnConfigOptions.VCORES, 2);
    configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 3);
    assertThat(YarnWorkerResourceSpecFactory.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 9 with CPUResource

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

the class YarnWorkerResourceSpecFactoryTest method testGetCpuCoresCommonOption.

@Test
public void testGetCpuCoresCommonOption() {
    final Configuration configuration = new Configuration();
    configuration.setDouble(TaskManagerOptions.CPU_CORES, 1.0);
    configuration.setInteger(YarnConfigOptions.VCORES, 2);
    configuration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, 3);
    assertThat(YarnWorkerResourceSpecFactory.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 10 with CPUResource

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

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