Search in sources :

Example 1 with History

use of org.apache.nifi.history.History 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 History

use of org.apache.nifi.history.History in project nifi by apache.

the class StandardNiFiServiceFacade method getActions.

@Override
public HistoryDTO getActions(final HistoryQueryDTO historyQueryDto) {
    // extract the query criteria
    final HistoryQuery historyQuery = new HistoryQuery();
    historyQuery.setStartDate(historyQueryDto.getStartDate());
    historyQuery.setEndDate(historyQueryDto.getEndDate());
    historyQuery.setSourceId(historyQueryDto.getSourceId());
    historyQuery.setUserIdentity(historyQueryDto.getUserIdentity());
    historyQuery.setOffset(historyQueryDto.getOffset());
    historyQuery.setCount(historyQueryDto.getCount());
    historyQuery.setSortColumn(historyQueryDto.getSortColumn());
    historyQuery.setSortOrder(historyQueryDto.getSortOrder());
    // perform the query
    final History history = auditService.getActions(historyQuery);
    // only retain authorized actions
    final HistoryDTO historyDto = dtoFactory.createHistoryDto(history);
    if (history.getActions() != null) {
        final List<ActionEntity> actionEntities = new ArrayList<>();
        for (final Action action : history.getActions()) {
            final AuthorizationResult result = authorizeAction(action);
            actionEntities.add(entityFactory.createActionEntity(dtoFactory.createActionDto(action), Result.Approved.equals(result.getResult())));
        }
        historyDto.setActions(actionEntities);
    }
    // create the response
    return historyDto;
}
Also used : HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) PropertyHistoryDTO(org.apache.nifi.web.api.dto.PropertyHistoryDTO) ComponentHistoryDTO(org.apache.nifi.web.api.dto.ComponentHistoryDTO) StatusHistoryDTO(org.apache.nifi.web.api.dto.status.StatusHistoryDTO) FlowChangeAction(org.apache.nifi.action.FlowChangeAction) RequestAction(org.apache.nifi.authorization.RequestAction) Action(org.apache.nifi.action.Action) HistoryQuery(org.apache.nifi.history.HistoryQuery) ArrayList(java.util.ArrayList) History(org.apache.nifi.history.History) AuthorizationResult(org.apache.nifi.authorization.AuthorizationResult) ActionEntity(org.apache.nifi.web.api.entity.ActionEntity)

Example 3 with History

use of org.apache.nifi.history.History in project nifi by apache.

the class StandardActionDAO method findActions.

@Override
public History findActions(HistoryQuery historyQuery) throws DataAccessException {
    // get the sort column
    String sortColumn = "ACTION_TIMESTAMP";
    if (StringUtils.isNotBlank(historyQuery.getSortColumn())) {
        String rawColumnName = historyQuery.getSortColumn();
        if (!columnMap.containsKey(rawColumnName)) {
            throw new IllegalArgumentException(String.format("Unrecognized column name '%s'.", rawColumnName));
        }
        sortColumn = columnMap.get(rawColumnName);
    }
    // get the sort order
    String sortOrder = "desc";
    if (StringUtils.isNotBlank(historyQuery.getSortOrder())) {
        sortOrder = historyQuery.getSortOrder();
    }
    History actionResult = new History();
    Collection<Action> actions = new ArrayList<>();
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        List<String> where = new ArrayList<>();
        // append the start time
        if (historyQuery.getStartDate() != null) {
            where.add("ACTION_TIMESTAMP >= ?");
        }
        // append the end time
        if (historyQuery.getEndDate() != null) {
            where.add("ACTION_TIMESTAMP <= ?");
        }
        // append the user id as necessary
        if (historyQuery.getUserIdentity() != null) {
            where.add("UPPER(IDENTITY) LIKE ?");
        }
        // append the source id as necessary
        if (historyQuery.getSourceId() != null) {
            where.add("SOURCE_ID = ?");
        }
        String sql = SELECT_ACTION_COUNT;
        if (!where.isEmpty()) {
            sql += " WHERE " + StringUtils.join(where, " AND ");
        }
        // get the total number of actions
        statement = connection.prepareStatement(sql);
        int paramIndex = 1;
        // set the start date as necessary
        if (historyQuery.getStartDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getStartDate().getTime()));
        }
        // set the end date as necessary
        if (historyQuery.getEndDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getEndDate().getTime()));
        }
        // set the user id as necessary
        if (historyQuery.getUserIdentity() != null) {
            statement.setString(paramIndex++, "%" + historyQuery.getUserIdentity().toUpperCase() + "%");
        }
        // set the source id as necessary
        if (historyQuery.getSourceId() != null) {
            statement.setString(paramIndex, historyQuery.getSourceId());
        }
        // execute the statement
        rs = statement.executeQuery();
        // ensure there are results
        if (rs.next()) {
            actionResult.setTotal(rs.getInt("ACTION_COUNT"));
        } else {
            throw new DataAccessException("Unable to determine total action count.");
        }
        sql = SELECT_ACTIONS;
        if (!where.isEmpty()) {
            sql += " WHERE " + StringUtils.join(where, " AND ");
        }
        // append the sort criteria
        sql += (" ORDER BY " + sortColumn + " " + sortOrder);
        // append the offset and limit
        sql += " LIMIT ? OFFSET ?";
        // close the previous statement
        statement.close();
        // create the statement
        statement = connection.prepareStatement(sql);
        paramIndex = 1;
        // set the start date as necessary
        if (historyQuery.getStartDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getStartDate().getTime()));
        }
        // set the end date as necessary
        if (historyQuery.getEndDate() != null) {
            statement.setTimestamp(paramIndex++, new java.sql.Timestamp(historyQuery.getEndDate().getTime()));
        }
        // set the user id as necessary
        if (historyQuery.getUserIdentity() != null) {
            statement.setString(paramIndex++, "%" + historyQuery.getUserIdentity().toUpperCase() + "%");
        }
        // set the source id as necessary
        if (historyQuery.getSourceId() != null) {
            statement.setString(paramIndex++, historyQuery.getSourceId());
        }
        // set the limit
        statement.setInt(paramIndex++, historyQuery.getCount());
        // set the offset according to the currented page calculated above
        statement.setInt(paramIndex, historyQuery.getOffset());
        // execute the query
        rs = statement.executeQuery();
        // create each corresponding action
        while (rs.next()) {
            final Integer actionId = rs.getInt("ID");
            final Operation operation = Operation.valueOf(rs.getString("OPERATION"));
            final Component component = Component.valueOf(rs.getString("SOURCE_TYPE"));
            FlowChangeAction action = new FlowChangeAction();
            action.setId(actionId);
            action.setUserIdentity(rs.getString("IDENTITY"));
            action.setOperation(Operation.valueOf(rs.getString("OPERATION")));
            action.setTimestamp(new Date(rs.getTimestamp("ACTION_TIMESTAMP").getTime()));
            action.setSourceId(rs.getString("SOURCE_ID"));
            action.setSourceName(rs.getString("SOURCE_NAME"));
            action.setSourceType(Component.valueOf(rs.getString("SOURCE_TYPE")));
            // get the component details if appropriate
            ComponentDetails componentDetails = null;
            if (Component.Processor.equals(component) || Component.ControllerService.equals(component) || Component.ReportingTask.equals(component)) {
                componentDetails = getExtensionDetails(actionId);
            } else if (Component.RemoteProcessGroup.equals(component)) {
                componentDetails = getRemoteProcessGroupDetails(actionId);
            }
            if (componentDetails != null) {
                action.setComponentDetails(componentDetails);
            }
            // get the action details if appropriate
            ActionDetails actionDetails = null;
            if (Operation.Move.equals(operation)) {
                actionDetails = getMoveDetails(actionId);
            } else if (Operation.Configure.equals(operation)) {
                actionDetails = getConfigureDetails(actionId);
            } else if (Operation.Connect.equals(operation) || Operation.Disconnect.equals(operation)) {
                actionDetails = getConnectDetails(actionId);
            } else if (Operation.Purge.equals(operation)) {
                actionDetails = getPurgeDetails(actionId);
            }
            // set the action details
            if (actionDetails != null) {
                action.setActionDetails(actionDetails);
            }
            // add the action
            actions.add(action);
        }
        // populate the action result
        actionResult.setActions(actions);
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return actionResult;
}
Also used : FlowChangeAction(org.apache.nifi.action.FlowChangeAction) Action(org.apache.nifi.action.Action) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) Operation(org.apache.nifi.action.Operation) History(org.apache.nifi.history.History) Date(java.util.Date) ResultSet(java.sql.ResultSet) ActionDetails(org.apache.nifi.action.details.ActionDetails) Component(org.apache.nifi.action.Component) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 4 with History

use of org.apache.nifi.history.History in project nifi by apache.

the class GetActionsAction method execute.

@Override
public History execute(DAOFactory daoFactory) {
    ActionDAO actionDao = daoFactory.getActionDAO();
    // find all matching history
    History history = actionDao.findActions(query);
    history.setLastRefreshed(new Date());
    return history;
}
Also used : History(org.apache.nifi.history.History) Date(java.util.Date) ActionDAO(org.apache.nifi.admin.dao.ActionDAO)

Example 5 with History

use of org.apache.nifi.history.History in project nifi by apache.

the class StandardAuditService method getActions.

@Override
public History getActions(HistoryQuery query) {
    Transaction transaction = null;
    History history = null;
    readLock.lock();
    try {
        // start the transaction
        transaction = transactionBuilder.start();
        // seed the accounts
        GetActionsAction getActions = new GetActionsAction(query);
        history = transaction.execute(getActions);
        // commit the transaction
        transaction.commit();
    } catch (TransactionException | DataAccessException te) {
        rollback(transaction);
        throw new AdministrationException(te);
    } catch (Throwable t) {
        rollback(transaction);
        throw t;
    } finally {
        closeQuietly(transaction);
        readLock.unlock();
    }
    return history;
}
Also used : TransactionException(org.apache.nifi.admin.service.transaction.TransactionException) Transaction(org.apache.nifi.admin.service.transaction.Transaction) GetActionsAction(org.apache.nifi.admin.service.action.GetActionsAction) History(org.apache.nifi.history.History) AdministrationException(org.apache.nifi.admin.service.AdministrationException) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Aggregations

History (org.apache.nifi.history.History)6 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Action (org.apache.nifi.action.Action)3 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)3 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)2 ActionDetails (org.apache.nifi.action.details.ActionDetails)2 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)2 RequestAction (org.apache.nifi.authorization.RequestAction)2 HistoryDTO (org.apache.nifi.web.api.dto.action.HistoryDTO)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Collator (java.text.Collator)1 NumberFormat (java.text.NumberFormat)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1