use of javax.ws.rs.Path in project pinot by linkedin.
the class EmailResource method addFunctionInEmail.
@POST
@Path("{emailId}/add/{functionId}")
public void addFunctionInEmail(@PathParam("emailId") Long emailId, @PathParam("functionId") Long functionId) {
AnomalyFunctionDTO function = functionDAO.findById(functionId);
EmailConfigurationDTO emailConfiguration = emailDAO.findById(emailId);
List<EmailConfigurationDTO> emailConfigurationsWithFunction = emailDAO.findByFunctionId(functionId);
for (EmailConfigurationDTO emailConfigurationDTO : emailConfigurationsWithFunction) {
emailConfigurationDTO.getFunctions().remove(function);
emailDAO.update(emailConfigurationDTO);
}
if (function != null && emailConfiguration != null) {
if (!emailConfiguration.getFunctions().contains(function)) {
emailConfiguration.getFunctions().add(function);
emailDAO.update(emailConfiguration);
}
} else {
throw new IllegalArgumentException("function or email not found for email : " + emailId + " function : " + functionId);
}
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class EmailResource method generateAndSendAlertForDatasets.
// TODO : add end points for AlertConfig
@GET
@Path("generate/datasets/{startTime}/{endTime}")
public Response generateAndSendAlertForDatasets(@PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime, @QueryParam("datasets") String datasets, @QueryParam("from") String fromAddr, @QueryParam("to") String toAddr, @QueryParam("subject") String subject, @QueryParam("includeSentAnomaliesOnly") boolean includeSentAnomaliesOnly, @QueryParam("teHost") String teHost, @QueryParam("smtpHost") String smtpHost, @QueryParam("smtpPort") int smtpPort) {
if (Strings.isNullOrEmpty(datasets)) {
throw new WebApplicationException("datasets null or empty : " + datasets);
}
String[] dataSetArr = datasets.split(",");
if (dataSetArr.length == 0) {
throw new WebApplicationException("Datasets empty : " + datasets);
}
if (Strings.isNullOrEmpty(toAddr)) {
throw new WebApplicationException("Empty : list of recipients" + toAddr);
}
if (Strings.isNullOrEmpty(teHost)) {
throw new WebApplicationException("Invalid TE host" + teHost);
}
if (Strings.isNullOrEmpty(smtpHost)) {
throw new WebApplicationException("invalid smtp host" + smtpHost);
}
AnomalyReportGenerator anomalyReportGenerator = AnomalyReportGenerator.getInstance();
List<MergedAnomalyResultDTO> anomalies = anomalyReportGenerator.getAnomaliesForDatasets(Arrays.asList(dataSetArr), startTime, endTime);
ThirdEyeAnomalyConfiguration configuration = new ThirdEyeAnomalyConfiguration();
SmtpConfiguration smtpConfiguration = new SmtpConfiguration();
smtpConfiguration.setSmtpHost(smtpHost);
smtpConfiguration.setSmtpPort(smtpPort);
configuration.setSmtpConfiguration(smtpConfiguration);
configuration.setDashboardHost(teHost);
configuration.setPhantomJsPath(thirdeyeConfiguration.getPhantomJsPath());
configuration.setRootDir(thirdeyeConfiguration.getRootDir());
String emailSub = Strings.isNullOrEmpty(subject) ? "Thirdeye Anomaly Report" : subject;
anomalyReportGenerator.buildReport(startTime, endTime, anomalies, emailSub, configuration, includeSentAnomaliesOnly, toAddr, fromAddr, "Thirdeye Anomaly Report", true);
return Response.ok().build();
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class IngraphDashboardConfigResource method updateDashboardConfig.
@GET
@Path("/update")
public String updateDashboardConfig(@NotNull @QueryParam("id") long ingraphDashboardConfigId, @QueryParam("name") String name, @QueryParam("fabricGroup") String fabricGroup, @QueryParam("active") boolean active, @QueryParam("bootstrap") boolean bootstrap, @QueryParam("fromIngraphDashboard") boolean fromIngraphDashboard, @QueryParam("startTime") String bootstrapStartTime, @QueryParam("endTime") String bootstrapEndTime, @QueryParam("fetchIntervalPeriod") String fetchIntervalPeriod, @QueryParam("mergeNumAvroRecords") String mergeNumAvroRecords, @QueryParam("granularitySize") String granularitySize, @QueryParam("granularityUnit") String granularityUnit) {
try {
IngraphDashboardConfigDTO ingraphDashboardConfigDTO = ingraphDashboardConfigDAO.findById(ingraphDashboardConfigId);
ingraphDashboardConfigDTO.setName(name);
ingraphDashboardConfigDTO.setFabricGroup(fabricGroup);
if (StringUtils.isNotBlank(fetchIntervalPeriod)) {
ingraphDashboardConfigDTO.setFetchIntervalPeriod(Long.valueOf(fetchIntervalPeriod));
}
if (StringUtils.isNotBlank(mergeNumAvroRecords)) {
ingraphDashboardConfigDTO.setMergeNumAvroRecords(Integer.valueOf(mergeNumAvroRecords));
}
if (StringUtils.isNotBlank(granularitySize)) {
ingraphDashboardConfigDTO.setGranularitySize(Integer.valueOf(granularitySize));
}
if (StringUtils.isNotBlank(granularityUnit)) {
ingraphDashboardConfigDTO.setGranularityUnit(TimeUnit.valueOf(granularityUnit));
}
Boolean isActive = Boolean.valueOf(active);
ingraphDashboardConfigDTO.setActive(isActive);
Boolean isFromIngraphDashboard = Boolean.valueOf(fromIngraphDashboard);
ingraphDashboardConfigDTO.setFromIngraphDashboard(isFromIngraphDashboard);
Boolean needBootstrap = Boolean.valueOf(bootstrap);
ingraphDashboardConfigDTO.setBootstrap(needBootstrap);
if (needBootstrap) {
long startTimeInMs = sdf.parse(bootstrapStartTime).getTime();
long endTimeInMs = sdf.parse(bootstrapEndTime).getTime();
ingraphDashboardConfigDTO.setBootstrapStartTime(startTimeInMs);
ingraphDashboardConfigDTO.setBootstrapEndTime(endTimeInMs);
}
int numRowsUpdated = ingraphDashboardConfigDAO.update(ingraphDashboardConfigDTO);
if (numRowsUpdated == 1) {
return JsonResponseUtil.buildResponseJSON(ingraphDashboardConfigDTO).toString();
} else {
return JsonResponseUtil.buildErrorResponseJSON("Failed to update dashboard id:" + ingraphDashboardConfigId).toString();
}
} catch (Exception e) {
return JsonResponseUtil.buildErrorResponseJSON("Failed to update dashboard id:" + ingraphDashboardConfigId + ". Exception:" + e.getMessage()).toString();
}
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class AnomaliesResource method getAnomalyDataCompareResults.
@GET
@Path("/{anomalyId}")
public AnomalyDataCompare.Response getAnomalyDataCompareResults(@PathParam("anomalyId") Long anomalyId) {
MergedAnomalyResultDTO anomaly = mergedAnomalyResultDAO.findById(anomalyId);
if (anomaly == null) {
LOG.error("Anomaly not found with id " + anomalyId);
throw new IllegalArgumentException("Anomaly not found with id " + anomalyId);
}
AnomalyDataCompare.Response response = new AnomalyDataCompare.Response();
response.setCurrentStart(anomaly.getStartTime());
response.setCurrenEnd(anomaly.getEndTime());
try {
DatasetConfigDTO dataset = datasetConfigDAO.findByDataset(anomaly.getCollection());
TimeGranularity granularity = new TimeGranularity(dataset.getTimeDuration(), dataset.getTimeUnit());
// Lets compute currentTimeRange
Pair<Long, Long> currentTmeRange = new Pair<>(anomaly.getStartTime(), anomaly.getEndTime());
MetricTimeSeries ts = TimeSeriesUtil.getTimeSeriesByDimension(anomaly.getFunction(), Arrays.asList(currentTmeRange), anomaly.getDimensions(), granularity, false);
double currentVal = getTotalFromTimeSeries(ts, dataset.isAdditive());
response.setCurrentVal(currentVal);
for (AlertConfigBean.COMPARE_MODE compareMode : AlertConfigBean.COMPARE_MODE.values()) {
long baselineOffset = EmailHelper.getBaselineOffset(compareMode);
Pair<Long, Long> baselineTmeRange = new Pair<>(anomaly.getStartTime() - baselineOffset, anomaly.getEndTime() - baselineOffset);
MetricTimeSeries baselineTs = TimeSeriesUtil.getTimeSeriesByDimension(anomaly.getFunction(), Arrays.asList(baselineTmeRange), anomaly.getDimensions(), granularity, false);
AnomalyDataCompare.CompareResult cr = new AnomalyDataCompare.CompareResult();
double baseLineval = getTotalFromTimeSeries(baselineTs, dataset.isAdditive());
cr.setBaselineValue(baseLineval);
cr.setCompareMode(compareMode);
cr.setChange(calculateChange(currentVal, baseLineval));
response.getCompareResults().add(cr);
}
} catch (Exception e) {
LOG.error("Error fetching the timeseries data from pinot", e);
throw new RuntimeException(e);
}
return response;
}
use of javax.ws.rs.Path in project pinot by linkedin.
the class AnomaliesResource method getAnomaliesByAnomalyIds.
/**
* Find anomalies by anomaly ids
* @param startTime
* @param endTime
* @param anomalyIdsString
* @param functionName
* @return
* @throws Exception
*/
@GET
@Path("search/anomalyIds/{startTime}/{endTime}/{pageNumber}")
public AnomaliesWrapper getAnomaliesByAnomalyIds(@PathParam("startTime") Long startTime, @PathParam("endTime") Long endTime, @PathParam("pageNumber") int pageNumber, @QueryParam("anomalyIds") String anomalyIdsString, @QueryParam("functionName") String functionName) throws Exception {
String[] anomalyIds = anomalyIdsString.split(COMMA_SEPARATOR);
List<MergedAnomalyResultDTO> mergedAnomalies = new ArrayList<>();
for (String id : anomalyIds) {
Long anomalyId = Long.valueOf(id);
MergedAnomalyResultDTO anomaly = mergedAnomalyResultDAO.findById(anomalyId);
if (anomaly != null) {
mergedAnomalies.add(anomaly);
}
}
AnomaliesWrapper anomaliesWrapper = constructAnomaliesWrapperFromMergedAnomalies(mergedAnomalies, pageNumber);
return anomaliesWrapper;
}
Aggregations