Search in sources :

Example 66 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project pinot by linkedin.

the class DetectionJobRunner method createTasks.

private List<Long> createTasks(DetectionJobContext detectionJobContext, List<DateTime> monitoringWindowStartTimes, List<DateTime> monitoringWindowEndTimes) {
    List<Long> taskIds = new ArrayList<>();
    try {
        List<DetectionTaskInfo> tasks = taskGenerator.createDetectionTasks(detectionJobContext, monitoringWindowStartTimes, monitoringWindowEndTimes);
        for (DetectionTaskInfo taskInfo : tasks) {
            String taskInfoJson = null;
            try {
                taskInfoJson = OBJECT_MAPPER.writeValueAsString(taskInfo);
            } catch (JsonProcessingException e) {
                LOG.error("Exception when converting DetectionTaskInfo {} to jsonString", taskInfo, e);
            }
            TaskDTO taskSpec = new TaskDTO();
            taskSpec.setTaskType(TaskType.ANOMALY_DETECTION);
            taskSpec.setJobName(detectionJobContext.getJobName());
            taskSpec.setStatus(TaskStatus.WAITING);
            taskSpec.setStartTime(System.currentTimeMillis());
            taskSpec.setTaskInfo(taskInfoJson);
            taskSpec.setJobId(detectionJobContext.getJobExecutionId());
            long taskId = DAO_REGISTRY.getTaskDAO().save(taskSpec);
            taskIds.add(taskId);
            LOG.info("Created anomalyTask {} with taskId {}", taskSpec, taskId);
        }
    } catch (Exception e) {
        LOG.error("Exception in creating detection tasks", e);
    }
    return taskIds;
}
Also used : ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 67 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project SimianArmy by Netflix.

the class RDSJanitorResourceTracker method addOrUpdate.

/** {@inheritDoc} */
@Override
public void addOrUpdate(Resource resource) {
    Resource orig = getResource(resource.getId(), resource.getRegion());
    LOGGER.debug(String.format("Saving resource %s to RDB table %s in region %s", resource.getId(), table, resource.getRegion()));
    String json;
    try {
        json = new ObjectMapper().writeValueAsString(additionalFieldsAsMap(resource));
    } catch (JsonProcessingException e) {
        LOGGER.error("ERROR generating additional field JSON when saving resource " + resource.getId(), e);
        return;
    }
    if (orig == null) {
        StringBuilder sb = new StringBuilder();
        sb.append("insert into ").append(table);
        sb.append(" (");
        sb.append(AWSResource.FIELD_RESOURCE_ID).append(",");
        sb.append(AWSResource.FIELD_RESOURCE_TYPE).append(",");
        sb.append(AWSResource.FIELD_REGION).append(",");
        sb.append(AWSResource.FIELD_OWNER_EMAIL).append(",");
        sb.append(AWSResource.FIELD_DESCRIPTION).append(",");
        sb.append(AWSResource.FIELD_STATE).append(",");
        sb.append(AWSResource.FIELD_TERMINATION_REASON).append(",");
        sb.append(AWSResource.FIELD_EXPECTED_TERMINATION_TIME).append(",");
        sb.append(AWSResource.FIELD_ACTUAL_TERMINATION_TIME).append(",");
        sb.append(AWSResource.FIELD_NOTIFICATION_TIME).append(",");
        sb.append(AWSResource.FIELD_LAUNCH_TIME).append(",");
        sb.append(AWSResource.FIELD_MARK_TIME).append(",");
        sb.append(AWSResource.FIELD_OPT_OUT_OF_JANITOR).append(",");
        sb.append("additionalFields").append(") values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
        LOGGER.debug(String.format("Insert statement is '%s'", sb));
        int updated = this.jdbcTemplate.update(sb.toString(), resource.getId(), value(resource.getResourceType().toString()), value(resource.getRegion()), emailValue(resource.getOwnerEmail()), value(resource.getDescription()), value(resource.getState().toString()), value(resource.getTerminationReason()), value(resource.getExpectedTerminationTime()), value(resource.getActualTerminationTime()), value(resource.getNotificationTime()), value(resource.getLaunchTime()), value(resource.getMarkTime()), value(resource.isOptOutOfJanitor()), json);
        LOGGER.debug(String.format("%d rows inserted", updated));
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append("update ").append(table).append(" set ");
        sb.append(AWSResource.FIELD_RESOURCE_TYPE).append("=?,");
        sb.append(AWSResource.FIELD_REGION).append("=?,");
        sb.append(AWSResource.FIELD_OWNER_EMAIL).append("=?,");
        sb.append(AWSResource.FIELD_DESCRIPTION).append("=?,");
        sb.append(AWSResource.FIELD_STATE).append("=?,");
        sb.append(AWSResource.FIELD_TERMINATION_REASON).append("=?,");
        sb.append(AWSResource.FIELD_EXPECTED_TERMINATION_TIME).append("=?,");
        sb.append(AWSResource.FIELD_ACTUAL_TERMINATION_TIME).append("=?,");
        sb.append(AWSResource.FIELD_NOTIFICATION_TIME).append("=?,");
        sb.append(AWSResource.FIELD_LAUNCH_TIME).append("=?,");
        sb.append(AWSResource.FIELD_MARK_TIME).append("=?,");
        sb.append(AWSResource.FIELD_OPT_OUT_OF_JANITOR).append("=?,");
        sb.append("additionalFields").append("=? where ");
        sb.append(AWSResource.FIELD_RESOURCE_ID).append("=? and ");
        sb.append(AWSResource.FIELD_REGION).append("=?");
        LOGGER.debug(String.format("Update statement is '%s'", sb));
        int updated = this.jdbcTemplate.update(sb.toString(), resource.getResourceType().toString(), value(resource.getRegion()), emailValue(resource.getOwnerEmail()), value(resource.getDescription()), value(resource.getState().toString()), value(resource.getTerminationReason()), value(resource.getExpectedTerminationTime()), value(resource.getActualTerminationTime()), value(resource.getNotificationTime()), value(resource.getLaunchTime()), value(resource.getMarkTime()), value(resource.isOptOutOfJanitor()), json, resource.getId(), resource.getRegion());
        LOGGER.debug(String.format("%d rows updated", updated));
    }
    LOGGER.debug("Successfully saved.");
}
Also used : Resource(com.netflix.simianarmy.Resource) AWSResource(com.netflix.simianarmy.aws.AWSResource) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 68 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project feign by OpenFeign.

the class JacksonEncoder method encode.

@Override
public void encode(Object object, Type bodyType, RequestTemplate template) {
    try {
        JavaType javaType = mapper.getTypeFactory().constructType(bodyType);
        template.body(mapper.writerFor(javaType).writeValueAsString(object));
    } catch (JsonProcessingException e) {
        throw new EncodeException(e.getMessage(), e);
    }
}
Also used : JavaType(com.fasterxml.jackson.databind.JavaType) EncodeException(feign.codec.EncodeException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 69 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project presto by prestodb.

the class QueryMonitor method splitCompletedEvent.

private void splitCompletedEvent(TaskId taskId, DriverStats driverStats, @Nullable String failureType, @Nullable String failureMessage) {
    Optional<Duration> timeToStart = Optional.empty();
    if (driverStats.getStartTime() != null) {
        timeToStart = Optional.of(ofMillis(driverStats.getStartTime().getMillis() - driverStats.getCreateTime().getMillis()));
    }
    Optional<Duration> timeToEnd = Optional.empty();
    if (driverStats.getEndTime() != null) {
        timeToEnd = Optional.of(ofMillis(driverStats.getEndTime().getMillis() - driverStats.getCreateTime().getMillis()));
    }
    Optional<SplitFailureInfo> splitFailureMetadata = Optional.empty();
    if (failureType != null) {
        splitFailureMetadata = Optional.of(new SplitFailureInfo(failureType, failureMessage != null ? failureMessage : ""));
    }
    try {
        eventListenerManager.splitCompleted(new SplitCompletedEvent(taskId.getQueryId().toString(), taskId.getStageId().toString(), Integer.toString(taskId.getId()), driverStats.getCreateTime().toDate().toInstant(), Optional.ofNullable(driverStats.getStartTime()).map(startTime -> startTime.toDate().toInstant()), Optional.ofNullable(driverStats.getEndTime()).map(endTime -> endTime.toDate().toInstant()), new SplitStatistics(ofMillis(driverStats.getTotalCpuTime().toMillis()), ofMillis(driverStats.getElapsedTime().toMillis()), ofMillis(driverStats.getQueuedTime().toMillis()), ofMillis(driverStats.getTotalUserTime().toMillis()), ofMillis(driverStats.getRawInputReadTime().toMillis()), driverStats.getRawInputPositions(), driverStats.getRawInputDataSize().toBytes(), driverStats.getPeakMemoryReservation().toBytes(), timeToStart, timeToEnd), splitFailureMetadata, objectMapper.writeValueAsString(driverStats)));
    } catch (JsonProcessingException e) {
        log.error(e, "Error processing split completion event for task %s", taskId);
    }
}
Also used : SplitCompletedEvent(com.facebook.presto.spi.eventlistener.SplitCompletedEvent) SplitStatistics(com.facebook.presto.spi.eventlistener.SplitStatistics) SplitFailureInfo(com.facebook.presto.spi.eventlistener.SplitFailureInfo) Duration(java.time.Duration) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 70 with JsonProcessingException

use of com.fasterxml.jackson.core.JsonProcessingException in project presto by prestodb.

the class ArrayToJsonCast method toJson.

public static Slice toJson(Type arrayType, ConnectorSession session, Block array) {
    Type elementType = arrayType.getTypeParameters().get(0);
    List<Object> objectValues = new ArrayList<>(array.getPositionCount());
    for (int i = 0; i < array.getPositionCount(); i++) {
        objectValues.add(JsonFunctions.getJsonObjectValue(elementType, session, array, i));
    }
    try {
        return Slices.utf8Slice(OBJECT_MAPPER.get().writeValueAsString(objectValues));
    } catch (JsonProcessingException e) {
        throw Throwables.propagate(e);
    }
}
Also used : Type(com.facebook.presto.spi.type.Type) OperatorType(com.facebook.presto.spi.function.OperatorType) ArrayList(java.util.ArrayList) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)117 IOException (java.io.IOException)28 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)26 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 InputStream (java.io.InputStream)7 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)6 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)6 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)6 OutputStreamWriter (java.io.OutputStreamWriter)6 Map (java.util.Map)6 Status (com.ctrip.platform.dal.daogen.domain.Status)5 TaskDTO (com.linkedin.thirdeye.datalayer.dto.TaskDTO)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 IncorrectRPCMethodException (com.exalttech.trex.remote.exceptions.IncorrectRPCMethodException)3 InvalidRPCResponseException (com.exalttech.trex.remote.exceptions.InvalidRPCResponseException)3