ovirt_metrics 1.4.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +0 -1
  3. data/lib/active_record/connection_adapters/ovirt_postgresql_adapter.rb +30 -0
  4. data/lib/ovirt_metrics.rb +9 -9
  5. data/lib/ovirt_metrics/column_definitions.rb +4 -4
  6. data/lib/ovirt_metrics/models/host_configuration.rb +0 -14
  7. data/lib/ovirt_metrics/models/host_samples_history.rb +1 -1
  8. data/lib/ovirt_metrics/models/vm_device_history.rb +1 -0
  9. data/lib/ovirt_metrics/models/vm_samples_history.rb +1 -1
  10. data/lib/ovirt_metrics/version.rb +1 -1
  11. data/spec/models/host_samples_history_spec.rb +10 -10
  12. data/spec/models/vm_disk_samples_history_spec.rb +4 -4
  13. data/spec/models/vm_samples_history_spec.rb +3 -8
  14. data/spec/ovirt_metrics_spec.rb +30 -0
  15. data/spec/support/active_record.rb +0 -6
  16. metadata +15 -58
  17. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/column.rb +0 -15
  18. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/database_statements.rb +0 -170
  19. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/explain_pretty_printer.rb +0 -42
  20. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid.rb +0 -31
  21. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/array.rb +0 -70
  22. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit.rb +0 -52
  23. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying.rb +0 -13
  24. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea.rb +0 -15
  25. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr.rb +0 -48
  26. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time.rb +0 -21
  27. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal.rb +0 -13
  28. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum.rb +0 -19
  29. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore.rb +0 -59
  30. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet.rb +0 -13
  31. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/json.rb +0 -10
  32. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb.rb +0 -23
  33. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/money.rb +0 -39
  34. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/point.rb +0 -43
  35. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point.rb +0 -50
  36. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/range.rb +0 -93
  37. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string.rb +0 -15
  38. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer.rb +0 -109
  39. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid.rb +0 -21
  40. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector.rb +0 -26
  41. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml.rb +0 -28
  42. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/quoting.rb +0 -116
  43. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/referential_integrity.rb +0 -49
  44. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_definitions.rb +0 -180
  45. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_dumper.rb +0 -47
  46. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/schema_statements.rb +0 -682
  47. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/type_metadata.rb +0 -35
  48. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql/utils.rb +0 -77
  49. data/lib/active_record/connection_adapters/ovirt_legacy_postgresql_adapter.rb +0 -856
  50. data/spec/models/host_configuration_spec.rb +0 -31
  51. data/spec/schemas/schema_rhev30.rb +0 -655
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- # PostgreSQL-specific extensions to column definitions in a table.
4
- class OvirtLegacyPostgreSQLColumn < Column #:nodoc:
5
- delegate :array, :oid, :fmod, to: :sql_type_metadata
6
- alias :array? :array
7
-
8
- def serial?
9
- return unless default_function
10
-
11
- %r{\Anextval\('"?#{table_name}_#{name}_seq"?'::regclass\)\z} === default_function
12
- end
13
- end
14
- end
15
- end
@@ -1,170 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module DatabaseStatements
5
- def explain(arel, binds = [])
6
- sql = "EXPLAIN #{to_sql(arel, binds)}"
7
- OvirtLegacyPostgreSQL::ExplainPrettyPrinter.new.pp(exec_query(sql, 'EXPLAIN', binds))
8
- end
9
-
10
- def select_value(arel, name = nil, binds = [])
11
- arel, binds = binds_from_relation arel, binds
12
- sql = to_sql(arel, binds)
13
- execute_and_clear(sql, name, binds) do |result|
14
- result.getvalue(0, 0) if result.ntuples > 0 && result.nfields > 0
15
- end
16
- end
17
-
18
- def select_values(arel, name = nil, binds = [])
19
- arel, binds = binds_from_relation arel, binds
20
- sql = to_sql(arel, binds)
21
- execute_and_clear(sql, name, binds) do |result|
22
- if result.nfields > 0
23
- result.column_values(0)
24
- else
25
- []
26
- end
27
- end
28
- end
29
-
30
- # Executes a SELECT query and returns an array of rows. Each row is an
31
- # array of field values.
32
- def select_rows(sql, name = nil, binds = [])
33
- execute_and_clear(sql, name, binds) do |result|
34
- result.values
35
- end
36
- end
37
-
38
- # The internal PostgreSQL identifier of the money data type.
39
- MONEY_COLUMN_TYPE_OID = 790 #:nodoc:
40
- # The internal PostgreSQL identifier of the BYTEA data type.
41
- BYTEA_COLUMN_TYPE_OID = 17 #:nodoc:
42
-
43
- # create a 2D array representing the result set
44
- def result_as_array(res) #:nodoc:
45
- # check if we have any binary column and if they need escaping
46
- ftypes = Array.new(res.nfields) do |i|
47
- [i, res.ftype(i)]
48
- end
49
-
50
- rows = res.values
51
- return rows unless ftypes.any? { |_, x|
52
- x == BYTEA_COLUMN_TYPE_OID || x == MONEY_COLUMN_TYPE_OID
53
- }
54
-
55
- typehash = ftypes.group_by { |_, type| type }
56
- binaries = typehash[BYTEA_COLUMN_TYPE_OID] || []
57
- monies = typehash[MONEY_COLUMN_TYPE_OID] || []
58
-
59
- rows.each do |row|
60
- # unescape string passed BYTEA field (OID == 17)
61
- binaries.each do |index, _|
62
- row[index] = unescape_bytea(row[index])
63
- end
64
-
65
- # If this is a money type column and there are any currency symbols,
66
- # then strip them off. Indeed it would be prettier to do this in
67
- # OvirtLegacyPostgreSQLColumn.string_to_decimal but would break form input
68
- # fields that call value_before_type_cast.
69
- monies.each do |index, _|
70
- data = row[index]
71
- # Because money output is formatted according to the locale, there are two
72
- # cases to consider (note the decimal separators):
73
- # (1) $12,345,678.12
74
- # (2) $12.345.678,12
75
- case data
76
- when /^-?\D+[\d,]+\.\d{2}$/ # (1)
77
- data.gsub!(/[^-\d.]/, '')
78
- when /^-?\D+[\d.]+,\d{2}$/ # (2)
79
- data.gsub!(/[^-\d,]/, '').sub!(/,/, '.')
80
- end
81
- end
82
- end
83
- end
84
-
85
- # Queries the database and returns the results in an Array-like object
86
- def query(sql, name = nil) #:nodoc:
87
- log(sql, name) do
88
- result_as_array @connection.async_exec(sql)
89
- end
90
- end
91
-
92
- # Executes an SQL statement, returning a PGresult object on success
93
- # or raising a PGError exception otherwise.
94
- # Note: the PGresult object is manually memory managed; if you don't
95
- # need it specifically, you many want consider the exec_query wrapper.
96
- def execute(sql, name = nil)
97
- log(sql, name) do
98
- @connection.async_exec(sql)
99
- end
100
- end
101
-
102
- def exec_query(sql, name = 'SQL', binds = [], prepare: false)
103
- execute_and_clear(sql, name, binds, prepare: prepare) do |result|
104
- types = {}
105
- fields = result.fields
106
- fields.each_with_index do |fname, i|
107
- ftype = result.ftype i
108
- fmod = result.fmod i
109
- types[fname] = get_oid_type(ftype, fmod, fname)
110
- end
111
- ActiveRecord::Result.new(fields, result.values, types)
112
- end
113
- end
114
-
115
- def exec_delete(sql, name = 'SQL', binds = [])
116
- execute_and_clear(sql, name, binds) {|result| result.cmd_tuples }
117
- end
118
- alias :exec_update :exec_delete
119
-
120
- def sql_for_insert(sql, pk, id_value, sequence_name, binds) # :nodoc:
121
- if pk.nil?
122
- # Extract the table from the insert sql. Yuck.
123
- table_ref = extract_table_ref_from_insert_sql(sql)
124
- pk = primary_key(table_ref) if table_ref
125
- end
126
-
127
- if pk && use_insert_returning?
128
- sql = "#{sql} RETURNING #{quote_column_name(pk)}"
129
- end
130
-
131
- super
132
- end
133
-
134
- def exec_insert(sql, name, binds, pk = nil, sequence_name = nil)
135
- val = exec_query(sql, name, binds)
136
- if !use_insert_returning? && pk
137
- unless sequence_name
138
- table_ref = extract_table_ref_from_insert_sql(sql)
139
- sequence_name = default_sequence_name(table_ref, pk)
140
- return val unless sequence_name
141
- end
142
- last_insert_id_result(sequence_name)
143
- else
144
- val
145
- end
146
- end
147
-
148
- # Begins a transaction.
149
- def begin_db_transaction
150
- execute "BEGIN"
151
- end
152
-
153
- def begin_isolated_db_transaction(isolation)
154
- begin_db_transaction
155
- execute "SET TRANSACTION ISOLATION LEVEL #{transaction_isolation_levels.fetch(isolation)}"
156
- end
157
-
158
- # Commits a transaction.
159
- def commit_db_transaction
160
- execute "COMMIT"
161
- end
162
-
163
- # Aborts a transaction.
164
- def exec_rollback_db_transaction
165
- execute "ROLLBACK"
166
- end
167
- end
168
- end
169
- end
170
- end
@@ -1,42 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- class ExplainPrettyPrinter # :nodoc:
5
- # Pretty prints the result of an EXPLAIN in a way that resembles the output of the
6
- # PostgreSQL shell:
7
- #
8
- # QUERY PLAN
9
- # ------------------------------------------------------------------------------
10
- # Nested Loop Left Join (cost=0.00..37.24 rows=8 width=0)
11
- # Join Filter: (posts.user_id = users.id)
12
- # -> Index Scan using users_pkey on users (cost=0.00..8.27 rows=1 width=4)
13
- # Index Cond: (id = 1)
14
- # -> Seq Scan on posts (cost=0.00..28.88 rows=8 width=4)
15
- # Filter: (posts.user_id = 1)
16
- # (6 rows)
17
- #
18
- def pp(result)
19
- header = result.columns.first
20
- lines = result.rows.map(&:first)
21
-
22
- # We add 2 because there's one char of padding at both sides, note
23
- # the extra hyphens in the example above.
24
- width = [header, *lines].map(&:length).max + 2
25
-
26
- pp = []
27
-
28
- pp << header.center(width).rstrip
29
- pp << '-' * width
30
-
31
- pp += lines.map {|line| " #{line}"}
32
-
33
- nrows = result.rows.length
34
- rows_label = nrows == 1 ? 'row' : 'rows'
35
- pp << "(#{nrows} #{rows_label})"
36
-
37
- pp.join("\n") + "\n"
38
- end
39
- end
40
- end
41
- end
42
- end
@@ -1,31 +0,0 @@
1
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/array'
2
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit'
3
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bit_varying'
4
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/bytea'
5
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/cidr'
6
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/date_time'
7
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/decimal'
8
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/enum'
9
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/hstore'
10
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/inet'
11
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/json'
12
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/jsonb'
13
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/money'
14
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/point'
15
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/rails_5_1_point'
16
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/range'
17
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/specialized_string'
18
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/uuid'
19
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/vector'
20
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/xml'
21
-
22
- require 'active_record/connection_adapters/ovirt_legacy_postgresql/oid/type_map_initializer'
23
-
24
- module ActiveRecord
25
- module ConnectionAdapters
26
- module OvirtLegacyPostgreSQL
27
- module OID # :nodoc:
28
- end
29
- end
30
- end
31
- end
@@ -1,70 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class Array < Type::Value # :nodoc:
6
- include Type::Helpers::Mutable
7
-
8
- attr_reader :subtype, :delimiter
9
- delegate :type, :user_input_in_time_zone, :limit, to: :subtype
10
-
11
- def initialize(subtype, delimiter = ',')
12
- @subtype = subtype
13
- @delimiter = delimiter
14
-
15
- @pg_encoder = PG::TextEncoder::Array.new name: "#{type}[]", delimiter: delimiter
16
- @pg_decoder = PG::TextDecoder::Array.new name: "#{type}[]", delimiter: delimiter
17
- end
18
-
19
- def deserialize(value)
20
- if value.is_a?(::String)
21
- type_cast_array(@pg_decoder.decode(value), :deserialize)
22
- else
23
- super
24
- end
25
- end
26
-
27
- def cast(value)
28
- if value.is_a?(::String)
29
- value = @pg_decoder.decode(value)
30
- end
31
- type_cast_array(value, :cast)
32
- end
33
-
34
- def serialize(value)
35
- if value.is_a?(::Array)
36
- @pg_encoder.encode(type_cast_array(value, :serialize))
37
- else
38
- super
39
- end
40
- end
41
-
42
- def ==(other)
43
- other.is_a?(Array) &&
44
- subtype == other.subtype &&
45
- delimiter == other.delimiter
46
- end
47
-
48
- def type_cast_for_schema(value)
49
- return super unless value.is_a?(::Array)
50
- "[" + value.map { |v| subtype.type_cast_for_schema(v) }.join(", ") + "]"
51
- end
52
-
53
- def map(value, &block)
54
- value.map(&block)
55
- end
56
-
57
- private
58
-
59
- def type_cast_array(value, method)
60
- if value.is_a?(::Array)
61
- value.map { |item| type_cast_array(item, method) }
62
- else
63
- @subtype.public_send(method, value)
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end
70
- end
@@ -1,52 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class Bit < Type::Value # :nodoc:
6
- def type
7
- :bit
8
- end
9
-
10
- def cast(value)
11
- if ::String === value
12
- case value
13
- when /^0x/i
14
- value[2..-1].hex.to_s(2) # Hexadecimal notation
15
- else
16
- value # Bit-string notation
17
- end
18
- else
19
- value
20
- end
21
- end
22
-
23
- def serialize(value)
24
- Data.new(super) if value
25
- end
26
-
27
- class Data
28
- def initialize(value)
29
- @value = value
30
- end
31
-
32
- def to_s
33
- value
34
- end
35
-
36
- def binary?
37
- /\A[01]*\Z/ === value
38
- end
39
-
40
- def hex?
41
- /\A[0-9A-F]*\Z/i === value
42
- end
43
-
44
- protected
45
-
46
- attr_reader :value
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,13 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class BitVarying < OID::Bit # :nodoc:
6
- def type
7
- :bit_varying
8
- end
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module ConnectionAdapters
3
- module OvirtLegacyPostgreSQL
4
- module OID # :nodoc:
5
- class Bytea < Type::Binary # :nodoc:
6
- def deserialize(value)
7
- return if value.nil?
8
- return value.to_s if value.is_a?(Type::Binary::Data)
9
- PGconn.unescape_bytea(super)
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,48 +0,0 @@
1
- require 'ipaddr'
2
-
3
- module ActiveRecord
4
- module ConnectionAdapters
5
- module OvirtLegacyPostgreSQL
6
- module OID # :nodoc:
7
- class Cidr < Type::Value # :nodoc:
8
- def type
9
- :cidr
10
- end
11
-
12
- def type_cast_for_schema(value)
13
- subnet_mask = value.instance_variable_get(:@mask_addr)
14
-
15
- # If the subnet mask is equal to /32, don't output it
16
- if subnet_mask == (2**32 - 1)
17
- "\"#{value}\""
18
- else
19
- "\"#{value}/#{subnet_mask.to_s(2).count('1')}\""
20
- end
21
- end
22
-
23
- def serialize(value)
24
- if IPAddr === value
25
- "#{value}/#{value.instance_variable_get(:@mask_addr).to_s(2).count('1')}"
26
- else
27
- value
28
- end
29
- end
30
-
31
- def cast_value(value)
32
- if value.nil?
33
- nil
34
- elsif String === value
35
- begin
36
- IPAddr.new(value)
37
- rescue ArgumentError
38
- nil
39
- end
40
- else
41
- value
42
- end
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end