org.apache.nifi.util.FormatUtils Java Examples

The following examples show how to use org.apache.nifi.util.FormatUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardRemoteProcessGroup.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void setCommunicationsTimeout(final String timePeriod) throws IllegalArgumentException {
    // verify the timePeriod is legit
    try {
        final long millis = FormatUtils.getTimeDuration(timePeriod, TimeUnit.MILLISECONDS);
        if (millis <= 0) {
            throw new IllegalArgumentException("Time Period must be more than 0 milliseconds; Invalid Time Period: " + timePeriod);
        }
        if (millis > Integer.MAX_VALUE) {
            throw new IllegalArgumentException("Timeout is too long; cannot be greater than " + Integer.MAX_VALUE + " milliseconds");
        }
        this.communicationsTimeout = timePeriod;
    } catch (final Exception e) {
        throw new IllegalArgumentException("Invalid Time Period: " + timePeriod);
    }
}
 
Example #2
Source File: ExpireFlowFiles.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void expireFlowFiles(final Connectable connectable) {
    // determine if the incoming connections for this Connectable have Expiration configured.
    boolean expirationConfigured = false;
    for (final Connection incomingConn : connectable.getIncomingConnections()) {
        if (FormatUtils.getTimeDuration(incomingConn.getFlowFileQueue().getFlowFileExpiration(), TimeUnit.MILLISECONDS) > 0) {
            expirationConfigured = true;
            break;
        }
    }

    // If expiration is not configured... don't bother running through the FlowFileQueue
    if (!expirationConfigured) {
        return;
    }

    final StandardProcessSession session = createSession(connectable);
    session.expireFlowFiles();
    session.commit();
}
 
Example #3
Source File: MonitorDiskUsage.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
static void checkThreshold(final String pathName, final Path path, final int threshold, final ComponentLog logger) {
    final File file = path.toFile();
    final long totalBytes = file.getTotalSpace();
    final long freeBytes = file.getFreeSpace();
    final long usedBytes = totalBytes - freeBytes;

    final double usedPercent = (double) usedBytes / (double) totalBytes * 100D;

    if (usedPercent >= threshold) {
        final String usedSpace = FormatUtils.formatDataSize(usedBytes);
        final String totalSpace = FormatUtils.formatDataSize(totalBytes);
        final String freeSpace = FormatUtils.formatDataSize(freeBytes);

        final double freePercent = (double) freeBytes / (double) totalBytes * 100D;

        final String message = String.format("%1$s exceeds configured threshold of %2$s%%, having %3$s / %4$s (%5$.2f%%) used and %6$s (%7$.2f%%) free",
                pathName, threshold, usedSpace, totalSpace, usedPercent, freeSpace, freePercent);
        logger.warn(message);
    }
}
 
Example #4
Source File: ControllerStatusReportingTask.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private String toDiff(final long oldValue, final long newValue, final boolean formatDataSize, final boolean formatTime) {
    if (formatDataSize && formatTime) {
        throw new IllegalArgumentException("Cannot format units as both data size and time");
    }

    final long diff = Math.abs(newValue - oldValue);

    final String formattedDiff = formatDataSize ? FormatUtils.formatDataSize(diff)
            : (formatTime ? FormatUtils.formatHoursMinutesSeconds(diff, TimeUnit.NANOSECONDS) : String.valueOf(diff));

    if (oldValue > newValue) {
        return " (-" + formattedDiff + ")";
    } else {
        return " (+" + formattedDiff + ")";
    }
}
 
Example #5
Source File: FileSystemRepository.java    From nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Will determine the scheduling interval to be used by archive cleanup task
 * (in milliseconds). This method will enforce the minimum allowed value of
 * 1 second (1000 milliseconds). If attempt is made to set lower value a
 * warning will be logged and the method will return minimum value of 1000
 */
private long determineCleanupInterval(NiFiProperties properties) {
    long cleanupInterval = MIN_CLEANUP_INTERVAL_MILLIS;
    String archiveCleanupFrequency = properties.getProperty(NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY);
    if (archiveCleanupFrequency != null) {
        try {
            cleanupInterval = FormatUtils.getTimeDuration(archiveCleanupFrequency.trim(), TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            throw new RuntimeException(
                    "Invalid value set for property " + NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY);
        }
        if (cleanupInterval < MIN_CLEANUP_INTERVAL_MILLIS) {
            LOG.warn("The value of " + NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY + " property is set to '"
                    + archiveCleanupFrequency + "' which is "
                    + "below the allowed minimum of 1 second (1000 milliseconds). Minimum value of 1 sec will be used as scheduling interval for archive cleanup task.");
            cleanupInterval = MIN_CLEANUP_INTERVAL_MILLIS;
        }
    }
    return cleanupInterval;
}
 
Example #6
Source File: PopularVoteFlowElectionFactoryBean.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public PopularVoteFlowElection getObject() throws Exception {
    final String maxWaitTime = properties.getFlowElectionMaxWaitTime();
    long maxWaitMillis;
    try {
        maxWaitMillis = FormatUtils.getTimeDuration(maxWaitTime, TimeUnit.MILLISECONDS);
    } catch (final Exception e) {
        logger.warn("Failed to parse value of property '{}' as a valid time period. Value was '{}'. Ignoring this value and using the default value of '{}'",
            NiFiProperties.FLOW_ELECTION_MAX_WAIT_TIME, maxWaitTime, NiFiProperties.DEFAULT_FLOW_ELECTION_MAX_WAIT_TIME);
        maxWaitMillis = FormatUtils.getTimeDuration(NiFiProperties.DEFAULT_FLOW_ELECTION_MAX_WAIT_TIME, TimeUnit.MILLISECONDS);
    }

    final Integer maxNodes = properties.getFlowElectionMaxCandidates();

    final StringEncryptor encryptor = StringEncryptor.createEncryptor(properties);
    final FingerprintFactory fingerprintFactory = new FingerprintFactory(encryptor);
    return new PopularVoteFlowElection(maxWaitMillis, TimeUnit.MILLISECONDS, maxNodes, fingerprintFactory);
}
 
Example #7
Source File: TestFormatUtils.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testFormatTime() throws Exception {
    assertEquals("00:00:00.000", FormatUtils.formatHoursMinutesSeconds(0, TimeUnit.DAYS));
    assertEquals("01:00:00.000", FormatUtils.formatHoursMinutesSeconds(1, TimeUnit.HOURS));
    assertEquals("02:00:00.000", FormatUtils.formatHoursMinutesSeconds(2, TimeUnit.HOURS));
    assertEquals("00:01:00.000", FormatUtils.formatHoursMinutesSeconds(1, TimeUnit.MINUTES));
    assertEquals("00:00:10.000", FormatUtils.formatHoursMinutesSeconds(10, TimeUnit.SECONDS));
    assertEquals("00:00:00.777", FormatUtils.formatHoursMinutesSeconds(777, TimeUnit.MILLISECONDS));
    assertEquals("00:00:07.777", FormatUtils.formatHoursMinutesSeconds(7777, TimeUnit.MILLISECONDS));

    assertEquals("20:11:36.897", FormatUtils.formatHoursMinutesSeconds(TimeUnit.MILLISECONDS.convert(20, TimeUnit.HOURS)
            + TimeUnit.MILLISECONDS.convert(11, TimeUnit.MINUTES)
            + TimeUnit.MILLISECONDS.convert(36, TimeUnit.SECONDS)
            + TimeUnit.MILLISECONDS.convert(897, TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS));

    assertEquals("1000:01:01.001", FormatUtils.formatHoursMinutesSeconds(TimeUnit.MILLISECONDS.convert(999, TimeUnit.HOURS)
            + TimeUnit.MILLISECONDS.convert(60, TimeUnit.MINUTES)
            + TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS)
            + TimeUnit.MILLISECONDS.convert(1001, TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS));
}
 
Example #8
Source File: StatusMerger.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static void updatePrettyPrintedFields(final SystemDiagnosticsSnapshotDTO target) {
    // heap
    target.setMaxHeap(FormatUtils.formatDataSize(target.getMaxHeapBytes()));
    target.setTotalHeap(FormatUtils.formatDataSize(target.getTotalHeapBytes()));
    target.setUsedHeap(FormatUtils.formatDataSize(target.getUsedHeapBytes()));
    target.setFreeHeap(FormatUtils.formatDataSize(target.getFreeHeapBytes()));
    if (target.getMaxHeapBytes() != -1) {
        target.setHeapUtilization(FormatUtils.formatUtilization(getUtilization(target.getUsedHeapBytes(), target.getMaxHeapBytes())));
    }

    // non heap
    target.setMaxNonHeap(FormatUtils.formatDataSize(target.getMaxNonHeapBytes()));
    target.setTotalNonHeap(FormatUtils.formatDataSize(target.getTotalNonHeapBytes()));
    target.setUsedNonHeap(FormatUtils.formatDataSize(target.getUsedNonHeapBytes()));
    target.setFreeNonHeap(FormatUtils.formatDataSize(target.getFreeNonHeapBytes()));
    if (target.getMaxNonHeapBytes() != -1) {
        target.setNonHeapUtilization(FormatUtils.formatUtilization(getUtilization(target.getUsedNonHeapBytes(), target.getMaxNonHeapBytes())));
    }
}
 
Example #9
Source File: ServerSocketConfigurationFactoryBean.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ServerSocketConfiguration getObject() throws Exception {
    if (configuration == null) {
        configuration = new ServerSocketConfiguration();
        configuration.setNeedClientAuth(properties.getNeedClientAuth());

        final int timeout = (int) FormatUtils.getTimeDuration(properties.getClusterNodeReadTimeout(), TimeUnit.MILLISECONDS);
        configuration.setSocketTimeout(timeout);
        configuration.setReuseAddress(true);
        if (Boolean.valueOf(properties.getProperty(NiFiProperties.CLUSTER_PROTOCOL_IS_SECURE))) {
            configuration.setSSLContextFactory(new SSLContextFactory(properties));
        }
    }
    return configuration;

}
 
Example #10
Source File: StatelessRemoteInputPort.java    From nifi with Apache License 2.0 6 votes vote down vote up
public StatelessRemoteInputPort(final VersionedRemoteProcessGroup rpg, final VersionedRemoteGroupPort remotePort, final SSLContext sslContext) {
    final String timeout = rpg.getCommunicationsTimeout();
    final long timeoutMillis = FormatUtils.getTimeDuration(timeout, TimeUnit.MILLISECONDS);

    url = rpg.getTargetUris();
    name = remotePort.getName();

    client = new SiteToSiteClient.Builder()
        .portName(remotePort.getName())
        .timeout(timeoutMillis, TimeUnit.MILLISECONDS)
        .transportProtocol(SiteToSiteTransportProtocol.valueOf(rpg.getTransportProtocol()))
        .url(rpg.getTargetUris())
        .useCompression(remotePort.isUseCompression())
        .sslContext(sslContext)
        .eventReporter(EventReporter.NO_OP)
        .build();
}
 
Example #11
Source File: ControllerStatusReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
private String toDiff(final long oldValue, final long newValue, final boolean formatDataSize, final boolean formatTime) {
    if (formatDataSize && formatTime) {
        throw new IllegalArgumentException("Cannot format units as both data size and time");
    }

    final long diff = Math.abs(newValue - oldValue);

    final String formattedDiff = formatDataSize ? FormatUtils.formatDataSize(diff)
            : (formatTime ? FormatUtils.formatHoursMinutesSeconds(diff, TimeUnit.NANOSECONDS) : String.valueOf(diff));

    if (oldValue > newValue) {
        return " (-" + formattedDiff + ")";
    } else {
        return " (+" + formattedDiff + ")";
    }
}
 
Example #12
Source File: FlowConfigurationArchiveManager.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public FlowConfigurationArchiveManager(final Path flowConfigFile, final NiFiProperties properties) {
    final String archiveDirVal = properties.getFlowConfigurationArchiveDir();
    final Path archiveDir = (archiveDirVal == null || archiveDirVal.equals(""))
            ? flowConfigFile.getParent().resolve("archive") : new File(archiveDirVal).toPath();

    this.maxCount = properties.getFlowConfigurationArchiveMaxCount();

    String maxTime = properties.getFlowConfigurationArchiveMaxTime();
    String maxStorage = properties.getFlowConfigurationArchiveMaxStorage();

    if (maxCount == null && StringUtils.isBlank(maxTime) && StringUtils.isBlank(maxStorage)) {
        // None of limitation is specified, fall back to the default configuration;
        maxTime = NiFiProperties.DEFAULT_FLOW_CONFIGURATION_ARCHIVE_MAX_TIME;
        maxStorage = NiFiProperties.DEFAULT_FLOW_CONFIGURATION_ARCHIVE_MAX_STORAGE;
        logger.info("None of archive max limitation is specified, fall back to the default configuration, maxTime={}, maxStorage={}",
                maxTime, maxStorage);
    }

    this.maxTimeMillis = StringUtils.isBlank(maxTime) ? null : FormatUtils.getTimeDuration(maxTime, TimeUnit.MILLISECONDS);
    this.maxStorageBytes = StringUtils.isBlank(maxStorage) ? null : DataUnit.parseDataSize(maxStorage, DataUnit.B).longValue();

    this.flowConfigFile = flowConfigFile;
    this.archiveDir = archiveDir;
}
 
Example #13
Source File: ServerSocketConfigurationFactoryBean.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ServerSocketConfiguration getObject() throws Exception {
    if (configuration == null) {
        configuration = new ServerSocketConfiguration();
        configuration.setNeedClientAuth(true);

        final int timeout = (int) FormatUtils.getPreciseTimeDuration(properties.getClusterNodeReadTimeout(), TimeUnit.MILLISECONDS);
        configuration.setSocketTimeout(timeout);
        configuration.setReuseAddress(true);

        // If the cluster protocol is marked as secure
        if (Boolean.parseBoolean(properties.getProperty(NiFiProperties.CLUSTER_PROTOCOL_IS_SECURE))) {
            // Parse the TLS configuration from the properties
            configuration.setTlsConfiguration(TlsConfiguration.fromNiFiProperties(properties));
        }
    }
    return configuration;

}
 
Example #14
Source File: LongRunningProcessorTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public DiagnosticsDumpElement captureDump(final boolean verbose) {
    final List<String> details = new ArrayList<>();
    final ThreadDetails threadDetails = ThreadDetails.capture();

    for (final ProcessorNode processorNode : flowController.getFlowManager().getRootGroup().findAllProcessors()) {
        final List<ActiveThreadInfo> activeThreads = processorNode.getActiveThreads(threadDetails);

        for (final ActiveThreadInfo activeThread : activeThreads) {
            if (activeThread.getActiveMillis() > MIN_ACTIVE_MILLIS) {
                String threadName = activeThread.getThreadName();
                if (activeThread.isTerminated()) {
                    threadName = threadName + " (Terminated)";
                }

                details.add(processorNode + " - " + threadName + " has been active for " + FormatUtils.formatMinutesSeconds(activeThread.getActiveMillis(), TimeUnit.MILLISECONDS) + " minutes");
            }
        }
    }

    if (details.isEmpty()) {
        details.add("No long-running tasks identified");
    }

    return new StandardDiagnosticsDumpElement("Long-Running Processor Tasks", details);
}
 
Example #15
Source File: HttpRemoteSiteListener.java    From nifi with Apache License 2.0 6 votes vote down vote up
private HttpRemoteSiteListener(final NiFiProperties nifiProperties) {
    super();
    taskExecutor = Executors.newScheduledThreadPool(1, new ThreadFactory() {
        @Override
        public Thread newThread(final Runnable r) {
            final Thread thread = Executors.defaultThreadFactory().newThread(r);
            thread.setName("Http Site-to-Site Transaction Maintenance");
            thread.setDaemon(true);
            return thread;
        }
    });

    int txTtlSec;
    try {
        final String snapshotFrequency = nifiProperties.getProperty(SITE_TO_SITE_HTTP_TRANSACTION_TTL, DEFAULT_SITE_TO_SITE_HTTP_TRANSACTION_TTL);
        txTtlSec = (int) FormatUtils.getTimeDuration(snapshotFrequency, TimeUnit.SECONDS);
    } catch (final Exception e) {
        txTtlSec = (int) FormatUtils.getTimeDuration(DEFAULT_SITE_TO_SITE_HTTP_TRANSACTION_TTL, TimeUnit.SECONDS);
        logger.warn("Failed to parse {} due to {}, use default as {} secs.",
                SITE_TO_SITE_HTTP_TRANSACTION_TTL, e.getMessage(), txTtlSec);
    }
    transactionTtlSec = txTtlSec;
}
 
Example #16
Source File: ExpireFlowFiles.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void expireFlowFiles(final Connectable connectable) {
    // determine if the incoming connections for this Connectable have Expiration configured.
    boolean expirationConfigured = false;
    for (final Connection incomingConn : connectable.getIncomingConnections()) {
        if (FormatUtils.getTimeDuration(incomingConn.getFlowFileQueue().getFlowFileExpiration(), TimeUnit.MILLISECONDS) > 0) {
            expirationConfigured = true;
            break;
        }
    }

    // If expiration is not configured... don't bother running through the FlowFileQueue
    if (!expirationConfigured) {
        return;
    }

    final StandardProcessSession session = createSession(connectable);
    session.expireFlowFiles();
    session.commit();
}
 
Example #17
Source File: WriteAheadFlowFileRepository.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public WriteAheadFlowFileRepository(final NiFiProperties nifiProperties) {
    alwaysSync = Boolean.parseBoolean(nifiProperties.getProperty(NiFiProperties.FLOWFILE_REPOSITORY_ALWAYS_SYNC, "false"));

    // determine the database file path and ensure it exists
    for (final String propertyName : nifiProperties.getPropertyKeys()) {
        if (propertyName.startsWith(FLOWFILE_REPOSITORY_DIRECTORY_PREFIX)) {
            final String directoryName = nifiProperties.getProperty(propertyName);
            flowFileRepositoryPaths.add(Paths.get(directoryName));
        }
    }

    numPartitions = nifiProperties.getFlowFileRepositoryPartitions();
    checkpointDelayMillis = FormatUtils.getTimeDuration(nifiProperties.getFlowFileRepositoryCheckpointInterval(), TimeUnit.MILLISECONDS);

    checkpointExecutor = Executors.newSingleThreadScheduledExecutor();
}
 
Example #18
Source File: FileSystemRepository.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Will determine the scheduling interval to be used by archive cleanup task
 * (in milliseconds). This method will enforce the minimum allowed value of
 * 1 second (1000 milliseconds). If attempt is made to set lower value a
 * warning will be logged and the method will return minimum value of 1000
 */
private long determineCleanupInterval(NiFiProperties properties) {
    long cleanupInterval = MIN_CLEANUP_INTERVAL_MILLIS;
    String archiveCleanupFrequency = properties.getProperty(NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY);
    if (archiveCleanupFrequency != null) {
        try {
            cleanupInterval = FormatUtils.getTimeDuration(archiveCleanupFrequency.trim(), TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            throw new RuntimeException(
                    "Invalid value set for property " + NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY);
        }
        if (cleanupInterval < MIN_CLEANUP_INTERVAL_MILLIS) {
            LOG.warn("The value of " + NiFiProperties.CONTENT_ARCHIVE_CLEANUP_FREQUENCY + " property is set to '"
                    + archiveCleanupFrequency + "' which is "
                    + "below the allowed minimum of 1 second (1000 milliseconds). Minimum value of 1 sec will be used as scheduling interval for archive cleanup task.");
            cleanupInterval = MIN_CLEANUP_INTERVAL_MILLIS;
        }
    }
    return cleanupInterval;
}
 
Example #19
Source File: StatusMerger.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static void updatePrettyPrintedFields(final SystemDiagnosticsSnapshotDTO target) {
    // heap
    target.setMaxHeap(FormatUtils.formatDataSize(target.getMaxHeapBytes()));
    target.setTotalHeap(FormatUtils.formatDataSize(target.getTotalHeapBytes()));
    target.setUsedHeap(FormatUtils.formatDataSize(target.getUsedHeapBytes()));
    target.setFreeHeap(FormatUtils.formatDataSize(target.getFreeHeapBytes()));
    if (target.getMaxHeapBytes() != -1) {
        target.setHeapUtilization(FormatUtils.formatUtilization(getUtilization(target.getUsedHeapBytes(), target.getMaxHeapBytes())));
    }

    // non heap
    target.setMaxNonHeap(FormatUtils.formatDataSize(target.getMaxNonHeapBytes()));
    target.setTotalNonHeap(FormatUtils.formatDataSize(target.getTotalNonHeapBytes()));
    target.setUsedNonHeap(FormatUtils.formatDataSize(target.getUsedNonHeapBytes()));
    target.setFreeNonHeap(FormatUtils.formatDataSize(target.getFreeNonHeapBytes()));
    if (target.getMaxNonHeapBytes() != -1) {
        target.setNonHeapUtilization(FormatUtils.formatUtilization(getUtilization(target.getUsedNonHeapBytes(), target.getMaxNonHeapBytes())));
    }
}
 
Example #20
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the status of this controller.
 *
 * @return the status of this controller
 */
public ControllerStatusDTO getControllerStatus() {
    final ProcessGroup rootGroup = flowController.getGroup(flowController.getRootGroupId());

    final QueueSize controllerQueueSize = flowController.getTotalFlowFileCount(rootGroup);
    final ControllerStatusDTO controllerStatus = new ControllerStatusDTO();
    controllerStatus.setActiveThreadCount(flowController.getActiveThreadCount());
    controllerStatus.setQueued(FormatUtils.formatCount(controllerQueueSize.getObjectCount()) + " / " + FormatUtils.formatDataSize(controllerQueueSize.getByteCount()));
    controllerStatus.setBytesQueued(controllerQueueSize.getByteCount());
    controllerStatus.setFlowFilesQueued(controllerQueueSize.getObjectCount());

    final ProcessGroupCounts counts = rootGroup.getCounts();
    controllerStatus.setRunningCount(counts.getRunningCount());
    controllerStatus.setStoppedCount(counts.getStoppedCount());
    controllerStatus.setInvalidCount(counts.getInvalidCount());
    controllerStatus.setDisabledCount(counts.getDisabledCount());
    controllerStatus.setActiveRemotePortCount(counts.getActiveRemotePortCount());
    controllerStatus.setInactiveRemotePortCount(counts.getInactiveRemotePortCount());

    return controllerStatus;
}
 
Example #21
Source File: StandardValidators.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
    if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
        return new ValidationResult.Builder().subject(subject).input(input).explanation("Expression Language Present").valid(true).build();
    }

    if (input == null) {
        return new ValidationResult.Builder().subject(subject).input(input).valid(false).explanation("Time Period cannot be null").build();
    }
    if (Pattern.compile(FormatUtils.TIME_DURATION_REGEX).matcher(input.toLowerCase()).matches()) {
        return new ValidationResult.Builder().subject(subject).input(input).valid(true).build();
    } else {
        return new ValidationResult.Builder()
                .subject(subject)
                .input(input)
                .valid(false)
                .explanation("Must be of format <duration> <TimeUnit> where <duration> is a "
                        + "non-negative integer and TimeUnit is a supported Time Unit, such "
                        + "as: nanos, millis, secs, mins, hrs, days")
                .build();
    }
}
 
Example #22
Source File: AbstractPort.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void setScheduldingPeriod(final String schedulingPeriod) {
    final long schedulingNanos = FormatUtils.getTimeDuration(requireNonNull(schedulingPeriod), TimeUnit.NANOSECONDS);
    if (schedulingNanos < 0) {
        throw new IllegalArgumentException("Scheduling Period must be positive");
    }

    this.schedulingPeriod.set(schedulingPeriod);
    this.schedulingNanos.set(Math.max(MINIMUM_SCHEDULING_NANOS, schedulingNanos));
}
 
Example #23
Source File: AbstractFlowFileQueue.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void setFlowFileExpiration(final String flowExpirationPeriod) {
    final long millis = FormatUtils.getTimeDuration(flowExpirationPeriod, TimeUnit.MILLISECONDS);
    if (millis < 0) {
        throw new IllegalArgumentException("FlowFile Expiration Period must be positive");
    }

    expirationPeriod.set(new TimePeriod(flowExpirationPeriod, millis));
}
 
Example #24
Source File: SpringContextProcessor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 *
 */
@OnScheduled
public void initializeSpringContext(ProcessContext processContext) {
    this.applicationContextConfigFileName = processContext.getProperty(CTX_CONFIG_PATH).getValue();
    this.applicationContextLibPath = processContext.getProperty(CTX_LIB_PATH).getValue();

    String stStr = processContext.getProperty(SEND_TIMEOUT).getValue();
    this.sendTimeout = stStr == null ? 0 : FormatUtils.getTimeDuration(stStr, TimeUnit.MILLISECONDS);

    String rtStr = processContext.getProperty(RECEIVE_TIMEOUT).getValue();
    this.receiveTimeout = rtStr == null ? 0 : FormatUtils.getTimeDuration(rtStr, TimeUnit.MILLISECONDS);

    try {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "Initializing Spring Application Context defined in " + this.applicationContextConfigFileName);
        }
        this.exchanger = SpringContextFactory.createSpringContextDelegate(this.applicationContextLibPath,
                this.applicationContextConfigFileName);
    } catch (Exception e) {
        throw new IllegalStateException("Failed while initializing Spring Application Context", e);
    }
    if (logger.isInfoEnabled()) {
        logger.info("Successfully initialized Spring Application Context defined in "
                + this.applicationContextConfigFileName);
    }
}
 
Example #25
Source File: LdapProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void setTimeout(final LoginIdentityProviderConfigurationContext configurationContext,
        final Map<String, Object> baseEnvironment,
        final String configurationProperty,
        final String environmentKey) {

    final String rawTimeout = configurationContext.getProperty(configurationProperty);
    if (StringUtils.isNotBlank(rawTimeout)) {
        try {
            final Long timeout = FormatUtils.getTimeDuration(rawTimeout, TimeUnit.MILLISECONDS);
            baseEnvironment.put(environmentKey, timeout.toString());
        } catch (final IllegalArgumentException iae) {
            throw new ProviderCreationException(String.format("The %s '%s' is not a valid time duration", configurationProperty, rawTimeout));
        }
    }
}
 
Example #26
Source File: StandardProcessorNode.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public synchronized void setScheduldingPeriod(final String schedulingPeriod) {
    if (isRunning()) {
        throw new IllegalStateException("Cannot modify Processor configuration while the Processor is running");
    }

    switch (schedulingStrategy) {
    case CRON_DRIVEN: {
        try {
            new CronExpression(schedulingPeriod);
        } catch (final Exception e) {
            throw new IllegalArgumentException(
                    "Scheduling Period is not a valid cron expression: " + schedulingPeriod);
        }
    }
        break;
    case PRIMARY_NODE_ONLY:
    case TIMER_DRIVEN: {
        final long schedulingNanos = FormatUtils.getTimeDuration(requireNonNull(schedulingPeriod),
                TimeUnit.NANOSECONDS);
        if (schedulingNanos < 0) {
            throw new IllegalArgumentException("Scheduling Period must be positive");
        }
        this.schedulingNanos.set(Math.max(MINIMUM_SCHEDULING_NANOS, schedulingNanos));
    }
        break;
    case EVENT_DRIVEN:
    default:
        return;
    }

    this.schedulingPeriod.set(schedulingPeriod);
}
 
Example #27
Source File: StandardRemoteGroupPort.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onSchedulingStart() {
    super.onSchedulingStart();

    final long penalizationMillis = FormatUtils.getTimeDuration(remoteGroup.getYieldDuration(), TimeUnit.MILLISECONDS);

    final SiteToSiteClient.Builder clientBuilder = new SiteToSiteClient.Builder()
            .urls(SiteToSiteRestApiClient.parseClusterUrls(remoteGroup.getTargetUris()))
            .portIdentifier(getTargetIdentifier())
            .sslContext(sslContext)
            .useCompression(isUseCompression())
            .eventReporter(remoteGroup.getEventReporter())
            .stateManager(remoteGroup.getStateManager())
            .nodePenalizationPeriod(penalizationMillis, TimeUnit.MILLISECONDS)
            .timeout(remoteGroup.getCommunicationsTimeout(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS)
            .transportProtocol(remoteGroup.getTransportProtocol())
            .httpProxy(new HttpProxy(remoteGroup.getProxyHost(), remoteGroup.getProxyPort(), remoteGroup.getProxyUser(), remoteGroup.getProxyPassword()))
            .localAddress(remoteGroup.getLocalAddress());

    final Integer batchCount = getBatchCount();
    if (batchCount != null) {
        clientBuilder.requestBatchCount(batchCount);
    }

    final String batchSize = getBatchSize();
    if (batchSize != null && batchSize.length() > 0) {
        clientBuilder.requestBatchSize(DataUnit.parseDataSize(batchSize.trim(), DataUnit.B).intValue());
    }

    final String batchDuration = getBatchDuration();
    if (batchDuration != null && batchDuration.length() > 0) {
        clientBuilder.requestBatchDuration(FormatUtils.getTimeDuration(batchDuration.trim(), TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS);
    }

    clientRef.set(clientBuilder.build());
}
 
Example #28
Source File: SocketConfigurationFactoryBean.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public SocketConfiguration getObject() throws Exception {
    if (configuration == null) {
        configuration = new SocketConfiguration();

        final int timeout = (int) FormatUtils.getTimeDuration(properties.getClusterNodeReadTimeout(), TimeUnit.MILLISECONDS);
        configuration.setSocketTimeout(timeout);
        configuration.setReuseAddress(true);
        if (Boolean.valueOf(properties.getProperty(NiFiProperties.CLUSTER_PROTOCOL_IS_SECURE))) {
            configuration.setSSLContextFactory(new SSLContextFactory(properties));
        }
    }
    return configuration;

}
 
Example #29
Source File: LdapUserGroupProvider.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void setTimeout(final AuthorizerConfigurationContext configurationContext,
                        final Map<String, Object> baseEnvironment,
                        final String configurationProperty,
                        final String environmentKey) {

    final PropertyValue rawTimeout = configurationContext.getProperty(configurationProperty);
    if (rawTimeout.isSet()) {
        try {
            final Long timeout = FormatUtils.getTimeDuration(rawTimeout.getValue(), TimeUnit.MILLISECONDS);
            baseEnvironment.put(environmentKey, timeout.toString());
        } catch (final IllegalArgumentException iae) {
            throw new AuthorizerCreationException(String.format("The %s '%s' is not a valid time duration", configurationProperty, rawTimeout));
        }
    }
}
 
Example #30
Source File: StatusMerger.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static String formatDataSize(final Long longStatus) {
    if (longStatus == null) {
        return EMPTY_BYTES;
    }
    if (longStatus == 0L) {
        return ZERO_BYTES;
    }

    return FormatUtils.formatDataSize(longStatus);
}