Search in sources :

Example 91 with Path

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);
    }
}
Also used : AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) EmailConfigurationDTO(com.linkedin.thirdeye.datalayer.dto.EmailConfigurationDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 92 with Path

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();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) SmtpConfiguration(com.linkedin.thirdeye.anomaly.SmtpConfiguration) AnomalyReportGenerator(com.linkedin.thirdeye.anomaly.alert.util.AnomalyReportGenerator) ThirdEyeAnomalyConfiguration(com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 93 with Path

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();
    }
}
Also used : IngraphDashboardConfigDTO(com.linkedin.thirdeye.datalayer.dto.IngraphDashboardConfigDTO) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 94 with Path

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;
}
Also used : AlertConfigBean(com.linkedin.thirdeye.datalayer.pojo.AlertConfigBean) MetricTimeSeries(com.linkedin.thirdeye.api.MetricTimeSeries) TimeoutException(java.util.concurrent.TimeoutException) JSONException(org.json.JSONException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeSeriesResponse(com.linkedin.thirdeye.client.timeseries.TimeSeriesResponse) DatasetConfigDTO(com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) TimeGranularity(com.linkedin.thirdeye.api.TimeGranularity) AnomalyDataCompare(com.linkedin.thirdeye.dashboard.resources.v2.pojo.AnomalyDataCompare) Pair(com.linkedin.pinot.pql.parsers.utils.Pair) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 95 with Path

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;
}
Also used : MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) ArrayList(java.util.ArrayList) AnomaliesWrapper(com.linkedin.thirdeye.dashboard.resources.v2.pojo.AnomaliesWrapper) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Path (javax.ws.rs.Path)6273 Produces (javax.ws.rs.Produces)3678 GET (javax.ws.rs.GET)3072 POST (javax.ws.rs.POST)1783 Consumes (javax.ws.rs.Consumes)1440 ApiOperation (io.swagger.annotations.ApiOperation)1213 ApiResponses (io.swagger.annotations.ApiResponses)997 PUT (javax.ws.rs.PUT)850 IOException (java.io.IOException)677 DELETE (javax.ws.rs.DELETE)662 ArrayList (java.util.ArrayList)591 WebApplicationException (javax.ws.rs.WebApplicationException)556 Response (javax.ws.rs.core.Response)540 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)490 HashMap (java.util.HashMap)394 Timed (com.codahale.metrics.annotation.Timed)383 URI (java.net.URI)374 List (java.util.List)287 Map (java.util.Map)259 NotFoundException (javax.ws.rs.NotFoundException)258