Search in sources :

Example 6 with MismatchedInputException

use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project alluxio by Alluxio.

the class Benchmark method processMethodProfiles.

/**
 * @param startMs the start time
 * @param endMs the end time
 * @param nameTransformer function which transforms the type and method into a name. If the
 *                        function returns null, then the method is skipped
 * @return a map of names to statistics
 */
@SuppressFBWarnings(value = "DMI_HARDCODED_ABSOLUTE_FILENAME")
protected Map<String, MethodStatistics> processMethodProfiles(long startMs, long endMs, Function<ProfileInput, String> nameTransformer) throws IOException {
    Map<String, MethodStatistics> nameStatistics = new HashMap<>();
    try (final BufferedReader reader = new BufferedReader(new FileReader(BaseParameters.AGENT_OUTPUT_PATH))) {
        String line;
        long bucketSize = (endMs - startMs) / StressConstants.MAX_TIME_COUNT;
        final ObjectMapper objectMapper = new ObjectMapper();
        while ((line = reader.readLine()) != null) {
            final Map<String, Object> lineMap;
            try {
                lineMap = objectMapper.readValue(line, Map.class);
            } catch (JsonParseException | MismatchedInputException e) {
                // skip the last line of a not completed file
                break;
            }
            final String type = (String) lineMap.get("type");
            final String methodName = (String) lineMap.get("methodName");
            final Number timestampNumber = (Number) lineMap.get("timestamp");
            final Number durationNumber = (Number) lineMap.get("duration");
            final Boolean ttfbFlag = (Boolean) lineMap.get("ttfb");
            if (type == null || methodName == null || timestampNumber == null || durationNumber == null || ttfbFlag == null) {
                continue;
            }
            final long timestamp = timestampNumber.longValue();
            final long duration = durationNumber.longValue();
            final boolean ttfb = ttfbFlag.booleanValue();
            if (timestamp <= startMs) {
                continue;
            }
            ProfileInput profileInput = new ProfileInput(type, methodName, ttfb);
            final String name = nameTransformer.apply(profileInput);
            if (name == null) {
                continue;
            }
            if (!nameStatistics.containsKey(name)) {
                nameStatistics.put(name, new MethodStatistics());
            }
            final MethodStatistics statistic = nameStatistics.get(name);
            statistic.mTimeNs.recordValue(duration);
            statistic.mNumSuccess += 1;
            int bucket = Math.min(statistic.mMaxTimeNs.length - 1, (int) ((timestamp - startMs) / bucketSize));
            statistic.mMaxTimeNs[bucket] = Math.max(statistic.mMaxTimeNs[bucket], duration);
        }
    }
    return nameStatistics;
}
Also used : HashMap(java.util.HashMap) JsonParseException(com.fasterxml.jackson.core.JsonParseException) BufferedReader(java.io.BufferedReader) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) FileReader(java.io.FileReader) HashMap(java.util.HashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SuppressFBWarnings(alluxio.annotation.SuppressFBWarnings)

Example 7 with MismatchedInputException

use of com.fasterxml.jackson.databind.exc.MismatchedInputException in project dhis2-core by dhis2.

the class SystemSetting method convertValueToSerializable.

private Serializable convertValueToSerializable() {
    Serializable valueAsSerializable = null;
    if (hasValue()) {
        Optional<SettingKey> settingKey = SettingKey.getByName(name);
        try {
            if (settingKey.isPresent()) {
                Object valueAsObject = objectMapper.readValue(value, settingKey.get().getClazz());
                valueAsSerializable = (Serializable) valueAsObject;
            } else {
                valueAsSerializable = StringEscapeUtils.unescapeJava(value);
            }
        } catch (MismatchedInputException ex) {
            log.warn("Content could not be de-serialized by Jackson", ex);
            valueAsSerializable = StringEscapeUtils.unescapeJava(value);
        } catch (JsonProcessingException ex) {
            log.error(String.format("An error occurred while de-serializing system setting: '%s'", name), ex);
        }
    }
    return valueAsSerializable;
}
Also used : Serializable(java.io.Serializable) MismatchedInputException(com.fasterxml.jackson.databind.exc.MismatchedInputException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

MismatchedInputException (com.fasterxml.jackson.databind.exc.MismatchedInputException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Map (java.util.Map)2 SuppressFBWarnings (alluxio.annotation.SuppressFBWarnings)1 PortVlan (com.cisco.trex.stateless.model.port.PortVlan)1 ConnectionManager (com.exalttech.trex.core.ConnectionManager)1 Port (com.exalttech.trex.ui.models.Port)1 PortModel (com.exalttech.trex.ui.models.PortModel)1 PortStatus (com.exalttech.trex.ui.models.PortStatus)1 Util (com.exalttech.trex.util.Util)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JavaType (com.fasterxml.jackson.databind.JavaType)1 JsonObject (io.vertx.core.json.JsonObject)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1