Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxcapades committed May 17, 2024
1 parent 1801684 commit c986182
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ object DatasetReinstaller {
for (dataset in datasets) {
try {
processDataset(dataset, projectID, manager)
} catch (e: PluginRequestException) {
Metrics.Reinstaller.failedDatasetReinstall.inc()
log.error("failed to process dataset ${dataset.owner}/${dataset.datasetID} reinstallation for project $projectID via plugin ${e.plugin}", e)
} catch (e: PluginException) {
Metrics.Reinstaller.failedDatasetReinstall.inc()
log.error("failed to process dataset ${dataset.owner}/${dataset.datasetID} reinstallation for project $projectID via plugin ${e.plugin}", e)
} catch (e: Throwable) {
Metrics.Reinstaller.failedDatasetReinstall.inc()
log.error("failed to process dataset ${dataset.owner}/${dataset.datasetID} reinstallation for project $projectID", e)
Expand Down Expand Up @@ -128,7 +134,7 @@ object DatasetReinstaller {
val uninstallResult = try {
handler.client.postUninstall(dataset.datasetID, projectID)
} catch (e: Throwable) {
throw PluginRequestException("uninstall", handler.displayName, projectID, dataset.datasetID, e)
throw PluginRequestException("uninstall", handler.displayName, projectID, dataset.owner, dataset.datasetID, e)
}

when (uninstallResult.type) {
Expand Down Expand Up @@ -170,7 +176,7 @@ object DatasetReinstaller {
val response = try {
withInstallBundle(directory) { handler.client.postInstallData(dataset.datasetID, projectID, it) }
} catch (e: Throwable) {
throw PluginRequestException("install-data", handler.displayName, projectID, dataset.datasetID, e)
throw PluginRequestException("install-data", handler.displayName, projectID, dataset.owner, dataset.datasetID, e)
}

when (response.type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,74 +1,53 @@
package vdi.component.plugin.client

import org.slf4j.Logger
import org.veupathdb.vdi.lib.common.field.DatasetID
import org.veupathdb.vdi.lib.common.field.ProjectID
import org.veupathdb.vdi.lib.common.field.UserID

class PluginException : Exception {
open class PluginException : Exception {
val action: String
val plugin: String
val projectID: ProjectID
val userID: UserID
val datasetID: DatasetID

constructor(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
) : super(makeMessage(action, plugin, projectID, userID, datasetID)) {
this.action = action
this.plugin = plugin
this.projectID = projectID
this.userID = userID
this.datasetID = datasetID
}
override val message: String
get() = super.message!!

constructor(
protected constructor(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String,
) : super(makeMessage(action, plugin, projectID, userID, datasetID, message)) {
) : super(message) {
this.action = action
this.plugin = plugin
this.projectID = projectID
this.userID = userID
this.datasetID = datasetID
}

constructor(
protected constructor(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String,
cause: Throwable,
) : super(makeMessage(action, plugin, projectID, userID, datasetID, null, cause), cause) {
) : super(message, cause) {
this.action = action
this.plugin = plugin
this.projectID = projectID
this.userID = userID
this.datasetID = datasetID
}

constructor(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String,
cause: Throwable,
) : super(makeMessage(action, plugin, projectID, userID, datasetID, message), cause) {
this.action = action
this.plugin = plugin
this.projectID = projectID
this.userID = userID
this.datasetID = datasetID
fun log(logFn: (String, Throwable) -> Unit) {
logFn(message, this)
}

companion object {
Expand Down Expand Up @@ -119,12 +98,14 @@ class PluginException : Exception {
datasetID: DatasetID,
message: String?,
cause: Throwable?,
) = when {
message != null && cause != null -> PluginException(action, plugin, projectID, userID, datasetID, message, cause)
message != null -> PluginException(action, plugin, projectID, userID, datasetID, message)
cause != null -> PluginException(action, plugin, projectID, userID, datasetID, cause)
else -> PluginException(action, plugin, projectID, userID, datasetID)
}
) =
makeMessage(action, plugin, projectID, userID, datasetID, message, cause)
.let {
if (cause == null)
PluginException(action, plugin, projectID, userID, datasetID, it)
else
PluginException(action, plugin, projectID, userID, datasetID, it, cause)
}

private fun makeMessage(
action: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,97 @@ package vdi.component.plugin.client

import org.veupathdb.vdi.lib.common.field.DatasetID
import org.veupathdb.vdi.lib.common.field.ProjectID
import org.veupathdb.vdi.lib.common.field.UserID

class PluginRequestException : PluginException {
private constructor(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String,
) : super(action, plugin, projectID, userID, datasetID, message)

private constructor(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String,
cause: Throwable,
) : super(action, plugin, projectID, userID, datasetID, message, cause)

companion object {
@JvmStatic
fun import(plugin: String, userID: UserID, datasetID: DatasetID, message: String? = null, cause: Throwable? = null) =
new("import", plugin, "N/A", userID, datasetID, message, cause)

@JvmStatic
fun installData(
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String? = null,
cause: Throwable? = null,
) = new("install-data", plugin, projectID, userID, datasetID, message, cause)

@JvmStatic
fun installMeta(
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String? = null,
cause: Throwable? = null,
) = new("install-meta", plugin, projectID, userID, datasetID, message, cause)

@JvmStatic
fun uninstall(
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String? = null,
cause: Throwable? = null,
) = new("uninstall", plugin, projectID, userID, datasetID, message, cause)

private fun new(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String?,
cause: Throwable?,
) =
makeMessage(action, plugin, projectID, userID, datasetID, message, cause)
.let {
if (cause == null)
PluginRequestException(action, plugin, projectID, userID, datasetID, it)
else
PluginRequestException(action, plugin, projectID, userID, datasetID, it, cause)
}

private fun makeMessage(
action: String,
plugin: String,
projectID: ProjectID,
userID: UserID,
datasetID: DatasetID,
message: String?,
cause: Throwable?,
) =
"error while making a(n) $action request to plugin $plugin for dataset $userID/$datasetID targeting project " +
projectID +
if (message != null)
": $message"
else if (cause != null)
": ${cause.message}"
else
" for unknown reasons"
}
}

class PluginRequestException(
val request: String,
val plugin: String,
val projectID: ProjectID,
val datasetID: DatasetID,
cause: Throwable,
) : Exception(makeMessage(request, plugin, projectID, datasetID, cause), cause)

private fun makeMessage(
request: String,
plugin: String,
projectID: ProjectID,
datasetID: DatasetID,
cause: Throwable
) =
"error while making a(n) $request request to plugin $plugin for dataset $datasetID targeting project $projectID: " +
cause.message
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class AppDBTarget(override val name: String, private val projectID: Str
val res = try {
handler.client.postUninstall(dataset.datasetID, projectID)
} catch (e: Throwable) {
throw PluginRequestException("uninstall", handler.displayName, projectID, dataset.datasetID, e)
throw PluginRequestException.uninstall(handler.displayName, projectID, dataset.ownerID, dataset.datasetID, cause = e)
}

if (!res.isSuccessResponse)
Expand Down
Loading

0 comments on commit c986182

Please sign in to comment.