Java Code Examples for org.apache.nifi.util.FormatUtils#getTimeDuration()

The following examples show how to use org.apache.nifi.util.FormatUtils#getTimeDuration() . 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: TimerDrivenSchedulingAgent.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public TimerDrivenSchedulingAgent(
        final FlowController flowController,
        final FlowEngine flowEngine,
        final ProcessContextFactory contextFactory,
        final StringEncryptor encryptor,
        final VariableRegistry variableRegistry,
        final NiFiProperties nifiProperties) {
    super(flowEngine);
    this.flowController = flowController;
    this.contextFactory = contextFactory;
    this.encryptor = encryptor;
    this.variableRegistry = variableRegistry;

    final String boredYieldDuration = nifiProperties.getBoredYieldDuration();
    try {
        noWorkYieldNanos = FormatUtils.getTimeDuration(boredYieldDuration, TimeUnit.NANOSECONDS);
    } catch (final IllegalArgumentException e) {
        throw new RuntimeException("Failed to create SchedulingAgent because the " + NiFiProperties.BORED_YIELD_DURATION + " property is set to an invalid time duration: " + boredYieldDuration);
    }
}
 
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: 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 4
Source File: KerberosProvider.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public final void onConfigured(final LoginIdentityProviderConfigurationContext configurationContext) throws ProviderCreationException {
    final String rawExpiration = configurationContext.getProperty("Authentication Expiration");
    if (StringUtils.isBlank(rawExpiration)) {
        throw new ProviderCreationException("The Authentication Expiration must be specified.");
    }

    try {
        expiration = FormatUtils.getTimeDuration(rawExpiration, TimeUnit.MILLISECONDS);
    } catch (final IllegalArgumentException iae) {
        throw new ProviderCreationException(String.format("The Expiration Duration '%s' is not a valid time duration", rawExpiration));
    }

    provider = new KerberosAuthenticationProvider();
    SunJaasKerberosClient client = new SunJaasKerberosClient();
    client.setDebug(true);
    provider.setKerberosClient(client);
    provider.setUserDetailsService(new KerberosUserDetailsService());
}
 
Example 5
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 6
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 7
Source File: DtoFactory.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public FlowConfigurationDTO createFlowConfigurationDto(final String autoRefreshInterval) {
    final FlowConfigurationDTO dto = new FlowConfigurationDTO();

    // get the refresh interval
    final long refreshInterval = FormatUtils.getTimeDuration(autoRefreshInterval, TimeUnit.SECONDS);
    dto.setAutoRefreshIntervalSeconds(refreshInterval);
    dto.setSupportsConfigurableAuthorizer(authorizer instanceof AbstractPolicyBasedAuthorizer);

    final Date now = new Date();
    dto.setTimeOffset(TimeZone.getDefault().getOffset(now.getTime()));
    dto.setCurrentTime(now);

    return dto;
}
 
Example 8
Source File: StandardConfigurationContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
public StandardConfigurationContext(final ComponentNode component, final ControllerServiceLookup serviceLookup, final String schedulingPeriod,
                                    final VariableRegistry variableRegistry) {
    this.component = component;
    this.serviceLookup = serviceLookup;
    this.schedulingPeriod = schedulingPeriod;
    this.variableRegistry = variableRegistry;

    if (schedulingPeriod == null) {
        schedulingNanos = null;
    } else {
        if (FormatUtils.TIME_DURATION_PATTERN.matcher(schedulingPeriod).matches()) {
            schedulingNanos = FormatUtils.getTimeDuration(schedulingPeriod, TimeUnit.NANOSECONDS);
        } else {
            schedulingNanos = null;
        }
    }

    preparedQueries = new HashMap<>();
    for (final Map.Entry<PropertyDescriptor, String> entry : component.getEffectivePropertyValues().entrySet()) {
        final PropertyDescriptor desc = entry.getKey();
        String value = entry.getValue();
        if (value == null) {
            value = desc.getDefaultValue();
        }

        final PreparedQuery pq = Query.prepare(value);
        preparedQueries.put(desc, pq);
    }
}
 
Example 9
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 10
Source File: StandardFunnel.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 11
Source File: WriteAheadFlowFileRepository.java    From nifi with Apache License 2.0 5 votes vote down vote up
public WriteAheadFlowFileRepository(final NiFiProperties nifiProperties) {
    alwaysSync = Boolean.parseBoolean(nifiProperties.getProperty(NiFiProperties.FLOWFILE_REPOSITORY_ALWAYS_SYNC, "false"));
    this.nifiProperties = nifiProperties;

    // determine the database file path and ensure it exists
    String writeAheadLogImpl = nifiProperties.getProperty(WRITE_AHEAD_LOG_IMPL);
    if (writeAheadLogImpl == null) {
        writeAheadLogImpl = DEFAULT_WAL_IMPLEMENTATION;
    }
    this.walImplementation = writeAheadLogImpl;

    // We used to use one implementation (minimal locking) of the write-ahead log, but we now want to use the other
    // (sequential access), we must address this. Since the MinimalLockingWriteAheadLog supports multiple partitions,
    // we need to ensure that we recover records from all partitions, so we build up a List of Files for the
    // recovery files.
    for (final String propertyName : nifiProperties.getPropertyKeys()) {
        if (propertyName.startsWith(FLOWFILE_REPOSITORY_DIRECTORY_PREFIX)) {
            final String dirName = nifiProperties.getProperty(propertyName);
            recoveryFiles.add(new File(dirName));
        }
    }

    if (isSequentialAccessWAL(walImplementation)) {
        final String directoryName = nifiProperties.getProperty(FLOWFILE_REPOSITORY_DIRECTORY_PREFIX);
        flowFileRepositoryPaths.add(new File(directoryName));
    } else {
        flowFileRepositoryPaths.addAll(recoveryFiles);
    }


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

    checkpointExecutor = Executors.newSingleThreadScheduledExecutor();
}
 
Example 12
Source File: StandardReportingInitializationContext.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public long getSchedulingPeriod(final TimeUnit timeUnit) {
    if (schedulingStrategy == SchedulingStrategy.TIMER_DRIVEN) {
        return FormatUtils.getTimeDuration(schedulingPeriod, timeUnit);
    }
    return -1L;
}
 
Example 13
Source File: ZooKeeperClientConfig.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static int getTimePeriod(final NiFiProperties nifiProperties, final String propertyName, final String defaultValue) {
    final String timeout = nifiProperties.getProperty(propertyName, defaultValue);
    try {
        return (int) FormatUtils.getTimeDuration(timeout, TimeUnit.MILLISECONDS);
    } catch (final Exception e) {
        logger.warn("Value of '" + propertyName + "' property is set to '" + timeout + "', which is not a valid time period. Using default of " + defaultValue);
        return (int) FormatUtils.getTimeDuration(defaultValue, TimeUnit.MILLISECONDS);
    }
}
 
Example 14
Source File: AbstractPort.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void setYieldPeriod(final String yieldPeriod) {
    final long yieldMillis = FormatUtils.getTimeDuration(requireNonNull(yieldPeriod), TimeUnit.MILLISECONDS);
    if (yieldMillis < 0) {
        throw new IllegalArgumentException("Yield duration must be positive");
    }
    this.yieldPeriod.set(yieldPeriod);
}
 
Example 15
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 16
Source File: StandardProcessorNode.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public 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 17
Source File: AbstractHeartbeatMonitor.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public AbstractHeartbeatMonitor(final ClusterCoordinator clusterCoordinator, final NiFiProperties nifiProperties) {
    this.clusterCoordinator = clusterCoordinator;
    final String heartbeatInterval = nifiProperties.getProperty(NiFiProperties.CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL,
            NiFiProperties.DEFAULT_CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL);
    this.heartbeatIntervalMillis = (int) FormatUtils.getTimeDuration(heartbeatInterval, TimeUnit.MILLISECONDS);
}
 
Example 18
Source File: StandardHttpResponseMapper.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public StandardHttpResponseMapper(final NiFiProperties nifiProperties) {
    final String snapshotFrequency = nifiProperties.getProperty(NiFiProperties.COMPONENT_STATUS_SNAPSHOT_FREQUENCY, NiFiProperties.DEFAULT_COMPONENT_STATUS_SNAPSHOT_FREQUENCY);
    long snapshotMillis;
    try {
        snapshotMillis = FormatUtils.getTimeDuration(snapshotFrequency, TimeUnit.MILLISECONDS);
    } catch (final Exception e) {
        snapshotMillis = FormatUtils.getTimeDuration(NiFiProperties.DEFAULT_COMPONENT_STATUS_SNAPSHOT_FREQUENCY, TimeUnit.MILLISECONDS);
    }
    endpointMergers.add(new ControllerStatusEndpointMerger());
    endpointMergers.add(new ControllerBulletinsEndpointMerger());
    endpointMergers.add(new GroupStatusEndpointMerger());
    endpointMergers.add(new ProcessorStatusEndpointMerger());
    endpointMergers.add(new ConnectionStatusEndpointMerger());
    endpointMergers.add(new PortStatusEndpointMerger());
    endpointMergers.add(new RemoteProcessGroupStatusEndpointMerger());
    endpointMergers.add(new ProcessorEndpointMerger());
    endpointMergers.add(new ProcessorsEndpointMerger());
    endpointMergers.add(new ConnectionEndpointMerger());
    endpointMergers.add(new ConnectionsEndpointMerger());
    endpointMergers.add(new PortEndpointMerger());
    endpointMergers.add(new InputPortsEndpointMerger());
    endpointMergers.add(new OutputPortsEndpointMerger());
    endpointMergers.add(new RemoteProcessGroupEndpointMerger());
    endpointMergers.add(new RemoteProcessGroupsEndpointMerger());
    endpointMergers.add(new ProcessGroupEndpointMerger());
    endpointMergers.add(new ProcessGroupsEndpointMerger());
    endpointMergers.add(new FlowSnippetEndpointMerger());
    endpointMergers.add(new ProvenanceQueryEndpointMerger());
    endpointMergers.add(new ProvenanceEventEndpointMerger());
    endpointMergers.add(new ControllerServiceEndpointMerger());
    endpointMergers.add(new ControllerServicesEndpointMerger());
    endpointMergers.add(new ControllerServiceReferenceEndpointMerger());
    endpointMergers.add(new ReportingTaskEndpointMerger());
    endpointMergers.add(new ReportingTasksEndpointMerger());
    endpointMergers.add(new DropRequestEndpointMerger());
    endpointMergers.add(new ListFlowFilesEndpointMerger());
    endpointMergers.add(new ComponentStateEndpointMerger());
    endpointMergers.add(new BulletinBoardEndpointMerger());
    endpointMergers.add(new StatusHistoryEndpointMerger(snapshotMillis));
    endpointMergers.add(new SystemDiagnosticsEndpointMerger());
    endpointMergers.add(new CountersEndpointMerger());
    endpointMergers.add(new FlowMerger());
    endpointMergers.add(new ControllerConfigurationEndpointMerger());
    endpointMergers.add(new CurrentUserEndpointMerger());
    endpointMergers.add(new FlowConfigurationEndpointMerger());
    endpointMergers.add(new TemplatesEndpointMerger());
    endpointMergers.add(new LabelEndpointMerger());
    endpointMergers.add(new LabelsEndpointMerger());
    endpointMergers.add(new FunnelEndpointMerger());
    endpointMergers.add(new FunnelsEndpointMerger());
    endpointMergers.add(new ControllerEndpointMerger());
}
 
Example 19
Source File: ControllerFacade.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Saves the state of the flow controller.
 *
 * @throws NiFiCoreException ex
 */
public void save() throws NiFiCoreException {
    // save the flow controller
    final long writeDelaySeconds = FormatUtils.getTimeDuration(properties.getFlowServiceWriteDelay(), TimeUnit.SECONDS);
    flowService.saveFlowChanges(TimeUnit.SECONDS, writeDelaySeconds);
}
 
Example 20
Source File: EventDrivenSchedulingAgent.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public long getAdministrativeYieldDuration(final TimeUnit timeUnit) {
    return FormatUtils.getTimeDuration(adminYieldDuration, timeUnit);
}