/** * 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; }
@Override public void onError(Throwable error) { if (error instanceof ResponseException) { ResponseException responseException = (ResponseException) error; send(buildErrorResponse(responseException), asyncResponse); } else { LOG.error(ErrorMessageFormat.FAILED_TO_PUBLISH_ERROR.getMessageFormat(), error); throw new RuntimeException(ErrorMessageFormat.FAILED_TO_PUBLISH_ERROR.getMessageFormat(), error); } }
/** * Constructor. * * @param value String that was not able to be parsed into a Granularity. */ public GranularityParseException(String value) { super(UNKNOWN_GRANULARITY.format(value)); } }
public String getLogMessage() { return PAGINATION_PAGE_INVALID.logFormat(page, rowsPerPage, lastPage); }
@Override public String getMessage() { return PAGINATION_PAGE_INVALID.format(page, rowsPerPage, lastPage); }
/** * Log an error message and throw an exception for an unsupported query type. * * @param queryType The query type that is not supported */ private void unsupportedQueryType(QueryType queryType) { String msg = RESULT_SET_ERROR.logFormat(queryType); LOG.error(msg); throw new UnsupportedOperationException(msg); }
/** * 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)); } }
@Override public LookbackQuery withPostAggregations(Collection<PostAggregation> postAggregations) { throw new UnsupportedOperationException(ErrorMessageFormat.UNSUPPORTED_LOOKBACKQUERY_OPERATION.format()); }
/** * Confirm count size is non negative. * * @param countRequest The value of the count from the request (if any) * @param count The bound value for the count */ protected void validateCount(String countRequest, int count) { // This is the validation part for count that is inlined here because currently it is very brief. if (count < 0) { LOG.debug(INTEGER_INVALID.logFormat(countRequest, "count")); throw new BadApiRequestException(INTEGER_INVALID.logFormat(countRequest, "count")); } } /**
/** * 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()); } ) ); } }
/** * 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)); }; }
/** * Parses the requested input String by converting it to an integer, while treating null as zero. * * @param value The requested integer value as String. * @param parameterName The parameter name that corresponds to the requested integer value. * * @return The integer corresponding to {@code value} or zero if {@code value} is null. * @throws BadApiRequestException if the input String can not be parsed as an integer. */ protected int generateInteger(String value, String parameterName) throws BadApiRequestException { try { return value == null ? 0 : Integer.parseInt(value); } catch (NumberFormatException nfe) { LOG.debug(INTEGER_INVALID.logFormat(value, parameterName), nfe); throw new BadApiRequestException(INTEGER_INVALID.logFormat(value, parameterName), nfe); } }
/** * 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; } }
/** * Confirm the top N bucket size (if any) is valid. * * @param topNRequest The value of the count from the request (if any) * @param sorts collection of sorted columns * @param topN The bound value for the count */ protected void validateTopN(String topNRequest, int topN, LinkedHashSet<OrderByColumn> sorts) { // This is the validation part for topN that is inlined here because currently it is very brief. if (topN < 0) { LOG.debug(INTEGER_INVALID.logFormat(topNRequest, "topN")); throw new BadApiRequestException(INTEGER_INVALID.logFormat(topNRequest, "topN")); } else if (topN > 0 && this.sorts.isEmpty()) { LOG.debug(TOP_N_UNSORTED.logFormat(topNRequest)); throw new BadApiRequestException(TOP_N_UNSORTED.format(topNRequest)); } }
/** * 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); } }
/** * Extracts the metric to be examined from the having tokenizedQuery. * * @param tokenizedQuery The parsed "having" tokenizedQuery. * @param metricDictionary The cache containing all the valid metric objects. * * @return The metric to be examined. * @throws BadHavingException If the metric does not exist. */ private LogicalMetric extractMetric( Matcher tokenizedQuery, Map<String, LogicalMetric> metricDictionary ) throws BadHavingException { String metricName = tokenizedQuery.group(1); LogicalMetric extractedMetric = metricDictionary.get(metricName); if (extractedMetric == null) { LOG.debug(HAVING_METRIC_UNDEFINED.logFormat(metricName)); throw new BadHavingException(HAVING_METRIC_UNDEFINED.logFormat(metricName)); } return extractedMetric; }
/** * Bind the table name against a Logical table in the table dictionary. * * @param tableName Name of the logical table from the query * @param table The bound logical table for this query * @param granularity The granularity for this request * @param logicalTableDictionary Dictionary to resolve logical tables against. * * @throws BadApiRequestException if invalid */ protected void validateLogicalTable( String tableName, LogicalTable table, Granularity granularity, LogicalTableDictionary logicalTableDictionary ) throws BadApiRequestException { if (table == null) { LOG.debug(TABLE_UNDEFINED.logFormat(tableName)); throw new BadApiRequestException(TABLE_UNDEFINED.format(tableName)); } }
/** * Custom serialization for ResponseContext object. * * @param responseContext ResponseContext object to be serialized * @param responseContextMapper objectMapper instance which preservers object types * * @return Serialized responseContext */ private String getSerializedResponseContext(ResponseContext responseContext, ObjectMapper responseContextMapper) { try { return responseContextMapper.writeValueAsString(responseContext); } catch (JsonProcessingException e) { String msg = ErrorMessageFormat.UNABLE_TO_SERIALIZE.format("ResponseContext"); LOG.error(msg, e); throw new DeserializationException(msg, e); } } }