NIFI-5609: Fixed NullPointer when attempting to view status history for a component that has not yet run

Signed-off-by: Matthew Burgess <mattyb149@apache.org>

This closes #3012
This commit is contained in:
Mark Payne 2018-09-19 16:17:29 -04:00 committed by Matthew Burgess
parent f570cb980d
commit 3dd548e807
1 changed files with 23 additions and 1 deletions

View File

@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -166,13 +167,34 @@ public class VolatileComponentStatusRepository implements ComponentStatusReposit
private synchronized StatusHistory getStatusHistory(final String componentId, final boolean includeCounters, final Set<MetricDescriptor<?>> defaultMetricDescriptors) {
final ComponentStatusHistory history = componentStatusHistories.get(componentId);
if (history == null) {
return null;
return createEmptyStatusHistory();
}
final List<Date> dates = timestamps.asList();
return history.toStatusHistory(dates, includeCounters, defaultMetricDescriptors);
}
private StatusHistory createEmptyStatusHistory() {
final Date dateGenerated = new Date();
return new StatusHistory() {
@Override
public Date getDateGenerated() {
return dateGenerated;
}
@Override
public Map<String, String> getComponentDetails() {
return Collections.emptyMap();
}
@Override
public List<StatusSnapshot> getStatusSnapshots() {
return Collections.emptyList();
}
};
}
@Override
public GarbageCollectionHistory getGarbageCollectionHistory(final Date start, final Date end) {