Search in sources :

Example 1 with ConfigurationContext

use of org.apache.nifi.controller.ConfigurationContext in project nifi by apache.

the class TestAmbariReportingTask method testOnTrigger.

@Test
public void testOnTrigger() throws InitializationException, IOException {
    final String metricsUrl = "http://myambari:6188/ws/v1/timeline/metrics";
    final String applicationId = "NIFI";
    final String hostName = "localhost";
    // create the jersey client mocks for handling the post
    final Client client = Mockito.mock(Client.class);
    final WebTarget target = Mockito.mock(WebTarget.class);
    final Invocation.Builder builder = Mockito.mock(Invocation.Builder.class);
    final Response response = Mockito.mock(Response.class);
    Mockito.when(response.getStatus()).thenReturn(200);
    Mockito.when(client.target(metricsUrl)).thenReturn(target);
    Mockito.when(target.request()).thenReturn(builder);
    Mockito.when(builder.post(Matchers.any(Entity.class))).thenReturn(response);
    // mock the ReportingInitializationContext for initialize(...)
    final ComponentLog logger = Mockito.mock(ComponentLog.class);
    final ReportingInitializationContext initContext = Mockito.mock(ReportingInitializationContext.class);
    Mockito.when(initContext.getIdentifier()).thenReturn(UUID.randomUUID().toString());
    Mockito.when(initContext.getLogger()).thenReturn(logger);
    // mock the ConfigurationContext for setup(...)
    final ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    // mock the ReportingContext for onTrigger(...)
    final ReportingContext context = Mockito.mock(ReportingContext.class);
    Mockito.when(context.getProperty(AmbariReportingTask.METRICS_COLLECTOR_URL)).thenReturn(new MockPropertyValue(metricsUrl));
    Mockito.when(context.getProperty(AmbariReportingTask.APPLICATION_ID)).thenReturn(new MockPropertyValue(applicationId));
    Mockito.when(context.getProperty(AmbariReportingTask.HOSTNAME)).thenReturn(new MockPropertyValue(hostName));
    Mockito.when(context.getProperty(AmbariReportingTask.PROCESS_GROUP_ID)).thenReturn(new MockPropertyValue("1234"));
    final EventAccess eventAccess = Mockito.mock(EventAccess.class);
    Mockito.when(context.getEventAccess()).thenReturn(eventAccess);
    Mockito.when(eventAccess.getControllerStatus()).thenReturn(status);
    // create a testable instance of the reporting task
    final AmbariReportingTask task = new TestableAmbariReportingTask(client);
    task.initialize(initContext);
    task.setup(configurationContext);
    task.onTrigger(context);
}
Also used : EventAccess(org.apache.nifi.reporting.EventAccess) Entity(javax.ws.rs.client.Entity) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) Invocation(javax.ws.rs.client.Invocation) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) ComponentLog(org.apache.nifi.logging.ComponentLog) ReportingContext(org.apache.nifi.reporting.ReportingContext) Response(javax.ws.rs.core.Response) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 2 with ConfigurationContext

use of org.apache.nifi.controller.ConfigurationContext in project nifi by apache.

the class TestAvroSchemaRegistry method validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties.

@Test
public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() throws Exception {
    String schemaName = "fooSchema";
    ConfigurationContext configContext = mock(ConfigurationContext.class);
    Map<PropertyDescriptor, String> properties = new HashMap<>();
    PropertyDescriptor fooSchema = new PropertyDescriptor.Builder().name(schemaName).dynamic(true).build();
    // NOTE: name of record and name of first field are not Avro-compliant, verified below
    String fooSchemaText = "{\"namespace\": \"example.avro\", " + "\"type\": \"record\", " + "\"name\": \"$User\", " + "\"fields\": [ " + "{\"name\": \"@name\", \"type\": [\"string\", \"null\"]}, " + "{\"name\": \"favorite_number\",  \"type\": [\"int\", \"null\"]}, " + "{\"name\": \"foo\",  \"type\": [\"int\", \"null\"]}, " + "{\"name\": \"favorite_color\", \"type\": [\"string\", \"null\"]} " + "]" + "}";
    PropertyDescriptor barSchema = new PropertyDescriptor.Builder().name("barSchema").dynamic(false).build();
    properties.put(fooSchema, fooSchemaText);
    properties.put(barSchema, "");
    AvroSchemaRegistry delegate = new AvroSchemaRegistry();
    delegate.getSupportedPropertyDescriptors().forEach(prop -> properties.put(prop, prop.getDisplayName()));
    when(configContext.getProperties()).thenReturn(properties);
    ValidationContext validationContext = mock(ValidationContext.class);
    when(validationContext.getProperties()).thenReturn(properties);
    PropertyValue propertyValue = mock(PropertyValue.class);
    when(validationContext.getProperty(AvroSchemaRegistry.VALIDATE_FIELD_NAMES)).thenReturn(propertyValue);
    // Strict parsing
    when(propertyValue.asBoolean()).thenReturn(true);
    Collection<ValidationResult> results = delegate.customValidate(validationContext);
    assertTrue(results.stream().anyMatch(result -> !result.isValid()));
    // Non-strict parsing
    when(propertyValue.asBoolean()).thenReturn(false);
    results = delegate.customValidate(validationContext);
    results.forEach(result -> assertTrue(result.isValid()));
}
Also used : ValidationContext(org.apache.nifi.components.ValidationContext) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SchemaNotFoundException(org.apache.nifi.schema.access.SchemaNotFoundException) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) PropertyValue(org.apache.nifi.components.PropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Map(java.util.Map) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) ValidationResult(org.apache.nifi.components.ValidationResult) Mockito.mock(org.mockito.Mockito.mock) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) PropertyValue(org.apache.nifi.components.PropertyValue) ValidationResult(org.apache.nifi.components.ValidationResult) ValidationContext(org.apache.nifi.components.ValidationContext) Test(org.junit.Test)

Example 3 with ConfigurationContext

use of org.apache.nifi.controller.ConfigurationContext in project nifi by apache.

the class StandardProcessScheduler method unschedule.

@Override
public void unschedule(final ReportingTaskNode taskNode) {
    final LifecycleState lifecycleState = getLifecycleState(requireNonNull(taskNode), false);
    if (!lifecycleState.isScheduled()) {
        return;
    }
    taskNode.verifyCanStop();
    final SchedulingAgent agent = getSchedulingAgent(taskNode.getSchedulingStrategy());
    final ReportingTask reportingTask = taskNode.getReportingTask();
    taskNode.setScheduledState(ScheduledState.STOPPED);
    final Runnable unscheduleReportingTaskRunnable = new Runnable() {

        @Override
        public void run() {
            final ConfigurationContext configurationContext = taskNode.getConfigurationContext();
            synchronized (lifecycleState) {
                lifecycleState.setScheduled(false);
                try {
                    try (final NarCloseable x = NarCloseable.withComponentNarLoader(reportingTask.getClass(), reportingTask.getIdentifier())) {
                        ReflectionUtils.invokeMethodsWithAnnotation(OnUnscheduled.class, reportingTask, configurationContext);
                    }
                } catch (final Exception e) {
                    final Throwable cause = e instanceof InvocationTargetException ? e.getCause() : e;
                    final ComponentLog componentLog = new SimpleProcessLogger(reportingTask.getIdentifier(), reportingTask);
                    componentLog.error("Failed to invoke @OnUnscheduled method due to {}", cause);
                    LOG.error("Failed to invoke the @OnUnscheduled methods of {} due to {}; administratively yielding this ReportingTask and will attempt to schedule it again after {}", reportingTask, cause.toString(), administrativeYieldDuration);
                    LOG.error("", cause);
                    try {
                        Thread.sleep(administrativeYieldMillis);
                    } catch (final InterruptedException ie) {
                    }
                }
                agent.unschedule(taskNode, lifecycleState);
                if (lifecycleState.getActiveThreadCount() == 0 && lifecycleState.mustCallOnStoppedMethods()) {
                    ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnStopped.class, reportingTask, configurationContext);
                }
            }
        }
    };
    componentLifeCycleThreadPool.execute(unscheduleReportingTaskRunnable);
}
Also used : ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) NarCloseable(org.apache.nifi.nar.NarCloseable) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) ComponentLog(org.apache.nifi.logging.ComponentLog) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ReportingTask(org.apache.nifi.reporting.ReportingTask)

Example 4 with ConfigurationContext

use of org.apache.nifi.controller.ConfigurationContext in project nifi by apache.

the class StandardProcessGroup method removeControllerService.

@Override
public void removeControllerService(final ControllerServiceNode service) {
    boolean removed = false;
    writeLock.lock();
    try {
        final ControllerServiceNode existing = controllerServices.get(requireNonNull(service).getIdentifier());
        if (existing == null) {
            throw new IllegalStateException("ControllerService " + service.getIdentifier() + " is not a member of this Process Group");
        }
        service.verifyCanDelete();
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(service.getControllerServiceImplementation().getClass(), service.getIdentifier())) {
            final ConfigurationContext configurationContext = new StandardConfigurationContext(service, controllerServiceProvider, null, variableRegistry);
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnRemoved.class, service.getControllerServiceImplementation(), configurationContext);
        }
        for (final Map.Entry<PropertyDescriptor, String> entry : service.getProperties().entrySet()) {
            final PropertyDescriptor descriptor = entry.getKey();
            if (descriptor.getControllerServiceDefinition() != null) {
                final String value = entry.getValue() == null ? descriptor.getDefaultValue() : entry.getValue();
                if (value != null) {
                    final ControllerServiceNode referencedNode = getControllerService(value);
                    if (referencedNode != null) {
                        referencedNode.removeReference(service);
                    }
                }
            }
        }
        controllerServices.remove(service.getIdentifier());
        onComponentModified();
        // For any component that references this Controller Service, find the component's Process Group
        // and notify the Process Group that a component has been modified. This way, we know to re-calculate
        // whether or not the Process Group has local modifications.
        service.getReferences().getReferencingComponents().stream().map(ConfiguredComponent::getProcessGroupIdentifier).filter(id -> !id.equals(getIdentifier())).forEach(groupId -> {
            final ProcessGroup descendant = findProcessGroup(groupId);
            if (descendant != null) {
                descendant.onComponentModified();
            }
        });
        flowController.getStateManagerProvider().onComponentRemoved(service.getIdentifier());
        removed = true;
        LOG.info("{} removed from {}", service, this);
    } finally {
        if (removed) {
            try {
                ExtensionManager.removeInstanceClassLoader(service.getIdentifier());
            } catch (Throwable t) {
            }
        }
        writeLock.unlock();
    }
}
Also used : OnRemoved(org.apache.nifi.annotation.lifecycle.OnRemoved) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) Size(org.apache.nifi.connectable.Size) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) StringUtils(org.apache.commons.lang3.StringUtils) ReflectionUtils(org.apache.nifi.util.ReflectionUtils) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) SecureRandom(java.security.SecureRandom) NiFiRegistryException(org.apache.nifi.registry.client.NiFiRegistryException) ComponentType(org.apache.nifi.registry.flow.ComponentType) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) SnippetUtils(org.apache.nifi.util.SnippetUtils) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Connectable(org.apache.nifi.connectable.Connectable) Connection(org.apache.nifi.connectable.Connection) Bundle(org.apache.nifi.registry.flow.Bundle) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) FlowDifferenceFilters(org.apache.nifi.util.FlowDifferenceFilters) VersionedFlowStatus(org.apache.nifi.registry.flow.VersionedFlowStatus) Set(java.util.Set) VersionedFlowCoordinates(org.apache.nifi.registry.flow.VersionedFlowCoordinates) VersionedRemoteGroupPort(org.apache.nifi.registry.flow.VersionedRemoteGroupPort) FlowController(org.apache.nifi.controller.FlowController) StandardCharsets(java.nio.charset.StandardCharsets) StateManagerProvider(org.apache.nifi.components.state.StateManagerProvider) Position(org.apache.nifi.connectable.Position) ScheduledState(org.apache.nifi.controller.ScheduledState) ControllerService(org.apache.nifi.controller.ControllerService) ExtensionManager(org.apache.nifi.nar.ExtensionManager) StandardVersionControlInformation(org.apache.nifi.registry.flow.StandardVersionControlInformation) Resource(org.apache.nifi.authorization.Resource) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator) StaticDifferenceDescriptor(org.apache.nifi.registry.flow.diff.StaticDifferenceDescriptor) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) SiteToSiteTransportProtocol(org.apache.nifi.remote.protocol.SiteToSiteTransportProtocol) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ArrayList(java.util.ArrayList) Relationship(org.apache.nifi.processor.Relationship) ControllerServiceReference(org.apache.nifi.controller.service.ControllerServiceReference) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) VersionedLabel(org.apache.nifi.registry.flow.VersionedLabel) LinkedHashSet(java.util.LinkedHashSet) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) EvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.EvolvingDifferenceDescriptor) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) Positionable(org.apache.nifi.connectable.Positionable) ExecutionNode(org.apache.nifi.scheduling.ExecutionNode) IOException(java.io.IOException) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) NiFiRegistryFlowMapper(org.apache.nifi.registry.flow.mapping.NiFiRegistryFlowMapper) Lock(java.util.concurrent.locks.Lock) NiFiProperties(org.apache.nifi.util.NiFiProperties) VariableImpact(org.apache.nifi.attribute.expression.language.VariableImpact) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) URL(java.net.URL) ConnectableType(org.apache.nifi.connectable.ConnectableType) ConnectableComponent(org.apache.nifi.registry.flow.ConnectableComponent) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) LoggerFactory(org.slf4j.LoggerFactory) Port(org.apache.nifi.connectable.Port) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) Query(org.apache.nifi.attribute.expression.language.Query) ResourceType(org.apache.nifi.authorization.resource.ResourceType) TemplateDTO(org.apache.nifi.web.api.dto.TemplateDTO) SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) VersionedPort(org.apache.nifi.registry.flow.VersionedPort) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) StandardProcessScheduler(org.apache.nifi.controller.scheduling.StandardProcessScheduler) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) DifferenceType(org.apache.nifi.registry.flow.diff.DifferenceType) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection) Template(org.apache.nifi.controller.Template) Label(org.apache.nifi.controller.label.Label) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) OnShutdown(org.apache.nifi.annotation.lifecycle.OnShutdown) MutableVariableRegistry(org.apache.nifi.registry.variable.MutableVariableRegistry) Authorizable(org.apache.nifi.authorization.resource.Authorizable) UUID(java.util.UUID) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) Snippet(org.apache.nifi.controller.Snippet) Collectors(java.util.stream.Collectors) ResourceFactory(org.apache.nifi.authorization.resource.ResourceFactory) Objects(java.util.Objects) List(java.util.List) BatchSize(org.apache.nifi.registry.flow.BatchSize) VersionedFunnel(org.apache.nifi.registry.flow.VersionedFunnel) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) Optional(java.util.Optional) LocalPort(org.apache.nifi.connectable.LocalPort) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) ProcessorNode(org.apache.nifi.controller.ProcessorNode) Revision(org.apache.nifi.web.Revision) Funnel(org.apache.nifi.connectable.Funnel) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ToStringStyle(org.apache.commons.lang3.builder.ToStringStyle) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) HashSet(java.util.HashSet) StringEncryptor(org.apache.nifi.encrypt.StringEncryptor) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) Objects.requireNonNull(java.util.Objects.requireNonNull) StandardConfigurationContext(org.apache.nifi.controller.service.StandardConfigurationContext) NarCloseable(org.apache.nifi.nar.NarCloseable) LogLevel(org.apache.nifi.logging.LogLevel) VersionedProcessor(org.apache.nifi.registry.flow.VersionedProcessor) Logger(org.slf4j.Logger) StateManager(org.apache.nifi.components.state.StateManager) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) StandardRemoteProcessGroupPortDescriptor(org.apache.nifi.remote.StandardRemoteProcessGroupPortDescriptor) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) VersionedControllerService(org.apache.nifi.registry.flow.VersionedControllerService) TimeUnit(java.util.concurrent.TimeUnit) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) VersionedPropertyDescriptor(org.apache.nifi.registry.flow.VersionedPropertyDescriptor) Collections(java.util.Collections) LogRepositoryFactory(org.apache.nifi.logging.LogRepositoryFactory) NarCloseable(org.apache.nifi.nar.NarCloseable) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) StandardConfigurationContext(org.apache.nifi.controller.service.StandardConfigurationContext) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) VersionedPropertyDescriptor(org.apache.nifi.registry.flow.VersionedPropertyDescriptor) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) StandardConfigurationContext(org.apache.nifi.controller.service.StandardConfigurationContext) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) VersionedRemoteProcessGroup(org.apache.nifi.registry.flow.VersionedRemoteProcessGroup) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with ConfigurationContext

use of org.apache.nifi.controller.ConfigurationContext in project nifi by apache.

the class StandardControllerServiceNode method enable.

/**
 * Will atomically enable this service by invoking its @OnEnabled operation.
 * It uses CAS operation on {@link #stateRef} to transition this service
 * from DISABLED to ENABLING state. If such transition succeeds the service
 * will be marked as 'active' (see {@link ControllerServiceNode#isActive()}).
 * If such transition doesn't succeed then no enabling logic will be
 * performed and the method will exit. In other words it is safe to invoke
 * this operation multiple times and from multiple threads.
 * <br>
 * This operation will also perform re-try of service enabling in the event
 * of exception being thrown by previous invocation of @OnEnabled.
 * <br>
 * Upon successful invocation of @OnEnabled this service will be transitioned to
 * ENABLED state.
 * <br>
 * In the event where enabling took longer then expected by the user and such user
 * initiated disable operation, this service will be automatically disabled as soon
 * as it reached ENABLED state.
 */
@Override
public CompletableFuture<Void> enable(final ScheduledExecutorService scheduler, final long administrativeYieldMillis) {
    final CompletableFuture<Void> future = new CompletableFuture<>();
    if (this.stateTransition.transitionToEnabling(ControllerServiceState.DISABLED, future)) {
        synchronized (active) {
            this.active.set(true);
        }
        final StandardControllerServiceNode service = this;
        final ConfigurationContext configContext = new StandardConfigurationContext(this, this.serviceProvider, null, getVariableRegistry());
        scheduler.execute(new Runnable() {

            @Override
            public void run() {
                try {
                    try (final NarCloseable nc = NarCloseable.withComponentNarLoader(getControllerServiceImplementation().getClass(), getIdentifier())) {
                        ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, getControllerServiceImplementation(), configContext);
                    }
                    boolean shouldEnable;
                    synchronized (active) {
                        shouldEnable = active.get() && stateTransition.enable();
                    }
                    if (!shouldEnable) {
                        LOG.debug("Disabling service {} after it has been enabled due to disable action being initiated.", service);
                        // Can only happen if user initiated DISABLE operation before service finished enabling. It's state will be
                        // set to DISABLING (see disable() operation)
                        invokeDisable(configContext);
                        stateTransition.disable();
                    } else {
                        LOG.debug("Successfully enabled {}", service);
                    }
                } catch (Exception e) {
                    future.completeExceptionally(e);
                    final Throwable cause = e instanceof InvocationTargetException ? e.getCause() : e;
                    final ComponentLog componentLog = new SimpleProcessLogger(getIdentifier(), StandardControllerServiceNode.this);
                    componentLog.error("Failed to invoke @OnEnabled method due to {}", cause);
                    LOG.error("Failed to invoke @OnEnabled method of {} due to {}", getControllerServiceImplementation(), cause.toString());
                    invokeDisable(configContext);
                    if (isActive()) {
                        scheduler.schedule(this, administrativeYieldMillis, TimeUnit.MILLISECONDS);
                    } else {
                        try (final NarCloseable nc = NarCloseable.withComponentNarLoader(getControllerServiceImplementation().getClass(), getIdentifier())) {
                            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnDisabled.class, getControllerServiceImplementation(), configContext);
                        }
                        stateTransition.disable();
                    }
                }
            }
        });
    } else {
        future.complete(null);
    }
    return future;
}
Also used : ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) NarCloseable(org.apache.nifi.nar.NarCloseable) OnEnabled(org.apache.nifi.annotation.lifecycle.OnEnabled) ComponentLog(org.apache.nifi.logging.ComponentLog) InvocationTargetException(java.lang.reflect.InvocationTargetException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CompletableFuture(java.util.concurrent.CompletableFuture) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger)

Aggregations

ConfigurationContext (org.apache.nifi.controller.ConfigurationContext)13 HashMap (java.util.HashMap)6 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)6 Test (org.junit.Test)5 IOException (java.io.IOException)4 Map (java.util.Map)4 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)4 MockConfigurationContext (org.apache.nifi.util.MockConfigurationContext)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 NarCloseable (org.apache.nifi.nar.NarCloseable)3 EventAccess (org.apache.nifi.reporting.EventAccess)3 ReportingContext (org.apache.nifi.reporting.ReportingContext)3 ReportingInitializationContext (org.apache.nifi.reporting.ReportingInitializationContext)3 SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)3 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)3 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)2 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)2 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)2