Unverified Commit 412382ef authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

add new statuses for report


Signed-off-by: Sebastian Schüpbach's avatarSebastian Schüpbach <sebastian.schuepbach@unibas.ch>
parent 00b18515
......@@ -66,14 +66,17 @@ object App extends scala.App with Logging with RecordUtils {
} yield (record, processed) match {
case (rec, ProcessSuccess(id, msg)) =>
logger.debug(msg)
reporter.send(Report(id, ProcessingIsSuccess, msg, getInstitutionAndRecordSet(rec.value)))
case (rec, ProcessWarn(id, msg)) =>
reporter.send(ReportingObject(id, ProcessingSuccess, msg, getInstitutionAndRecordSet(rec.value)))
case (rec, ProcessIgnore(id, msg)) =>
logger.info(msg)
reporter.send(ReportingObject(id, ProcessingIgnore, msg, getInstitutionAndRecordSet(rec.value)))
case (rec, ProcessWarning(id, msg)) =>
logger.warn(msg)
reporter.send(Report(id, ProcessingIsFailure, msg, getInstitutionAndRecordSet(rec.value)))
case (rec, ProcessFailure(id, msg, ex)) =>
reporter.send(ReportingObject(id, ProcessingWarning, msg, getInstitutionAndRecordSet(rec.value)))
case (rec, ProcessFatal(id, msg, ex)) =>
logger.error(msg)
logger.debug(ex.getStackTrace.mkString("\n"))
reporter.send(Report(id, ProcessingIsFailure, msg, getInstitutionAndRecordSet((rec.value))))
reporter.send(ReportingObject(id, ProcessingFatal, msg, getInstitutionAndRecordSet(rec.value)))
}
}
} catch {
......
......@@ -32,9 +32,11 @@ sealed trait ProcessOutcome
case class ProcessSuccess(id: String, msg: String) extends ProcessOutcome
case class ProcessFailure(id: String, msg: String, ex: Throwable) extends ProcessOutcome
case class ProcessFatal(id: String, msg: String, ex: Throwable) extends ProcessOutcome
case class ProcessWarn(id: String, msg: String) extends ProcessOutcome
case class ProcessWarning(id: String, msg: String) extends ProcessOutcome
case class ProcessIgnore(id: String, msg: String) extends ProcessOutcome
class RecordProcessor(fileHandler: DisseminationCopyHandler,
......@@ -48,10 +50,10 @@ class RecordProcessor(fileHandler: DisseminationCopyHandler,
case Success(binaryResource) =>
handleBinaryResource(binaryResource, record.key())
case Failure(ex) => List(ex match {
case e: NoLocalBinary => ProcessWarn(record.key(), e.getMessage)
case e: NoDigitalObject => ProcessWarn(record.key(), e.getMessage)
case e: UnmanageableMediaFileType => ProcessWarn(record.key(), e.getMessage)
case e: Exception => ProcessFailure(record.key(), e.getMessage, e)
case e: NoLocalBinary => ProcessIgnore(record.key(), e.getMessage)
case e: NoDigitalObject => ProcessIgnore(record.key(), e.getMessage)
case e: UnmanageableMediaFileType => ProcessWarning(record.key(), e.getMessage)
case e: Exception => ProcessFatal(record.key(), e.getMessage, e)
})
}
}
......@@ -66,20 +68,20 @@ class RecordProcessor(fileHandler: DisseminationCopyHandler,
binaryResource.mimeType,
binaryResource.instantiationType,
data)
case Failure(ex) => List(ProcessFailure(recordKey, "Failed to retrieve binary from Fedora", ex))
case Failure(ex) => List(ProcessFatal(recordKey, "Failed to retrieve binary from Fedora", ex))
}
}
private def createOutcome(res: Try[Boolean], id: String, destFile: String): List[ProcessOutcome] = List(res match {
case Success(true) => ProcessSuccess(id, s"Updating of file $destFile successful")
case Success(false) => ProcessSuccess(id, s"Creation of file $destFile successful")
case Failure(ex) => ProcessFailure(id, s"Creation of file $destFile failed", ex)
case Failure(ex) => ProcessFatal(id, s"Creation of file $destFile failed", ex)
})
private def deleteOutcome(res: Try[Boolean], id: String, destFile: String): List[ProcessOutcome] = List(res match {
case Success(true) => ProcessSuccess(id, s"Deletion of file $destFile successful")
case Success(false) => ProcessSuccess(id, s"No deletion of file $destFile because object does not exist")
case Failure(ex) => ProcessFailure(id, s"Deletion of file $destFile failed", ex)
case Failure(ex) => ProcessFatal(id, s"Deletion of file $destFile failed", ex)
})
......
......@@ -38,7 +38,7 @@ class Reporter(props: Properties, reportingTopic: String) {
private val producer = new KafkaProducer[String, String](props)
def send(report: models.Report): JavaFuture[RecordMetadata] = {
def send(report: models.ReportingObject): JavaFuture[RecordMetadata] = {
val headers = createHeaders(report.institutionRecordSet._2.getOrElse(""), report.institutionRecordSet._1.getOrElse(""))
val producerRecord = new ProducerRecord[String, String](reportingTopic, 0, report.id, report.toString, headers)
producer.send(producerRecord)
......
......@@ -19,20 +19,51 @@
package ch.memobase.models
import java.text.SimpleDateFormat
import java.util.Calendar
sealed trait ProcessingStatus
case object ProcessingIsSuccess extends ProcessingStatus
sealed trait ProcessingStatus {
val value: String
}
case object ProcessingSuccess extends ProcessingStatus {
override val value: String = "SUCCESS"
}
case object ProcessingWarning extends ProcessingStatus {
override val value: String = "WARNING"
}
case object ProcessingIgnore extends ProcessingStatus {
override val value: String = "IGNORE"
}
case object ProcessingFatal extends ProcessingStatus {
override val value: String = "FATAL"
}
case object ProcessingIsFailure extends ProcessingStatus
case class ReportingObject(id: String, status: ProcessingStatus, message: String, institutionRecordSet: (Option[String], Option[String])) {
import ReportingObject._
case class Report(id: String, status: ProcessingStatus, message: String, institutionRecordSet: (Option[String], Option[String])) {
override def toString: String =
s"""{"id": "$id", "status": "${
s"""{"step": "media-converter", "timestamp": "$createTimestamp", "id": "$id", "status": "${
status match {
case ProcessingIsSuccess => "SUCCESS"
case ProcessingIsFailure => "FAILURE"
case ProcessingSuccess => ProcessingSuccess.value
case ProcessingWarning => ProcessingWarning.value
case ProcessingIgnore => ProcessingIgnore.value
case ProcessingFatal => ProcessingFatal.value
}
}", "message": "$message"}"""
}", "message": "${escapeApostrophes(message)}"}"""
}
object ReportingObject {
val dateFormatter = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ss.SSS")
def createTimestamp: String = dateFormatter.format(Calendar.getInstance().getTime)
def escapeApostrophes(value: String): String =
value.replaceAll(""""""", """\\"""")
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment