mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
parent
ca8775e35e
commit
78689716b7
17 changed files with 69 additions and 58 deletions
|
@ -1,7 +1,5 @@
|
|||
package org.logstash;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class Accessors {
|
||||
|
||||
private Accessors() {
|
||||
|
@ -102,7 +100,7 @@ public final class Accessors {
|
|||
}
|
||||
|
||||
private static Object setChild(final Object target, final String key, final Object value) {
|
||||
if (target instanceof Map) {
|
||||
if (target instanceof ConvertedMap) {
|
||||
((ConvertedMap) target).putInterned(key, value);
|
||||
return value;
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,13 @@
|
|||
package org.logstash;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public final class Cloner {
|
||||
|
||||
|
@ -24,8 +31,6 @@ public final class Cloner {
|
|||
clone = new LinkedList<>();
|
||||
} else if (list instanceof ArrayList<?>) {
|
||||
clone = new ArrayList<>();
|
||||
} else if (list instanceof ConvertedList) {
|
||||
clone = new ArrayList<>();
|
||||
} else {
|
||||
throw new ClassCastException("unexpected List type " + list.getClass());
|
||||
}
|
||||
|
|
|
@ -42,9 +42,9 @@ public final class ConvertedMap extends IdentityHashMap<String, Object> {
|
|||
super(size);
|
||||
}
|
||||
|
||||
public static ConvertedMap newFromMap(Map<Serializable, Object> o) {
|
||||
public static ConvertedMap newFromMap(Map<? extends Serializable, Object> o) {
|
||||
ConvertedMap cm = new ConvertedMap(o.size());
|
||||
for (final Map.Entry<Serializable, Object> entry : o.entrySet()) {
|
||||
for (final Map.Entry<? extends Serializable, Object> entry : o.entrySet()) {
|
||||
final Serializable found = entry.getKey();
|
||||
if (found instanceof String) {
|
||||
cm.put((String) found, Valuefier.convert(entry.getValue()));
|
||||
|
|
|
@ -2,7 +2,9 @@ package org.logstash;
|
|||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -56,7 +58,7 @@ public final class Event implements Cloneable, Queueable {
|
|||
* @param data Map that is assumed to have either {@link String} or {@link RubyString}
|
||||
* keys and may contain Java and Ruby objects.
|
||||
*/
|
||||
public Event(Map data) {
|
||||
public Event(final Map<? extends Serializable, Object> data) {
|
||||
this(ConvertedMap.newFromMap(data));
|
||||
}
|
||||
|
||||
|
@ -72,7 +74,8 @@ public final class Event implements Cloneable, Queueable {
|
|||
}
|
||||
|
||||
if (this.data.containsKey(METADATA)) {
|
||||
this.metadata = ConvertedMap.newFromMap((Map) this.data.remove(METADATA));
|
||||
this.metadata =
|
||||
ConvertedMap.newFromMap((Map<String, Object>) this.data.remove(METADATA));
|
||||
} else {
|
||||
this.metadata = new ConvertedMap(10);
|
||||
}
|
||||
|
@ -150,7 +153,7 @@ public final class Event implements Cloneable, Queueable {
|
|||
public void setField(final FieldReference field, final Object value) {
|
||||
switch (field.type()) {
|
||||
case FieldReference.META_PARENT:
|
||||
this.metadata = ConvertedMap.newFromMap((Map) value);
|
||||
this.metadata = ConvertedMap.newFromMap((Map<String, Object>) value);
|
||||
break;
|
||||
case FieldReference.META_CHILD:
|
||||
Accessors.set(metadata, field, value);
|
||||
|
@ -209,15 +212,13 @@ public final class Event implements Cloneable, Queueable {
|
|||
Object o = JSON_MAPPER.readValue(json, Object.class);
|
||||
// we currently only support Map or Array json objects
|
||||
if (o instanceof Map) {
|
||||
result = new Event[]{ new Event((Map)o) };
|
||||
result = new Event[]{ new Event((Map<String, Object>)o) };
|
||||
} else if (o instanceof List) {
|
||||
result = new Event[((List) o).size()];
|
||||
final Collection<Map<String, Object>> list = (Collection<Map<String, Object>>) o;
|
||||
result = new Event[list.size()];
|
||||
int i = 0;
|
||||
for (Object e : (List)o) {
|
||||
if (!(e instanceof Map)) {
|
||||
throw new IOException("incompatible inner json array object type=" + e.getClass().getName() + " , only hash map is supported");
|
||||
}
|
||||
result[i++] = new Event((Map)e);
|
||||
for (final Map<String, Object> e : list) {
|
||||
result[i++] = new Event(e);
|
||||
}
|
||||
} else {
|
||||
throw new IOException("incompatible json object type=" + o.getClass().getName() + " , only hash map or arrays are supported");
|
||||
|
@ -226,13 +227,13 @@ public final class Event implements Cloneable, Queueable {
|
|||
return result;
|
||||
}
|
||||
|
||||
public Map toMap() {
|
||||
public Map<String, Object> toMap() {
|
||||
return Cloner.deep(this.data);
|
||||
}
|
||||
|
||||
public Event overwrite(Event e) {
|
||||
this.data = e.getData();
|
||||
this.cancelled = e.isCancelled();
|
||||
this.data = e.data;
|
||||
this.cancelled = e.cancelled;
|
||||
try {
|
||||
this.timestamp = e.getTimestamp();
|
||||
} catch (IOException exception) {
|
||||
|
@ -262,7 +263,7 @@ public final class Event implements Cloneable, Queueable {
|
|||
|
||||
@Override
|
||||
public Event clone() {
|
||||
return new Event(Cloner.<Map>deep(this.data));
|
||||
return new Event(Cloner.<Map<String, Object>>deep(this.data));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class Javafier {
|
|||
try {
|
||||
return BiValues.newBiValue(o).javaValue();
|
||||
} catch (IllegalArgumentException e) {
|
||||
Class cls = o.getClass();
|
||||
final Class<?> cls = o.getClass();
|
||||
throw new IllegalArgumentException(String.format(ERR_TEMPLATE, cls.getName(), cls.getSimpleName()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,13 +122,15 @@ public final class Valuefier {
|
|||
)
|
||||
);
|
||||
converters.put(RubyHash.class, input -> ConvertedMap.newFromRubyHash((RubyHash) input));
|
||||
converters.put(Map.class, input -> ConvertedMap.newFromMap((Map) input));
|
||||
converters.put(Map.class, input -> ConvertedMap.newFromMap((Map<String, Object>) input));
|
||||
converters.put(List.class, input -> ConvertedList.newFromList((List) input));
|
||||
converters.put(ArrayJavaProxy.class, JAVAPROXY_CONVERTER);
|
||||
converters.put(ConcreteJavaProxy.class, JAVAPROXY_CONVERTER);
|
||||
converters.put(
|
||||
MapJavaProxy.class,
|
||||
input -> ConvertedMap.newFromMap((Map) ((MapJavaProxy) input).getObject())
|
||||
input -> ConvertedMap.newFromMap(
|
||||
(Map<String, Object>) ((MapJavaProxy) input).getObject()
|
||||
)
|
||||
);
|
||||
converters.put(
|
||||
RubyArray.class, input -> ConvertedList.newFromRubyArray((RubyArray) input)
|
||||
|
|
|
@ -88,7 +88,7 @@ public abstract class BiValue<R extends IRubyObject, J> implements Serializable
|
|||
return String.valueOf(javaValue);
|
||||
}
|
||||
|
||||
protected static Object newProxy(BiValue instance) {
|
||||
protected static Object newProxy(BiValue<?, ?> instance) {
|
||||
return new SerializationProxy(instance);
|
||||
}
|
||||
|
||||
|
|
|
@ -159,12 +159,12 @@ public final class DeadLetterQueueWriter implements Closeable {
|
|||
* @param event Logstash Event
|
||||
* @return boolean indicating whether the event is eligible to be added to the DLQ
|
||||
*/
|
||||
private boolean alreadyProcessed(final Event event) {
|
||||
private static boolean alreadyProcessed(final Event event) {
|
||||
return event.getMetadata() != null && event.getMetadata().containsKey(DEAD_LETTER_QUEUE_METADATA_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void close() throws IOException {
|
||||
public synchronized void close() {
|
||||
if (currentWriter != null) {
|
||||
try {
|
||||
currentWriter.close();
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package org.logstash.config.ir.graph.algorithms;
|
||||
|
||||
import org.logstash.config.ir.graph.Edge;
|
||||
import org.logstash.config.ir.graph.Graph;
|
||||
import org.logstash.config.ir.graph.Vertex;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.logstash.config.ir.SourceComponent;
|
||||
import org.logstash.config.ir.graph.Edge;
|
||||
import org.logstash.config.ir.graph.Graph;
|
||||
import org.logstash.config.ir.graph.Vertex;
|
||||
|
||||
/**
|
||||
* Created by andrewvc on 1/5/17.
|
||||
|
@ -86,14 +86,15 @@ public class GraphDiff {
|
|||
return output.toString();
|
||||
}
|
||||
|
||||
private static String detailedDiffFor(String name, Collection removed, Collection added) {
|
||||
return (name + " GraphDiff: " + "\n") +
|
||||
"--------------------------\n" +
|
||||
Stream.concat(removed.stream().map(c -> "-" + c.toString()),
|
||||
added.stream().map(c -> "+" + c.toString())).
|
||||
map(Object::toString).
|
||||
collect(Collectors.joining("\n")) +
|
||||
"\n--------------------------";
|
||||
private static String detailedDiffFor(final String name,
|
||||
final Collection<? extends SourceComponent> removed,
|
||||
final Collection<? extends SourceComponent> added) {
|
||||
return name + " GraphDiff: \n--------------------------\n" +
|
||||
Stream.concat(
|
||||
removed.stream().map(c -> '-' + c.toString()),
|
||||
added.stream().map(c -> '+' + c.toString())
|
||||
).map(Object::toString).collect(Collectors.joining("\n")) +
|
||||
"\n--------------------------";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,8 +219,8 @@ public class JrubyEventExtLibrary implements Library {
|
|||
|
||||
@JRubyMethod(name = "to_hash_with_metadata")
|
||||
public IRubyObject ruby_to_hash_with_metadata(ThreadContext context) {
|
||||
Map data = this.event.toMap();
|
||||
Map metadata = this.event.getMetadata();
|
||||
Map<String, Object> data = this.event.toMap();
|
||||
Map<String, Object> metadata = this.event.getMetadata();
|
||||
|
||||
if (!metadata.isEmpty()) {
|
||||
data.put(Event.METADATA, metadata);
|
||||
|
@ -323,7 +323,7 @@ public class JrubyEventExtLibrary implements Library {
|
|||
this.event = new Event();
|
||||
} else if (data instanceof MapJavaProxy) {
|
||||
this.event = new Event(ConvertedMap.newFromMap(
|
||||
(Map)((MapJavaProxy)data).getObject())
|
||||
(Map<String, Object>)((MapJavaProxy)data).getObject())
|
||||
);
|
||||
} else {
|
||||
throw context.runtime.newTypeError("wrong argument type " + data.getMetaClass() + " (expected Hash)");
|
||||
|
|
|
@ -21,6 +21,7 @@ public interface Metric<T> {
|
|||
* @return This metric value
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
default T get() {
|
||||
return getValue();
|
||||
}
|
||||
|
@ -45,6 +46,7 @@ public interface Metric<T> {
|
|||
* @return A description of this Metric that can be used for logging.
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
default String inspect() {
|
||||
return toString();
|
||||
}
|
||||
|
@ -55,6 +57,7 @@ public interface Metric<T> {
|
|||
* @return The {@link String} version of the {@link MetricType}
|
||||
* @deprecated
|
||||
*/
|
||||
@Deprecated
|
||||
default String type() {
|
||||
return getType().asString();
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ public class LazyDelegatingGauge extends AbstractMetric<Object> implements Gauge
|
|||
} else if (value instanceof RubyHash) {
|
||||
lazyMetric = new RubyHashGauge(key, (RubyHash) value);
|
||||
} else if (value instanceof RubyTimestamp) {
|
||||
lazyMetric = new RubyTimeStampGauge(key, ((RubyTimestamp) value));
|
||||
lazyMetric = new RubyTimeStampGauge(key, (RubyTimestamp) value);
|
||||
} else {
|
||||
LOGGER.warn("A gauge metric of an unknown type ({}) has been create for key: {}. This may result in invalid serialization. It is recommended to " +
|
||||
"log an issue to the responsible developer/development team.", value.getClass().getCanonicalName(), key);
|
||||
|
|
|
@ -94,7 +94,7 @@ public class DeadLetterQueueWitness implements SerializableWitness {
|
|||
/**
|
||||
* The snitch for the dead letter queue. Used to retrieve discrete metric values.
|
||||
*/
|
||||
public class Snitch {
|
||||
public static class Snitch {
|
||||
private final DeadLetterQueueWitness witness;
|
||||
|
||||
private Snitch(DeadLetterQueueWitness witness) {
|
||||
|
|
|
@ -89,8 +89,8 @@ public class PluginsWitness implements SerializableWitness {
|
|||
* @param id the id of the plugin
|
||||
* @return existing or new {@link PluginWitness}
|
||||
*/
|
||||
private PluginWitness getPlugin(Map<String, PluginWitness> plugin, String id) {
|
||||
return plugin.computeIfAbsent(id, k -> new PluginWitness(k));
|
||||
private static PluginWitness getPlugin(Map<String, PluginWitness> plugin, String id) {
|
||||
return plugin.computeIfAbsent(id, PluginWitness::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -84,13 +84,13 @@ public final class QueueWitness implements SerializableWitness {
|
|||
|
||||
@Override
|
||||
public void genJson(JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||
SERIALIZER.innerSerialize(this, gen);
|
||||
Serializer.innerSerialize(this, gen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner witness for the queue capacity
|
||||
*/
|
||||
public class CapacityWitness {
|
||||
public static class CapacityWitness {
|
||||
|
||||
private final NumberGauge queueSizeInBytes;
|
||||
private final NumberGauge pageCapacityInBytes;
|
||||
|
@ -156,7 +156,7 @@ public final class QueueWitness implements SerializableWitness {
|
|||
/**
|
||||
* Snitch for queue capacity. Provides discrete metric values.
|
||||
*/
|
||||
public class Snitch {
|
||||
public static class Snitch {
|
||||
|
||||
private final CapacityWitness witness;
|
||||
|
||||
|
@ -206,7 +206,7 @@ public final class QueueWitness implements SerializableWitness {
|
|||
/**
|
||||
* Inner witness for the queue data
|
||||
*/
|
||||
public class DataWitness {
|
||||
public static class DataWitness {
|
||||
|
||||
private final TextGauge path;
|
||||
private final NumberGauge freeSpaceInBytes;
|
||||
|
@ -261,7 +261,7 @@ public final class QueueWitness implements SerializableWitness {
|
|||
/**
|
||||
* Snitch for queue capacity. Provides discrete metric values.
|
||||
*/
|
||||
public class Snitch {
|
||||
public static class Snitch {
|
||||
|
||||
private final DataWitness witness;
|
||||
|
||||
|
@ -329,7 +329,7 @@ public final class QueueWitness implements SerializableWitness {
|
|||
gen.writeEndObject();
|
||||
}
|
||||
|
||||
void innerSerialize(QueueWitness witness, JsonGenerator gen) throws IOException {
|
||||
static void innerSerialize(QueueWitness witness, JsonGenerator gen) throws IOException {
|
||||
gen.writeObjectFieldStart(KEY);
|
||||
MetricSerializer<Metric<Number>> numberSerializer = MetricSerializer.Get.numberSerializer(gen);
|
||||
MetricSerializer<Metric<String>> stringSerializer = MetricSerializer.Get.stringSerializer(gen);
|
||||
|
|
|
@ -116,7 +116,7 @@ public final class ReloadWitness implements SerializableWitness {
|
|||
|
||||
@Override
|
||||
public void genJson(JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||
SERIALIZER.innerSerialize(this, gen, provider);
|
||||
Serializer.innerSerialize(this, gen, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,8 @@ public final class ReloadWitness implements SerializableWitness {
|
|||
gen.writeEndObject();
|
||||
}
|
||||
|
||||
void innerSerialize(ReloadWitness witness, JsonGenerator gen, SerializerProvider provider) throws IOException {
|
||||
static void innerSerialize(ReloadWitness witness, JsonGenerator gen,
|
||||
SerializerProvider provider) throws IOException {
|
||||
gen.writeObjectFieldStart(ReloadWitness.KEY);
|
||||
witness.lastError.genJson(gen, provider);
|
||||
MetricSerializer<Metric<Long>> longSerializer = MetricSerializer.Get.longSerializer(gen);
|
||||
|
|
|
@ -275,17 +275,17 @@ public final class EventTest {
|
|||
Event.fromJson("gabeutch");
|
||||
}
|
||||
|
||||
@Test(expected=IOException.class)
|
||||
@Test(expected=ClassCastException.class)
|
||||
public void testFromJsonWithInvalidJsonArray1() throws Exception {
|
||||
Event.fromJson("[1,2]");
|
||||
}
|
||||
|
||||
@Test(expected=IOException.class)
|
||||
@Test(expected=ClassCastException.class)
|
||||
public void testFromJsonWithInvalidJsonArray2() throws Exception {
|
||||
Event.fromJson("[\"gabeutch\"]");
|
||||
}
|
||||
|
||||
@Test(expected=IOException.class)
|
||||
@Test(expected=ClassCastException.class)
|
||||
public void testFromJsonWithPartialInvalidJsonArray() throws Exception {
|
||||
Event.fromJson("[{\"foo\":\"bar\"}, 1]");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue