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;
}
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;
}
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();
}
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();
}
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;
}
Aggregations