Search in sources :

Example 26 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class FlowController method createReportingTask.

public ReportingTaskNode createReportingTask(final String type, final String id, final BundleCoordinate bundleCoordinate, final Set<URL> additionalUrls, final boolean firstTimeAdded, final boolean register) throws ReportingTaskInstantiationException {
    if (type == null || id == null || bundleCoordinate == null) {
        throw new NullPointerException();
    }
    LoggableComponent<ReportingTask> task = null;
    boolean creationSuccessful = true;
    try {
        task = instantiateReportingTask(type, id, bundleCoordinate, additionalUrls);
    } catch (final Exception e) {
        LOG.error("Could not create Reporting Task of type " + type + " for ID " + id + "; creating \"Ghost\" implementation", e);
        final GhostReportingTask ghostTask = new GhostReportingTask();
        ghostTask.setIdentifier(id);
        ghostTask.setCanonicalClassName(type);
        task = new LoggableComponent<>(ghostTask, bundleCoordinate, null);
        creationSuccessful = false;
    }
    final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(controllerServiceProvider, componentVarRegistry);
    final ReportingTaskNode taskNode;
    if (creationSuccessful) {
        taskNode = new StandardReportingTaskNode(task, id, this, processScheduler, validationContextFactory, componentVarRegistry, this);
    } else {
        final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
        final String componentType = "(Missing) " + simpleClassName;
        taskNode = new StandardReportingTaskNode(task, id, this, processScheduler, validationContextFactory, componentType, type, componentVarRegistry, this, true);
    }
    taskNode.setName(taskNode.getReportingTask().getClass().getSimpleName());
    if (firstTimeAdded) {
        final ReportingInitializationContext config = new StandardReportingInitializationContext(id, taskNode.getName(), SchedulingStrategy.TIMER_DRIVEN, "1 min", taskNode.getLogger(), this, nifiProperties, this);
        try {
            taskNode.getReportingTask().initialize(config);
        } catch (final InitializationException ie) {
            throw new ReportingTaskInstantiationException("Failed to initialize reporting task of type " + type, ie);
        }
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(taskNode.getReportingTask().getClass(), taskNode.getReportingTask().getIdentifier())) {
            ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, taskNode.getReportingTask());
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, taskNode.getReportingTask());
        } catch (final Exception e) {
            throw new ComponentLifeCycleException("Failed to invoke On-Added Lifecycle methods of " + taskNode.getReportingTask(), e);
        }
    }
    if (register) {
        reportingTasks.put(id, taskNode);
        // Register log observer to provide bulletins when reporting task logs anything at WARN level or above
        final LogRepository logRepository = LogRepositoryFactory.getRepository(id);
        logRepository.addObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID, LogLevel.WARN, new ReportingTaskLogObserver(getBulletinRepository(), taskNode));
    }
    return taskNode;
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) LogRepository(org.apache.nifi.logging.LogRepository) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) InitializationException(org.apache.nifi.reporting.InitializationException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) ConfigException(org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException) IOException(java.io.IOException) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) UnknownServiceAddressException(org.apache.nifi.cluster.protocol.UnknownServiceAddressException) FlowSerializationException(org.apache.nifi.controller.serialization.FlowSerializationException) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) InitializationException(org.apache.nifi.reporting.InitializationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) CommunicationsException(org.apache.nifi.controller.exception.CommunicationsException) FlowSynchronizationException(org.apache.nifi.controller.serialization.FlowSynchronizationException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) GhostReportingTask(org.apache.nifi.reporting.GhostReportingTask) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) StandardReportingInitializationContext(org.apache.nifi.controller.reporting.StandardReportingInitializationContext) StandardReportingTaskNode(org.apache.nifi.controller.reporting.StandardReportingTaskNode) StandardReportingTaskNode(org.apache.nifi.controller.reporting.StandardReportingTaskNode) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) ReportingTaskLogObserver(org.apache.nifi.logging.ReportingTaskLogObserver) ReportingTask(org.apache.nifi.reporting.ReportingTask) GhostReportingTask(org.apache.nifi.reporting.GhostReportingTask)

Example 27 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class TestGetHTTP method useSSLContextService.

private void useSSLContextService(final Map<String, String> sslProperties) {
    final SSLContextService service = new StandardSSLContextService();
    try {
        controller.addControllerService("ssl-service", service, sslProperties);
        controller.enableControllerService(service);
    } catch (InitializationException ex) {
        ex.printStackTrace();
        Assert.fail("Could not create SSL Context Service");
    }
    controller.setProperty(GetHTTP.SSL_CONTEXT_SERVICE, "ssl-service");
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) InitializationException(org.apache.nifi.reporting.InitializationException)

Example 28 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class TestHandleHttpRequest method useSSLContextService.

private static SSLContext useSSLContextService(final TestRunner controller, final Map<String, String> sslProperties) {
    final SSLContextService service = new StandardRestrictedSSLContextService();
    try {
        controller.addControllerService("ssl-service", service, sslProperties);
        controller.enableControllerService(service);
    } catch (InitializationException ex) {
        ex.printStackTrace();
        Assert.fail("Could not create SSL Context Service");
    }
    controller.setProperty(HandleHttpRequest.SSL_CONTEXT, "ssl-service");
    return service.createSSLContext(SSLContextService.ClientAuth.WANT);
}
Also used : StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) InitializationException(org.apache.nifi.reporting.InitializationException)

Example 29 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi by apache.

the class TestServerAndClient method testNonPersistentMapServerAndClient.

@Test
public void testNonPersistentMapServerAndClient() throws InitializationException, IOException, InterruptedException {
    /**
     * This bypasses the test for build environments in OS X running Java 1.8 due to a JVM bug
     * See:  https://issues.apache.org/jira/browse/NIFI-437
     */
    Assume.assumeFalse("test is skipped due to build environment being OS X with JDK 1.8. See https://issues.apache.org/jira/browse/NIFI-437", SystemUtils.IS_OS_MAC && SystemUtils.IS_JAVA_1_8);
    LOGGER.info("Testing " + Thread.currentThread().getStackTrace()[1].getMethodName());
    // Create server
    final DistributedMapCacheServer server = new MapServer();
    final TestRunner runner = TestRunners.newTestRunner(Mockito.mock(Processor.class));
    runner.addControllerService("server", server);
    runner.enableControllerService(server);
    DistributedMapCacheClientService client = new DistributedMapCacheClientService();
    MockControllerServiceInitializationContext clientInitContext = new MockControllerServiceInitializationContext(client, "client");
    client.initialize(clientInitContext);
    final Map<PropertyDescriptor, String> clientProperties = new HashMap<>();
    clientProperties.put(DistributedMapCacheClientService.HOSTNAME, "localhost");
    clientProperties.put(DistributedMapCacheClientService.PORT, String.valueOf(server.getPort()));
    clientProperties.put(DistributedMapCacheClientService.COMMUNICATIONS_TIMEOUT, "360 secs");
    MockConfigurationContext clientContext = new MockConfigurationContext(clientProperties, clientInitContext.getControllerServiceLookup());
    client.cacheConfig(clientContext);
    final Serializer<String> valueSerializer = new StringSerializer();
    final Serializer<String> keySerializer = new StringSerializer();
    final Deserializer<String> deserializer = new StringDeserializer();
    final String original = client.getAndPutIfAbsent("testKey", "test", keySerializer, valueSerializer, deserializer);
    assertEquals(null, original);
    LOGGER.debug("end getAndPutIfAbsent");
    final boolean contains = client.containsKey("testKey", keySerializer);
    assertTrue(contains);
    LOGGER.debug("end containsKey");
    final boolean added = client.putIfAbsent("testKey", "test", keySerializer, valueSerializer);
    assertFalse(added);
    LOGGER.debug("end putIfAbsent");
    final String originalAfterPut = client.getAndPutIfAbsent("testKey", "test", keySerializer, valueSerializer, deserializer);
    assertEquals("test", originalAfterPut);
    LOGGER.debug("end getAndPutIfAbsent");
    final boolean removed = client.remove("testKey", keySerializer);
    assertTrue(removed);
    LOGGER.debug("end remove");
    client.put("testKey", "testValue", keySerializer, valueSerializer);
    assertTrue(client.containsKey("testKey", keySerializer));
    String removedValue = client.removeAndGet("testKey", keySerializer, deserializer);
    assertEquals("testValue", removedValue);
    removedValue = client.removeAndGet("testKey", keySerializer, deserializer);
    assertNull(removedValue);
    final Set<String> keys = client.keySet(deserializer);
    assertEquals(0, keys.size());
    // Test removeByPattern, the first two should be removed and the last should remain
    client.put("test.1", "1", keySerializer, keySerializer);
    client.put("test.2", "2", keySerializer, keySerializer);
    client.put("test3", "2", keySerializer, keySerializer);
    final long removedTwo = client.removeByPattern("test\\..*");
    assertEquals(2L, removedTwo);
    assertFalse(client.containsKey("test.1", keySerializer));
    assertFalse(client.containsKey("test.2", keySerializer));
    assertTrue(client.containsKey("test3", keySerializer));
    final boolean containedAfterRemove = client.containsKey("testKey", keySerializer);
    assertFalse(containedAfterRemove);
    client.putIfAbsent("testKey", "test", keySerializer, valueSerializer);
    client.close();
    try {
        client.containsKey("testKey", keySerializer);
        fail("Should be closed and not accessible");
    } catch (final Exception e) {
    }
    DistributedMapCacheClientService client2 = new DistributedMapCacheClientService();
    MockControllerServiceInitializationContext clientInitContext2 = new MockControllerServiceInitializationContext(client2, "client2");
    client2.initialize(clientInitContext2);
    MockConfigurationContext clientContext2 = new MockConfigurationContext(clientProperties, clientInitContext2.getControllerServiceLookup());
    client2.cacheConfig(clientContext2);
    assertFalse(client2.putIfAbsent("testKey", "test", keySerializer, valueSerializer));
    assertTrue(client2.containsKey("testKey", keySerializer));
    server.shutdownServer();
    Thread.sleep(1000);
    try {
        client2.containsKey("testKey", keySerializer);
        fail("Should have blown exception!");
    } catch (final ConnectException e) {
        client2 = null;
        clientContext2 = null;
        clientInitContext2 = null;
    }
    LOGGER.debug("end testNonPersistentMapServerAndClient");
}
Also used : Processor(org.apache.nifi.processor.Processor) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) TestRunner(org.apache.nifi.util.TestRunner) DistributedMapCacheServer(org.apache.nifi.distributed.cache.server.map.DistributedMapCacheServer) InitializationException(org.apache.nifi.reporting.InitializationException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) SerializationException(org.apache.commons.lang3.SerializationException) DeserializationException(org.apache.nifi.distributed.cache.client.exception.DeserializationException) DistributedMapCacheClientService(org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService) MockControllerServiceInitializationContext(org.apache.nifi.util.MockControllerServiceInitializationContext) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 30 with InitializationException

use of org.apache.nifi.reporting.InitializationException in project nifi-minifi by apache.

the class ExtensionManager method initializeTempComponent.

private static void initializeTempComponent(final ConfigurableComponent configurableComponent) {
    ConfigurableComponentInitializer initializer = null;
    try {
        initializer = ConfigurableComponentInitializerFactory.createComponentInitializer(configurableComponent.getClass());
        initializer.initialize(configurableComponent);
    } catch (final InitializationException e) {
        logger.warn(String.format("Unable to initialize component %s due to %s", configurableComponent.getClass().getName(), e.getMessage()));
    }
}
Also used : InitializationException(org.apache.nifi.reporting.InitializationException) ConfigurableComponentInitializer(org.apache.nifi.init.ConfigurableComponentInitializer)

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