Search in sources :

Example 1 with OverrideConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO in project pinot by linkedin.

the class OverrideConfigHelper method convertToScalingFactors.

/**
   * Convert a list of OverrideConfigDTO to a list of scaling factor, in which each scaling factor
   * are filtered through target level.
   *
   * @param overrideConfigDTOs the list of OverrideConfigDTO
   * @param timeSereisTargetLevel the
   *                              filtration rule for applying OverrideConfigDTO
   * @return a list of scaling factor
   */
public static List<ScalingFactor> convertToScalingFactors(List<OverrideConfigDTO> overrideConfigDTOs, Map<String, String> timeSereisTargetLevel) {
    List<ScalingFactor> results = new ArrayList<>();
    for (OverrideConfigDTO overrideConfigDTO : overrideConfigDTOs) {
        if (OverrideConfigHelper.isEnabled(timeSereisTargetLevel, overrideConfigDTO)) {
            long startTime = overrideConfigDTO.getStartTime();
            long endTime = overrideConfigDTO.getEndTime();
            if (MapUtils.isNotEmpty(overrideConfigDTO.getOverrideProperties())) {
                try {
                    double scalingFactor = Double.parseDouble(overrideConfigDTO.getOverrideProperties().get(ScalingFactor.SCALING_FACTOR));
                    ScalingFactor sf = new ScalingFactor(startTime, endTime, scalingFactor);
                    results.add(sf);
                } catch (Exception e) {
                    LOG.warn("Failed to parse scaling factor from override config:{}, Exception: {}", overrideConfigDTO, e);
                }
            } else {
                LOG.warn("Unable to parse scaling factor due to empty override properties. Config:{}", overrideConfigDTO);
            }
        }
    }
    return results;
}
Also used : OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) ArrayList(java.util.ArrayList) ScalingFactor(com.linkedin.thirdeye.detector.metric.transfer.ScalingFactor)

Example 2 with OverrideConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO in project pinot by linkedin.

the class OverrideConfigHelper method getTimeSeriesOverrideConfigs.

/**
   * Get a list of OverrideConfigDTOs according to the given start and end time ranges.
   *
   * @param startEndTimeRanges a list of start and end time ranges for retrieving override configs
   * @param overrideConfigDAO the data access object for retrieving override configs
   *
   * @return a list of OverrideConfigDTOs
   */
public static List<OverrideConfigDTO> getTimeSeriesOverrideConfigs(List<Pair<Long, Long>> startEndTimeRanges, OverrideConfigManager overrideConfigDAO) {
    // The Set is used to prevent duplicate override configs are loaded, which could happen if
    // there exists an override config that overlaps both time ranges of current and baseline
    // values
    Set<OverrideConfigDTO> overrideConfigDTOSet = new HashSet<>();
    for (Pair<Long, Long> startEndTimeRange : startEndTimeRanges) {
        List<OverrideConfigDTO> overrideConfigDTOList = overrideConfigDAO.findAllConflictByTargetType(OverrideConfigHelper.ENTITY_TIME_SERIES, startEndTimeRange.getFirst(), startEndTimeRange.getSecond());
        for (OverrideConfigDTO overrideConfig : overrideConfigDTOList) {
            if (overrideConfig.isActive()) {
                overrideConfigDTOSet.add(overrideConfig);
            }
        }
    }
    List<OverrideConfigDTO> results = new ArrayList<>(overrideConfigDTOSet);
    return results;
}
Also used : OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with OverrideConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO in project pinot by linkedin.

the class OverrideConfigResource method createOverrideConfig.

@POST
@Path("/override-config/create")
public Response createOverrideConfig(@NotNull @QueryParam("startTime") long startTimeMillis, @NotNull @QueryParam("endTime") long endTimeMillis, @QueryParam("targetLevel") String targetLevelJson, @NotNull @QueryParam("targetEntity") String targetEntity, @QueryParam("overrideProperties") String overridePropertiesJson, @QueryParam("active") boolean active) {
    Map<String, List<String>> targetLevel;
    if (StringUtils.isEmpty(targetLevelJson)) {
        targetLevel = Collections.emptyMap();
    } else {
        try {
            targetLevel = OBJECT_MAPPER.readValue(targetLevelJson, HashMap.class);
        } catch (IOException e) {
            LOG.error("Invalid JSON string {}", targetLevelJson);
            return Response.status(Response.Status.NOT_ACCEPTABLE).build();
        }
    }
    if (StringUtils.isEmpty(targetEntity)) {
        LOG.error("Received null for one of the mandatory params \"targetEntity\": {}", targetEntity);
        return Response.status(Response.Status.NOT_ACCEPTABLE).build();
    }
    Map<String, String> overrideProperties;
    if (StringUtils.isEmpty(overridePropertiesJson)) {
        overrideProperties = Collections.emptyMap();
    } else {
        try {
            overrideProperties = OBJECT_MAPPER.readValue(overridePropertiesJson, HashMap.class);
        } catch (IOException e) {
            LOG.error("Invalid JSON string {}", overridePropertiesJson);
            return Response.status(Response.Status.NOT_ACCEPTABLE).build();
        }
    }
    OverrideConfigDTO overrideConfigDTO = new OverrideConfigDTO();
    overrideConfigDTO.setStartTime(startTimeMillis);
    overrideConfigDTO.setEndTime(endTimeMillis);
    overrideConfigDTO.setTargetLevel(targetLevel);
    overrideConfigDTO.setTargetEntity(targetEntity);
    overrideConfigDTO.setOverrideProperties(overrideProperties);
    overrideConfigDTO.setActive(active);
    OverrideConfigManager overrideConfigDAO = DAO_REGISTRY.getOverrideConfigDAO();
    // Check if there exists any duplicate override config
    List<OverrideConfigDTO> existingOverrideConfigDTOs = overrideConfigDAO.findAllConflictByTargetType(targetEntity, startTimeMillis, endTimeMillis);
    for (OverrideConfigDTO existingOverrideConfig : existingOverrideConfigDTOs) {
        if (existingOverrideConfig.equals(overrideConfigDTO)) {
            LOG.error("Exists a duplicate override config: {}", existingOverrideConfig.toString());
            return Response.status(Response.Status.NOT_ACCEPTABLE).build();
        }
    }
    overrideConfigDAO.save(overrideConfigDTO);
    return Response.ok().build();
}
Also used : OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) HashMap(java.util.HashMap) List(java.util.List) IOException(java.io.IOException) OverrideConfigManager(com.linkedin.thirdeye.datalayer.bao.OverrideConfigManager) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with OverrideConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO in project pinot by linkedin.

the class EntityManagerResource method updateEntity.

@POST
public Response updateEntity(@QueryParam("entityType") String entityTypeStr, String jsonPayload) {
    if (Strings.isNullOrEmpty(entityTypeStr)) {
        throw new WebApplicationException("EntryType can not be null");
    }
    EntityType entityType = EntityType.valueOf(entityTypeStr);
    try {
        switch(entityType) {
            case ANOMALY_FUNCTION:
                AnomalyFunctionDTO anomalyFunctionDTO = OBJECT_MAPPER.readValue(jsonPayload, AnomalyFunctionDTO.class);
                if (anomalyFunctionDTO.getId() == null) {
                    anomalyFunctionManager.save(anomalyFunctionDTO);
                } else {
                    anomalyFunctionManager.update(anomalyFunctionDTO);
                }
                break;
            case EMAIL_CONFIGURATION:
                EmailConfigurationDTO emailConfigurationDTO = OBJECT_MAPPER.readValue(jsonPayload, EmailConfigurationDTO.class);
                emailConfigurationManager.update(emailConfigurationDTO);
                break;
            case DASHBOARD_CONFIG:
                DashboardConfigDTO dashboardConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, DashboardConfigDTO.class);
                dashboardConfigManager.update(dashboardConfigDTO);
                break;
            case DATASET_CONFIG:
                DatasetConfigDTO datasetConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, DatasetConfigDTO.class);
                datasetConfigManager.update(datasetConfigDTO);
                break;
            case METRIC_CONFIG:
                MetricConfigDTO metricConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, MetricConfigDTO.class);
                metricConfigManager.update(metricConfigDTO);
                break;
            case OVERRIDE_CONFIG:
                OverrideConfigDTO overrideConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, OverrideConfigDTO.class);
                if (overrideConfigDTO.getId() == null) {
                    overrideConfigManager.save(overrideConfigDTO);
                } else {
                    overrideConfigManager.update(overrideConfigDTO);
                }
                break;
            case ALERT_CONFIG:
                AlertConfigDTO alertConfigDTO = OBJECT_MAPPER.readValue(jsonPayload, AlertConfigDTO.class);
                if (alertConfigDTO.getId() == null) {
                    alertConfigManager.save(alertConfigDTO);
                } else {
                    alertConfigManager.update(alertConfigDTO);
                }
                break;
        }
    } catch (IOException e) {
        LOG.error("Error saving the entity with payload : " + jsonPayload, e);
        throw new WebApplicationException(e);
    }
    return Response.ok().build();
}
Also used : DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) MetricConfigDTO(com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO) OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) WebApplicationException(javax.ws.rs.WebApplicationException) AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) AlertConfigDTO(com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO) IOException(java.io.IOException) DashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO) POST(javax.ws.rs.POST)

Example 5 with OverrideConfigDTO

use of com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO in project pinot by linkedin.

the class OverrideConfigManagerImpl method findByPredicate.

private List<OverrideConfigDTO> findByPredicate(Predicate predicate) {
    List<OverrideConfigBean> list = genericPojoDao.get(predicate, OverrideConfigBean.class);
    List<OverrideConfigDTO> result = new ArrayList<>();
    for (OverrideConfigBean bean : list) {
        OverrideConfigDTO dto = convertBean2DTO(bean, OverrideConfigDTO.class);
        result.add(dto);
    }
    return result;
}
Also used : OverrideConfigDTO(com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO) OverrideConfigBean(com.linkedin.thirdeye.datalayer.pojo.OverrideConfigBean) ArrayList(java.util.ArrayList)

Aggregations

OverrideConfigDTO (com.linkedin.thirdeye.datalayer.dto.OverrideConfigDTO)12 HashMap (java.util.HashMap)5 List (java.util.List)4 Test (org.testng.annotations.Test)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 POST (javax.ws.rs.POST)3 OverrideConfigManager (com.linkedin.thirdeye.datalayer.bao.OverrideConfigManager)2 Path (javax.ws.rs.Path)2 AlertConfigDTO (com.linkedin.thirdeye.datalayer.dto.AlertConfigDTO)1 AnomalyFunctionDTO (com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO)1 DashboardConfigDTO (com.linkedin.thirdeye.datalayer.dto.DashboardConfigDTO)1 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)1 EmailConfigurationDTO (com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO)1 MetricConfigDTO (com.linkedin.thirdeye.datalayer.dto.MetricConfigDTO)1 OverrideConfigBean (com.linkedin.thirdeye.datalayer.pojo.OverrideConfigBean)1 ScalingFactor (com.linkedin.thirdeye.detector.metric.transfer.ScalingFactor)1 HashSet (java.util.HashSet)1 WebApplicationException (javax.ws.rs.WebApplicationException)1