/**
   * Set up for the AnomalyScoreCalculationFilterTest.
   *
   * @throws IllegalStateException If illegal state
   * @throws AnalysisConfigurationException If wrong configuration
   */
  @Before
  public void setUp() throws IllegalStateException, AnalysisConfigurationException {
    this.controller = new AnalysisController();

    // READER
    final Configuration readerScoreCalcConfiguration = new Configuration();
    readerScoreCalcConfiguration.setProperty(
        ListReader.CONFIG_PROPERTY_NAME_AWAIT_TERMINATION, Boolean.TRUE.toString());
    final ListReader<ForecastMeasurementPair> theReaderScoreCalc =
        new ListReader<ForecastMeasurementPair>(readerScoreCalcConfiguration, this.controller);
    theReaderScoreCalc.addAllObjects(this.createInputEventSetScoreCalc());

    final Configuration scoreConfiguration = new Configuration();
    final AnomalyScoreCalculationFilter scoreCalc =
        new AnomalyScoreCalculationFilter(scoreConfiguration, this.controller);

    // SINK 1
    this.sinkAnomalyScore =
        new ListCollectionFilter<StorableDetectionResult>(new Configuration(), this.controller);

    // CONNECTION
    this.controller.connect(
        theReaderScoreCalc,
        ListReader.OUTPUT_PORT_NAME,
        scoreCalc,
        AnomalyScoreCalculationFilter.INPUT_PORT_CURRENT_FORECAST_PAIR);
    this.controller.connect(
        scoreCalc,
        AnomalyScoreCalculationFilter.OUTPUT_PORT_ANOMALY_SCORE,
        this.sinkAnomalyScore,
        ListCollectionFilter.INPUT_PORT_NAME);
  }
 /** {@inheritDoc} */
 @Override
 public Configuration getCurrentConfiguration() {
   final Configuration configuration = new Configuration();
   configuration.setProperty(CONFIG_PROPERTY_NAME_TIMEUNIT, this.timeunit.name());
   configuration.setProperty(
       CONFIG_PROPERTY_NAME_TIME_RESOLUTION, Long.toString(this.timerResolution));
   return configuration;
 }
  public void init() throws IllegalStateException, AnalysisConfigurationException {
    final Configuration producerConfig = new Configuration();
    producerConfig.setProperty(
        ObjectProducer.CONFIG_PROPERTY_NAME_OBJECTS_TO_CREATE, Long.toString(this.numInputObjects));
    final ObjectProducer<T> producer =
        new ObjectProducer<T>(producerConfig, this.ac, this.inputObjectCreator);

    EmptyPassOnFilter predecessor = new EmptyPassOnFilter(new Configuration(), this.ac);
    this.ac.connect(
        producer, ObjectProducer.OUTPUT_PORT_NAME, predecessor, EmptyPassOnFilter.INPUT_PORT_NAME);
    for (int idx = 0; idx < (this.numNoopFilters - 1); idx++) {
      final EmptyPassOnFilter newPredecessor = new EmptyPassOnFilter(new Configuration(), this.ac);
      this.ac.connect(
          predecessor,
          EmptyPassOnFilter.OUTPUT_PORT_NAME,
          newPredecessor,
          EmptyPassOnFilter.INPUT_PORT_NAME);
      predecessor = newPredecessor;
    }
  }
  @Override
  protected List<IMonitoringRecord> readEvents() throws Exception {
    final AnalysisController analysisController = new AnalysisController();

    final Configuration dbReaderConfig = new Configuration();
    dbReaderConfig.setProperty(DbReader.CONFIG_PROPERTY_NAME_DRIVERCLASSNAME, DRIVERCLASSNAME);
    dbReaderConfig.setProperty(
        DbReader.CONFIG_PROPERTY_NAME_CONNECTIONSTRING, this.getConnectionString());
    dbReaderConfig.setProperty(DbReader.CONFIG_PROPERTY_NAME_TABLEPREFIX, TABLEPREFIX);

    final DbReader dbReader = new DbReader(dbReaderConfig, analysisController);
    final ListCollectionFilter<IMonitoringRecord> sinkFilter =
        new ListCollectionFilter<IMonitoringRecord>(new Configuration(), analysisController);

    analysisController.connect(
        dbReader,
        DbReader.OUTPUT_PORT_NAME_RECORDS,
        sinkFilter,
        ListCollectionFilter.INPUT_PORT_NAME);
    analysisController.run();
    return sinkFilter.getList();
  }
  /**
   * Creates an event generator which generates time events with the given resolution in timeunits
   * via the output port {@link #OUTPUT_PORT_NAME_CURRENT_TIME_RECORD}.
   *
   * @param configuration The configuration to be used for this plugin.
   * @param projectContext The project context to be used for this plugin.
   */
  public CurrentTimeEventGenerationFilter(
      final Configuration configuration, final IProjectContext projectContext) {
    super(configuration, projectContext);

    this.timeunit = super.recordsTimeUnitFromProjectContext;

    final String configTimeunitProperty =
        configuration.getStringProperty(CONFIG_PROPERTY_NAME_TIMEUNIT);
    TimeUnit configTimeunit;
    try {
      configTimeunit = TimeUnit.valueOf(configTimeunitProperty);
    } catch (final IllegalArgumentException ex) {
      this.log.warn(
          configTimeunitProperty
              + " is no valid TimeUnit! Using inherited value of "
              + this.timeunit.name()
              + " instead.");
      configTimeunit = this.timeunit;
    }

    this.timerResolution =
        this.timeunit.convert(
            configuration.getLongProperty(CONFIG_PROPERTY_NAME_TIME_RESOLUTION), configTimeunit);
  }
Esempio n. 6
0
  /**
   * This is a factory method creating a new monitoring controller instance using the given
   * configuration.
   *
   * @param configuration The configuration for the new controller.
   * @return A new controller.
   */
  public static final IMonitoringController createInstance(final Configuration configuration) {
    final MonitoringController monitoringController = new MonitoringController(configuration);
    // Initialize and handle early Termination (once for each Controller!)
    monitoringController.stateController.setMonitoringController(monitoringController);
    if (monitoringController.stateController.isTerminated()) {
      monitoringController.terminate();
    }
    monitoringController.samplingController.setMonitoringController(monitoringController);
    if (monitoringController.samplingController.isTerminated()) {
      monitoringController.terminate();
    }
    monitoringController.jmxController.setMonitoringController(monitoringController);
    if (monitoringController.jmxController.isTerminated()) {
      monitoringController.terminate();
    }
    monitoringController.writerController.setMonitoringController(monitoringController);
    if (monitoringController.writerController.isTerminated()) {
      monitoringController.terminate();
    }
    monitoringController.timeSourceController.setMonitoringController(monitoringController);
    if (monitoringController.timeSourceController.isTerminated()) {
      monitoringController.terminate();
    }
    monitoringController.registryController.setMonitoringController(monitoringController);
    if (monitoringController.registryController.isTerminated()) {
      monitoringController.terminate();
    }
    monitoringController.probeController.setMonitoringController(monitoringController);
    if (monitoringController.probeController.isTerminated()) {
      monitoringController.terminate();
    }
    monitoringController.setMonitoringController(monitoringController);
    if (monitoringController.isTerminated()) {
      return monitoringController;
    }

    if (configuration.getBooleanProperty(ConfigurationFactory.USE_SHUTDOWN_HOOK)) {
      // This ensures that the terminateMonitoring() method is always called before shutting down
      // the JVM. This method ensures that necessary cleanup steps are
      // finished and no information is lost due to asynchronous writers.
      try {
        Runtime.getRuntime()
            .addShutdownHook(
                new Thread() {

                  @Override
                  public void run() {
                    if (!monitoringController.isMonitoringTerminated()) {
                      // WONTFIX: We should not use a logger in shutdown hooks, logger may already
                      // be down! (#26)
                      LOG.info(
                          "ShutdownHook notifies controller to initiate shutdown in "
                              + SHUTDOWN_DELAY_MILLIS
                              + " milliseconds");
                      // System.err.println(monitoringController.toString());
                      try {
                        Thread.sleep(SHUTDOWN_DELAY_MILLIS);
                      } catch (final InterruptedException e) {
                        LOG.warn("ShutdownHook was interrupted while waiting");
                      }
                      monitoringController.terminateMonitoring();
                    }
                  }
                });
      } catch (final Exception e) { // NOPMD NOCS (Exception)
        LOG.warn("Failed to add shutdownHook");
      }
    } else {
      LOG.warn("Shutdown Hook is disabled, loss of monitoring data might occur.");
    }
    LOG.info(monitoringController.toString());
    return monitoringController;
  }
 /**
  * Here, we make sure that the reader aborts on the first occurrence of an unknown type.
  *
  * @param config The configuration to modify.
  */
 @Override
 protected void refineFSReaderConfiguration(final Configuration config) {
   config.setProperty(
       FSReader.CONFIG_PROPERTY_NAME_IGNORE_UNKNOWN_RECORD_TYPES, Boolean.FALSE.toString());
 }