@Override
 public long getSchedulingPeriod(final TimeUnit timeUnit) {
   if (schedulingStrategy == SchedulingStrategy.TIMER_DRIVEN) {
     return FormatUtils.getTimeDuration(schedulingPeriod, timeUnit);
   }
   return -1L;
 }
예제 #2
0
 public AbstractHeartbeatMonitor(
     final ClusterCoordinator clusterCoordinator, final Properties properties) {
   this.clusterCoordinator = clusterCoordinator;
   final String heartbeatInterval =
       properties.getProperty(
           NiFiProperties.CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL,
           NiFiProperties.DEFAULT_CLUSTER_PROTOCOL_HEARTBEAT_INTERVAL);
   this.heartbeatIntervalMillis =
       (int) FormatUtils.getTimeDuration(heartbeatInterval, TimeUnit.MILLISECONDS);
 }
예제 #3
0
 @Override
 public void setPenalizationPeriod(final String penalizationPeriod) {
   writeLock.lock();
   try {
     if (isRunning()) {
       throw new IllegalStateException(
           "Cannot modify Processor configuration while the Processor is running");
     }
     final long penalizationMillis =
         FormatUtils.getTimeDuration(requireNonNull(penalizationPeriod), TimeUnit.MILLISECONDS);
     if (penalizationMillis < 0) {
       throw new IllegalArgumentException("Penalization duration must be positive");
     }
     this.penalizationPeriod.set(penalizationPeriod);
   } finally {
     writeLock.unlock();
   }
 }
예제 #4
0
  @Override
  public NiFiUser checkAuthorization(String dn) {
    Transaction transaction = null;

    writeLock.lock();
    try {
      // create the connection
      transaction = transactionBuilder.start();

      // determine how long the cache is valid for
      final int cacheSeconds;
      try {
        cacheSeconds =
            (int)
                FormatUtils.getTimeDuration(
                    properties.getUserCredentialCacheDuration(), TimeUnit.SECONDS);
      } catch (IllegalArgumentException iae) {
        throw new AdministrationException(
            "User credential cache duration is not configured correctly.");
      }

      // attempt to authorize the user
      AuthorizeUserAction authorizeUser = new AuthorizeUserAction(dn, cacheSeconds);
      NiFiUser user = transaction.execute(authorizeUser);

      // commit the transaction
      transaction.commit();

      // return the nifi user
      return user;
    } catch (DataAccessException | TransactionException dae) {
      rollback(transaction);
      throw new AdministrationException(dae);
    } catch (AccountDisabledException | AccountPendingException ade) {
      rollback(transaction);
      throw ade;
    } catch (Throwable t) {
      rollback(transaction);
      throw t;
    } finally {
      closeQuietly(transaction);
      writeLock.unlock();
    }
  }
예제 #5
0
  @Override
  public void setScheduldingPeriod(final String schedulingPeriod) {
    writeLock.lock();
    try {
      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);
    } finally {
      writeLock.unlock();
    }
  }
예제 #6
0
  public TimerDrivenSchedulingAgent(
      final FlowController flowController,
      final FlowEngine flowEngine,
      final ProcessContextFactory contextFactory,
      final StringEncryptor encryptor) {
    this.flowController = flowController;
    this.flowEngine = flowEngine;
    this.contextFactory = contextFactory;
    this.encryptor = encryptor;

    final String boredYieldDuration = NiFiProperties.getInstance().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);
    }
  }
예제 #7
0
 @Override
 public long getSchedulingPeriod(final TimeUnit timeUnit) {
   return FormatUtils.getTimeDuration(schedulingPeriod.get(), timeUnit);
 }
예제 #8
0
 @Override
 public long getPenalizationPeriod(final TimeUnit timeUnit) {
   return FormatUtils.getTimeDuration(
       getPenalizationPeriod(), timeUnit == null ? DEFAULT_TIME_UNIT : timeUnit);
 }
예제 #9
0
 @Override
 public long getAdministrativeYieldDuration(final TimeUnit timeUnit) {
   return FormatUtils.getTimeDuration(adminYieldDuration, timeUnit);
 }