Class: JayAPI::PropertiesFetcher

Inherits:
Object
  • Object
show all
Includes:
Elasticsearch::Time
Defined in:
lib/jay_api/properties_fetcher.rb

Overview

Fetches build properties from the provided information. ATTENTION: There’s a maximum number of data hashes that are returned (see MAX_SIZE).

Constant Summary collapse

MAX_SIZE =
100
BUILD_NAME_FIELD =

Name of the field used when querying the index for data using the name of the build job.

'build_properties.build_name.keyword'
BUILD_NUMBER_FIELD =
'build_properties.build_number'
VERSION_CODE_FIELD =

Name of the field used when querying the index for data using the version of the software.

'build_properties.version_code.keyword'
BUILD_RELEASE_FIELD =
'build_properties.build_release'
SUT_REVISION_FIELD =

Name of the field used when querying the index for data using the SUT Revision.

'sut_revision.keyword'
TIMESTAMP_FIELD =
'timestamp'

Constants included from Elasticsearch::Time

Elasticsearch::Time::TIME_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Elasticsearch::Time

#format_time

Constructor Details

#initialize(index:) ⇒ PropertiesFetcher

Initializes a PropertiesFetcher object

Parameters:

  • index (JsyAPI::Elasticsearch::Index)

    The Elasticsearch index to use to fetch build properties data.



35
36
37
# File 'lib/jay_api/properties_fetcher.rb', line 35

def initialize(index:)
  @index = index
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



30
31
32
# File 'lib/jay_api/properties_fetcher.rb', line 30

def index
  @index
end

Instance Method Details

#after(timestamp) ⇒ JayAPI::PropertiesFetcher

Constraints the results to properties that were pushed after the given timestamp.

Parameters:

  • timestamp (Time, String)

    A timestamp to filter the build properties with. If a String is given it is assumed to be in the right format for Elasticsearch. No conversion / checking will be performed over it.

Returns:



98
99
100
101
102
103
# File 'lib/jay_api/properties_fetcher.rb', line 98

def after(timestamp)
  # noinspection RubyMismatchedParameterType (checked by the if modifier)
  timestamp = format_time(timestamp) if timestamp.is_a?(Time)
  query_builder.query.bool.must.query_string(fields: TIMESTAMP_FIELD, query: "> \"#{timestamp}\"")
  self
end

#all {|Hash| ... } ⇒ Enumerator

Allows the caller to retrieve or iterate over the set of Build Properties entries. The method can be called with or without a block. If a block is given then each of the Build Properties entries will be yielded to the block, if no block is given then an Enumerator is returned.

Yields:

  • (Hash)

    One of the Build Properties entries.

Returns:

  • (Enumerator)

    If no block is given an Enumerator object for all the property sets that were found is returned (might be empty). With a block the return value is undefined.



166
167
168
# File 'lib/jay_api/properties_fetcher.rb', line 166

def all(&block)
  fetch_properties.all(&block)
end

#andJayAPI::PropertiesFetcher

This method is here only for readability. It is meant to act as a conjunction between two method calls.

Examples:

properties_fetcher.by_build_job('Release-XYZ01-Master').and.by_build_number(106)

Returns:



125
126
127
# File 'lib/jay_api/properties_fetcher.rb', line 125

def and
  self
end

#before(timestamp) ⇒ JayAPI::PropertiesFetcher

Constraints the results to properties that were pushed before the given timestamp.

Parameters:

  • timestamp (Time, String)

    A timestamp to filter the build properties with. If a String is given it is assumed to be in the right format for Elasticsearch. No conversion / checking will be performed over it.

Returns:



112
113
114
115
116
117
# File 'lib/jay_api/properties_fetcher.rb', line 112

def before(timestamp)
  # noinspection RubyMismatchedParameterType (checked by the if modifier)
  timestamp = format_time(timestamp) if timestamp.is_a?(Time)
  query_builder.query.bool.must.query_string(fields: TIMESTAMP_FIELD, query: "< \"#{timestamp}\"")
  self
end

#by_build_job(build_job) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties belonging to the given build job

Parameters:

  • build_job (String)

    The name of the build job, for example: ‘Release-XYZ01-Master’.

Returns:



55
56
57
58
# File 'lib/jay_api/properties_fetcher.rb', line 55

def by_build_job(build_job)
  query_builder.query.bool.must.match_phrase(field: BUILD_NAME_FIELD, phrase: build_job)
  self
end

#by_build_number(build_number) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties belonging to the given build number

Parameters:

  • build_number (String, Integer)

    The build number, for example 432

Returns:



65
66
67
68
# File 'lib/jay_api/properties_fetcher.rb', line 65

def by_build_number(build_number)
  query_builder.query.bool.must.query_string(fields: BUILD_NUMBER_FIELD, query: build_number)
  self
end

#by_release_tag(release_tag) ⇒ JayAPI::PropertiesFetcher

Constraint the results to properties that belong or don’t belong to (depending on the release_tag parameter) a release build.

Parameters:

  • release_tag (Boolean)

    True If build properties should come from a release, false if they SHOULD NOT.

Returns:



86
87
88
89
# File 'lib/jay_api/properties_fetcher.rb', line 86

def by_release_tag(release_tag)
  query_builder.query.bool.must.query_string(fields: BUILD_RELEASE_FIELD, query: release_tag)
  self
end

#by_software_version(software_version) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties for which the software version matches the given one.

Parameters:

  • software_version (String)

    The software version, for example ‘D310’.

Returns:



75
76
77
78
# File 'lib/jay_api/properties_fetcher.rb', line 75

def by_software_version(software_version)
  query_builder.query.bool.must.match_phrase(field: VERSION_CODE_FIELD, phrase: software_version)
  self
end

#by_sut_revision(sut_revision) ⇒ JayAPI::PropertiesFetcher

Constraints the results to those properties belonging to the given SUT Revision.

Parameters:

  • sut_revision (String)

    For example: ‘23-08-02/master’.

Returns:



44
45
46
47
# File 'lib/jay_api/properties_fetcher.rb', line 44

def by_sut_revision(sut_revision)
  query_builder.query.bool.must.match_phrase(field: SUT_REVISION_FIELD, phrase: sut_revision)
  self
end

#firstHash?

Returns The first set of properties (ordered chronologically) or nil if no properties are found.

Returns:

  • (Hash, nil)

    The first set of properties (ordered chronologically) or nil if no properties are found



138
139
140
141
# File 'lib/jay_api/properties_fetcher.rb', line 138

def first
  sort_records('asc').size(1)
  fetch_properties.first
end

#lastHash?

Returns The last set of properties (ordered chronologically) or nil if no properties are found.

Returns:

  • (Hash, nil)

    The last set of properties (ordered chronologically) or nil if no properties are found.



131
132
133
134
# File 'lib/jay_api/properties_fetcher.rb', line 131

def last
  sort_records('asc').size(1)
  fetch_properties.last
end

#limit(size) ⇒ JayAPI::PropertiesFetcher Also known as: size

Limits the amount of records returned to the given number.

Parameters:

  • size (Integer)

    The number of records to return. If this number is greater than MAX_SIZE then MAX_SIZE will be used instead.

Returns:



148
149
150
151
152
153
# File 'lib/jay_api/properties_fetcher.rb', line 148

def limit(size)
  size = [size, MAX_SIZE].min
  # noinspection RubyMismatchedParameterType (The array will never be empty)
  query_builder.size(size)
  self
end