Search in sources :

Example 1 with FlowController

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

the class DtoFactory method createJvmDiagnosticsSnapshotDto.

private JVMDiagnosticsSnapshotDTO createJvmDiagnosticsSnapshotDto(final FlowController flowController) {
    final JVMDiagnosticsSnapshotDTO dto = new JVMDiagnosticsSnapshotDTO();
    final JVMControllerDiagnosticsSnapshotDTO controllerDiagnosticsDto = new JVMControllerDiagnosticsSnapshotDTO();
    final JVMFlowDiagnosticsSnapshotDTO flowDiagnosticsDto = new JVMFlowDiagnosticsSnapshotDTO();
    final JVMSystemDiagnosticsSnapshotDTO systemDiagnosticsDto = new JVMSystemDiagnosticsSnapshotDTO();
    dto.setControllerDiagnostics(controllerDiagnosticsDto);
    dto.setFlowDiagnosticsDto(flowDiagnosticsDto);
    dto.setSystemDiagnosticsDto(systemDiagnosticsDto);
    final SystemDiagnostics systemDiagnostics = flowController.getSystemDiagnostics();
    // flow-related information
    final Set<BundleDTO> bundlesLoaded = ExtensionManager.getAllBundles().stream().map(bundle -> bundle.getBundleDetails().getCoordinate()).sorted((a, b) -> a.getCoordinate().compareTo(b.getCoordinate())).map(this::createBundleDto).collect(Collectors.toCollection(LinkedHashSet::new));
    flowDiagnosticsDto.setActiveEventDrivenThreads(flowController.getActiveEventDrivenThreadCount());
    flowDiagnosticsDto.setActiveTimerDrivenThreads(flowController.getActiveTimerDrivenThreadCount());
    flowDiagnosticsDto.setBundlesLoaded(bundlesLoaded);
    flowDiagnosticsDto.setTimeZone(System.getProperty("user.timezone"));
    flowDiagnosticsDto.setUptime(FormatUtils.formatHoursMinutesSeconds(systemDiagnostics.getUptime(), TimeUnit.MILLISECONDS));
    // controller-related information
    controllerDiagnosticsDto.setClusterCoordinator(flowController.isClusterCoordinator());
    controllerDiagnosticsDto.setPrimaryNode(flowController.isPrimary());
    controllerDiagnosticsDto.setMaxEventDrivenThreads(flowController.getMaxEventDrivenThreadCount());
    controllerDiagnosticsDto.setMaxTimerDrivenThreads(flowController.getMaxTimerDrivenThreadCount());
    // system-related information
    systemDiagnosticsDto.setMaxOpenFileDescriptors(systemDiagnostics.getMaxOpenFileHandles());
    systemDiagnosticsDto.setOpenFileDescriptors(systemDiagnostics.getOpenFileHandles());
    systemDiagnosticsDto.setPhysicalMemoryBytes(systemDiagnostics.getTotalPhysicalMemory());
    systemDiagnosticsDto.setPhysicalMemory(FormatUtils.formatDataSize(systemDiagnostics.getTotalPhysicalMemory()));
    final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
    percentageFormat.setMaximumFractionDigits(2);
    final Set<RepositoryUsageDTO> contentRepoUsage = new HashSet<>();
    for (final Map.Entry<String, StorageUsage> entry : systemDiagnostics.getContentRepositoryStorageUsage().entrySet()) {
        final String repoName = entry.getKey();
        final StorageUsage usage = entry.getValue();
        final RepositoryUsageDTO usageDto = new RepositoryUsageDTO();
        usageDto.setName(repoName);
        usageDto.setFileStoreHash(DigestUtils.sha256Hex(flowController.getContentRepoFileStoreName(repoName)));
        usageDto.setFreeSpace(FormatUtils.formatDataSize(usage.getFreeSpace()));
        usageDto.setFreeSpaceBytes(usage.getFreeSpace());
        usageDto.setTotalSpace(FormatUtils.formatDataSize(usage.getTotalSpace()));
        usageDto.setTotalSpaceBytes(usage.getTotalSpace());
        final double usedPercentage = (usage.getTotalSpace() - usage.getFreeSpace()) / (double) usage.getTotalSpace();
        final String utilization = percentageFormat.format(usedPercentage);
        usageDto.setUtilization(utilization);
        contentRepoUsage.add(usageDto);
    }
    final Set<RepositoryUsageDTO> provRepoUsage = new HashSet<>();
    for (final Map.Entry<String, StorageUsage> entry : systemDiagnostics.getProvenanceRepositoryStorageUsage().entrySet()) {
        final String repoName = entry.getKey();
        final StorageUsage usage = entry.getValue();
        final RepositoryUsageDTO usageDto = new RepositoryUsageDTO();
        usageDto.setName(repoName);
        usageDto.setFileStoreHash(DigestUtils.sha256Hex(flowController.getProvenanceRepoFileStoreName(repoName)));
        usageDto.setFreeSpace(FormatUtils.formatDataSize(usage.getFreeSpace()));
        usageDto.setFreeSpaceBytes(usage.getFreeSpace());
        usageDto.setTotalSpace(FormatUtils.formatDataSize(usage.getTotalSpace()));
        usageDto.setTotalSpaceBytes(usage.getTotalSpace());
        final double usedPercentage = (usage.getTotalSpace() - usage.getFreeSpace()) / (double) usage.getTotalSpace();
        final String utilization = percentageFormat.format(usedPercentage);
        usageDto.setUtilization(utilization);
        provRepoUsage.add(usageDto);
    }
    final RepositoryUsageDTO flowFileRepoUsage = new RepositoryUsageDTO();
    for (final Map.Entry<String, StorageUsage> entry : systemDiagnostics.getProvenanceRepositoryStorageUsage().entrySet()) {
        final String repoName = entry.getKey();
        final StorageUsage usage = entry.getValue();
        flowFileRepoUsage.setName(repoName);
        flowFileRepoUsage.setFileStoreHash(DigestUtils.sha256Hex(flowController.getFlowRepoFileStoreName()));
        flowFileRepoUsage.setFreeSpace(FormatUtils.formatDataSize(usage.getFreeSpace()));
        flowFileRepoUsage.setFreeSpaceBytes(usage.getFreeSpace());
        flowFileRepoUsage.setTotalSpace(FormatUtils.formatDataSize(usage.getTotalSpace()));
        flowFileRepoUsage.setTotalSpaceBytes(usage.getTotalSpace());
        final double usedPercentage = (usage.getTotalSpace() - usage.getFreeSpace()) / (double) usage.getTotalSpace();
        final String utilization = percentageFormat.format(usedPercentage);
        flowFileRepoUsage.setUtilization(utilization);
    }
    systemDiagnosticsDto.setContentRepositoryStorageUsage(contentRepoUsage);
    systemDiagnosticsDto.setCpuCores(systemDiagnostics.getAvailableProcessors());
    systemDiagnosticsDto.setCpuLoadAverage(systemDiagnostics.getProcessorLoadAverage());
    systemDiagnosticsDto.setFlowFileRepositoryStorageUsage(flowFileRepoUsage);
    systemDiagnosticsDto.setMaxHeapBytes(systemDiagnostics.getMaxHeap());
    systemDiagnosticsDto.setMaxHeap(FormatUtils.formatDataSize(systemDiagnostics.getMaxHeap()));
    systemDiagnosticsDto.setProvenanceRepositoryStorageUsage(provRepoUsage);
    // Create the Garbage Collection History info
    final GarbageCollectionHistory gcHistory = flowController.getGarbageCollectionHistory();
    final List<GarbageCollectionDiagnosticsDTO> gcDiagnostics = new ArrayList<>();
    for (final String memoryManager : gcHistory.getMemoryManagerNames()) {
        final List<GarbageCollectionStatus> statuses = gcHistory.getGarbageCollectionStatuses(memoryManager);
        final List<GCDiagnosticsSnapshotDTO> gcSnapshots = new ArrayList<>();
        for (final GarbageCollectionStatus status : statuses) {
            final GCDiagnosticsSnapshotDTO snapshotDto = new GCDiagnosticsSnapshotDTO();
            snapshotDto.setTimestamp(status.getTimestamp());
            snapshotDto.setCollectionCount(status.getCollectionCount());
            snapshotDto.setCollectionMillis(status.getCollectionMillis());
            gcSnapshots.add(snapshotDto);
        }
        final GarbageCollectionDiagnosticsDTO gcDto = new GarbageCollectionDiagnosticsDTO();
        gcDto.setMemoryManagerName(memoryManager);
        gcDto.setSnapshots(gcSnapshots);
        gcDiagnostics.add(gcDto);
    }
    systemDiagnosticsDto.setGarbageCollectionDiagnostics(gcDiagnostics);
    return dto;
}
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) ArrayList(java.util.ArrayList) GCDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.GCDiagnosticsSnapshotDTO) JVMDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMDiagnosticsSnapshotDTO) RepositoryUsageDTO(org.apache.nifi.web.api.dto.diagnostics.RepositoryUsageDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) GarbageCollectionHistory(org.apache.nifi.controller.status.history.GarbageCollectionHistory) GarbageCollectionStatus(org.apache.nifi.controller.status.history.GarbageCollectionStatus) JVMFlowDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMFlowDiagnosticsSnapshotDTO) JVMControllerDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMControllerDiagnosticsSnapshotDTO) SystemDiagnostics(org.apache.nifi.diagnostics.SystemDiagnostics) GarbageCollectionDiagnosticsDTO(org.apache.nifi.web.api.dto.diagnostics.GarbageCollectionDiagnosticsDTO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) StateMap(org.apache.nifi.components.state.StateMap) HashMap(java.util.HashMap) StorageUsage(org.apache.nifi.diagnostics.StorageUsage) JVMSystemDiagnosticsSnapshotDTO(org.apache.nifi.web.api.dto.diagnostics.JVMSystemDiagnosticsSnapshotDTO) NumberFormat(java.text.NumberFormat)

Example 2 with FlowController

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

the class TestStandardControllerServiceProvider method testOrderingOfServices.

@Test
public void testOrderingOfServices() {
    final ProcessGroup procGroup = new MockProcessGroup(controller);
    final FlowController controller = Mockito.mock(FlowController.class);
    Mockito.when(controller.getGroup(Mockito.anyString())).thenReturn(procGroup);
    final StandardControllerServiceProvider provider = new StandardControllerServiceProvider(controller, null, null, stateManagerProvider, variableRegistry, niFiProperties);
    final ControllerServiceNode serviceNode1 = provider.createControllerService(ServiceA.class.getName(), "1", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ControllerServiceNode serviceNode2 = provider.createControllerService(ServiceB.class.getName(), "2", systemBundle.getBundleDetails().getCoordinate(), null, false);
    setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
    final Map<String, ControllerServiceNode> nodeMap = new LinkedHashMap<>();
    nodeMap.put("1", serviceNode1);
    nodeMap.put("2", serviceNode2);
    List<List<ControllerServiceNode>> branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(2, branches.size());
    List<ControllerServiceNode> ordered = branches.get(0);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    assertTrue(ordered.get(1) == serviceNode1);
    assertEquals(1, branches.get(1).size());
    assertTrue(branches.get(1).get(0) == serviceNode2);
    nodeMap.clear();
    nodeMap.put("2", serviceNode2);
    nodeMap.put("1", serviceNode1);
    branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(2, branches.size());
    ordered = branches.get(1);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    assertTrue(ordered.get(1) == serviceNode1);
    assertEquals(1, branches.get(0).size());
    assertTrue(branches.get(0).get(0) == serviceNode2);
    // add circular dependency on self.
    nodeMap.clear();
    setProperty(serviceNode1, ServiceA.OTHER_SERVICE_2.getName(), "1");
    nodeMap.put("1", serviceNode1);
    nodeMap.put("2", serviceNode2);
    branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(2, branches.size());
    ordered = branches.get(0);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    assertTrue(ordered.get(1) == serviceNode1);
    nodeMap.clear();
    nodeMap.put("2", serviceNode2);
    nodeMap.put("1", serviceNode1);
    branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(2, branches.size());
    ordered = branches.get(1);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    assertTrue(ordered.get(1) == serviceNode1);
    // add circular dependency once removed. In this case, we won't actually be able to enable these because of the
    // circular dependency because they will never be valid because they will always depend on a disabled service.
    // But we want to ensure that the method returns successfully without throwing a StackOverflowException or anything
    // like that.
    nodeMap.clear();
    final ControllerServiceNode serviceNode3 = provider.createControllerService(ServiceA.class.getName(), "3", systemBundle.getBundleDetails().getCoordinate(), null, false);
    setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "3");
    setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "1");
    nodeMap.put("1", serviceNode1);
    nodeMap.put("3", serviceNode3);
    branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(2, branches.size());
    ordered = branches.get(0);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode3);
    assertTrue(ordered.get(1) == serviceNode1);
    nodeMap.clear();
    nodeMap.put("3", serviceNode3);
    nodeMap.put("1", serviceNode1);
    branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(2, branches.size());
    ordered = branches.get(1);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode3);
    assertTrue(ordered.get(1) == serviceNode1);
    // Add multiple completely disparate branches.
    nodeMap.clear();
    setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
    final ControllerServiceNode serviceNode4 = provider.createControllerService(ServiceB.class.getName(), "4", systemBundle.getBundleDetails().getCoordinate(), null, false);
    final ControllerServiceNode serviceNode5 = provider.createControllerService(ServiceB.class.getName(), "5", systemBundle.getBundleDetails().getCoordinate(), null, false);
    setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "4");
    nodeMap.put("1", serviceNode1);
    nodeMap.put("2", serviceNode2);
    nodeMap.put("3", serviceNode3);
    nodeMap.put("4", serviceNode4);
    nodeMap.put("5", serviceNode5);
    branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(5, branches.size());
    ordered = branches.get(0);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    assertTrue(ordered.get(1) == serviceNode1);
    assertEquals(1, branches.get(1).size());
    assertTrue(branches.get(1).get(0) == serviceNode2);
    ordered = branches.get(2);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode4);
    assertTrue(ordered.get(1) == serviceNode3);
    assertEquals(1, branches.get(3).size());
    assertTrue(branches.get(3).get(0) == serviceNode4);
    assertEquals(1, branches.get(4).size());
    assertTrue(branches.get(4).get(0) == serviceNode5);
    // create 2 branches both dependent on the same service
    nodeMap.clear();
    setProperty(serviceNode1, ServiceA.OTHER_SERVICE.getName(), "2");
    setProperty(serviceNode3, ServiceA.OTHER_SERVICE.getName(), "2");
    nodeMap.put("1", serviceNode1);
    nodeMap.put("2", serviceNode2);
    nodeMap.put("3", serviceNode3);
    branches = StandardControllerServiceProvider.determineEnablingOrder(nodeMap);
    assertEquals(3, branches.size());
    ordered = branches.get(0);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    assertTrue(ordered.get(1) == serviceNode1);
    ordered = branches.get(1);
    assertEquals(1, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    ordered = branches.get(2);
    assertEquals(2, ordered.size());
    assertTrue(ordered.get(0) == serviceNode2);
    assertTrue(ordered.get(1) == serviceNode3);
}
Also used : ServiceB(org.apache.nifi.controller.service.mock.ServiceB) ServiceA(org.apache.nifi.controller.service.mock.ServiceA) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) LinkedHashMap(java.util.LinkedHashMap) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProcessGroup(org.apache.nifi.controller.service.mock.MockProcessGroup) StandardProcessGroup(org.apache.nifi.groups.StandardProcessGroup) List(java.util.List) FlowController(org.apache.nifi.controller.FlowController) Test(org.junit.Test)

Example 3 with FlowController

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

the class TestStandardRemoteProcessGroupDAO method testVerifyUpdateInputPort.

@Test
public void testVerifyUpdateInputPort() {
    final StandardRemoteProcessGroupDAO dao = new StandardRemoteProcessGroupDAO();
    final String remoteProcessGroupId = "remote-process-group-id";
    final String remoteProcessGroupInputPortId = "remote-process-group-input-port-id";
    final FlowController flowController = mock(FlowController.class);
    final ProcessGroup processGroup = mock(ProcessGroup.class);
    final RemoteProcessGroup remoteProcessGroup = mock(RemoteProcessGroup.class);
    final RemoteGroupPort remoteGroupPort = mock(RemoteGroupPort.class);
    dao.setFlowController(flowController);
    when(flowController.getGroup(any())).thenReturn(processGroup);
    when(processGroup.findRemoteProcessGroup(eq(remoteProcessGroupId))).thenReturn(remoteProcessGroup);
    when(remoteProcessGroup.getInputPort(remoteProcessGroupInputPortId)).thenReturn(remoteGroupPort);
    when(remoteGroupPort.getName()).thenReturn("remote-group-port");
    final RemoteProcessGroupPortDTO dto = new RemoteProcessGroupPortDTO();
    dto.setGroupId(remoteProcessGroupId);
    dto.setId(remoteProcessGroupInputPortId);
    dto.setTargetId(remoteProcessGroupInputPortId);
    final BatchSettingsDTO batchSettings = new BatchSettingsDTO();
    dto.setBatchSettings(batchSettings);
    // Empty input values should pass validation.
    dao.verifyUpdateInputPort(remoteProcessGroupId, dto);
    // Concurrent tasks
    dto.setConcurrentlySchedulableTaskCount(0);
    validate(dao, dto, "Concurrent tasks", "positive integer");
    dto.setConcurrentlySchedulableTaskCount(2);
    validate(dao, dto);
    // Batch count
    batchSettings.setCount(-1);
    validate(dao, dto, "Batch count", "positive integer");
    batchSettings.setCount(0);
    validate(dao, dto);
    batchSettings.setCount(1000);
    validate(dao, dto);
    // Batch size
    batchSettings.setSize("AB");
    validate(dao, dto, "Batch size", "Data Size");
    batchSettings.setSize("10 days");
    validate(dao, dto, "Batch size", "Data Size");
    batchSettings.setSize("300MB");
    validate(dao, dto);
    // Batch duration
    batchSettings.setDuration("AB");
    validate(dao, dto, "Batch duration", "Time Unit");
    batchSettings.setDuration("10 KB");
    validate(dao, dto, "Batch duration", "Time Unit");
    batchSettings.setDuration("10 secs");
    validate(dao, dto);
}
Also used : BatchSettingsDTO(org.apache.nifi.web.api.dto.BatchSettingsDTO) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) RemoteGroupPort(org.apache.nifi.remote.RemoteGroupPort) ProcessGroup(org.apache.nifi.groups.ProcessGroup) RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) FlowController(org.apache.nifi.controller.FlowController) RemoteProcessGroupPortDTO(org.apache.nifi.web.api.dto.RemoteProcessGroupPortDTO) Test(org.junit.Test)

Example 4 with FlowController

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

the class StandardFlowServiceFactoryBean method getObject.

@Override
public Object getObject() throws Exception {
    if (flowService == null) {
        final FlowController flowController = applicationContext.getBean("flowController", FlowController.class);
        final RevisionManager revisionManager = applicationContext.getBean("revisionManager", RevisionManager.class);
        if (properties.isNode()) {
            final NodeProtocolSenderListener nodeProtocolSenderListener = applicationContext.getBean("nodeProtocolSenderListener", NodeProtocolSenderListener.class);
            final ClusterCoordinator clusterCoordinator = applicationContext.getBean("clusterCoordinator", ClusterCoordinator.class);
            flowService = StandardFlowService.createClusteredInstance(flowController, properties, nodeProtocolSenderListener, clusterCoordinator, encryptor, revisionManager, authorizer);
        } else {
            flowService = StandardFlowService.createStandaloneInstance(flowController, properties, encryptor, revisionManager, authorizer);
        }
    }
    return flowService;
}
Also used : RevisionManager(org.apache.nifi.web.revision.RevisionManager) ClusterCoordinator(org.apache.nifi.cluster.coordination.ClusterCoordinator) FlowController(org.apache.nifi.controller.FlowController) NodeProtocolSenderListener(org.apache.nifi.cluster.protocol.impl.NodeProtocolSenderListener)

Example 5 with FlowController

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

the class TestProcessorLifecycle method buildFlowControllerForTest.

private FlowControllerAndSystemBundle buildFlowControllerForTest(final String propKey, final String propValue) throws Exception {
    final Map<String, String> addProps = new HashMap<>();
    addProps.put(NiFiProperties.ADMINISTRATIVE_YIELD_DURATION, "1 sec");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE, "target/test-classes/state-management.xml");
    addProps.put(NiFiProperties.STATE_MANAGEMENT_LOCAL_PROVIDER_ID, "local-provider");
    addProps.put(NiFiProperties.PROVENANCE_REPO_IMPLEMENTATION_CLASS, MockProvenanceRepository.class.getName());
    addProps.put("nifi.remote.input.socket.port", "");
    addProps.put("nifi.remote.input.secure", "");
    if (propKey != null && propValue != null) {
        addProps.put(propKey, propValue);
    }
    final NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(propsFile, addProps);
    final Bundle systemBundle = SystemBundle.create(nifiProperties);
    ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
    final FlowController flowController = FlowController.createStandaloneInstance(mock(FlowFileEventRepository.class), nifiProperties, mock(Authorizer.class), mock(AuditService.class), null, new VolatileBulletinRepository(), new FileBasedVariableRegistry(nifiProperties.getVariableRegistryPropertiesPaths()), mock(FlowRegistryClient.class));
    return new FlowControllerAndSystemBundle(flowController, systemBundle);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) VolatileBulletinRepository(org.apache.nifi.events.VolatileBulletinRepository) HashMap(java.util.HashMap) Bundle(org.apache.nifi.bundle.Bundle) SystemBundle(org.apache.nifi.nar.SystemBundle) FlowRegistryClient(org.apache.nifi.registry.flow.FlowRegistryClient) FlowFileEventRepository(org.apache.nifi.controller.repository.FlowFileEventRepository) Authorizer(org.apache.nifi.authorization.Authorizer) MockProvenanceRepository(org.apache.nifi.provenance.MockProvenanceRepository) FlowController(org.apache.nifi.controller.FlowController) AuditService(org.apache.nifi.admin.service.AuditService) FileBasedVariableRegistry(org.apache.nifi.registry.variable.FileBasedVariableRegistry)

Aggregations

FlowController (org.apache.nifi.controller.FlowController)16 ProcessGroup (org.apache.nifi.groups.ProcessGroup)10 Test (org.junit.Test)9 MockProcessGroup (org.apache.nifi.controller.service.mock.MockProcessGroup)7 StandardProcessScheduler (org.apache.nifi.controller.scheduling.StandardProcessScheduler)6 ServiceA (org.apache.nifi.controller.service.mock.ServiceA)6 ServiceB (org.apache.nifi.controller.service.mock.ServiceB)6 StandardProcessGroup (org.apache.nifi.groups.StandardProcessGroup)6 AuditService (org.apache.nifi.admin.service.AuditService)3 Authorizer (org.apache.nifi.authorization.Authorizer)3 FlowFileEventRepository (org.apache.nifi.controller.repository.FlowFileEventRepository)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)2 ProcessorNode (org.apache.nifi.controller.ProcessorNode)2 ServiceC (org.apache.nifi.controller.service.mock.ServiceC)2 StringEncryptor (org.apache.nifi.encrypt.StringEncryptor)2 VolatileBulletinRepository (org.apache.nifi.events.VolatileBulletinRepository)2