In order to mitigate against the brute force attacks against Gitlab accounts, we are moving to all edu-ID Logins. We would like to remind you to link your account with your edu-id. Login will be possible only by edu-ID after November 30, 2021. Here you can find the instructions for linking your account.

If you don't have a SWITCH edu-ID, you can create one with this guide here

kind regards

Commit 08569f9e authored by Thomas Bernhart's avatar Thomas Bernhart
Browse files

Improve reporting

parent f99da3db
Pipeline #16454 passed with stages
in 5 minutes and 44 seconds
......@@ -24,6 +24,9 @@ import java.util.Properties
import org.apache.kafka.clients.consumer.ConsumerRecord
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.fcrepo.client.FcrepoOperationFailedException
import org.memobase.exceptions.MissingMimeTypeException
import org.memobase.exceptions.SftpClientException
import org.memobase.fedora.FedoraClient
import org.memobase.fedora.FedoraClientImpl
import org.memobase.settings.SettingsLoader
......@@ -80,32 +83,57 @@ class Service(fileName: String = "app.yml") : Closeable {
fun processRecords() {
for (record in consumer.fetchRecords()) {
val ingestReport = processRecord(record)
producer.sendReport(record.headers(), ingestReport)
processRecord(record)
}
}
private fun processRecord(record: ConsumerRecord<String, String>): Report {
private fun processRecord(record: ConsumerRecord<String, String>) {
val ingester = Ingester(
settings.sftpSettings,
createFedoraClient(settings.appSettings),
settings.appSettings.getProperty("$FEDORA_PROPERTIES_PREFIX.externalBaseUrl")
)
return try {
try {
ingester.ingest(record.key(), record.value())
Report(
val report = Report(
id = record.key(),
status = ReportStatus.success,
message = ReportMessages.ingestedRecord(record.key())
)
} catch (ex: Exception) {
log.error("Ingestion of record ${record.key()} failed: ${ex.localizedMessage}", ex)
Report(
producer.sendReport(record.headers(), report)
} catch (ex: FcrepoOperationFailedException) {
log.error("${ex.javaClass.canonicalName}:: ${ex.localizedMessage}", ex)
val report = Report(
id = record.key(),
status = ReportStatus.failure,
message = ReportMessages.ingestFailed(record.key())
message = "Fedora Exception: ${ex.localizedMessage}"
)
producer.sendReport(record.headers(), report)
} catch (ex: MissingMimeTypeException) {
log.error("${ex.javaClass.canonicalName}:: ${ex.localizedMessage}", ex)
val report = Report(
id = record.key(),
status = ReportStatus.failure,
message = "Missing MimeType Exception: ${ex.localizedMessage}"
)
producer.sendReport(record.headers(), report)
} catch (ex: SftpClientException) {
log.error("${ex.javaClass.canonicalName}: ${ex.localizedMessage}", ex)
val report = Report(
id = record.key(),
status = ReportStatus.failure,
message = "SFTP Exception: ${ex.localizedMessage}"
)
producer.sendReport(record.headers(), report)
} catch (ex: Exception) {
log.error("${ex.javaClass.canonicalName}: ${ex.localizedMessage}", ex)
val report = Report(
id = record.key(),
status = ReportStatus.failure,
message = "Unknown Exception: ${ex.localizedMessage}"
)
producer.sendReport(record.headers(), report)
}
}
......
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