Skip to content

Commit

Permalink
NIFI-13942 Improve failure message for uploaded NARs that fail to ins…
Browse files Browse the repository at this point in the history
…tall
  • Loading branch information
bbende committed Oct 28, 2024
1 parent 852f3a2 commit 1b16607
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public String getFailureMessage() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,18 @@ public void run() {
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);
}
}

Expand All @@ -152,7 +151,7 @@ public void run() {
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);
}
Expand All @@ -167,8 +166,7 @@ public void run() {

} catch (final Throwable t) {
LOGGER.error("Failed to install NAR [{}]", coordinate, t);
narNode.setState(NarState.FAILED);
narNode.setFailureMessage(t.getMessage());
narNode.setFailure(t);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,21 @@ public void completeInstall(final String identifier) {
}

@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
Expand Down

0 comments on commit 1b16607

Please sign in to comment.