Search in sources :

Example 6 with InitializationException

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);
}
Also used : IOException(java.io.IOException) InitializationException(org.apache.nifi.reporting.InitializationException) MockRecordParser(org.apache.nifi.serialization.record.MockRecordParser)

Example 7 with InitializationException

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);
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) InitializationException(org.apache.nifi.reporting.InitializationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MockStateManager(org.apache.nifi.state.MockStateManager) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with InitializationException

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());
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) InitializationException(org.apache.nifi.reporting.InitializationException) ValidationResult(org.apache.nifi.components.ValidationResult) AbstractControllerService(org.apache.nifi.controller.AbstractControllerService) ControllerService(org.apache.nifi.controller.ControllerService) Test(org.junit.Test)

Example 9 with InitializationException

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");
    }
}
Also used : MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean) InitializationException(org.apache.nifi.reporting.InitializationException) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Example 10 with InitializationException

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);
    }
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) GangliaReporter(com.yammer.metrics.reporting.GangliaReporter) IOException(java.io.IOException) InitializationException(org.apache.nifi.reporting.InitializationException) MetricName(com.yammer.metrics.core.MetricName) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Aggregations

InitializationException (org.apache.nifi.reporting.InitializationException)30 IOException (java.io.IOException)10 OnEnabled (org.apache.nifi.annotation.lifecycle.OnEnabled)7 MalformedURLException (java.net.MalformedURLException)6 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)5 SSLContextService (org.apache.nifi.ssl.SSLContextService)5 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)4 ProcessException (org.apache.nifi.processor.exception.ProcessException)4 StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)4 Test (org.junit.Test)4 ConnectException (java.net.ConnectException)3 KeyManagementException (java.security.KeyManagementException)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 UnrecoverableKeyException (java.security.UnrecoverableKeyException)3 CertificateException (java.security.cert.CertificateException)3 Driver (java.sql.Driver)3 ArrayList (java.util.ArrayList)3 MockRecordParser (org.apache.nifi.serialization.record.MockRecordParser)3