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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations