Java Code Examples for org.apache.commons.collections4.MapUtils#getBooleanValue()

The following examples show how to use org.apache.commons.collections4.MapUtils#getBooleanValue() . 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: LegacyAnomalyFunctionAlgorithm.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Instantiates a new Legacy anomaly function algorithm.
 *
 * @param provider the provider
 * @param config the config
 * @param startTime the start time
 * @param endTime the end time
 * @throws Exception the exception
 */
public LegacyAnomalyFunctionAlgorithm(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) throws Exception {
  super(provider, config, startTime, endTime);
  // TODO: Round start and end time stamps
  Preconditions.checkArgument(config.getProperties().containsKey(PROP_ANOMALY_FUNCTION_CLASS));
  String anomalyFunctionClassName = MapUtils.getString(config.getProperties(), PROP_ANOMALY_FUNCTION_CLASS);

  String specs = OBJECT_MAPPER.writeValueAsString(ConfigUtils.getMap(config.getProperties().get(PROP_SPEC)));
  this.anomalyFunction = (BaseAnomalyFunction) Class.forName(anomalyFunctionClassName).newInstance();
  this.anomalyFunction.init(OBJECT_MAPPER.readValue(specs, AnomalyFunctionDTO.class));

  this.dataFilter = DataFilterFactory.fromSpec(this.anomalyFunction.getSpec().getDataFilter());
  this.failOnError = MapUtils.getBooleanValue(config.getProperties(), PROP_FAIL_ON_ERROR, false);

  if (config.getProperties().containsKey(PROP_METRIC_URN)) {
    this.metricEntity = MetricEntity.fromURN(MapUtils.getString(config.getProperties(), PROP_METRIC_URN));
  } else {
    this.metricEntity = makeEntity(this.anomalyFunction.getSpec());
  }
}
 
Example 2
Source File: YamlResource.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private void updateDetectionConfig(ThirdEyePrincipal user, long detectionID, @NotNull String payload, long startTime,
    long endTime)
    throws IllegalArgumentException {
  DetectionConfigDTO existingDetectionConfig = this.detectionConfigDAO.findById(detectionID);
  Preconditions.checkNotNull(existingDetectionConfig, "Cannot find detection pipeline " + detectionID);

  authorizeUser(user, detectionID, PROP_DETECTION);
  DetectionConfigDTO detectionConfig;
  try {
    detectionConfig = buildDetectionConfigFromYaml(startTime, endTime, payload, existingDetectionConfig);

    // Validate updated config before saving it
    detectionValidator.validateUpdatedConfig(detectionConfig, existingDetectionConfig);
    // Save the detection config
    Long id = this.detectionConfigDAO.save(detectionConfig);
    Preconditions.checkNotNull(id, "Error while saving the detection pipeline");
  } finally {
    // If it is to disable the pipeline then no need to do validation and parsing.
    // It is possible that the metric or dataset was deleted so the validation will fail.
    Map<String, Object> detectionConfigMap = new HashMap<>(ConfigUtils.getMap(this.yaml.load(payload)));
    if (!MapUtils.getBooleanValue(detectionConfigMap, PROP_ACTIVE, true)) {
      existingDetectionConfig.setActive(false);
      existingDetectionConfig.setYaml(payload);
      this.detectionConfigDAO.save(existingDetectionConfig);
    }
  }
}
 
Example 3
Source File: MetricMappingPipeline.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
/**
 * Alternate constructor for RCAFrameworkLoader
 *
 * @param outputName pipeline output name
 * @param inputNames input pipeline names
 * @param properties configuration properties ({@code PROP_INCLUDE_FILTERS}, {@code PROP_EXCLUDE_METRICS})
 */
public MetricMappingPipeline(String outputName, Set<String> inputNames, Map<String, Object> properties) {
  super(outputName, inputNames);
  this.metricDAO = DAORegistry.getInstance().getMetricConfigDAO();
  this.datasetDAO = DAORegistry.getInstance().getDatasetConfigDAO();
  this.mappingDAO = DAORegistry.getInstance().getEntityToEntityMappingDAO();
  this.includeFilters = MapUtils.getBooleanValue(properties, PROP_INCLUDE_FILTERS, PROP_INCLUDE_FILTERS_DEFAULT);

  if (properties.containsKey(PROP_EXCLUDE_METRICS)) {
    this.excludeMetrics = new HashSet<>((Collection<String>) properties.get(PROP_EXCLUDE_METRICS));
  } else {
    this.excludeMetrics = PROP_EXCLUDE_METRICS_DEFAULT;
  }
}
 
Example 4
Source File: DetectionRegistry.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public boolean isBaselineProvider(String type) {
  Preconditions.checkArgument(REGISTRY_MAP.containsKey(type), type + " not found in registry");
  return MapUtils.getBooleanValue(REGISTRY_MAP.get(type), KEY_IS_BASELINE_PROVIDER);
}
 
Example 5
Source File: MovingWindowAlgorithm.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public MovingWindowAlgorithm(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);

  Preconditions.checkArgument(config.getProperties().containsKey(PROP_METRIC_URN));

  String metricUrn = MapUtils.getString(config.getProperties(), PROP_METRIC_URN);
  MetricEntity me = MetricEntity.fromURN(metricUrn);

  this.quantileMin = MapUtils.getDoubleValue(config.getProperties(), "quantileMin", Double.NaN);
  this.quantileMax = MapUtils.getDoubleValue(config.getProperties(), "quantileMax", Double.NaN);
  this.zscoreMin = MapUtils.getDoubleValue(config.getProperties(), "zscoreMin", Double.NaN);
  this.zscoreMax = MapUtils.getDoubleValue(config.getProperties(), "zscoreMax", Double.NaN);
  this.zscoreOutlier = MapUtils.getDoubleValue(config.getProperties(), "zscoreOutlier", Double.NaN);
  this.kernelSize = MapUtils.getIntValue(config.getProperties(), "kernelSize", 1);
  this.timezone = DateTimeZone.forID(MapUtils.getString(config.getProperties(), "timezone", "UTC"));
  this.windowSize = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "windowSize", "1week"));
  this.lookbackPeriod = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "lookbackPeriod", "1week"));
  this.reworkPeriod = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "reworkPeriod", "1day"));
  this.changeDuration = ConfigUtils.parsePeriod(MapUtils.getString(config.getProperties(), "changeDuration", "5days"));
  this.changeFraction = MapUtils.getDoubleValue(config.getProperties(), "changeFraction", 0.666);
  this.baselineWeeks = MapUtils.getIntValue(config.getProperties(), "baselineWeeks", 0);
  this.applyLog = MapUtils.getBooleanValue(config.getProperties(), "applyLog", true);
  this.learningRate = MapUtils.getDoubleValue(config.getProperties(), "learningRate", 0.666);

  Preconditions.checkArgument(Double.isNaN(this.quantileMin) || (this.quantileMin >= 0 && this.quantileMin <= 1.0), "quantileMin must be between 0.0 and 1.0");
  Preconditions.checkArgument(Double.isNaN(this.quantileMax) || (this.quantileMax >= 0 && this.quantileMax <= 1.0), "quantileMax must be between 0.0 and 1.0");

  this.effectiveStartTime = new DateTime(startTime, this.timezone).minus(this.lookbackPeriod).getMillis();

  DateTime trainStart = new DateTime(this.effectiveStartTime, this.timezone).minus(this.windowSize);
  DateTime dataStart = trainStart.minus(new Period().withField(DurationFieldType.weeks(), baselineWeeks));
  DateTime detectionStart = new DateTime(startTime, this.timezone).minus(this.reworkPeriod);

  this.sliceData = MetricSlice.from(me.getId(), dataStart.getMillis(), endTime, me.getFilters());
  this.sliceDetection = MetricSlice.from(me.getId(), detectionStart.getMillis(), endTime, me.getFilters());

  AnomalySlice slice = new AnomalySlice().withStart(this.sliceData.getStart()).withEnd(this.sliceData.getEnd());
  if (this.config.getId() != null) {
    this.anomalySlice = slice.withDetectionId(this.config.getId());
  } else {
    this.anomalySlice = slice;
  }
}
 
Example 6
Source File: AnomalyDetectorWrapper.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
public AnomalyDetectorWrapper(DataProvider provider, DetectionConfigDTO config, long startTime, long endTime) {
  super(provider, config, startTime, endTime);

  Preconditions.checkArgument(this.config.getProperties().containsKey(PROP_SUB_ENTITY_NAME));
  this.entityName = MapUtils.getString(config.getProperties(), PROP_SUB_ENTITY_NAME);

  this.metricUrn = MapUtils.getString(config.getProperties(), PROP_METRIC_URN);
  this.metricEntity = MetricEntity.fromURN(this.metricUrn);
  this.metric = provider.fetchMetrics(Collections.singleton(this.metricEntity.getId())).get(this.metricEntity.getId());

  Preconditions.checkArgument(this.config.getProperties().containsKey(PROP_DETECTOR));
  this.detectorName = DetectionUtils.getComponentKey(MapUtils.getString(config.getProperties(), PROP_DETECTOR));
  Preconditions.checkArgument(this.config.getComponents().containsKey(this.detectorName));
  this.anomalyDetector = (AnomalyDetector) this.config.getComponents().get(this.detectorName);

  // emulate moving window or now
  this.isMovingWindowDetection = MapUtils.getBooleanValue(config.getProperties(), PROP_MOVING_WINDOW_DETECTION, false);
  // delays to wait for data becomes available
  this.windowDelay = MapUtils.getIntValue(config.getProperties(), PROP_WINDOW_DELAY, 0);
  // window delay unit
  this.windowDelayUnit = TimeUnit.valueOf(MapUtils.getString(config.getProperties(), PROP_WINDOW_DELAY_UNIT, "DAYS"));
  // detection window size
  this.windowSize = MapUtils.getIntValue(config.getProperties(), PROP_WINDOW_SIZE, 1);
  // detection window unit
  this.windowUnit = TimeUnit.valueOf(MapUtils.getString(config.getProperties(), PROP_WINDOW_UNIT, "DAYS"));
  // run frequency, used to determine moving windows for minute-level detection
  Map<String, Object> frequency = (Map<String, Object>) MapUtils.getMap(config.getProperties(), PROP_FREQUENCY);
  this.functionFrequency = new TimeGranularity(MapUtils.getIntValue(frequency, "size", 15), TimeUnit.valueOf(MapUtils.getString(frequency, "unit", "MINUTES")));

  MetricConfigDTO metricConfigDTO = this.provider.fetchMetrics(Collections.singletonList(this.metricEntity.getId())).get(this.metricEntity.getId());
  this.dataset = this.provider.fetchDatasets(Collections.singletonList(metricConfigDTO.getDataset()))
      .get(metricConfigDTO.getDataset());
  // date time zone for moving windows. use dataset time zone as default
  this.dateTimeZone = DateTimeZone.forID(MapUtils.getString(config.getProperties(), PROP_TIMEZONE, this.dataset.getTimezone()));

  String bucketStr = MapUtils.getString(config.getProperties(), PROP_BUCKET_PERIOD);
  this.bucketPeriod = bucketStr == null ? this.getBucketSizePeriodForDataset() : Period.parse(bucketStr);
  this.cachingPeriodLookback = config.getProperties().containsKey(PROP_CACHE_PERIOD_LOOKBACK) ?
      MapUtils.getLong(config.getProperties(), PROP_CACHE_PERIOD_LOOKBACK) : ThirdEyeUtils.getCachingPeriodLookback(this.dataset.bucketTimeGranularity());

  speedUpMinuteLevelDetection();
}