NIFI-4403 - add group name to bulletins model. This closes #2167

This commit is contained in:
Pierre Villard 2017-09-21 14:12:29 +02:00 committed by Matt Gilman
parent 0c0c33411d
commit 50d018566d
No known key found for this signature in database
GPG Key ID: DF61EC19432AEE37
11 changed files with 64 additions and 7 deletions

View File

@ -32,6 +32,7 @@ public abstract class Bulletin implements Comparable<Bulletin> {
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<Bulletin> {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getSourceId() {
return sourceId;
}

View File

@ -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);

View File

@ -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<Bulletin> bulletins = componentBulletinsCreated.get(componentId);
if (bulletins == null) {
bulletins = new ArrayList<>();

View File

@ -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);

View File

@ -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;
}

View File

@ -34,7 +34,8 @@ public class BulletinAdapter extends XmlAdapter<AdaptedBulletin, Bulletin> {
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<AdaptedBulletin, Bulletin> {
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());

View File

@ -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);
}

View File

@ -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));
}
};

View File

@ -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));
}
};

View File

@ -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());

View File

@ -54,7 +54,7 @@ public class TestSiteToSiteBulletinReportingTask {
public void testSerializedForm() throws IOException, InitializationException {
// creating the list of bulletins
final List<Bulletin> bulletins = new ArrayList<Bulletin>();
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