use of org.apache.nifi.reporting.Bulletin in project nifi by apache.
the class ControllerServiceLogObserver method onLogMessage.
@Override
public void onLogMessage(final LogMessage message) {
// Map LogLevel.WARN to Severity.WARNING so that we are consistent with the Severity enumeration. Else, just use whatever
// the LogLevel is (INFO and ERROR map directly and all others we will just accept as they are).
final String bulletinLevel = message.getLevel() == LogLevel.WARN ? Severity.WARNING.name() : message.getLevel().toString();
final ProcessGroup pg = serviceNode.getProcessGroup();
final String groupId = pg == null ? null : pg.getIdentifier();
final String groupName = pg == null ? null : pg.getName();
final Bulletin bulletin = BulletinFactory.createBulletin(groupId, groupName, serviceNode.getIdentifier(), ComponentType.CONTROLLER_SERVICE, serviceNode.getName(), "Log Message", bulletinLevel, message.getMessage());
bulletinRepository.addBulletin(bulletin);
}
use of org.apache.nifi.reporting.Bulletin in project nifi by apache.
the class SocketProtocolListener method dispatchRequest.
@Override
public void dispatchRequest(final Socket socket) {
String hostname = null;
try {
final StopWatch stopWatch = new StopWatch(true);
hostname = socket.getInetAddress().getHostName();
final String requestId = UUID.randomUUID().toString();
logger.debug("Received request {} from {}", requestId, hostname);
String requestorDn = getRequestorDN(socket);
// unmarshall message
final ProtocolMessageUnmarshaller<ProtocolMessage> unmarshaller = protocolContext.createUnmarshaller();
final ByteCountingInputStream countingIn = new ByteCountingInputStream(socket.getInputStream());
InputStream wrappedInStream = countingIn;
if (logger.isDebugEnabled()) {
// don't buffer more than 1 MB of the message
final int maxMsgBuffer = 1024 * 1024;
final CopyingInputStream copyingInputStream = new CopyingInputStream(wrappedInStream, maxMsgBuffer);
wrappedInStream = copyingInputStream;
}
final ProtocolMessage request;
try {
request = unmarshaller.unmarshal(wrappedInStream);
} finally {
if (logger.isDebugEnabled() && wrappedInStream instanceof CopyingInputStream) {
final CopyingInputStream copyingInputStream = (CopyingInputStream) wrappedInStream;
byte[] receivedMessage = copyingInputStream.getBytesRead();
logger.debug("Received message: " + new String(receivedMessage));
}
}
request.setRequestorDN(requestorDn);
// dispatch message to handler
ProtocolHandler desiredHandler = null;
final Collection<ProtocolHandler> handlers = getHandlers();
for (final ProtocolHandler handler : handlers) {
if (handler.canHandle(request)) {
desiredHandler = handler;
break;
}
}
// if no handler found, throw exception; otherwise handle request
if (desiredHandler == null) {
logger.error("Received request of type {} but none of the following Protocol Handlers were able to process the request: {}", request.getType(), handlers);
throw new ProtocolException("No handler assigned to handle message type: " + request.getType());
} else {
final ProtocolMessage response = desiredHandler.handle(request);
if (response != null) {
try {
logger.debug("Sending response for request {}", requestId);
// marshal message to output stream
final ProtocolMessageMarshaller<ProtocolMessage> marshaller = protocolContext.createMarshaller();
marshaller.marshal(response, socket.getOutputStream());
} catch (final IOException ioe) {
throw new ProtocolException("Failed marshalling protocol message in response to message type: " + request.getType() + " due to " + ioe, ioe);
}
}
}
stopWatch.stop();
final NodeIdentifier nodeId = getNodeIdentifier(request);
final String from = nodeId == null ? hostname : nodeId.toString();
logger.info("Finished processing request {} (type={}, length={} bytes) from {} in {}", requestId, request.getType(), countingIn.getBytesRead(), from, stopWatch.getDuration());
} catch (final IOException | ProtocolException e) {
logger.warn("Failed processing protocol message from " + hostname + " due to " + e, e);
if (bulletinRepository != null) {
final Bulletin bulletin = BulletinFactory.createBulletin("Clustering", "WARNING", String.format("Failed to process protocol message from %s due to: %s", hostname, e.toString()));
bulletinRepository.addBulletin(bulletin);
}
}
}
use of org.apache.nifi.reporting.Bulletin in project nifi-minifi by apache.
the class StatusRequestParser method transformBulletins.
private static List<BulletinStatus> transformBulletins(List<Bulletin> bulletinList) {
List<BulletinStatus> bulletinStatusList = new LinkedList<>();
if (!bulletinList.isEmpty()) {
for (Bulletin bulletin : bulletinList) {
BulletinStatus bulletinStatus = new BulletinStatus();
bulletinStatus.setMessage(bulletin.getMessage());
bulletinStatus.setTimestamp(bulletin.getTimestamp());
bulletinStatusList.add(bulletinStatus);
}
}
return bulletinStatusList;
}
use of org.apache.nifi.reporting.Bulletin in project nifi-minifi by apache.
the class StatusRequestParser method parseControllerServiceStatusRequest.
static ControllerServiceStatus parseControllerServiceStatusRequest(ControllerServiceNode controllerServiceNode, String statusTypes, FlowController flowController, Logger logger) {
ControllerServiceStatus controllerServiceStatus = new ControllerServiceStatus();
String id = controllerServiceNode.getIdentifier();
controllerServiceStatus.setName(id);
String[] statusSplits = statusTypes.split(",");
List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(new BulletinQuery.Builder().sourceIdMatches(id).build());
for (String statusType : statusSplits) {
switch(statusType.toLowerCase().trim()) {
case "health":
ControllerServiceHealth controllerServiceHealth = new ControllerServiceHealth();
controllerServiceHealth.setState(controllerServiceNode.getState().name());
controllerServiceHealth.setHasBulletins(!bulletinList.isEmpty());
Collection<ValidationResult> validationResults = controllerServiceNode.getValidationErrors();
controllerServiceHealth.setValidationErrorList(transformValidationResults(validationResults));
controllerServiceStatus.setControllerServiceHealth(controllerServiceHealth);
break;
case "bulletins":
controllerServiceStatus.setBulletinList(transformBulletins(bulletinList));
break;
}
}
return controllerServiceStatus;
}
use of org.apache.nifi.reporting.Bulletin in project nifi-minifi by apache.
the class StatusRequestParser method parseProcessorStatusRequest.
static ProcessorStatusBean parseProcessorStatusRequest(ProcessorStatus inputProcessorStatus, String statusTypes, FlowController flowController, Collection<ValidationResult> validationResults) {
ProcessorStatusBean processorStatusBean = new ProcessorStatusBean();
processorStatusBean.setName(inputProcessorStatus.getName());
String[] statusSplits = statusTypes.split(",");
List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(new BulletinQuery.Builder().sourceIdMatches(inputProcessorStatus.getId()).build());
for (String statusType : statusSplits) {
switch(statusType.toLowerCase().trim()) {
case "health":
ProcessorHealth processorHealth = new ProcessorHealth();
processorHealth.setRunStatus(inputProcessorStatus.getRunStatus().name());
processorHealth.setHasBulletins(!bulletinList.isEmpty());
processorHealth.setValidationErrorList(transformValidationResults(validationResults));
processorStatusBean.setProcessorHealth(processorHealth);
break;
case "bulletins":
processorStatusBean.setBulletinList(transformBulletins(bulletinList));
break;
case "stats":
ProcessorStats processorStats = new ProcessorStats();
processorStats.setActiveThreads(inputProcessorStatus.getActiveThreadCount());
processorStats.setFlowfilesReceived(inputProcessorStatus.getFlowFilesReceived());
processorStats.setBytesRead(inputProcessorStatus.getBytesRead());
processorStats.setBytesWritten(inputProcessorStatus.getBytesWritten());
processorStats.setFlowfilesSent(inputProcessorStatus.getFlowFilesSent());
processorStats.setInvocations(inputProcessorStatus.getInvocations());
processorStats.setProcessingNanos(inputProcessorStatus.getProcessingNanos());
processorStatusBean.setProcessorStats(processorStats);
break;
}
}
return processorStatusBean;
}
Aggregations