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