-
Notifications
You must be signed in to change notification settings - Fork 5
#796 Add worker status tracking to log statuses of other running tasks on job completion. #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c1ae2f6
#796 Add worker status tracking to log statuses of other running task…
yruslan d0bdbf0
Fix imports
yruslan ea0ad92
#796 Mark worker status as finished for tasks running in a child thre…
yruslan ca9230c
#796 Move status logging outside the deferred dependency update (Than…
yruslan 5da1b2b
#796 Set worker status inside the task execution thread for timeout-b…
yruslan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
pramen/core/src/main/scala/za/co/absa/pramen/core/state/WorkerStatus.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright 2022 ABSA Group Limited | ||
| * | ||
| * Licensed 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 za.co.absa.pramen.core.state | ||
|
|
||
| case class WorkerStatus( | ||
| threadId: Long, | ||
| status: String | ||
| ) |
37 changes: 37 additions & 0 deletions
37
pramen/core/src/main/scala/za/co/absa/pramen/core/state/WorkerStatusManager.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Copyright 2022 ABSA Group Limited | ||
| * | ||
| * Licensed 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 za.co.absa.pramen.core.state | ||
|
|
||
| import scala.collection.mutable | ||
|
|
||
| object WorkerStatusManager { | ||
| private val workerStatus = new mutable.HashMap[Long, String]() | ||
|
|
||
| def setStatus(status: String): Unit = synchronized { | ||
| val threadId = Thread.currentThread().getId | ||
| workerStatus(threadId) = status | ||
| } | ||
|
|
||
| def setFinished(): Unit = synchronized { | ||
| val threadId = Thread.currentThread().getId | ||
| workerStatus.remove(threadId) | ||
| } | ||
|
|
||
| def getStatuses: Seq[WorkerStatus] = synchronized { | ||
| workerStatus.map { case (threadId, status) => WorkerStatus(threadId, status) }.toSeq | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
pramen/core/src/test/scala/za/co/absa/pramen/core/state/WorkerStatusManagerSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| * Copyright 2022 ABSA Group Limited | ||
| * | ||
| * Licensed 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 za.co.absa.pramen.core.state | ||
|
|
||
| import org.scalatest.wordspec.AnyWordSpec | ||
|
|
||
| import java.util.concurrent.{CountDownLatch, TimeUnit} | ||
|
|
||
| class WorkerStatusManagerSuite extends AnyWordSpec { | ||
| "setStatus" should { | ||
| "register the status of the current thread" in { | ||
| try { | ||
| WorkerStatusManager.setStatus("running task 1") | ||
|
|
||
| val statuses = WorkerStatusManager.getStatuses | ||
|
|
||
| assert(statuses.nonEmpty) | ||
| assert(statuses.exists(s => s.threadId == Thread.currentThread().getId && s.status == "running task 1")) | ||
| } finally { | ||
| WorkerStatusManager.setFinished() | ||
| } | ||
| } | ||
|
|
||
| "overwrite the previous status of the same thread" in { | ||
| try { | ||
| WorkerStatusManager.setStatus("running task 1") | ||
| WorkerStatusManager.setStatus("running task 2") | ||
|
|
||
| val statuses = WorkerStatusManager.getStatuses.filter(_.threadId == Thread.currentThread().getId) | ||
|
|
||
| assert(statuses.length == 1) | ||
| assert(statuses.head.status == "running task 2") | ||
| } finally { | ||
| WorkerStatusManager.setFinished() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| "setFinished" should { | ||
| "remove the status of the current thread" in { | ||
| WorkerStatusManager.setStatus("running task 1") | ||
| WorkerStatusManager.setFinished() | ||
|
|
||
| val statuses = WorkerStatusManager.getStatuses.filter(_.threadId == Thread.currentThread().getId) | ||
|
|
||
| assert(statuses.isEmpty) | ||
| } | ||
|
|
||
| "do nothing if the current thread has no registered status" in { | ||
| WorkerStatusManager.setFinished() | ||
| WorkerStatusManager.setFinished() | ||
|
|
||
| val statuses = WorkerStatusManager.getStatuses.filter(_.threadId == Thread.currentThread().getId) | ||
|
|
||
| assert(statuses.isEmpty) | ||
| } | ||
| } | ||
|
|
||
| "getStatuses" should { | ||
| "return an empty collection when no statuses are registered" in { | ||
| WorkerStatusManager.setFinished() | ||
|
|
||
| assert(WorkerStatusManager.getStatuses.isEmpty) | ||
| } | ||
|
|
||
| "return statuses of all running threads" in { | ||
| val threadsStarted = new CountDownLatch(2) | ||
| val allowToFinish = new CountDownLatch(1) | ||
|
|
||
| val threads = (1 to 2).map { i => | ||
| val thread = new Thread(new Runnable { | ||
| override def run(): Unit = { | ||
| WorkerStatusManager.setStatus(s"worker $i") | ||
| threadsStarted.countDown() | ||
| allowToFinish.await(10, TimeUnit.SECONDS) | ||
| WorkerStatusManager.setFinished() | ||
| } | ||
| }) | ||
| thread.start() | ||
| thread | ||
| } | ||
|
|
||
| threadsStarted.await(10, TimeUnit.SECONDS) | ||
|
|
||
| val statuses = WorkerStatusManager.getStatuses | ||
|
|
||
| allowToFinish.countDown() | ||
| threads.foreach(_.join(10000)) | ||
|
|
||
| assert(statuses.length == 2) | ||
| assert(statuses.map(_.status).sortBy(identity) == Seq("worker 1", "worker 2")) | ||
| assert(statuses.map(_.threadId).distinct.length == 2) | ||
| assert(WorkerStatusManager.getStatuses.isEmpty) | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.