-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/789 show messages to ingest on hyperdrive jobs #791
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
Changes from all commits
a52ea07
bca2ff4
ccabdfd
2b57086
520e6d7
63a56fd
c4ab308
d1fa3af
85c0380
5cba289
4e9b246
6c6f3b6
c7fb250
5afa29f
71eaa22
c2d99a7
01093e0
449996a
0891835
a3a3d15
bfcd428
aac15c7
54d2150
732738b
cd92e9c
b612fd4
b6bef1c
4fd8e76
7a4aa2e
d765916
8669327
bf47a0e
806a29c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Copyright 2018 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.hyperdrive.trigger.api.rest.controllers | ||
|
|
||
| import org.springframework.web.bind.annotation._ | ||
| import za.co.absa.hyperdrive.trigger.api.rest.services.HyperdriveService | ||
| import za.co.absa.hyperdrive.trigger.models._ | ||
|
|
||
| import java.util.concurrent.CompletableFuture | ||
| import javax.inject.Inject | ||
| import scala.compat.java8.FutureConverters._ | ||
| import scala.concurrent.ExecutionContext.Implicits.global | ||
|
|
||
| @RestController | ||
| class HyperdriveController @Inject() (hyperdriveService: HyperdriveService) { | ||
| @GetMapping(path = Array("/hyperdrive/workflows/{id}/ingestionStatus")) | ||
| def getIngestionStatus(@PathVariable id: Long): CompletableFuture[Seq[IngestionStatus]] = | ||
| hyperdriveService.getIngestionStatus(id).toJava.toCompletableFuture | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright 2018 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.hyperdrive.trigger.api.rest.services | ||
|
|
||
| import org.slf4j.LoggerFactory | ||
| import org.springframework.stereotype.Service | ||
| import za.co.absa.hyperdrive.trigger.models.{IngestionStatus, TopicStatus} | ||
| import za.co.absa.hyperdrive.trigger.models.enums.JobTypes | ||
| import za.co.absa.hyperdrive.trigger.persistance.WorkflowRepository | ||
|
|
||
| import scala.concurrent.{ExecutionContext, Future} | ||
| import scala.util.{Failure, Success} | ||
|
|
||
| trait HyperdriveService { | ||
| protected val workflowRepository: WorkflowRepository | ||
| protected val jobTemplateService: JobTemplateService | ||
| protected val hyperdriveOffsetService: HyperdriveOffsetService | ||
|
|
||
| def getIngestionStatus(id: Long)(implicit ec: ExecutionContext): Future[Seq[IngestionStatus]] | ||
| } | ||
|
|
||
| @Service | ||
| class HyperdriveServiceImpl( | ||
| override protected val workflowRepository: WorkflowRepository, | ||
| override protected val jobTemplateService: JobTemplateService, | ||
| override protected val hyperdriveOffsetService: HyperdriveOffsetService | ||
| ) extends HyperdriveService { | ||
| private val logger = LoggerFactory.getLogger(this.getClass) | ||
|
|
||
| override def getIngestionStatus(id: Long)(implicit ec: ExecutionContext): Future[Seq[IngestionStatus]] = { | ||
| workflowRepository.getWorkflow(id).flatMap { workflow => | ||
| jobTemplateService | ||
| .resolveJobTemplate(workflow.dagDefinitionJoined) | ||
| .flatMap(resolvedJobs => | ||
| Future.sequence( | ||
| resolvedJobs.map { | ||
| case resolvedJob if resolvedJob.jobParameters.jobType == JobTypes.Hyperdrive => | ||
| hyperdriveOffsetService.getNumberOfMessagesLeft(resolvedJob.jobParameters).transformWith { | ||
| case Failure(exception) => | ||
| logger.error(s"Failed to get number of messages left to ingest for a workflow: $id", exception) | ||
| Future.successful( | ||
| IngestionStatus( | ||
| jobName = resolvedJob.name, | ||
| jobType = resolvedJob.jobParameters.jobType.name, | ||
| topicStatus = None | ||
| ) | ||
| ) | ||
| case Success(messagesLeftOpt) => | ||
| Future.successful( | ||
| IngestionStatus( | ||
| jobName = resolvedJob.name, | ||
| jobType = resolvedJob.jobParameters.jobType.name, | ||
| topicStatus = messagesLeftOpt.map(messagesLeft => TopicStatus(messagesLeft._1, messagesLeft._2)) | ||
| ) | ||
| ) | ||
| } | ||
| case resolvedJob => | ||
| Future.successful( | ||
| IngestionStatus( | ||
| jobName = resolvedJob.name, | ||
| jobType = resolvedJob.jobParameters.jobType.name, | ||
| topicStatus = None | ||
| ) | ||
| ) | ||
| } | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import org.springframework.stereotype.Service | |
| import org.springframework.util.ConcurrentLruCache | ||
| import za.co.absa.hyperdrive.trigger.api.rest.services.KafkaServiceImpl.{BeginningOffsets, EndOffsets, OffsetFunction} | ||
| import za.co.absa.hyperdrive.trigger.configuration.application.GeneralConfig | ||
| import za.co.absa.hyperdrive.trigger.models.BeginningEndOffsets | ||
|
|
||
| import java.util.Properties | ||
| import java.util.UUID.randomUUID | ||
|
|
@@ -31,6 +32,7 @@ import scala.collection.JavaConverters._ | |
| trait KafkaService { | ||
| def getBeginningOffsets(topic: String, consumerProperties: Properties): Map[Int, Long] | ||
| def getEndOffsets(topic: String, consumerProperties: Properties): Map[Int, Long] | ||
| def getBeginningEndOffsets(topic: String, consumerProperties: Properties): BeginningEndOffsets | ||
| } | ||
|
|
||
| @Service | ||
|
|
@@ -50,6 +52,14 @@ class KafkaServiceImpl @Inject() (generalConfig: GeneralConfig) extends KafkaSer | |
| getOffsets(topic, consumerProperties, EndOffsets) | ||
| } | ||
|
|
||
| def getBeginningEndOffsets(topic: String, consumerProperties: Properties): BeginningEndOffsets = { | ||
| BeginningEndOffsets( | ||
| topic, | ||
| getOffsets(topic, consumerProperties, BeginningOffsets), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a suggestion for future projects because it would require reworking or unification of the entire architecture. I noticed that some services use Futures as output, and some don't even when they are blocking. case class Offset(beginning: Long, end: Long)
def getBeginningEndOffset(topic: String, consumerProperties: Properties): Future[Map[Long, Offset]] =
for {
kafkaConsumer <- consumerPool.getConsumer(consumerProperties)
parts <- listTopicPartitions(kafkaConsumer, topic)
futureBeginning = getBeginningOffsets(kafka, parts)
futureEnd = getEndOffsets(kafka, parts)
begin <- futureBegin
end <- futureEnd
} yield begin.map { case (part, bOff) => part -> Offset(bOff, end(part)) } // This might be done in safer mannerThis might improve performance.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. Please create an issue for this one. With this PR I just follow style that was already introduced
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do! |
||
| getOffsets(topic, consumerProperties, EndOffsets) | ||
| ) | ||
| } | ||
|
|
||
| def createKafkaConsumer(propertiesThreadId: (Properties, Long)): KafkaConsumer[String, String] = { | ||
| logger.info( | ||
| s"Creating new Kafka Consumer for thread id ${propertiesThreadId._2} and" + | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * Copyright 2018 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.hyperdrive.trigger.models | ||
|
|
||
| case class BeginningEndOffsets( | ||
| topic: String, | ||
| beginningOffsets: Map[Int, Long], | ||
filiphornak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| endOffsets: Map[Int, Long] | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright 2018 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.hyperdrive.trigger.models | ||
|
|
||
| case class IngestionStatus( | ||
| jobName: String, | ||
| jobType: String, | ||
| topicStatus: Option[TopicStatus] | ||
| ) | ||
|
|
||
| case class TopicStatus(topic: String, messagesToIngest: Map[Int, Long]) |
Uh oh!
There was an error while loading. Please reload this page.