From 50d018566db4d2c6f97995dcde7a180d7e154ae6 Mon Sep 17 00:00:00 2001 From: Pierre Villard Date: Thu, 21 Sep 2017 14:12:29 +0200 Subject: [PATCH] NIFI-4403 - add group name to bulletins model. This closes #2167 --- .../org/apache/nifi/reporting/Bulletin.java | 9 +++++++++ .../apache/nifi/reporting/BulletinFactory.java | 13 +++++++++++++ .../apache/nifi/util/MockReportingContext.java | 2 +- .../org/apache/nifi/events/BulletinFactory.java | 17 ++++++++++++++++- .../org/apache/nifi/jaxb/AdaptedBulletin.java | 9 +++++++++ .../org/apache/nifi/jaxb/BulletinAdapter.java | 4 +++- .../logging/ControllerServiceLogObserver.java | 7 ++++++- .../nifi/remote/StandardRemoteProcessGroup.java | 3 ++- .../nifi/remote/StandardRootGroupPort.java | 3 ++- .../SiteToSiteBulletinReportingTask.java | 1 + .../TestSiteToSiteBulletinReportingTask.java | 3 ++- 11 files changed, 64 insertions(+), 7 deletions(-) diff --git a/nifi-api/src/main/java/org/apache/nifi/reporting/Bulletin.java b/nifi-api/src/main/java/org/apache/nifi/reporting/Bulletin.java index fe370ae00e..50684d6523 100644 --- a/nifi-api/src/main/java/org/apache/nifi/reporting/Bulletin.java +++ b/nifi-api/src/main/java/org/apache/nifi/reporting/Bulletin.java @@ -32,6 +32,7 @@ public abstract class Bulletin implements Comparable { private String message; private String groupId; + private String groupName; private String sourceId; private String sourceName; private ComponentType sourceType; @@ -89,6 +90,14 @@ public abstract class Bulletin implements Comparable { this.groupId = groupId; } + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + public String getSourceId() { return sourceId; } diff --git a/nifi-mock/src/main/java/org/apache/nifi/reporting/BulletinFactory.java b/nifi-mock/src/main/java/org/apache/nifi/reporting/BulletinFactory.java index 221bed63d8..0208a2ec41 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/reporting/BulletinFactory.java +++ b/nifi-mock/src/main/java/org/apache/nifi/reporting/BulletinFactory.java @@ -33,6 +33,19 @@ public class BulletinFactory { return bulletin; } + public static Bulletin createBulletin(final String groupId, final String groupName, final String sourceId, final String sourceName, + final String category, final String severity, final String message) { + final Bulletin bulletin = new MockBulletin(currentId.getAndIncrement()); + bulletin.setGroupId(groupId); + bulletin.setGroupName(groupName); + bulletin.setSourceId(sourceId); + bulletin.setSourceName(sourceName); + bulletin.setCategory(category); + bulletin.setLevel(severity); + bulletin.setMessage(message); + return bulletin; + } + public static Bulletin createBulletin(final String category, final String severity, final String message) { final Bulletin bulletin = new MockBulletin(currentId.getAndIncrement()); bulletin.setCategory(category); diff --git a/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java b/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java index f65bc3e3a0..b9e23c381e 100644 --- a/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java +++ b/nifi-mock/src/main/java/org/apache/nifi/util/MockReportingContext.java @@ -100,7 +100,7 @@ public class MockReportingContext extends MockControllerServiceLookup implements @Override public Bulletin createBulletin(final String componentId, final String category, final Severity severity, final String message) { - final Bulletin bulletin = BulletinFactory.createBulletin(null, componentId, "test processor", category, severity.name(), message); + final Bulletin bulletin = BulletinFactory.createBulletin(null, null, componentId, "test processor", category, severity.name(), message); List bulletins = componentBulletinsCreated.get(componentId); if (bulletins == null) { bulletins = new ArrayList<>(); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/events/BulletinFactory.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/events/BulletinFactory.java index 0bd250016d..eb00402377 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/events/BulletinFactory.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/main/java/org/apache/nifi/events/BulletinFactory.java @@ -48,7 +48,8 @@ public final class BulletinFactory { final ProcessGroup group = connectable.getProcessGroup(); final String groupId = group == null ? null : group.getIdentifier(); - return BulletinFactory.createBulletin(groupId, connectable.getIdentifier(), type, connectable.getName(), category, severity, message); + final String groupName = group == null ? null : group.getName(); + return BulletinFactory.createBulletin(groupId, groupName, connectable.getIdentifier(), type, connectable.getName(), category, severity, message); } public static Bulletin createBulletin(final String groupId, final String sourceId, final ComponentType sourceType, final String sourceName, @@ -64,6 +65,20 @@ public final class BulletinFactory { return bulletin; } + public static Bulletin createBulletin(final String groupId, final String groupName, final String sourceId, final ComponentType sourceType, + final String sourceName, final String category, final String severity, final String message) { + final Bulletin bulletin = new ComponentBulletin(currentId.getAndIncrement()); + bulletin.setGroupId(groupId); + bulletin.setGroupName(groupName); + bulletin.setSourceId(sourceId); + bulletin.setSourceType(sourceType); + bulletin.setSourceName(sourceName); + bulletin.setCategory(category); + bulletin.setLevel(severity); + bulletin.setMessage(message); + return bulletin; + } + public static Bulletin createBulletin(final String category, final String severity, final String message) { final Bulletin bulletin = new SystemBulletin(currentId.getAndIncrement()); bulletin.setCategory(category); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/AdaptedBulletin.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/AdaptedBulletin.java index 17c59914e7..9fc0626dc5 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/AdaptedBulletin.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/AdaptedBulletin.java @@ -32,6 +32,7 @@ public class AdaptedBulletin { private String message; private String groupId; + private String groupName; private String sourceId; private String sourceName; private ComponentType sourceType; @@ -52,6 +53,14 @@ public class AdaptedBulletin { this.groupId = groupId; } + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + public long getId() { return id; } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/BulletinAdapter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/BulletinAdapter.java index acbe0ddadf..5f3fb94f56 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/BulletinAdapter.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/jaxb/BulletinAdapter.java @@ -34,7 +34,8 @@ public class BulletinAdapter extends XmlAdapter { if (b.getSourceId() == null) { return BulletinFactory.createBulletin(b.getCategory(), b.getLevel(), b.getMessage()); } else { - return BulletinFactory.createBulletin(b.getGroupId(), b.getSourceId(), b.getSourceType(), b.getSourceName(), b.getCategory(), b.getLevel(), b.getMessage()); + return BulletinFactory.createBulletin(b.getGroupId(), b.getGroupName(), b.getSourceId(), b.getSourceType(), + b.getSourceName(), b.getCategory(), b.getLevel(), b.getMessage()); } } @@ -47,6 +48,7 @@ public class BulletinAdapter extends XmlAdapter { aBulletin.setId(b.getId()); aBulletin.setTimestamp(b.getTimestamp()); aBulletin.setGroupId(b.getGroupId()); + aBulletin.setGroupName(b.getGroupName()); aBulletin.setSourceId(b.getSourceId()); aBulletin.setSourceType(b.getSourceType()); aBulletin.setSourceName(b.getSourceName()); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/ControllerServiceLogObserver.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/ControllerServiceLogObserver.java index 3ea432d401..b245904a6f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/ControllerServiceLogObserver.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/logging/ControllerServiceLogObserver.java @@ -18,6 +18,7 @@ package org.apache.nifi.logging; import org.apache.nifi.controller.service.ControllerServiceNode; import org.apache.nifi.events.BulletinFactory; +import org.apache.nifi.groups.ProcessGroup; import org.apache.nifi.reporting.Bulletin; import org.apache.nifi.reporting.BulletinRepository; import org.apache.nifi.reporting.ComponentType; @@ -39,7 +40,11 @@ public class ControllerServiceLogObserver implements LogObserver { // 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 Bulletin bulletin = BulletinFactory.createBulletin(null, serviceNode.getIdentifier(), ComponentType.CONTROLLER_SERVICE, + 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); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java index ff5e752308..30801956f4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java @@ -164,9 +164,10 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup { @Override public void reportEvent(final Severity severity, final String category, final String message) { final String groupId = StandardRemoteProcessGroup.this.getProcessGroup().getIdentifier(); + final String groupName = StandardRemoteProcessGroup.this.getProcessGroup().getName(); final String sourceId = StandardRemoteProcessGroup.this.getIdentifier(); final String sourceName = StandardRemoteProcessGroup.this.getName(); - bulletinRepository.addBulletin(BulletinFactory.createBulletin(groupId, sourceId, ComponentType.REMOTE_PROCESS_GROUP, + bulletinRepository.addBulletin(BulletinFactory.createBulletin(groupId, groupName, sourceId, ComponentType.REMOTE_PROCESS_GROUP, sourceName, category, severity.name(), message)); } }; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java index ee16406841..27f9d9c017 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/src/main/java/org/apache/nifi/remote/StandardRootGroupPort.java @@ -117,10 +117,11 @@ public class StandardRootGroupPort extends AbstractPort implements RootGroupPort @Override public void reportEvent(final Severity severity, final String category, final String message) { final String groupId = StandardRootGroupPort.this.getProcessGroup().getIdentifier(); + final String groupName = StandardRootGroupPort.this.getProcessGroup().getName(); final String sourceId = StandardRootGroupPort.this.getIdentifier(); final String sourceName = StandardRootGroupPort.this.getName(); final ComponentType componentType = direction == TransferDirection.RECEIVE ? ComponentType.INPUT_PORT : ComponentType.OUTPUT_PORT; - bulletinRepository.addBulletin(BulletinFactory.createBulletin(groupId, sourceId, componentType, sourceName, category, severity.name(), message)); + bulletinRepository.addBulletin(BulletinFactory.createBulletin(groupId, groupName, sourceId, componentType, sourceName, category, severity.name(), message)); } }; diff --git a/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/main/java/org/apache/nifi/reporting/SiteToSiteBulletinReportingTask.java b/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/main/java/org/apache/nifi/reporting/SiteToSiteBulletinReportingTask.java index b829c1e20f..27c864906e 100644 --- a/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/main/java/org/apache/nifi/reporting/SiteToSiteBulletinReportingTask.java +++ b/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/main/java/org/apache/nifi/reporting/SiteToSiteBulletinReportingTask.java @@ -192,6 +192,7 @@ public class SiteToSiteBulletinReportingTask extends AbstractSiteToSiteReporting addField(builder, "bulletinId", bulletin.getId()); addField(builder, "bulletinCategory", bulletin.getCategory()); addField(builder, "bulletinGroupId", bulletin.getGroupId()); + addField(builder, "bulletinGroupName", bulletin.getGroupName()); addField(builder, "bulletinLevel", bulletin.getLevel()); addField(builder, "bulletinMessage", bulletin.getMessage()); addField(builder, "bulletinNodeAddress", bulletin.getNodeAddress()); diff --git a/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/test/java/org/apache/nifi/reporting/TestSiteToSiteBulletinReportingTask.java b/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/test/java/org/apache/nifi/reporting/TestSiteToSiteBulletinReportingTask.java index d247a4e705..b15110dcd5 100644 --- a/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/test/java/org/apache/nifi/reporting/TestSiteToSiteBulletinReportingTask.java +++ b/nifi-nar-bundles/nifi-site-to-site-reporting-bundle/nifi-site-to-site-reporting-task/src/test/java/org/apache/nifi/reporting/TestSiteToSiteBulletinReportingTask.java @@ -54,7 +54,7 @@ public class TestSiteToSiteBulletinReportingTask { public void testSerializedForm() throws IOException, InitializationException { // creating the list of bulletins final List bulletins = new ArrayList(); - bulletins.add(BulletinFactory.createBulletin("category", "severity", "message")); + bulletins.add(BulletinFactory.createBulletin("group-id", "group-name", "source-id", "source-name", "category", "severity", "message")); // mock the access to the list of bulletins final ReportingContext context = Mockito.mock(ReportingContext.class); @@ -97,6 +97,7 @@ public class TestSiteToSiteBulletinReportingTask { JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes())); JsonObject bulletinJson = jsonReader.readArray().getJsonObject(0); assertEquals("message", bulletinJson.getString("bulletinMessage")); + assertEquals("group-name", bulletinJson.getString("bulletinGroupName")); } @Test