use of javax.ws.rs.WebApplicationException in project quickstarts by jboss-switchyard.
the class MyClientErrorInterceptor method handle.
public void handle(ClientResponse response) throws RuntimeException {
try {
BaseClientResponse r = (BaseClientResponse) response;
InputStream stream = r.getStreamFactory().getInputStream();
if (stream != null) {
stream.reset();
}
if ((response.getResponseStatus() != null) && (response.getResponseStatus().getStatusCode() == 404) && !(r.getException() instanceof ItemNotFoundException)) {
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new ApiError("Error at " + response.getHeaders().get("full-path"))).build());
}
} catch (IOException e) {
//...
}
}
use of javax.ws.rs.WebApplicationException 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.WebApplicationException 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 javax.ws.rs.WebApplicationException in project pinot by linkedin.
the class DataResource method getFiltersForMetric.
@GET
@Path("autocomplete/filters/metric/{metricId}")
public Map<String, List<String>> getFiltersForMetric(@PathParam("metricId") Long metricId) {
Map<String, List<String>> filterMap = new HashMap<>();
try {
// TODO : cache this
MetricConfigDTO metricConfigDTO = metricConfigDAO.findById(metricId);
DatasetConfigDTO datasetConfigDTO = datasetConfigDAO.findByDataset(metricConfigDTO.getDataset());
String dimensionFiltersJson = dimensionsFilterCache.get(datasetConfigDTO.getDataset());
if (!Strings.isNullOrEmpty(dimensionFiltersJson)) {
filterMap = OBJECT_MAPPER.readValue(dimensionFiltersJson, LinkedHashMap.class);
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new WebApplicationException(e);
}
return filterMap;
}
use of javax.ws.rs.WebApplicationException in project pinot by linkedin.
the class TimeSeriesResource method getContributorDataForDimension.
private TimeSeriesCompareMetricView getContributorDataForDimension(long metricId, long currentStart, long currentEnd, long baselineStart, long baselineEnd, String dimension, String filters, String granularity) {
MetricConfigDTO metricConfigDTO = metricConfigDAO.findById(metricId);
TimeSeriesCompareMetricView timeSeriesCompareMetricView = new TimeSeriesCompareMetricView(metricConfigDTO.getName(), metricId, currentStart, currentEnd);
try {
String dataset = metricConfigDTO.getDataset();
ContributorViewRequest request = new ContributorViewRequest();
request.setCollection(dataset);
MetricExpression metricExpression = ThirdEyeUtils.getMetricExpressionFromMetricConfig(metricConfigDTO);
request.setMetricExpressions(Arrays.asList(metricExpression));
DateTimeZone timeZoneForCollection = Utils.getDataTimeZone(dataset);
request.setBaselineStart(new DateTime(baselineStart, timeZoneForCollection));
request.setBaselineEnd(new DateTime(baselineEnd, timeZoneForCollection));
request.setCurrentStart(new DateTime(currentStart, timeZoneForCollection));
request.setCurrentEnd(new DateTime(currentEnd, timeZoneForCollection));
request.setTimeGranularity(Utils.getAggregationTimeGranularity(granularity, dataset));
if (filters != null && !filters.isEmpty()) {
filters = URLDecoder.decode(filters, "UTF-8");
request.setFilters(ThirdEyeUtils.convertToMultiMap(filters));
}
request.setGroupByDimensions(Arrays.asList(dimension));
ContributorViewHandler handler = new ContributorViewHandler(queryCache);
ContributorViewResponse response = handler.process(request);
// Assign the time buckets
List<Long> timeBucketsCurrent = new ArrayList<>();
List<Long> timeBucketsBaseline = new ArrayList<>();
timeSeriesCompareMetricView.setTimeBucketsCurrent(timeBucketsCurrent);
timeSeriesCompareMetricView.setTimeBucketsBaseline(timeBucketsBaseline);
Map<String, ValuesContainer> subDimensionValuesMap = new LinkedHashMap<>();
timeSeriesCompareMetricView.setSubDimensionContributionMap(subDimensionValuesMap);
int timeBuckets = response.getTimeBuckets().size();
// this is for over all values
ValuesContainer vw = new ValuesContainer();
subDimensionValuesMap.put(ALL, vw);
vw.setCurrentValues(new double[timeBuckets]);
vw.setBaselineValues(new double[timeBuckets]);
vw.setPercentageChange(new String[timeBuckets]);
vw.setCumulativeCurrentValues(new double[timeBuckets]);
vw.setCumulativeBaselineValues(new double[timeBuckets]);
vw.setCumulativePercentageChange(new String[timeBuckets]);
// lets find the indices
int subDimensionIndex = response.getResponseData().getSchema().getColumnsToIndexMapping().get("dimensionValue");
int currentValueIndex = response.getResponseData().getSchema().getColumnsToIndexMapping().get("currentValue");
int baselineValueIndex = response.getResponseData().getSchema().getColumnsToIndexMapping().get("baselineValue");
int percentageChangeIndex = response.getResponseData().getSchema().getColumnsToIndexMapping().get("percentageChange");
int cumCurrentValueIndex = response.getResponseData().getSchema().getColumnsToIndexMapping().get("cumulativeCurrentValue");
int cumBaselineValueIndex = response.getResponseData().getSchema().getColumnsToIndexMapping().get("cumulativeBaselineValue");
int cumPercentageChangeIndex = response.getResponseData().getSchema().getColumnsToIndexMapping().get("cumulativePercentageChange");
// populate current and baseline time buckets
for (int i = 0; i < timeBuckets; i++) {
TimeBucket tb = response.getTimeBuckets().get(i);
timeBucketsCurrent.add(tb.getCurrentStart());
timeBucketsBaseline.add(tb.getBaselineStart());
}
// set current and baseline values for sub dimensions
for (int i = 0; i < response.getResponseData().getResponseData().size(); i++) {
String[] data = response.getResponseData().getResponseData().get(i);
String subDimension = data[subDimensionIndex];
Double currentVal = Double.valueOf(data[currentValueIndex]);
Double baselineVal = Double.valueOf(data[baselineValueIndex]);
Double percentageChangeVal = Double.valueOf(data[percentageChangeIndex]);
Double cumCurrentVal = Double.valueOf(data[cumCurrentValueIndex]);
Double cumBaselineVal = Double.valueOf(data[cumBaselineValueIndex]);
Double cumPercentageChangeVal = Double.valueOf(data[cumPercentageChangeIndex]);
int index = i % timeBuckets;
// set overAll values
vw.getCurrentValues()[index] += currentVal;
vw.getBaselineValues()[index] += baselineVal;
vw.getCumulativeCurrentValues()[index] += cumCurrentVal;
vw.getCumulativeBaselineValues()[index] += cumBaselineVal;
// set individual sub-dimension values
if (!subDimensionValuesMap.containsKey(subDimension)) {
ValuesContainer subDimVals = new ValuesContainer();
subDimVals.setCurrentValues(new double[timeBuckets]);
subDimVals.setBaselineValues(new double[timeBuckets]);
subDimVals.setPercentageChange(new String[timeBuckets]);
subDimVals.setCumulativeCurrentValues(new double[timeBuckets]);
subDimVals.setCumulativeBaselineValues(new double[timeBuckets]);
subDimVals.setCumulativePercentageChange(new String[timeBuckets]);
subDimensionValuesMap.put(subDimension, subDimVals);
}
subDimensionValuesMap.get(subDimension).getCurrentValues()[index] = currentVal;
subDimensionValuesMap.get(subDimension).getBaselineValues()[index] = baselineVal;
subDimensionValuesMap.get(subDimension).getPercentageChange()[index] = String.format(DECIMAL_FORMAT, percentageChangeVal);
subDimensionValuesMap.get(subDimension).getCumulativeCurrentValues()[index] = cumCurrentVal;
subDimensionValuesMap.get(subDimension).getCumulativeBaselineValues()[index] = cumBaselineVal;
subDimensionValuesMap.get(subDimension).getCumulativePercentageChange()[index] = String.format(DECIMAL_FORMAT, cumPercentageChangeVal);
}
// TODO : compute cumulative values for all
for (int i = 0; i < vw.getCurrentValues().length; i++) {
vw.getPercentageChange()[i] = String.format(DECIMAL_FORMAT, getPercentageChange(vw.getCurrentValues()[i], vw.getBaselineValues()[i]));
vw.getCumulativePercentageChange()[i] = String.format(DECIMAL_FORMAT, getPercentageChange(vw.getCumulativeCurrentValues()[i], vw.getCumulativeBaselineValues()[i]));
}
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new WebApplicationException(e);
}
return timeSeriesCompareMetricView;
}
Aggregations