You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2021/02/03 16:47:14 UTC
[GitHub] [flink] tillrohrmann opened a new pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
tillrohrmann opened a new pull request #14853:
URL: https://github.com/apache/flink/pull/14853
## What is the purpose of the change
This PR adds the `DeclarativeSlotPoolService` which encapsulates the `DeclarativeSlotPool` and makes it usable by the `JobMaster`.
## Verifying this change
Added `DeclarativeSlotPoolServiceTest`.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (yes / **no**)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
- The serializers: (yes / **no** / don't know)
- The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn/Mesos, ZooKeeper: (yes / **no** / don't know)
- The S3 file system connector: (yes / **no** / don't know)
## Documentation
- Does this pull request introduce a new feature? (yes / **no**)
- If yes, how is the feature documented? (**not applicable** / docs / JavaDocs / not documented)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] zentol commented on a change in pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
zentol commented on a change in pull request #14853:
URL: https://github.com/apache/flink/pull/14853#discussion_r570095199
##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DeclarativeSlotPoolServiceTest.java
##########
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.jobmaster.slotpool;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter;
+import org.apache.flink.runtime.instance.SimpleSlotContext;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotInfo;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotReport;
+import org.apache.flink.runtime.jobmaster.JobMasterId;
+import org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway;
+import org.apache.flink.runtime.jobmaster.SlotContext;
+import org.apache.flink.runtime.jobmaster.SlotInfo;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway;
+import org.apache.flink.runtime.slots.ResourceRequirement;
+import org.apache.flink.runtime.slots.ResourceRequirements;
+import org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder;
+import org.apache.flink.runtime.taskexecutor.slot.SlotOffer;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.clock.SystemClock;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.Test;
+
+import javax.annotation.Nonnull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/** Tests for the {@link DeclarativeSlotPoolService}. */
+public class DeclarativeSlotPoolServiceTest extends TestLogger {
+
+ private static final JobID jobId = new JobID();
+ private static final JobMasterId jobMasterId = JobMasterId.generate();
+ private final ComponentMainThreadExecutor mainThreadExecutor =
+ ComponentMainThreadExecutorServiceAdapter.forMainThread();
+ private static final String address = "localhost";
+
+ @Test
+ public void testUnknownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID unknownTaskManager = ResourceID.generate();
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ unknownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testKnownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+
+ assertTrue(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testReleaseTaskManager() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+ declarativeSlotPoolService.releaseTaskManager(
+ knownTaskManager, new FlinkException("Test cause"));
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfUnknownTaskManagerIsIgnored() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ final Collection<SlotOffer> acceptedSlots =
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(acceptedSlots, is(empty()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfKnownTaskManager() throws Exception {
+ final AtomicReference<Collection<? extends SlotOffer>> receivedSlotOffers =
+ new AtomicReference<>();
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService(
+ new TestingDeclarativeSlotPoolFactory(
+ new TestingDeclarativeSlotPoolBuilder()
+ .setOfferSlotsFunction(
+ (slotOffers,
+ taskManagerLocation,
+ taskManagerGateway,
+ aLong) -> {
+ receivedSlotOffers.set(slotOffers);
+ return new ArrayList<>(slotOffers);
+ })))) {
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ declarativeSlotPoolService.registerTaskManager(taskManagerLocation.getResourceID());
+
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(receivedSlotOffers.get(), is(slotOffers));
+ }
+ }
+
+ @Test
+ public void testConnectToResourceManagerDeclaresRequiredResources() throws Exception {
+ final Collection<ResourceRequirement> requiredResources =
+ Arrays.asList(
+ ResourceRequirement.create(ResourceProfile.ANY, 2),
Review comment:
use `UNKNOWN` instead. `ANY` should only be used for the resource profile of a slot.
This isn't really about the correctness of this test in particular but more about not spreading code that would in other places lead to subtle issues.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tillrohrmann commented on pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on pull request #14853:
URL: https://github.com/apache/flink/pull/14853#issuecomment-773236770
Thanks a lot for the review @zentol. Merging this PR after addressing your comment.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot edited a comment on pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14853:
URL: https://github.com/apache/flink/pull/14853#issuecomment-772668796
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "f6769b09f44d57e56b51771ac1063500e279ddcf",
"status" : "SUCCESS",
"url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=12881",
"triggerID" : "f6769b09f44d57e56b51771ac1063500e279ddcf",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* f6769b09f44d57e56b51771ac1063500e279ddcf Azure: [SUCCESS](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=12881)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot edited a comment on pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14853:
URL: https://github.com/apache/flink/pull/14853#issuecomment-772655323
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.
## Automated Checks
Last check on commit f6769b09f44d57e56b51771ac1063500e279ddcf (Fri May 28 08:17:27 UTC 2021)
**Warnings:**
* No documentation files were touched! Remember to keep the Flink docs up to date!
<sub>Mention the bot in a comment to re-run the automated checks.</sub>
## Review Progress
* ❓ 1. The [description] looks good.
* ❓ 2. There is [consensus] that the contribution should go into to Flink.
* ❓ 3. Needs [attention] from.
* ❓ 4. The change fits into the overall [architecture].
* ❓ 5. Overall code [quality] is good.
Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
- `@flinkbot approve all` to approve all aspects
- `@flinkbot approve-until architecture` to approve everything until `architecture`
- `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
- `@flinkbot disapprove architecture` to remove an approval you gave earlier
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #14853:
URL: https://github.com/apache/flink/pull/14853#issuecomment-772655323
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.
## Automated Checks
Last check on commit f6769b09f44d57e56b51771ac1063500e279ddcf (Wed Feb 03 16:49:40 UTC 2021)
**Warnings:**
* No documentation files were touched! Remember to keep the Flink docs up to date!
<sub>Mention the bot in a comment to re-run the automated checks.</sub>
## Review Progress
* ❓ 1. The [description] looks good.
* ❓ 2. There is [consensus] that the contribution should go into to Flink.
* ❓ 3. Needs [attention] from.
* ❓ 4. The change fits into the overall [architecture].
* ❓ 5. Overall code [quality] is good.
Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
- `@flinkbot approve all` to approve all aspects
- `@flinkbot approve-until architecture` to approve everything until `architecture`
- `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
- `@flinkbot disapprove architecture` to remove an approval you gave earlier
</details>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] zentol commented on a change in pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
zentol commented on a change in pull request #14853:
URL: https://github.com/apache/flink/pull/14853#discussion_r570095199
##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DeclarativeSlotPoolServiceTest.java
##########
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.jobmaster.slotpool;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter;
+import org.apache.flink.runtime.instance.SimpleSlotContext;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotInfo;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotReport;
+import org.apache.flink.runtime.jobmaster.JobMasterId;
+import org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway;
+import org.apache.flink.runtime.jobmaster.SlotContext;
+import org.apache.flink.runtime.jobmaster.SlotInfo;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway;
+import org.apache.flink.runtime.slots.ResourceRequirement;
+import org.apache.flink.runtime.slots.ResourceRequirements;
+import org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder;
+import org.apache.flink.runtime.taskexecutor.slot.SlotOffer;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.clock.SystemClock;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.Test;
+
+import javax.annotation.Nonnull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/** Tests for the {@link DeclarativeSlotPoolService}. */
+public class DeclarativeSlotPoolServiceTest extends TestLogger {
+
+ private static final JobID jobId = new JobID();
+ private static final JobMasterId jobMasterId = JobMasterId.generate();
+ private final ComponentMainThreadExecutor mainThreadExecutor =
+ ComponentMainThreadExecutorServiceAdapter.forMainThread();
+ private static final String address = "localhost";
+
+ @Test
+ public void testUnknownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID unknownTaskManager = ResourceID.generate();
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ unknownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testKnownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+
+ assertTrue(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testReleaseTaskManager() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+ declarativeSlotPoolService.releaseTaskManager(
+ knownTaskManager, new FlinkException("Test cause"));
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfUnknownTaskManagerIsIgnored() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ final Collection<SlotOffer> acceptedSlots =
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(acceptedSlots, is(empty()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfKnownTaskManager() throws Exception {
+ final AtomicReference<Collection<? extends SlotOffer>> receivedSlotOffers =
+ new AtomicReference<>();
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService(
+ new TestingDeclarativeSlotPoolFactory(
+ new TestingDeclarativeSlotPoolBuilder()
+ .setOfferSlotsFunction(
+ (slotOffers,
+ taskManagerLocation,
+ taskManagerGateway,
+ aLong) -> {
+ receivedSlotOffers.set(slotOffers);
+ return new ArrayList<>(slotOffers);
+ })))) {
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ declarativeSlotPoolService.registerTaskManager(taskManagerLocation.getResourceID());
+
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(receivedSlotOffers.get(), is(slotOffers));
+ }
+ }
+
+ @Test
+ public void testConnectToResourceManagerDeclaresRequiredResources() throws Exception {
+ final Collection<ResourceRequirement> requiredResources =
+ Arrays.asList(
+ ResourceRequirement.create(ResourceProfile.ANY, 2),
Review comment:
use `UNKNOWN` instead. `ANY` should only be used for the resource profile of a slot.
This isn't really about the correctness of this test in particular but more about not spreading code that would in other places lead to subtle issues.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tillrohrmann closed pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
tillrohrmann closed pull request #14853:
URL: https://github.com/apache/flink/pull/14853
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tillrohrmann commented on a change in pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #14853:
URL: https://github.com/apache/flink/pull/14853#discussion_r570142565
##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DeclarativeSlotPoolServiceTest.java
##########
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.jobmaster.slotpool;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter;
+import org.apache.flink.runtime.instance.SimpleSlotContext;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotInfo;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotReport;
+import org.apache.flink.runtime.jobmaster.JobMasterId;
+import org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway;
+import org.apache.flink.runtime.jobmaster.SlotContext;
+import org.apache.flink.runtime.jobmaster.SlotInfo;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway;
+import org.apache.flink.runtime.slots.ResourceRequirement;
+import org.apache.flink.runtime.slots.ResourceRequirements;
+import org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder;
+import org.apache.flink.runtime.taskexecutor.slot.SlotOffer;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.clock.SystemClock;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.Test;
+
+import javax.annotation.Nonnull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/** Tests for the {@link DeclarativeSlotPoolService}. */
+public class DeclarativeSlotPoolServiceTest extends TestLogger {
+
+ private static final JobID jobId = new JobID();
+ private static final JobMasterId jobMasterId = JobMasterId.generate();
+ private final ComponentMainThreadExecutor mainThreadExecutor =
+ ComponentMainThreadExecutorServiceAdapter.forMainThread();
+ private static final String address = "localhost";
+
+ @Test
+ public void testUnknownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID unknownTaskManager = ResourceID.generate();
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ unknownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testKnownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+
+ assertTrue(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testReleaseTaskManager() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+ declarativeSlotPoolService.releaseTaskManager(
+ knownTaskManager, new FlinkException("Test cause"));
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfUnknownTaskManagerIsIgnored() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ final Collection<SlotOffer> acceptedSlots =
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(acceptedSlots, is(empty()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfKnownTaskManager() throws Exception {
+ final AtomicReference<Collection<? extends SlotOffer>> receivedSlotOffers =
+ new AtomicReference<>();
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService(
+ new TestingDeclarativeSlotPoolFactory(
+ new TestingDeclarativeSlotPoolBuilder()
+ .setOfferSlotsFunction(
+ (slotOffers,
+ taskManagerLocation,
+ taskManagerGateway,
+ aLong) -> {
+ receivedSlotOffers.set(slotOffers);
+ return new ArrayList<>(slotOffers);
+ })))) {
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ declarativeSlotPoolService.registerTaskManager(taskManagerLocation.getResourceID());
+
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(receivedSlotOffers.get(), is(slotOffers));
+ }
+ }
+
+ @Test
+ public void testConnectToResourceManagerDeclaresRequiredResources() throws Exception {
+ final Collection<ResourceRequirement> requiredResources =
+ Arrays.asList(
+ ResourceRequirement.create(ResourceProfile.ANY, 2),
Review comment:
Very good point. Thanks a lot. I always get confused by `UNKNOWN` and `ANY`. I think it would be best to have two different types: 1) for the resource requirements and 2) for what the slot offers. Then we would also get rid of the problem with `ResourceProfile.isMatching` which confuses me every time in which order to supply the two `ResourceProfiles`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot edited a comment on pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on pull request #14853:
URL: https://github.com/apache/flink/pull/14853#issuecomment-772668796
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "f6769b09f44d57e56b51771ac1063500e279ddcf",
"status" : "PENDING",
"url" : "https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=12881",
"triggerID" : "f6769b09f44d57e56b51771ac1063500e279ddcf",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* f6769b09f44d57e56b51771ac1063500e279ddcf Azure: [PENDING](https://dev.azure.com/apache-flink/98463496-1af2-4620-8eab-a2ecc1a2e6fe/_build/results?buildId=12881)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tillrohrmann commented on pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on pull request #14853:
URL: https://github.com/apache/flink/pull/14853#issuecomment-773236770
Thanks a lot for the review @zentol. Merging this PR after addressing your comment.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] flinkbot commented on pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
flinkbot commented on pull request #14853:
URL: https://github.com/apache/flink/pull/14853#issuecomment-772668796
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "f6769b09f44d57e56b51771ac1063500e279ddcf",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "f6769b09f44d57e56b51771ac1063500e279ddcf",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* f6769b09f44d57e56b51771ac1063500e279ddcf UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tillrohrmann commented on a change in pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #14853:
URL: https://github.com/apache/flink/pull/14853#discussion_r570142565
##########
File path: flink-runtime/src/test/java/org/apache/flink/runtime/jobmaster/slotpool/DeclarativeSlotPoolServiceTest.java
##########
@@ -0,0 +1,334 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.jobmaster.slotpool;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor;
+import org.apache.flink.runtime.concurrent.ComponentMainThreadExecutorServiceAdapter;
+import org.apache.flink.runtime.instance.SimpleSlotContext;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotInfo;
+import org.apache.flink.runtime.jobmaster.AllocatedSlotReport;
+import org.apache.flink.runtime.jobmaster.JobMasterId;
+import org.apache.flink.runtime.jobmaster.RpcTaskManagerGateway;
+import org.apache.flink.runtime.jobmaster.SlotContext;
+import org.apache.flink.runtime.jobmaster.SlotInfo;
+import org.apache.flink.runtime.messages.Acknowledge;
+import org.apache.flink.runtime.resourcemanager.utils.TestingResourceManagerGateway;
+import org.apache.flink.runtime.slots.ResourceRequirement;
+import org.apache.flink.runtime.slots.ResourceRequirements;
+import org.apache.flink.runtime.taskexecutor.TestingTaskExecutorGatewayBuilder;
+import org.apache.flink.runtime.taskexecutor.slot.SlotOffer;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.TestLogger;
+import org.apache.flink.util.clock.SystemClock;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.Test;
+
+import javax.annotation.Nonnull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Optional;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+
+import static org.hamcrest.Matchers.contains;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/** Tests for the {@link DeclarativeSlotPoolService}. */
+public class DeclarativeSlotPoolServiceTest extends TestLogger {
+
+ private static final JobID jobId = new JobID();
+ private static final JobMasterId jobMasterId = JobMasterId.generate();
+ private final ComponentMainThreadExecutor mainThreadExecutor =
+ ComponentMainThreadExecutorServiceAdapter.forMainThread();
+ private static final String address = "localhost";
+
+ @Test
+ public void testUnknownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID unknownTaskManager = ResourceID.generate();
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ unknownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testKnownTaskManagerRegistration() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+
+ assertTrue(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testReleaseTaskManager() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final ResourceID knownTaskManager = ResourceID.generate();
+ declarativeSlotPoolService.registerTaskManager(knownTaskManager);
+ declarativeSlotPoolService.releaseTaskManager(
+ knownTaskManager, new FlinkException("Test cause"));
+
+ assertFalse(
+ declarativeSlotPoolService.isTaskManagerRegistered(
+ knownTaskManager.getResourceID()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfUnknownTaskManagerIsIgnored() throws Exception {
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService()) {
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ final Collection<SlotOffer> acceptedSlots =
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(acceptedSlots, is(empty()));
+ }
+ }
+
+ @Test
+ public void testSlotOfferingOfKnownTaskManager() throws Exception {
+ final AtomicReference<Collection<? extends SlotOffer>> receivedSlotOffers =
+ new AtomicReference<>();
+ try (DeclarativeSlotPoolService declarativeSlotPoolService =
+ createDeclarativeSlotPoolService(
+ new TestingDeclarativeSlotPoolFactory(
+ new TestingDeclarativeSlotPoolBuilder()
+ .setOfferSlotsFunction(
+ (slotOffers,
+ taskManagerLocation,
+ taskManagerGateway,
+ aLong) -> {
+ receivedSlotOffers.set(slotOffers);
+ return new ArrayList<>(slotOffers);
+ })))) {
+ final LocalTaskManagerLocation taskManagerLocation = new LocalTaskManagerLocation();
+
+ declarativeSlotPoolService.registerTaskManager(taskManagerLocation.getResourceID());
+
+ final Collection<SlotOffer> slotOffers =
+ Collections.singletonList(
+ new SlotOffer(new AllocationID(), 0, ResourceProfile.ANY));
+
+ declarativeSlotPoolService.offerSlots(
+ taskManagerLocation,
+ new RpcTaskManagerGateway(
+ new TestingTaskExecutorGatewayBuilder()
+ .createTestingTaskExecutorGateway(),
+ jobMasterId),
+ slotOffers);
+
+ assertThat(receivedSlotOffers.get(), is(slotOffers));
+ }
+ }
+
+ @Test
+ public void testConnectToResourceManagerDeclaresRequiredResources() throws Exception {
+ final Collection<ResourceRequirement> requiredResources =
+ Arrays.asList(
+ ResourceRequirement.create(ResourceProfile.ANY, 2),
Review comment:
Very good point. Thanks a lot. I always get confused by `UNKNOWN` and `ANY`. I think it would be best to have two different types: 1) for the resource requirements and 2) for what the slot offers. Then we would also get rid of the problem with `ResourceProfile.isMatching` which confuses me every time in which order to supply the two `ResourceProfiles`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [flink] tillrohrmann closed pull request #14853: [FLINK-21078] Add DeclarativeSlotPoolService which encapsulates a DeclarativeSlotPool
Posted by GitBox <gi...@apache.org>.
tillrohrmann closed pull request #14853:
URL: https://github.com/apache/flink/pull/14853
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org