NIFI-6805, NIFI-6806: Updated toString() of StandardControllerServiceNode so that it includes the component's type and UUID, updated the more generic Exception Mappers to include stack traces regardless of the log level that is enabled

This closes #3840

Signed-off-by: Mike Thomsen <mthomsen@apache.org>
This commit is contained in:
Mark Payne 2019-10-23 20:14:35 -04:00 committed by Mike Thomsen
parent 8771c35f4a
commit 8079d2531e
No known key found for this signature in database
GPG Key ID: 88511C3D4CAD246F
5 changed files with 26 additions and 45 deletions

View File

@ -420,9 +420,9 @@ public class StandardControllerServiceNode extends AbstractComponentNode impleme
final ValidationStatus validationStatus = getValidationStatus(); final ValidationStatus validationStatus = getValidationStatus();
if (validationStatus != ValidationStatus.VALID) { if (validationStatus != ValidationStatus.VALID) {
LOG.debug("Cannot enable {} because it is not currently valid. Will try again in 5 seconds", StandardControllerServiceNode.this); LOG.debug("Cannot enable {} because it is not currently valid. (Validation State is {}). Will try again in 1 second", StandardControllerServiceNode.this, getValidationState());
scheduler.schedule(this, 5, TimeUnit.SECONDS); scheduler.schedule(this, 1, TimeUnit.SECONDS);
future.completeExceptionally(new ControllerServiceNotValidException(this + " cannot be enabled because it is not currently valid. Will try again in 5 seconds.")); future.complete(null);
return; return;
} }
@ -569,19 +569,14 @@ public class StandardControllerServiceNode extends AbstractComponentNode impleme
@Override @Override
public String toString() { public String toString() {
String bundleCoordinate; final ControllerServiceDetails details = controllerServiceHolder.get();
try { final String bundleCoordinate = details == null ? "null" : String.valueOf(details.getBundleCoordinate());
bundleCoordinate = controllerServiceHolder.get().getBundleCoordinate().toString(); return "StandardControllerServiceNode[" +
} catch (NullPointerException e) { "service=" + super.toString() +
bundleCoordinate = "null";
}
return "StandardControllerServiceNode{" +
"controllerServiceHolder=" + bundleCoordinate +
", versionedComponentId=" + versionedComponentId + ", versionedComponentId=" + versionedComponentId +
", comment='" + comment + '\'' +
", processGroup=" + processGroup + ", processGroup=" + processGroup +
", active=" + active + ", active=" + active +
'}'; ']';
} }
@Override @Override

View File

@ -16,12 +16,12 @@
*/ */
package org.apache.nifi.web.api.config; package org.apache.nifi.web.api.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
import org.apache.nifi.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Maps web application exceptions into client responses. * Maps web application exceptions into client responses.
@ -34,8 +34,7 @@ public class IllegalArgumentExceptionMapper implements ExceptionMapper<IllegalAr
@Override @Override
public Response toResponse(IllegalArgumentException exception) { public Response toResponse(IllegalArgumentException exception) {
// log the error // log the error
logger.info(String.format("%s. Returning %s response.", exception, Response.Status.BAD_REQUEST)); logger.info("{}}. Returning {}} response.", exception, Response.Status.BAD_REQUEST, exception);
logger.debug(StringUtils.EMPTY, exception);
return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage()).type("text/plain").build(); return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage()).type("text/plain").build();
} }

View File

@ -16,12 +16,12 @@
*/ */
package org.apache.nifi.web.api.config; package org.apache.nifi.web.api.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
import org.apache.nifi.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Maps web application exceptions into client responses. * Maps web application exceptions into client responses.
@ -34,12 +34,7 @@ public class IllegalStateExceptionMapper implements ExceptionMapper<IllegalState
@Override @Override
public Response toResponse(IllegalStateException exception) { public Response toResponse(IllegalStateException exception) {
// log the error // log the error
logger.info(String.format("%s. Returning %s response.", exception, Response.Status.CONFLICT)); logger.warn("{}. Returning {} response.", exception, Response.Status.CONFLICT, exception);
if (logger.isDebugEnabled()) {
logger.debug(StringUtils.EMPTY, exception);
}
return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).type("text/plain").build(); return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).type("text/plain").build();
} }

View File

@ -16,14 +16,14 @@
*/ */
package org.apache.nifi.web.api.config; package org.apache.nifi.web.api.config;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.apache.nifi.util.StringUtils;
import org.apache.nifi.web.NiFiCoreException; import org.apache.nifi.web.NiFiCoreException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
/** /**
* Maps NiFi core exceptions into client responses. * Maps NiFi core exceptions into client responses.
*/ */
@ -35,12 +35,7 @@ public class NiFiCoreExceptionMapper implements ExceptionMapper<NiFiCoreExceptio
@Override @Override
public Response toResponse(NiFiCoreException exception) { public Response toResponse(NiFiCoreException exception) {
// log the error // log the error
logger.info(String.format("%s. Returning %s response.", exception, Response.Status.CONFLICT)); logger.warn("{}. Returning {} response.", exception, Response.Status.CONFLICT, exception);
if (logger.isDebugEnabled()) {
logger.debug(StringUtils.EMPTY, exception);
}
return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).type("text/plain").build(); return Response.status(Response.Status.CONFLICT).entity(exception.getMessage()).type("text/plain").build();
} }

View File

@ -16,13 +16,14 @@
*/ */
package org.apache.nifi.web.api.config; package org.apache.nifi.web.api.config;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.WebApplicationException; import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper; import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider; import javax.ws.rs.ext.Provider;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Maps web application exceptions into client responses. * Maps web application exceptions into client responses.
@ -50,11 +51,7 @@ public class WebApplicationExceptionMapper implements ExceptionMapper<WebApplica
final Response response = exception.getResponse(); final Response response = exception.getResponse();
// log the error // log the error
logger.info(String.format("%s. Returning %s response.", exception, response.getStatus())); logger.warn("{}. Returning {} response.", exception, response.getStatus(), exception);
if (logger.isDebugEnabled()) {
logger.debug(StringUtils.EMPTY, exception);
}
// generate the response // generate the response
return Response.status(response.getStatus()).entity(message).type("text/plain").build(); return Response.status(response.getStatus()).entity(message).type("text/plain").build();