This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 14614e3de3 NIFI-13942 Improve failure message for uploaded NARs that
fail to install (#9463)
14614e3de3 is described below
commit 14614e3de3b1d76d21a954c084bf7d9ef0267607
Author: Bryan Bende <[email protected]>
AuthorDate: Mon Oct 28 15:58:23 2024 -0400
NIFI-13942 Improve failure message for uploaded NARs that fail to install
(#9463)
Signed-off-by: David Handermann <[email protected]>
---
.../src/main/java/org/apache/nifi/nar/NarManager.java | 10 +++++++++-
.../src/main/java/org/apache/nifi/nar/NarNode.java | 5 +++--
.../src/main/java/org/apache/nifi/nar/NarInstallTask.java | 12 +++++-------
.../main/java/org/apache/nifi/nar/StandardNarManager.java | 12 ++++++++++--
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarManager.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarManager.java
index bd78bdee53..5b8350ef87 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarManager.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarManager.java
@@ -55,7 +55,15 @@ public interface NarManager {
* @param coordinate the coordinate of the NAR
* @param narState the new state
*/
- void updateState(BundleCoordinate coordinate, NarState narState, String
failureMessage);
+ void updateState(BundleCoordinate coordinate, NarState narState);
+
+ /**
+ * Updates the state of the NAR with the given coordinate to be in a
failed state for the given exception that caused the failure.
+ *
+ * @param coordinate the coordinate of the NAR
+ * @param failure the exception that caused the failure
+ */
+ void updateFailed(BundleCoordinate coordinate, Throwable failure);
/**
* @return all NARs contained in the NAR Manager
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarNode.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarNode.java
index 5fc657826f..38247b8b8f 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarNode.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/nar/NarNode.java
@@ -85,8 +85,9 @@ public class NarNode {
return failureMessage;
}
- public void setFailureMessage(final String failureMessage) {
- this.failureMessage = failureMessage;
+ public void setFailure(final Throwable failure) {
+ this.state = NarState.FAILED;
+ this.failureMessage = "%s -
%s".formatted(failure.getClass().getSimpleName(), failure.getMessage());
}
@Override
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/NarInstallTask.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/NarInstallTask.java
index c8e3c6984b..8c2673353d 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/NarInstallTask.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/NarInstallTask.java
@@ -117,19 +117,18 @@ public class NarInstallTask implements Runnable {
installed = true;
} catch (final Throwable t) {
LOGGER.error("Failed to install NAR [{}]", coordinate,
t);
- narNode.setState(NarState.FAILED);
- narNode.setFailureMessage(t.getMessage());
+ narNode.setFailure(t);
}
} else {
try {
verifyExtensionDefinitions(loadedCoordinate);
- narManager.updateState(loadedCoordinate,
NarState.INSTALLED, null);
+ narManager.updateState(loadedCoordinate,
NarState.INSTALLED);
installed = true;
} catch (final NarNotFoundException e) {
LOGGER.warn("NAR [{}] was loaded, but no longer exists
in the NAR Manager", loadedCoordinate);
} catch (final Throwable t) {
LOGGER.error("Failed to install NAR [{}]", coordinate,
t);
- narManager.updateState(loadedCoordinate,
NarState.FAILED, t.getMessage());
+ narManager.updateFailed(loadedCoordinate, t);
}
}
@@ -152,7 +151,7 @@ public class NarInstallTask implements Runnable {
narNode.setState(NarState.MISSING_DEPENDENCY);
} else {
try {
- narManager.updateState(skippedCoordinate,
NarState.MISSING_DEPENDENCY, null);
+ narManager.updateState(skippedCoordinate,
NarState.MISSING_DEPENDENCY);
} catch (final NarNotFoundException e) {
LOGGER.warn("NAR [{}] was skipped, but no longer
exists in the NAR Manager", skippedCoordinate);
}
@@ -167,8 +166,7 @@ public class NarInstallTask implements Runnable {
} catch (final Throwable t) {
LOGGER.error("Failed to install NAR [{}]", coordinate, t);
- narNode.setState(NarState.FAILED);
- narNode.setFailureMessage(t.getMessage());
+ narNode.setFailure(t);
}
}
diff --git
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/StandardNarManager.java
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/StandardNarManager.java
index 34a0e606e4..e50d0a3de6 100644
---
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/StandardNarManager.java
+++
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/nar/StandardNarManager.java
@@ -141,13 +141,21 @@ public class StandardNarManager implements NarManager,
InitializingBean, Closeab
}
@Override
- public synchronized void updateState(final BundleCoordinate coordinate,
final NarState narState, final String failureMessage) {
+ public synchronized void updateState(final BundleCoordinate coordinate,
final NarState narState) {
final NarNode narNode = narNodesById.values().stream()
.filter(n ->
n.getManifest().getCoordinate().equals(coordinate))
.findFirst()
.orElseThrow(() -> new NarNotFoundException(coordinate));
narNode.setState(narState);
- narNode.setFailureMessage(failureMessage);
+ }
+
+ @Override
+ public void updateFailed(final BundleCoordinate coordinate, final
Throwable failure) {
+ final NarNode narNode = narNodesById.values().stream()
+ .filter(n ->
n.getManifest().getCoordinate().equals(coordinate))
+ .findFirst()
+ .orElseThrow(() -> new NarNotFoundException(coordinate));
+ narNode.setFailure(failure);
}
@Override