Due to a scheduled upgrade to version 14.10, GitLab will be unavailabe on Monday 30.05., from 19:00 until 20:00.

Verified Commit 2f946fa0 authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

log more verbosly

parent 79d5be61
Pipeline #37776 passed with stages
in 5 minutes and 26 seconds
...@@ -44,7 +44,7 @@ trait BinaryHandler { ...@@ -44,7 +44,7 @@ trait BinaryHandler {
) )
.foldLeft[List[String]](List())((errors, x) => .foldLeft[List[String]](List())((errors, x) =>
if (!x._1) { if (!x._1) {
logger.warn(s"Deletion of file ${x._2} failed!") logger.warn(s"Deletion of file ${x._2} failed${if (record.dryRun) " (dry-run mode)" else ""}!")
errors :+ s"${x._2} deletion failed" errors :+ s"${x._2} deletion failed"
} else { } else {
errors errors
...@@ -52,7 +52,7 @@ trait BinaryHandler { ...@@ -52,7 +52,7 @@ trait BinaryHandler {
) )
if (result.isEmpty) { if (result.isEmpty) {
logger.debug( logger.debug(
s"Deletion of binaries for record ${record.recordId} successful" s"Deletion of binaries for record ${record.recordId} successful${if (record.dryRun) " (dry-run mode)" else ""}"
) )
record.setBinariesStatus( record.setBinariesStatus(
ProcessingSuccess, ProcessingSuccess,
...@@ -60,7 +60,7 @@ trait BinaryHandler { ...@@ -60,7 +60,7 @@ trait BinaryHandler {
) )
} else { } else {
logger.warn( logger.warn(
s"Deletion of binaries for record ${record.recordId} failed" s"Deletion of binaries for record ${record.recordId} failed${if (record.dryRun) " (dry-run mode)" else ""}"
) )
record.setBinariesStatus(ProcessingFatal, result.mkString("; ")) record.setBinariesStatus(ProcessingFatal, result.mkString("; "))
} }
......
...@@ -44,27 +44,51 @@ trait MariadbClient { ...@@ -44,27 +44,51 @@ trait MariadbClient {
private def isLocalFile(uri: String): Boolean = uri.startsWith("file:") private def isLocalFile(uri: String): Boolean = uri.startsWith("file:")
private def generateDeletionResultMessage( private def generateDeletionResultMessage(
resourceName: String, resourceName: String,
entitiesTable: Boolean, entitiesTable: Boolean,
metadataTable: Boolean, metadataTable: Boolean,
manifestV2Table: Boolean, manifestV2Table: Boolean,
manifestV3Table: Boolean manifestV3Table: Boolean
): String = { ): String = {
s"$resourceName entry deleted in tables " + s"$resourceName entry deleted in tables " +
s"${if (entitiesTable) { "entities, " } s"${
else { "" }}" + if (entitiesTable) {
s"${if (metadataTable) { "metadata, " } "entities, "
else { "" }}" + }
s"${if (manifestV2Table) { "iiif_manifests_v2, " } else {
else { "" }}" + ""
s"${if (manifestV3Table) { "iiif_manifests_v3" } }
else { "" }}" }" +
s"${
if (metadataTable) {
"metadata, "
}
else {
""
}
}" +
s"${
if (manifestV2Table) {
"iiif_manifests_v2, "
}
else {
""
}
}" +
s"${
if (manifestV3Table) {
"iiif_manifests_v3"
}
else {
""
}
}"
} }
private def updateDigitalObjectResult( private def updateDigitalObjectResult(
record: ProcessedRecord, record: ProcessedRecord,
deletionResult: DeletionResult deletionResult: DeletionResult
): ProcessedRecord = { ): ProcessedRecord = {
deletionResult match { deletionResult match {
case Success((None, false, false, false, false)) => case Success((None, false, false, false, false)) =>
record.setDigitalObjectStatus( record.setDigitalObjectStatus(
...@@ -73,10 +97,10 @@ trait MariadbClient { ...@@ -73,10 +97,10 @@ trait MariadbClient {
) )
case Success((uri, entities, metadata, manifestV2, manifestV3)) => case Success((uri, entities, metadata, manifestV2, manifestV3)) =>
(if (uri.isDefined && isLocalFile(uri.get)) { (if (uri.isDefined && isLocalFile(uri.get)) {
record.addBinary(uri.get) record.addBinary(uri.get)
} else { } else {
record record
}).setDigitalObjectStatus( }).setDigitalObjectStatus(
ProcessingSuccess, ProcessingSuccess,
generateDeletionResultMessage( generateDeletionResultMessage(
"Digital object", "Digital object",
...@@ -89,7 +113,7 @@ trait MariadbClient { ...@@ -89,7 +113,7 @@ trait MariadbClient {
case Failure(ex) => case Failure(ex) =>
record.setDigitalObjectStatus( record.setDigitalObjectStatus(
ProcessingFatal, ProcessingFatal,
s"Digital object media DB entries deletion failed: ${ex.getMessage}" s"Digital object media DB entries deletion failed${if (record.dryRun) " (dry-run mode)" else ""}: ${ex.getMessage}"
) )
} }
...@@ -97,35 +121,35 @@ trait MariadbClient { ...@@ -97,35 +121,35 @@ trait MariadbClient {
//noinspection ScalaStyle //noinspection ScalaStyle
private def updateThumbnailResult( private def updateThumbnailResult(
record: ProcessedRecord, record: ProcessedRecord,
posterDeletionResult: DeletionResult, posterDeletionResult: DeletionResult,
snippetDeletionResult: DeletionResult snippetDeletionResult: DeletionResult
): ProcessedRecord = { ): ProcessedRecord = {
(posterDeletionResult, snippetDeletionResult) match { (posterDeletionResult, snippetDeletionResult) match {
case (Failure(e), _) => case (Failure(e), _) =>
// Something went wrong // Something went wrong
record.setThumbnailStatus( record.setThumbnailStatus(
ProcessingFatal, ProcessingFatal,
s"Poster entries deletion failed: ${e.getMessage}" s"Poster entries deletion failed${if (record.dryRun) " (dry-run mode)" else ""}: ${e.getMessage}"
) )
case (_, Failure(e)) => case (_, Failure(e)) =>
// Something went wrong // Something went wrong
record.setThumbnailStatus( record.setThumbnailStatus(
ProcessingFatal, ProcessingFatal,
s"Snippet entries deletion failed: ${e.getMessage}" s"Snippet entries deletion failed${if (record.dryRun) " (dry-run mode)" else ""}: ${e.getMessage}"
) )
case (`noRows`, `noRows`) => case (`noRows`, `noRows`) =>
record.setThumbnailStatus(ProcessingIgnore, "No thumbnails found") record.setThumbnailStatus(ProcessingIgnore, "No thumbnails found")
case ( case (
Success((uri, entities, metadata, manifestV2, manifestV3)), Success((uri, entities, metadata, manifestV2, manifestV3)),
`noRows` `noRows`
) => ) =>
(if (uri.isDefined && isLocalFile(uri.get)) { (if (uri.isDefined && isLocalFile(uri.get)) {
record.addBinary(uri.get) record.addBinary(uri.get)
} else { } else {
logger.warn("Poster entry does not point to a local file!") logger.warn("Poster entry does not point to a local file!")
record record
}).setThumbnailStatus( }).setThumbnailStatus(
ProcessingSuccess, ProcessingSuccess,
generateDeletionResultMessage( generateDeletionResultMessage(
"Poster", "Poster",
...@@ -136,15 +160,15 @@ trait MariadbClient { ...@@ -136,15 +160,15 @@ trait MariadbClient {
) )
) )
case ( case (
`noRows`, `noRows`,
Success((uri, entities, metadata, manifestV2, manifestV3)) Success((uri, entities, metadata, manifestV2, manifestV3))
) => ) =>
(if (uri.isDefined && isLocalFile(uri.get)) { (if (uri.isDefined && isLocalFile(uri.get)) {
record.addBinary(uri.get) record.addBinary(uri.get)
} else { } else {
logger.warn("Snippet entry does not point to a local file!") logger.warn("Snippet entry does not point to a local file!")
record record
}).setThumbnailStatus( }).setThumbnailStatus(
ProcessingSuccess, ProcessingSuccess,
generateDeletionResultMessage( generateDeletionResultMessage(
"Snippet", "Snippet",
...@@ -184,11 +208,12 @@ trait MariadbClient { ...@@ -184,11 +208,12 @@ trait MariadbClient {
val introDeletionResult = val introDeletionResult =
deleteRows(s"$digitalObjectId-intro") deleteRows(s"$digitalObjectId-intro")
(if (record.dryRun) { (if (record.dryRun) {
Try(connection.rollback()) Try(connection.rollback())
} else { } else {
Try(connection.commit()) Try(connection.commit())
}) match { }) match {
case Success(_) => case Success(_) =>
logger.debug(s"MariaDB entries for record ${record.recordId} successfully deleted${if (record.dryRun) " (dry-run mode)" else ""}.")
val updatedRecord = updateDigitalObjectResult( val updatedRecord = updateDigitalObjectResult(
record, record,
digitalObjectDeletionResult digitalObjectDeletionResult
...@@ -199,6 +224,7 @@ trait MariadbClient { ...@@ -199,6 +224,7 @@ trait MariadbClient {
introDeletionResult introDeletionResult
) )
case Failure(ex) => case Failure(ex) =>
logger.warn(s"Deletion of MariaDB entries for record ${record.recordId} failed${if (record.dryRun) " (dry-run mode)" else ""}: ${ex.getMessage}.")
val updatedRecord = updateDigitalObjectResult( val updatedRecord = updateDigitalObjectResult(
record, record,
Failure(ex) Failure(ex)
...@@ -228,12 +254,13 @@ trait MariadbClient { ...@@ -228,12 +254,13 @@ trait MariadbClient {
/** /**
* Deletes related rows * Deletes related rows
*
* @param id Record's id * @param id Record's id
* @return An optional media file URI and success status for each row * @return An optional media file URI and success status for each row
*/ */
private def deleteRows( private def deleteRows(
id: String id: String
): DeletionResult = ): DeletionResult =
Try { Try {
val stmt = connection.createStatement val stmt = connection.createStatement
val deleteEntities = val deleteEntities =
......
...@@ -73,23 +73,23 @@ trait MemobaseElasticClient { ...@@ -73,23 +73,23 @@ trait MemobaseElasticClient {
} }
.map { .map {
case success: RequestSuccess[_] if success.status < 400 => case success: RequestSuccess[_] if success.status < 400 =>
logger.debug(s"Deletion of record ${record.recordId} successful") logger.debug(s"Deletion of record ${record.recordId} successful${if (record.dryRun) " (dry-run mode)" else ""}")
record.setRecordStatus( record.setRecordStatus(
ProcessingSuccess, ProcessingSuccess,
"Record deletion in Elasticsearch successful" "Record deletion in Elasticsearch successful"
) )
case _: RequestSuccess[_] => case _: RequestSuccess[_] =>
logger.debug(s"Deletion of record ${record.recordId} failed since record does not exist") logger.debug(s"Deletion of record ${record.recordId} failed since record does not exist${if (record.dryRun) " (dry-run mode)" else ""}")
record.setRecordStatus( record.setRecordStatus(
ProcessingIgnore, ProcessingIgnore,
"Record does not exist in Elasticearch" "Record does not exist in Elasticearch"
) )
case failure: RequestFailure => case failure: RequestFailure =>
logger.warn(s"Deletion of record ${record.recordId} failed: ${failure.error.reason}") logger.warn(s"Deletion of record ${record.recordId} failed${if (record.dryRun) " (dry-run mode)" else ""}: ${failure.error.reason}")
record.setRecordStatus( record.setRecordStatus(
ProcessingFatal, ProcessingFatal,
s"Record deletion in Elasticsearch failed: ${failure.error.reason}" s"Record deletion in Elasticsearch failed${if (record.dryRun) " (dry-run mode)" else ""}: ${failure.error.reason}"
) )
} }
.await .await
......
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