Class: LogStash::Config::LIRSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/config/lir_serializer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lir_pipeline) ⇒ LIRSerializer

Returns a new instance of LIRSerializer.



14
15
16
# File 'lib/logstash/config/lir_serializer.rb', line 14

def initialize(lir_pipeline)
  @lir_pipeline = lir_pipeline
end

Instance Attribute Details

#lir_pipelineObject (readonly)

Returns the value of attribute lir_pipeline.



8
9
10
# File 'lib/logstash/config/lir_serializer.rb', line 8

def lir_pipeline
  @lir_pipeline
end

Class Method Details

.serialize(lir_pipeline) ⇒ Object



10
11
12
# File 'lib/logstash/config/lir_serializer.rb', line 10

def self.serialize(lir_pipeline)
  self.new(lir_pipeline).serialize
end

Instance Method Details

#decorate_vertex(v, v_json) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/logstash/config/lir_serializer.rb', line 67

def decorate_vertex(v, v_json)
  v_json["meta"] = format_swm(v.)
  v_json["id"] = v.id
  v_json["explicit_id"] = !!v.explicit_id
  v_json["type"] = vertex_type(v).to_s
  v_json
end

#edge(e) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/logstash/config/lir_serializer.rb', line 93

def edge(e)
  e_json = {
    "from" => e.from.id,
    "to" => e.to.id,
    "id" => e.id
  }
  
  if e.java_kind_of?(org.logstash.config.ir.graph.BooleanEdge)
    e_json["when"] = e.edge_type
    e_json["type"] = "boolean"
  else
    e_json["type"] = "plain"
  end
  
  e_json
end

#edgesObject



34
35
36
# File 'lib/logstash/config/lir_serializer.rb', line 34

def edges
  graph.getEdges.map {|e| edge(e) }
end

#format_swm(source_with_metadata) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/logstash/config/lir_serializer.rb', line 110

def format_swm()
  return nil unless 
  {
    "source" => {
      "protocol" => .protocol,
      "id" => .id,
      "line" =>  .line,
      "column" => .column
      # We omit the text of the source code for security reasons
      # raw text may contain passwords
    }
  }
end

#graphObject



38
39
40
# File 'lib/logstash/config/lir_serializer.rb', line 38

def graph
  lir_pipeline.graph
end

#if_vertex(v) ⇒ Object



83
84
85
86
87
# File 'lib/logstash/config/lir_serializer.rb', line 83

def if_vertex(v)
  {
    "condition" => v.humanReadableExpression
  }
end

#plugin_vertex(v) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/logstash/config/lir_serializer.rb', line 75

def plugin_vertex(v)
  pd = v.plugin_definition
  {
    "config_name" => pd.name,
    "plugin_type" => pd.getType.to_s.downcase
  }
end

#queue_vertex(v) ⇒ Object



89
90
91
# File 'lib/logstash/config/lir_serializer.rb', line 89

def queue_vertex(v)
  {}
end

#serializeObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logstash/config/lir_serializer.rb', line 18

def serialize
  {
    "hash" => lir_pipeline.unique_hash,
    "type" => "lir",
    "version" => "0.0.0",
    "graph" => {
      "vertices" => vertices,
      "edges" => edges
    }
  }
end

#vertex(v) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/logstash/config/lir_serializer.rb', line 42

def vertex(v)
  hashified_vertex = case vertex_type(v) 
                     when :plugin 
                       plugin_vertex(v)
                     when :if 
                       if_vertex(v)
                     when :queue
                       queue_vertex(v)
                     end

  decorate_vertex(v, hashified_vertex)
end

#vertex_type(v) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/logstash/config/lir_serializer.rb', line 55

def vertex_type(v)
  if v.java_kind_of?(org.logstash.config.ir.graph.PluginVertex)
    :plugin
  elsif v.java_kind_of?(org.logstash.config.ir.graph.IfVertex)
    :if
  elsif v.java_kind_of?(org.logstash.config.ir.graph.QueueVertex)
    :queue
  else
    raise "Unexpected vertex type! #{v}"
  end
end

#verticesObject



30
31
32
# File 'lib/logstash/config/lir_serializer.rb', line 30

def vertices
  graph.getVertices.map {|v| vertex(v) }
end