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;
}
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.");
}
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);
}
}
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);
}
}
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);
}
}
Aggregations