Search in sources :

Example 6 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class PendingWorkerCounterTest method testPendingWorkerCounterDecreaseOnZero.

@Test(expected = IllegalStateException.class)
public void testPendingWorkerCounterDecreaseOnZero() {
    final WorkerResourceSpec spec = new WorkerResourceSpec.Builder().build();
    final PendingWorkerCounter counter = new PendingWorkerCounter();
    counter.decreaseAndGet(spec);
}
Also used : WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) Test(org.junit.Test)

Example 7 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class PendingWorkerCounterTest method testPendingWorkerCounterIncreaseAndDecrease.

@Test
public void testPendingWorkerCounterIncreaseAndDecrease() {
    final WorkerResourceSpec spec1 = new WorkerResourceSpec.Builder().setCpuCores(1.0).build();
    final WorkerResourceSpec spec2 = new WorkerResourceSpec.Builder().setCpuCores(2.0).build();
    final PendingWorkerCounter counter = new PendingWorkerCounter();
    assertThat(counter.getTotalNum(), is(0));
    assertThat(counter.getNum(spec1), is(0));
    assertThat(counter.getNum(spec2), is(0));
    assertThat(counter.increaseAndGet(spec1), is(1));
    assertThat(counter.getTotalNum(), is(1));
    assertThat(counter.getNum(spec1), is(1));
    assertThat(counter.getNum(spec2), is(0));
    assertThat(counter.increaseAndGet(spec1), is(2));
    assertThat(counter.getTotalNum(), is(2));
    assertThat(counter.getNum(spec1), is(2));
    assertThat(counter.getNum(spec2), is(0));
    assertThat(counter.increaseAndGet(spec2), is(1));
    assertThat(counter.getTotalNum(), is(3));
    assertThat(counter.getNum(spec1), is(2));
    assertThat(counter.getNum(spec2), is(1));
    assertThat(counter.decreaseAndGet(spec1), is(1));
    assertThat(counter.getTotalNum(), is(2));
    assertThat(counter.getNum(spec1), is(1));
    assertThat(counter.getNum(spec2), is(1));
    assertThat(counter.decreaseAndGet(spec2), is(0));
    assertThat(counter.getTotalNum(), is(1));
    assertThat(counter.getNum(spec1), is(1));
    assertThat(counter.getNum(spec2), is(0));
}
Also used : WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) Test(org.junit.Test)

Example 8 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class ActiveResourceManager method requestWorkerIfRequired.

private void requestWorkerIfRequired() {
    for (Map.Entry<WorkerResourceSpec, Integer> entry : getRequiredResources().entrySet()) {
        final WorkerResourceSpec workerResourceSpec = entry.getKey();
        final int requiredCount = entry.getValue();
        while (requiredCount > pendingWorkerCounter.getNum(workerResourceSpec)) {
            requestNewWorker(workerResourceSpec);
        }
    }
}
Also used : WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec in project flink by apache.

the class ActiveResourceManager method onWorkerRegistered.

@Override
protected void onWorkerRegistered(WorkerType worker) {
    final ResourceID resourceId = worker.getResourceID();
    log.info("Worker {} is registered.", resourceId.getStringWithMetadata());
    final WorkerResourceSpec workerResourceSpec = currentAttemptUnregisteredWorkers.remove(resourceId);
    previousAttemptUnregisteredWorkers.remove(resourceId);
    if (workerResourceSpec != null) {
        final int count = pendingWorkerCounter.decreaseAndGet(workerResourceSpec);
        log.info("Worker {} with resource spec {} was requested in current attempt." + " Current pending count after registering: {}.", resourceId.getStringWithMetadata(), workerResourceSpec, count);
    }
}
Also used : ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) WorkerResourceSpec(org.apache.flink.runtime.resourcemanager.WorkerResourceSpec)

Example 10 with WorkerResourceSpec

use of org.apache.flink.runtime.resourcemanager.WorkerResourceSpec 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)

Aggregations

WorkerResourceSpec (org.apache.flink.runtime.resourcemanager.WorkerResourceSpec)16 Test (org.junit.Test)12 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)7 CompletableFuture (java.util.concurrent.CompletableFuture)5 ExternalResource (org.apache.flink.api.common.resources.ExternalResource)4 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)4 TestingTaskExecutorGatewayBuilder (org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder)4 Executor (java.util.concurrent.Executor)3 Time (org.apache.flink.api.common.time.Time)3 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)3 SlotID (org.apache.flink.runtime.clusterframework.types.SlotID)3 TaskExecutorConnection (org.apache.flink.runtime.resourcemanager.registration.TaskExecutorConnection)3 SlotReport (org.apache.flink.runtime.taskexecutor.SlotReport)3 SlotStatus (org.apache.flink.runtime.taskexecutor.SlotStatus)3 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2