/** * Constructor. * * @param value String that was not able to be parsed into a Granularity. */ public GranularityParseException(String value) { super(UNKNOWN_GRANULARITY.format(value)); } }
@Override public String getMessage() { return PAGINATION_PAGE_INVALID.format(page, rowsPerPage, lastPage); }
@Override public LookbackQuery withPostAggregations(Collection<PostAggregation> postAggregations) { throw new UnsupportedOperationException(ErrorMessageFormat.UNSUPPORTED_LOOKBACKQUERY_OPERATION.format()); }
/** * Returns a merge function, suitable for use in * {@link java.util.Map#merge(Object, Object, java.util.function.BiFunction) Map.merge()} or * {@link Collectors#toMap(Function, Function, BinaryOperator) toMap()}, which always * throws {@code IllegalStateException}. This can be used to enforce the * assumption that the elements being collected are distinct. * * @param <T> the type of input arguments to the merge function * * @return a merge function which always throw {@code IllegalStateException} * @see Collectors#throwingMerger() */ public static <T> BinaryOperator<T> throwingMerger() { return (u, v) -> { throw new IllegalStateException(TWO_VALUES_OF_THE_SAME_KEY.format(u, v)); }; }
/** * Deletes a directory and all entries under that directory. * * @param path The location of the directory that is to be deleted */ private static void deleteDir(String path) { try { FileUtils.deleteDirectory(new File(path)); } catch (IOException e) { String message = ErrorMessageFormat.UNABLE_TO_DELETE_DIR.format(path); LOG.error(message); throw new RuntimeException(message); } }
/** * An internal-only constructor that provides the jobId directly, used by the copy-and-modify methods. * * @param jobId The unique identifier for this job * @param fieldValueMap The metadata about this job * * @throws IllegalArgumentException if jobId is not a key in fieldValueMap */ protected JobRow(@NotNull String jobId, Map<JobField, String> fieldValueMap) { super(fieldValueMap); if (jobId == null) { LOG.error(String.format(ErrorMessageFormat.MISSING_JOB_ID.getLoggingFormat(), fieldValueMap)); throw new IllegalArgumentException(ErrorMessageFormat.MISSING_JOB_ID.format(fieldValueMap)); } this.jobId = jobId; }
/** * Returns the Left value wrapped in this Either. * * @return The Left value wrapped in this Either * * @throws UnsupportedOperationException If this Either wraps a Right value instead */ public L getLeft() { if (!isLeft()) { LOG.error(String.format(ErrorMessageFormat.EITHER_ERROR_LEFT_OF_RIGHT.getLoggingFormat(), this)); throw new UnsupportedOperationException(ErrorMessageFormat.EITHER_ERROR_LEFT_OF_RIGHT.format(this)); } return left; }
@Override public void serialize(Dimension value, JsonGenerator gen, SerializerProvider provider) throws IOException { gen.writeString( SerializerUtil.findPhysicalName(value, gen).orElseThrow(() -> { LOG.error(ErrorMessageFormat.PHYSICAL_NAME_NOT_FOUND.logFormat(value.getApiName())); return new IllegalStateException(ErrorMessageFormat.PHYSICAL_NAME_NOT_FOUND.format()); } ) ); } }
@Override public void validateDuplicateMetrics(ArrayNode metricsJsonArray) { Set<String> metricsList = new HashSet<>(); List<String> duplicateMetrics = new ArrayList<>(); for (int i = 0; i < metricsJsonArray.size(); i++) { String metricName = metricsJsonArray.get(i).get("name").asText(); boolean status = metricsList.add(metricName); if (!status) { duplicateMetrics.add(metricName); } } if (!duplicateMetrics.isEmpty()) { LOG.debug(DUPLICATE_METRICS_IN_API_REQUEST.logFormat(duplicateMetrics.toString())); throw new BadApiRequestException(DUPLICATE_METRICS_IN_API_REQUEST.format(duplicateMetrics.toString())); } }
@Override public NoMatchFoundException noneFoundException() { LOG.error(MESSAGE_FORMAT.logFormat(logicalTableName, requestIntervals)); return new NoMatchFoundException(MESSAGE_FORMAT.format(logicalTableName, requestIntervals)); } }
/** * Returns the Right value wrapped in this Either. * * @return The Right value wrapped in this Either * * @throws UnsupportedOperationException If this Either wraps a Left value instead */ public R getRight() { if (isLeft()) { LOG.error(String.format(ErrorMessageFormat.EITHER_ERROR_RIGHT_OF_LEFT.getLoggingFormat(), this)); throw new UnsupportedOperationException(ErrorMessageFormat.EITHER_ERROR_RIGHT_OF_LEFT.format(this)); } return right; } }
@Override public NoMatchFoundException noneFoundException() { Set<String> aggDimensions = requestConstraint.getRequestDimensions().stream() .filter(Dimension::isAggregatable) .map(Dimension::getApiName) .collect(Collectors.toSet()); Set<String> nonAggDimensions = requestConstraint.getRequestDimensions().stream() .filter(StreamUtils.not(Dimension::isAggregatable)) .map(Dimension::getApiName) .collect(Collectors.toSet()); LOG.error(MESSAGE_FORMAT.logFormat(nonAggDimensions, aggDimensions)); return new NoMatchFoundException(MESSAGE_FORMAT.format(nonAggDimensions, aggDimensions)); } }
/** * Logs and gets error call back on the response with the provided error message. * * @param message The error message passed to the logger and the exception * @param query The query with the schema for processing this response */ private void logAndGetErrorCallback(String message, DruidAggregationQuery<?> query) { LOG.error(message); getErrorCallback(query).dispatch( INTERNAL_SERVER_ERROR.getStatusCode(), ErrorMessageFormat.INTERNAL_SERVER_ERROR_REASON_PHRASE.format(), message ); } }
/** * Verifies that the passed parameter is greater than 0. * * @param parameter The parameter to be validated. * @param parameterName The name of the parameter to appear in the error message * * @throws BadPaginationException if 'parameter' is not greater than 0. */ private static void validate(int parameter, String parameterName) throws BadPaginationException { if (parameter < MINIMAL_VALUE) { ErrorMessageFormat errorMessage = ErrorMessageFormat.PAGINATION_PARAMETER_INVALID; LOG.debug(errorMessage.logFormat(parameterName, parameter)); throw new BadPaginationException(errorMessage.format(parameterName, parameter)); } }
/** * Method to get dimension from DimensionDictionary for a given name. * * @param dimensionName To find Dimension from dimension dictionary * * @return The dimension with the given name */ private Dimension resolveDimensionName(String dimensionName) { Dimension dimension = dimensionDictionary.findByApiName(dimensionName); if (dimension == null) { String msg = ErrorMessageFormat.UNABLE_TO_FIND_DIMENSION_FROM_DICTIONARY.format(dimensionName); LOG.error(msg); throw new DeserializationException(msg); } return dimension; }
/** * Constructor. * * @param physicalTable The physical table of the data source. It must have only 1 backing data source. */ public TableDataSource(ConstrainedTable physicalTable) { super(DefaultDataSourceType.TABLE, physicalTable); if (physicalTable.getDataSourceNames().size() > 1) { LOG.error(TOO_MANY_BACKING_DATA_SOURCES.logFormat(getPhysicalTable())); throw new IllegalArgumentException(TOO_MANY_BACKING_DATA_SOURCES.format(getPhysicalTable())); } }
public String getName() { return getPhysicalTable().getDataSourceNames().stream().findFirst() .orElseThrow(() -> { LOG.error(TOO_FEW_BACKING_DATA_SOURCES.logFormat(getPhysicalTable())); return new IllegalArgumentException(TOO_FEW_BACKING_DATA_SOURCES.format(getPhysicalTable())); }).asName(); }
@Override public void serialize(Dimension value, JsonGenerator gen, SerializerProvider provider) throws IOException { String apiName = value.getApiName(); String physicalName = SerializerUtil.findPhysicalName(value, gen).orElseThrow(() -> { LOG.error(ErrorMessageFormat.PHYSICAL_NAME_NOT_FOUND.logFormat(value.getApiName())); return new IllegalStateException(ErrorMessageFormat.PHYSICAL_NAME_NOT_FOUND.format()); } ); // serialize to only apiName if api and physical name is same or there are nested queries if (physicalName.equals(apiName) || SerializerUtil.hasInnerQuery(gen)) { gen.writeString(apiName); } else { gen.writeObject(new DefaultDimensionSpec(physicalName, apiName, value)); } } }
/** * Returns an Observable over the Map representing the job to be returned to the user. * * @param ticket The ticket that uniquely identifies the job * * @return An Observable over the Map representing the job to be returned to the user or an Observable wrapping * JobNotFoundException if the Job is not available in the ApiJobStore */ public Observable<Map<String, String>> getJobViewObservable(String ticket) { return apiJobStore.get(ticket) .switchIfEmpty( Observable.error(new JobNotFoundException(ErrorMessageFormat.JOB_NOT_FOUND.format(ticket))) ) .map(jobRow -> jobPayloadBuilder.buildPayload(jobRow, uriInfo)); }
@Override public NoMatchFoundException noneFoundException() { String logicalTableName = requestConstraint.getLogicalTable().getName(); Set<String> logicalMetrics = requestConstraint.getLogicalMetricNames(); Set<String> dimensions = requestConstraint.getAllDimensionNames(); String grainName = requestConstraint.getMinimumGranularity().getName(); LOG.error(MESSAGE_FORMAT.logFormat(logicalTableName, dimensions, logicalMetrics, grainName)); return new NoMatchFoundException( MESSAGE_FORMAT.format(logicalTableName, dimensions, logicalMetrics, grainName)); } }