Search in sources :

Example 1 with ComponentVariableRegistry

use of org.apache.nifi.registry.ComponentVariableRegistry in project nifi by apache.

the class DtoFactory method createVariableRegistryDto.

public VariableRegistryDTO createVariableRegistryDto(final ProcessGroup processGroup, final RevisionManager revisionManager) {
    final ComponentVariableRegistry variableRegistry = processGroup.getVariableRegistry();
    final List<String> variableNames = variableRegistry.getVariableMap().keySet().stream().map(descriptor -> descriptor.getName()).collect(Collectors.toList());
    final Set<VariableEntity> variableEntities = new LinkedHashSet<>();
    for (final String variableName : variableNames) {
        final VariableDTO variableDto = new VariableDTO();
        variableDto.setName(variableName);
        variableDto.setValue(variableRegistry.getVariableValue(variableName));
        variableDto.setProcessGroupId(processGroup.getIdentifier());
        final Set<AffectedComponentEntity> affectedComponentEntities = createAffectedComponentEntities(processGroup.getComponentsAffectedByVariable(variableName), revisionManager);
        boolean canWrite = true;
        for (final AffectedComponentEntity affectedComponent : affectedComponentEntities) {
            final PermissionsDTO permissions = affectedComponent.getPermissions();
            if (!permissions.getCanRead() || !permissions.getCanWrite()) {
                canWrite = false;
                break;
            }
        }
        variableDto.setAffectedComponents(affectedComponentEntities);
        final VariableEntity variableEntity = new VariableEntity();
        variableEntity.setVariable(variableDto);
        variableEntity.setCanWrite(canWrite);
        variableEntities.add(variableEntity);
    }
    final VariableRegistryDTO registryDto = new VariableRegistryDTO();
    registryDto.setProcessGroupId(processGroup.getIdentifier());
    registryDto.setVariables(variableEntities);
    return registryDto;
}
Also used : ProcessorStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessorStatusSnapshotEntity) ConnectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ConnectionDiagnosticsDTO) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) FlowModification(org.apache.nifi.web.FlowModification) StringUtils(org.apache.commons.lang3.StringUtils) DropFlowFileStatus(org.apache.nifi.controller.queue.DropFlowFileStatus) QueueSize(org.apache.nifi.controller.queue.QueueSize) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) VariableRegistryUpdateStep(org.apache.nifi.registry.variable.VariableRegistryUpdateStep) Scope(org.apache.nifi.components.state.Scope) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) ControllerFacade(org.apache.nifi.web.controller.ControllerFacade) Map(java.util.Map) InstantiatedVersionedFunnel(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedFunnel) Connection(org.apache.nifi.connectable.Connection) NarClassLoaders(org.apache.nifi.nar.NarClassLoaders) FlowDifferenceFilters(org.apache.nifi.util.FlowDifferenceFilters) NodeEvent(org.apache.nifi.cluster.event.NodeEvent) VariableRegistryUpdateRequest(org.apache.nifi.registry.variable.VariableRegistryUpdateRequest) VersionedFlowStatus(org.apache.nifi.registry.flow.VersionedFlowStatus) AllowableValue(org.apache.nifi.components.AllowableValue) ComponentReferenceEntity(org.apache.nifi.web.api.entity.ComponentReferenceEntity) PortStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.PortStatusSnapshotDTO) AuthorizerCapabilityDetection(org.apache.nifi.authorization.AuthorizerCapabilityDetection) RemoteProcessGroupDetails(org.apache.nifi.action.component.details.RemoteProcessGroupDetails) ControllerService(org.apache.nifi.controller.ControllerService) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) InstantiatedVersionedProcessor(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessor) ExtensionManager(org.apache.nifi.nar.ExtensionManager) Tags(org.apache.nifi.annotation.documentation.Tags) AllowableValueEntity(org.apache.nifi.web.api.entity.AllowableValueEntity) ControllerServiceEntity(org.apache.nifi.web.api.entity.ControllerServiceEntity) RemoteProcessGroupCounts(org.apache.nifi.groups.RemoteProcessGroupCounts) ActionDTO(org.apache.nifi.web.api.dto.action.ActionDTO) Supplier(java.util.function.Supplier) LineageDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO) LinkedHashMap(java.util.LinkedHashMap) Relationship(org.apache.nifi.processor.Relationship) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) ProcessGroupCounts(org.apache.nifi.groups.ProcessGroupCounts) FlowDTO(org.apache.nifi.web.api.dto.flow.FlowDTO) JVMSystemDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMSystemDiagnosticsSnapshotDTO) Collator(java.text.Collator) Restricted(org.apache.nifi.annotation.behavior.Restricted) VersionedFlowState(org.apache.nifi.registry.flow.VersionedFlowState) ConnectionStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusSnapshotDTO) ProvenanceNodeDTO(org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceNodeDTO) ComponentDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.ComponentDetailsDTO) RequestAction(org.apache.nifi.authorization.RequestAction) InstantiatedVersionedLabel(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedLabel) HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ControllerServiceDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ControllerServiceDiagnosticsDTO) TreeMap(java.util.TreeMap) RemoteProcessGroupDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.RemoteProcessGroupDetailsDTO) ReportingTask(org.apache.nifi.reporting.ReportingTask) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity) CoreAttributes(org.apache.nifi.flowfile.attributes.CoreAttributes) FlowFileQueue(org.apache.nifi.controller.queue.FlowFileQueue) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ProcessGroup(org.apache.nifi.groups.ProcessGroup) Date(java.util.Date) ConnectableType(org.apache.nifi.connectable.ConnectableType) ProcessorStatusDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusDTO) InstantiatedVersionedRemoteGroupPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteGroupPort) SchedulingStrategy(org.apache.nifi.scheduling.SchedulingStrategy) RemoteProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusSnapshotDTO) Locale(java.util.Locale) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) ConnectionStatusSnapshotEntity(org.apache.nifi.web.api.entity.ConnectionStatusSnapshotEntity) ActiveThreadInfo(org.apache.nifi.controller.ActiveThreadInfo) Label(org.apache.nifi.controller.label.Label) Authorizable(org.apache.nifi.authorization.resource.Authorizable) TimeZone(java.util.TimeZone) Collection(java.util.Collection) RemoteProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupStatusSnapshotEntity) ProcessorStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ProcessorStatusSnapshotDTO) RevisionManager(org.apache.nifi.web.revision.RevisionManager) Snippet(org.apache.nifi.controller.Snippet) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Collectors(java.util.stream.Collectors) StateMap(org.apache.nifi.components.state.StateMap) Processor(org.apache.nifi.processor.Processor) Entry(java.util.Map.Entry) ConnectionStatusDTO(org.apache.nifi.web.api.dto.status.ConnectionStatusDTO) ProcessorNode(org.apache.nifi.controller.ProcessorNode) NodeHeartbeat(org.apache.nifi.cluster.coordination.heartbeat.NodeHeartbeat) ComputeLineageResult(org.apache.nifi.provenance.lineage.ComputeLineageResult) ControllerServiceNode(org.apache.nifi.controller.service.ControllerServiceNode) ProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO) Group(org.apache.nifi.authorization.Group) BundleDetails(org.apache.nifi.bundle.BundleDetails) Function(java.util.function.Function) GarbageCollectionStatus(org.apache.nifi.controller.status.history.GarbageCollectionStatus) FlowRegistry(org.apache.nifi.registry.flow.FlowRegistry) HashSet(java.util.HashSet) ActionDetailsDTO(org.apache.nifi.web.api.dto.action.details.ActionDetailsDTO) ThreadDumpDTO(org.apache.nifi.web.api.dto.diagnostics.ThreadDumpDTO) GarbageCollection(org.apache.nifi.diagnostics.GarbageCollection) ReportingTaskNode(org.apache.nifi.controller.ReportingTaskNode) FlowBreadcrumbEntity(org.apache.nifi.web.api.entity.FlowBreadcrumbEntity) ValidationResult(org.apache.nifi.components.ValidationResult) PurgeDetailsDTO(org.apache.nifi.web.api.dto.action.details.PurgeDetailsDTO) JVMControllerDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMControllerDiagnosticsSnapshotDTO) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) FlowBreadcrumbDTO(org.apache.nifi.web.api.dto.flow.FlowBreadcrumbDTO) ProvenanceLinkDTO(org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceLinkDTO) ComputeLineageSubmission(org.apache.nifi.provenance.lineage.ComputeLineageSubmission) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) NiFiUserUtils(org.apache.nifi.authorization.user.NiFiUserUtils) ProvenanceEventLineageNode(org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode) BulletinRepository(org.apache.nifi.reporting.BulletinRepository) AccessPolicyEntity(org.apache.nifi.web.api.entity.AccessPolicyEntity) DigestUtils(org.apache.commons.codec.digest.DigestUtils) Comparator(java.util.Comparator) InstantiatedVersionedComponent(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedComponent) Bundle(org.apache.nifi.bundle.Bundle) StorageUsage(org.apache.nifi.diagnostics.StorageUsage) GCDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.GCDiagnosticsSnapshotDTO) GarbageCollectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.GarbageCollectionDiagnosticsDTO) Arrays(java.util.Arrays) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) ClassLoaderDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ClassLoaderDiagnosticsDTO) ProcessGroupStatusSnapshotDTO(org.apache.nifi.web.api.dto.status.ProcessGroupStatusSnapshotDTO) ClassUtils(org.apache.commons.lang3.ClassUtils) TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) RootGroupPort(org.apache.nifi.remote.RootGroupPort) Connectable(org.apache.nifi.connectable.Connectable) Bulletin(org.apache.nifi.reporting.Bulletin) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Restriction(org.apache.nifi.annotation.behavior.Restriction) FlowFilePrioritizer(org.apache.nifi.flowfile.FlowFilePrioritizer) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) History(org.apache.nifi.history.History) AccessPolicySummaryEntity(org.apache.nifi.web.api.entity.AccessPolicySummaryEntity) Set(java.util.Set) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) StatusMerger(org.apache.nifi.cluster.manager.StatusMerger) FlowController(org.apache.nifi.controller.FlowController) ListFlowFileState(org.apache.nifi.controller.queue.ListFlowFileState) Stateful(org.apache.nifi.annotation.behavior.Stateful) ActionDetails(org.apache.nifi.action.details.ActionDetails) Position(org.apache.nifi.connectable.Position) ListFlowFileStatus(org.apache.nifi.controller.queue.ListFlowFileStatus) WebApplicationException(javax.ws.rs.WebApplicationException) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) LineageRequestDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO) RemoteProcessGroupStatusDTO(org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO) Resource(org.apache.nifi.authorization.Resource) Counter(org.apache.nifi.controller.Counter) FlowFileRecord(org.apache.nifi.controller.repository.FlowFileRecord) InstantiatedVersionedProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedProcessGroup) NumberFormat(java.text.NumberFormat) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) ControllerServiceProvider(org.apache.nifi.controller.service.ControllerServiceProvider) LineageEdge(org.apache.nifi.provenance.lineage.LineageEdge) ProcessGroupFlowDTO(org.apache.nifi.web.api.dto.flow.ProcessGroupFlowDTO) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) InstantiatedVersionedRemoteProcessGroup(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedRemoteProcessGroup) NodeConnectionStatus(org.apache.nifi.cluster.coordination.node.NodeConnectionStatus) LinkedHashSet(java.util.LinkedHashSet) ConfigureDetails(org.apache.nifi.action.details.ConfigureDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) ConfiguredComponent(org.apache.nifi.controller.ConfiguredComponent) MoveDetailsDTO(org.apache.nifi.web.api.dto.action.details.MoveDetailsDTO) InstantiatedVersionedControllerService(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedControllerService) DeprecationNotice(org.apache.nifi.annotation.documentation.DeprecationNotice) DropFlowFileState(org.apache.nifi.controller.queue.DropFlowFileState) Authorizer(org.apache.nifi.authorization.Authorizer) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) JVMFlowDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMFlowDiagnosticsSnapshotDTO) LineageResultsDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageResultsDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) Port(org.apache.nifi.connectable.Port) ConfigureDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConfigureDetailsDTO) ComponentAuthorizable(org.apache.nifi.authorization.resource.ComponentAuthorizable) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) ProcessGroupStatusSnapshotEntity(org.apache.nifi.web.api.entity.ProcessGroupStatusSnapshotEntity) LineageNode(org.apache.nifi.provenance.lineage.LineageNode) DifferenceType(org.apache.nifi.registry.flow.diff.DifferenceType) SortedStateUtils(org.apache.nifi.controller.state.SortedStateUtils) Template(org.apache.nifi.controller.Template) InstantiatedVersionedConnection(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedConnection) GarbageCollectionHistory(org.apache.nifi.controller.status.history.GarbageCollectionHistory) User(org.apache.nifi.authorization.User) JVMDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsDTO) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) PortStatusSnapshotEntity(org.apache.nifi.web.api.entity.PortStatusSnapshotEntity) SystemDiagnostics(org.apache.nifi.diagnostics.SystemDiagnostics) List(java.util.List) RepositoryUsageDTO(org.apache.nifi.web.api.dto.diagnostics.RepositoryUsageDTO) VersionControlInformation(org.apache.nifi.registry.flow.VersionControlInformation) MoveDetails(org.apache.nifi.action.details.MoveDetails) Action(org.apache.nifi.action.Action) InstantiatedVersionedPort(org.apache.nifi.registry.flow.mapping.InstantiatedVersionedPort) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) Revision(org.apache.nifi.web.Revision) CapabilityDescription(org.apache.nifi.annotation.documentation.CapabilityDescription) Funnel(org.apache.nifi.connectable.Funnel) FlowFileSummary(org.apache.nifi.controller.queue.FlowFileSummary) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) HashMap(java.util.HashMap) PortStatusDTO(org.apache.nifi.web.api.dto.status.PortStatusDTO) Iterator(java.util.Iterator) ProcessorDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.ProcessorDiagnosticsDTO) ExtensionDetails(org.apache.nifi.action.component.details.ExtensionDetails) TimeUnit(java.util.concurrent.TimeUnit) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) FormatUtils(org.apache.nifi.util.FormatUtils) ExtensionDetailsDTO(org.apache.nifi.web.api.dto.action.component.details.ExtensionDetailsDTO) AccessPolicy(org.apache.nifi.authorization.AccessPolicy) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConnectDetailsDTO) LineageRequestType(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO.LineageRequestType) Collections(java.util.Collections) LinkedHashSet(java.util.LinkedHashSet) VariableEntity(org.apache.nifi.web.api.entity.VariableEntity) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) AffectedComponentEntity(org.apache.nifi.web.api.entity.AffectedComponentEntity)

Example 2 with ComponentVariableRegistry

use of org.apache.nifi.registry.ComponentVariableRegistry in project nifi by apache.

the class ControllerSearchService method search.

private ComponentSearchResultDTO search(final String searchStr, final ProcessGroup group) {
    final List<String> matches = new ArrayList<>();
    final ProcessGroup parent = group.getParent();
    if (parent == null) {
        return null;
    }
    addIfAppropriate(searchStr, group.getIdentifier(), "Id", matches);
    addIfAppropriate(searchStr, group.getVersionedComponentId().orElse(null), "Version Control ID", matches);
    addIfAppropriate(searchStr, group.getName(), "Name", matches);
    addIfAppropriate(searchStr, group.getComments(), "Comments", matches);
    final ComponentVariableRegistry varRegistry = group.getVariableRegistry();
    if (varRegistry != null) {
        final Map<VariableDescriptor, String> variableMap = varRegistry.getVariableMap();
        for (final Map.Entry<VariableDescriptor, String> entry : variableMap.entrySet()) {
            addIfAppropriate(searchStr, entry.getKey().getName(), "Variable Name", matches);
            addIfAppropriate(searchStr, entry.getValue(), "Variable Value", matches);
        }
    }
    if (matches.isEmpty()) {
        return null;
    }
    final ComponentSearchResultDTO result = new ComponentSearchResultDTO();
    result.setId(group.getIdentifier());
    result.setName(group.getName());
    result.setGroupId(parent.getIdentifier());
    result.setMatches(matches);
    return result;
}
Also used : ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) ArrayList(java.util.ArrayList) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) ComponentSearchResultDTO(org.apache.nifi.web.api.dto.search.ComponentSearchResultDTO) VariableDescriptor(org.apache.nifi.registry.VariableDescriptor) Map(java.util.Map)

Example 3 with ComponentVariableRegistry

use of org.apache.nifi.registry.ComponentVariableRegistry in project nifi by apache.

the class StandardControllerServiceProvider method createControllerService.

@Override
public ControllerServiceNode createControllerService(final String type, final String id, final BundleCoordinate bundleCoordinate, final Set<URL> additionalUrls, final boolean firstTimeAdded) {
    if (type == null || id == null || bundleCoordinate == null) {
        throw new NullPointerException();
    }
    ClassLoader cl = null;
    final ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        final Class<?> rawClass;
        try {
            final Bundle csBundle = ExtensionManager.getBundle(bundleCoordinate);
            if (csBundle == null) {
                throw new ControllerServiceInstantiationException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate());
            }
            cl = ExtensionManager.createInstanceClassLoader(type, id, csBundle, additionalUrls);
            Thread.currentThread().setContextClassLoader(cl);
            rawClass = Class.forName(type, false, cl);
        } catch (final Exception e) {
            logger.error("Could not create Controller Service of type " + type + " for ID " + id + "; creating \"Ghost\" implementation", e);
            Thread.currentThread().setContextClassLoader(currentContextClassLoader);
            return createGhostControllerService(type, id, bundleCoordinate);
        }
        final Class<? extends ControllerService> controllerServiceClass = rawClass.asSubclass(ControllerService.class);
        final ControllerService originalService = controllerServiceClass.newInstance();
        final StandardControllerServiceInvocationHandler invocationHandler = new StandardControllerServiceInvocationHandler(originalService);
        // extract all interfaces... controllerServiceClass is non null so getAllInterfaces is non null
        final List<Class<?>> interfaceList = ClassUtils.getAllInterfaces(controllerServiceClass);
        final Class<?>[] interfaces = interfaceList.toArray(new Class<?>[interfaceList.size()]);
        final ControllerService proxiedService;
        if (cl == null) {
            proxiedService = (ControllerService) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces, invocationHandler);
        } else {
            proxiedService = (ControllerService) Proxy.newProxyInstance(cl, interfaces, invocationHandler);
        }
        logger.info("Created Controller Service of type {} with identifier {}", type, id);
        final ComponentLog serviceLogger = new SimpleProcessLogger(id, originalService);
        final TerminationAwareLogger terminationAwareLogger = new TerminationAwareLogger(serviceLogger);
        originalService.initialize(new StandardControllerServiceInitializationContext(id, terminationAwareLogger, this, getStateManager(id), nifiProperties));
        final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(this, variableRegistry);
        final LoggableComponent<ControllerService> originalLoggableComponent = new LoggableComponent<>(originalService, bundleCoordinate, terminationAwareLogger);
        final LoggableComponent<ControllerService> proxiedLoggableComponent = new LoggableComponent<>(proxiedService, bundleCoordinate, terminationAwareLogger);
        final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
        final ControllerServiceNode serviceNode = new StandardControllerServiceNode(originalLoggableComponent, proxiedLoggableComponent, invocationHandler, id, validationContextFactory, this, componentVarRegistry, flowController);
        serviceNode.setName(rawClass.getSimpleName());
        invocationHandler.setServiceNode(serviceNode);
        if (firstTimeAdded) {
            try (final NarCloseable x = NarCloseable.withComponentNarLoader(originalService.getClass(), originalService.getIdentifier())) {
                ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, originalService);
            } catch (final Exception e) {
                throw new ComponentLifeCycleException("Failed to invoke On-Added Lifecycle methods of " + originalService, e);
            }
        }
        serviceCache.putIfAbsent(id, serviceNode);
        return serviceNode;
    } catch (final Throwable t) {
        throw new ControllerServiceInstantiationException(t);
    } finally {
        if (currentContextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(currentContextClassLoader);
        }
    }
}
Also used : ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) ValidationContextFactory(org.apache.nifi.controller.ValidationContextFactory) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) ControllerService(org.apache.nifi.controller.ControllerService) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) SimpleProcessLogger(org.apache.nifi.processor.SimpleProcessLogger) NarCloseable(org.apache.nifi.nar.NarCloseable) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) Bundle(org.apache.nifi.bundle.Bundle) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) ComponentLog(org.apache.nifi.logging.ComponentLog) TimeoutException(java.util.concurrent.TimeoutException) ComponentLifeCycleException(org.apache.nifi.controller.exception.ComponentLifeCycleException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) LoggableComponent(org.apache.nifi.controller.LoggableComponent) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) TerminationAwareLogger(org.apache.nifi.controller.TerminationAwareLogger)

Example 4 with ComponentVariableRegistry

use of org.apache.nifi.registry.ComponentVariableRegistry in project nifi by apache.

the class StandardControllerServiceProvider method createGhostControllerService.

private ControllerServiceNode createGhostControllerService(final String type, final String id, final BundleCoordinate bundleCoordinate) {
    final ControllerServiceInvocationHandler invocationHandler = new ControllerServiceInvocationHandler() {

        @Override
        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
            final String methodName = method.getName();
            if ("validate".equals(methodName)) {
                final ValidationResult result = new ValidationResult.Builder().input("Any Property").subject("Missing Controller Service").valid(false).explanation("Controller Service could not be created because the Controller Service Type (" + type + ") could not be found").build();
                return Collections.singleton(result);
            } else if ("getPropertyDescriptor".equals(methodName)) {
                final String propertyName = (String) args[0];
                return new PropertyDescriptor.Builder().name(propertyName).description(propertyName).sensitive(true).required(true).build();
            } else if ("getPropertyDescriptors".equals(methodName)) {
                return Collections.emptyList();
            } else if ("onPropertyModified".equals(methodName)) {
                return null;
            } else if ("getIdentifier".equals(methodName)) {
                return id;
            } else if ("toString".equals(methodName)) {
                return "GhostControllerService[id=" + id + ", type=" + type + "]";
            } else if ("hashCode".equals(methodName)) {
                return 91 * type.hashCode() + 41 * id.hashCode();
            } else if ("equals".equals(methodName)) {
                return proxy == args[0];
            } else {
                throw new IllegalStateException("Controller Service could not be created because the Controller Service Type (" + type + ") could not be found");
            }
        }

        @Override
        public void setServiceNode(ControllerServiceNode serviceNode) {
        // nothing to do
        }
    };
    final ControllerService proxiedService = (ControllerService) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { ControllerService.class }, invocationHandler);
    final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
    final String componentType = "(Missing) " + simpleClassName;
    final LoggableComponent<ControllerService> proxiedLoggableComponent = new LoggableComponent<>(proxiedService, bundleCoordinate, null);
    final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
    final ControllerServiceNode serviceNode = new StandardControllerServiceNode(proxiedLoggableComponent, proxiedLoggableComponent, invocationHandler, id, new StandardValidationContextFactory(this, variableRegistry), this, componentType, type, componentVarRegistry, flowController, true);
    serviceCache.putIfAbsent(id, serviceNode);
    return serviceNode;
}
Also used : StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) Method(java.lang.reflect.Method) ValidationResult(org.apache.nifi.components.ValidationResult) ControllerService(org.apache.nifi.controller.ControllerService) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) LoggableComponent(org.apache.nifi.controller.LoggableComponent) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry)

Example 5 with ComponentVariableRegistry

use of org.apache.nifi.registry.ComponentVariableRegistry in project nifi by apache.

the class FlowController method createProcessor.

/**
 * <p>
 * Creates a new ProcessorNode with the given type and identifier and
 * optionally initializes it.
 * </p>
 *
 * @param type the fully qualified Processor class name
 * @param id the unique ID of the Processor
 * @param coordinate the bundle coordinate for this processor
 * @param firstTimeAdded whether or not this is the first time this
 * Processor is added to the graph. If {@code true}, will invoke methods
 * annotated with the {@link OnAdded} annotation.
 * @return new processor node
 * @throws NullPointerException if either arg is null
 * @throws ProcessorInstantiationException if the processor cannot be
 * instantiated for any reason
 */
public ProcessorNode createProcessor(final String type, String id, final BundleCoordinate coordinate, final Set<URL> additionalUrls, final boolean firstTimeAdded, final boolean registerLogObserver) throws ProcessorInstantiationException {
    id = id.intern();
    boolean creationSuccessful;
    LoggableComponent<Processor> processor;
    try {
        processor = instantiateProcessor(type, id, coordinate, additionalUrls);
        creationSuccessful = true;
    } catch (final ProcessorInstantiationException pie) {
        LOG.error("Could not create Processor of type " + type + " for ID " + id + "; creating \"Ghost\" implementation", pie);
        final GhostProcessor ghostProc = new GhostProcessor();
        ghostProc.setIdentifier(id);
        ghostProc.setCanonicalClassName(type);
        processor = new LoggableComponent<>(ghostProc, coordinate, null);
        creationSuccessful = false;
    }
    final ComponentVariableRegistry componentVarRegistry = new StandardComponentVariableRegistry(this.variableRegistry);
    final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(controllerServiceProvider, componentVarRegistry);
    final ProcessorNode procNode;
    if (creationSuccessful) {
        procNode = new StandardProcessorNode(processor, id, validationContextFactory, processScheduler, controllerServiceProvider, nifiProperties, componentVarRegistry, this);
    } else {
        final String simpleClassName = type.contains(".") ? StringUtils.substringAfterLast(type, ".") : type;
        final String componentType = "(Missing) " + simpleClassName;
        procNode = new StandardProcessorNode(processor, id, validationContextFactory, processScheduler, controllerServiceProvider, componentType, type, nifiProperties, componentVarRegistry, this, true);
    }
    final LogRepository logRepository = LogRepositoryFactory.getRepository(id);
    if (registerLogObserver) {
        logRepository.addObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID, LogLevel.WARN, new ProcessorLogObserver(getBulletinRepository(), procNode));
    }
    try {
        final Class<?> procClass = procNode.getProcessor().getClass();
        if (procClass.isAnnotationPresent(DefaultSettings.class)) {
            DefaultSettings ds = procClass.getAnnotation(DefaultSettings.class);
            try {
                procNode.setYieldPeriod(ds.yieldDuration());
            } catch (Throwable ex) {
                LOG.error(String.format("Error while setting yield period from DefaultSettings annotation:%s", ex.getMessage()), ex);
            }
            try {
                procNode.setPenalizationPeriod(ds.penaltyDuration());
            } catch (Throwable ex) {
                LOG.error(String.format("Error while setting penalty duration from DefaultSettings annotation:%s", ex.getMessage()), ex);
            }
            // the caller said to register the log observer, otherwise we could be changing the level when we didn't mean to
            if (registerLogObserver) {
                try {
                    procNode.setBulletinLevel(ds.bulletinLevel());
                } catch (Throwable ex) {
                    LOG.error(String.format("Error while setting bulletin level from DefaultSettings annotation:%s", ex.getMessage()), ex);
                }
            }
        }
    } catch (Throwable ex) {
        LOG.error(String.format("Error while setting default settings from DefaultSettings annotation: %s", ex.getMessage()), ex);
    }
    if (firstTimeAdded) {
        try (final NarCloseable x = NarCloseable.withComponentNarLoader(procNode.getProcessor().getClass(), procNode.getProcessor().getIdentifier())) {
            ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, procNode.getProcessor());
        } catch (final Exception e) {
            if (registerLogObserver) {
                logRepository.removeObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID);
            }
            throw new ComponentLifeCycleException("Failed to invoke @OnAdded methods of " + procNode.getProcessor(), e);
        }
        if (firstTimeAdded) {
            try (final NarCloseable nc = NarCloseable.withComponentNarLoader(procNode.getProcessor().getClass(), procNode.getProcessor().getIdentifier())) {
                ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnConfigurationRestored.class, procNode.getProcessor());
            }
        }
    }
    return procNode;
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) GhostProcessor(org.apache.nifi.processor.GhostProcessor) Processor(org.apache.nifi.processor.Processor) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) LogRepository(org.apache.nifi.logging.LogRepository) DefaultSettings(org.apache.nifi.annotation.configuration.DefaultSettings) StandardValidationContextFactory(org.apache.nifi.processor.StandardValidationContextFactory) 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) StandardComponentVariableRegistry(org.apache.nifi.registry.variable.StandardComponentVariableRegistry) ComponentVariableRegistry(org.apache.nifi.registry.ComponentVariableRegistry) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) GhostProcessor(org.apache.nifi.processor.GhostProcessor) ProcessorLogObserver(org.apache.nifi.logging.ProcessorLogObserver)

Aggregations

ComponentVariableRegistry (org.apache.nifi.registry.ComponentVariableRegistry)8 StandardValidationContextFactory (org.apache.nifi.processor.StandardValidationContextFactory)4 StandardComponentVariableRegistry (org.apache.nifi.registry.variable.StandardComponentVariableRegistry)4 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 Map (java.util.Map)3 ControllerService (org.apache.nifi.controller.ControllerService)3 ComponentLifeCycleException (org.apache.nifi.controller.exception.ComponentLifeCycleException)3 ControllerServiceInstantiationException (org.apache.nifi.controller.exception.ControllerServiceInstantiationException)3 NarCloseable (org.apache.nifi.nar.NarCloseable)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Bundle (org.apache.nifi.bundle.Bundle)2 ValidationResult (org.apache.nifi.components.ValidationResult)2 LoggableComponent (org.apache.nifi.controller.LoggableComponent)2 ProcessGroup (org.apache.nifi.groups.ProcessGroup)2 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)2 Processor (org.apache.nifi.processor.Processor)2