use of org.apache.nifi.reporting.InitializationException in project nifi by apache.
the class TestPutElasticsearchHttpRecord method generateTestData.
private void generateTestData() throws IOException {
final MockRecordParser parser = new MockRecordParser();
try {
runner.addControllerService("parser", parser);
} catch (InitializationException e) {
throw new IOException(e);
}
runner.enableControllerService(parser);
runner.setProperty(PutElasticsearchHttpRecord.RECORD_READER, "parser");
parser.addSchemaField("id", RecordFieldType.INT);
parser.addSchemaField("name", RecordFieldType.STRING);
parser.addSchemaField("code", RecordFieldType.INT);
parser.addRecord(1, "rec1", 101);
parser.addRecord(2, "rec2", 102);
parser.addRecord(3, "rec3", 103);
parser.addRecord(4, "rec4", 104);
}
use of org.apache.nifi.reporting.InitializationException in project nifi by apache.
the class StandardProcessorTestRunner method addControllerService.
@Override
public void addControllerService(final String identifier, final ControllerService service, final Map<String, String> properties) throws InitializationException {
final MockComponentLog logger = new MockComponentLog(identifier, service);
controllerServiceLoggers.put(identifier, logger);
final MockStateManager serviceStateManager = new MockStateManager(service);
final MockControllerServiceInitializationContext initContext = new MockControllerServiceInitializationContext(requireNonNull(service), requireNonNull(identifier), logger, serviceStateManager);
controllerServiceStateManagers.put(identifier, serviceStateManager);
initContext.addControllerServices(context);
service.initialize(initContext);
final Map<PropertyDescriptor, String> resolvedProps = new HashMap<>();
for (final Map.Entry<String, String> entry : properties.entrySet()) {
resolvedProps.put(service.getPropertyDescriptor(entry.getKey()), entry.getValue());
}
try {
ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, service);
} catch (final InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
throw new InitializationException(e);
}
context.addControllerService(identifier, service, resolvedProps, null);
}
use of org.apache.nifi.reporting.InitializationException in project nifi by apache.
the class TestStandardProcessorTestRunner method testControllerServiceUpdateShouldCallOnSetProperty.
@Test
public void testControllerServiceUpdateShouldCallOnSetProperty() {
// Arrange
final ControllerService testService = new SimpleTestService();
final AddAttributeProcessor proc = new AddAttributeProcessor();
final TestRunner runner = TestRunners.newTestRunner(proc);
final String serviceIdentifier = "test";
final String pdName = "name";
final String pdValue = "exampleName";
try {
runner.addControllerService(serviceIdentifier, testService);
} catch (InitializationException e) {
fail(e.getMessage());
}
assertFalse("onPropertyModified has been called", ((SimpleTestService) testService).isOpmCalled());
// Act
ValidationResult vr = runner.setProperty(testService, pdName, pdValue);
// Assert
assertTrue(vr.isValid());
ControllerServiceConfiguration csConf = ((MockProcessContext) runner.getProcessContext()).getConfiguration(serviceIdentifier);
PropertyDescriptor propertyDescriptor = testService.getPropertyDescriptor(pdName);
String retrievedPDValue = csConf.getProperties().get(propertyDescriptor);
assertEquals(pdValue, retrievedPDValue);
assertTrue("onPropertyModified has not been called", ((SimpleTestService) testService).isOpmCalled());
}
use of org.apache.nifi.reporting.InitializationException in project nifi by apache.
the class MonitorMemory method onConfigured.
@OnScheduled
public void onConfigured(final ConfigurationContext config) throws InitializationException {
final String desiredMemoryPoolName = config.getProperty(MEMORY_POOL_PROPERTY).getValue();
final String thresholdValue = config.getProperty(THRESHOLD_PROPERTY).getValue().trim();
threshold = thresholdValue;
final Long reportingIntervalValue = config.getProperty(REPORTING_INTERVAL).asTimePeriod(TimeUnit.MILLISECONDS);
if (reportingIntervalValue == null) {
reportingIntervalMillis = config.getSchedulingPeriod(TimeUnit.MILLISECONDS);
} else {
reportingIntervalMillis = reportingIntervalValue;
}
final List<MemoryPoolMXBean> memoryPoolBeans = ManagementFactory.getMemoryPoolMXBeans();
for (int i = 0; i < memoryPoolBeans.size() && monitoredBean == null; i++) {
MemoryPoolMXBean memoryPoolBean = memoryPoolBeans.get(i);
String memoryPoolName = memoryPoolBean.getName();
if (desiredMemoryPoolName.equals(memoryPoolName)) {
monitoredBean = memoryPoolBean;
if (memoryPoolBean.isCollectionUsageThresholdSupported()) {
long calculatedThreshold;
if (DATA_SIZE_PATTERN.matcher(thresholdValue).matches()) {
calculatedThreshold = DataUnit.parseDataSize(thresholdValue, DataUnit.B).longValue();
} else {
final String percentage = thresholdValue.substring(0, thresholdValue.length() - 1);
final double pct = Double.parseDouble(percentage) / 100D;
calculatedThreshold = (long) (monitoredBean.getUsage().getMax() * pct);
}
monitoredBean.setUsageThreshold(calculatedThreshold);
}
}
}
if (monitoredBean == null) {
throw new InitializationException("Found no JVM Memory Pool with name " + desiredMemoryPoolName + "; will not monitor Memory Pool");
}
}
use of org.apache.nifi.reporting.InitializationException in project nifi by apache.
the class StandardGangliaReporter method onConfigure.
@OnScheduled
public void onConfigure(final ConfigurationContext config) throws InitializationException {
metricsRegistry = new MetricsRegistry();
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "FlowFiles Received Last 5 mins"), new Gauge<Integer>() {
@Override
public Integer value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0;
}
final Integer value = status.getFlowFilesReceived();
return (value == null) ? 0 : value;
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Received Last 5 mins"), new Gauge<Long>() {
@Override
public Long value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0L;
}
return status.getBytesReceived();
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "FlowFiles Sent Last 5 mins"), new Gauge<Integer>() {
@Override
public Integer value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0;
}
return status.getFlowFilesSent();
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Sent Last 5 mins"), new Gauge<Long>() {
@Override
public Long value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0L;
}
return status.getBytesSent();
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "FlowFiles Queued"), new Gauge<Integer>() {
@Override
public Integer value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0;
}
final Integer value = status.getQueuedCount();
return (value == null) ? 0 : value;
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Queued"), new Gauge<Long>() {
@Override
public Long value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0L;
}
final Long value = status.getQueuedContentSize();
return (value == null) ? 0L : value;
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Read (5 mins)"), new Gauge<Long>() {
@Override
public Long value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0L;
}
final Long value = status.getBytesRead();
return (value == null) ? 0L : value;
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int64", "Bytes Written (5 mins)"), new Gauge<Long>() {
@Override
public Long value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0L;
}
final Long value = status.getBytesWritten();
return (value == null) ? 0L : value;
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "Active Threads"), new Gauge<Integer>() {
@Override
public Integer value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0;
}
final Integer value = status.getActiveThreadCount();
return (value == null) ? 0 : value;
}
});
metricsRegistry.newGauge(new MetricName(METRICS_GROUP, "int32", "Total Task Duration Seconds"), new Gauge<Integer>() {
@Override
public Integer value() {
final ProcessGroupStatus status = latestStatus.get();
if (status == null) {
return 0;
}
final long nanos = calculateProcessingNanos(status);
return (int) TimeUnit.NANOSECONDS.toSeconds(nanos);
}
});
final String gangliaHost = config.getProperty(HOSTNAME).getValue();
final int port = config.getProperty(PORT).asInteger();
try {
gangliaReporter = new GangliaReporter(metricsRegistry, gangliaHost, port, METRICS_GROUP) {
@Override
protected String sanitizeName(MetricName name) {
return name.getName();
}
};
gangliaReporter.printVMMetrics = config.getProperty(SEND_JVM_METRICS).asBoolean();
} catch (final IOException e) {
throw new InitializationException(e);
}
}
Aggregations