Commit ef87c5c1 authored by Eteri's avatar Eteri Committed by Klaus Wölfel

solve different tag problem

parent 06eb7d5c
...@@ -15,14 +15,12 @@ ...@@ -15,14 +15,12 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
require 'net/http' require 'net/http'
require 'openssl' require 'openssl'
require 'http'
# class representing a Wendelin client # class representing a Wendelin client
class WendelinClient class WendelinClient
# `streamtool_uri` - URI pointing to portal_input_data_stream "mountpoint" # `streamtool_uri` - URI pointing to portal_input_data_stream "mountpoint"
# `credentials` # {'user' => _, 'password' => _} TODO change to certificate # `credentials` # {'user' => _, 'password' => _} TODO change to certificate
# `log` - logger to use # `log` - logger to use
...@@ -32,35 +30,36 @@ class WendelinClient ...@@ -32,35 +30,36 @@ class WendelinClient
@log = log @log = log
end end
# start request in an independent function to keep the connection open # start request in an independent function to keep the connection open
def start_request(uri) def start_request(uri)
puts ' START NEW REQUEST'
@http = Net::HTTP.start(uri.hostname, uri.port, @http = Net::HTTP.start(uri.hostname, uri.port,
:use_ssl => (uri.scheme == 'https'), use_ssl: (uri.scheme == 'https'),
:verify_mode => OpenSSL::SSL::VERIFY_NONE, verify_mode: OpenSSL::SSL::VERIFY_NONE,
# Net::HTTP default open timeout is infinity, which results # Net::HTTP default open timeout is infinity, which results
# in thread hang forever if other side does not fully # in thread hang forever if other side does not fully
# establish connection. Default read_timeout is 60 seconds. # establish connection. Default read_timeout is 60 seconds.
# We go safe way and make sure all timeouts are defined. # We go safe way and make sure all timeouts are defined.
:ssl_timeout => 60, ssl_timeout: 60,
:open_timeout => 60, open_timeout: 60,
:read_timeout => 60, read_timeout: 60,
:keep_alive_timeout => 60,) keep_alive_timeout: 60)
end end
# ingest `data_chunk` to a stream referenced as `reference` # ingest `data_chunk` to a stream referenced as `reference`
def ingest(reference, data_chunk) def ingest(reference, data_chunk)
uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}") uri = URI("#{@streamtool_uri}/ingest?reference=#{reference}")
puts 'uri = '
puts uri
# call start_request if request is undefined # call start_request if request is undefined
@request ||= start_request(uri) @request ||= start_request(uri)
@request = Net::HTTP::Post.new(uri)
# connect again if the connection is not started # connect again if the connection is not started
if ! @http.started?() start_request(uri) unless @http.started?
start_request(uri)
end @request = Net::HTTP::Post.new(uri)
# When using 'application/x-www-form-urlencoded', Ruby encodes with regex # When using 'application/x-www-form-urlencoded', Ruby encodes with regex
# and it is far too slow. Such POST is legit: # and it is far too slow. Such POST is legit:
...@@ -68,7 +67,7 @@ class WendelinClient ...@@ -68,7 +67,7 @@ class WendelinClient
@request.body = data_chunk @request.body = data_chunk
@request.content_type = 'application/octet-stream' @request.content_type = 'application/octet-stream'
if @credentials.has_key?('user') if @credentials.key?('user')
@request.basic_auth @credentials['user'], @credentials['password'] @request.basic_auth @credentials['user'], @credentials['password']
end end
...@@ -79,35 +78,32 @@ class WendelinClient ...@@ -79,35 +78,32 @@ class WendelinClient
@log.trace "uri\t=> #{@request.uri}" @log.trace "uri\t=> #{@request.uri}"
@log.trace "body\t=> #{@request.body}" @log.trace "body\t=> #{@request.body}"
@log.trace "body_stream\t=> #{@request.body_stream}" @log.trace "body_stream\t=> #{@request.body_stream}"
@request.each {|h| @log.trace "#{h}:\t#{@request[h]}"} @request.each { |h| @log.trace "#{h}:\t#{@request[h]}" }
@log.trace @log.trace
end end
begin begin
res = @http.request(@request) # Net::HTTPResponse object res = @http.request(@request) # Net::HTTPResponse object
end end
rescue StandardError
rescue
# some http/ssl/other connection error # some http/ssl/other connection error
@log.warn "HTTP ERROR:" @log.warn 'HTTP ERROR:'
raise raise
else else
@log.on_trace do @log.on_trace do
@log.trace '>>> RESPONSE' @log.trace '>>> RESPONSE'
res.each {|h| @log.trace "#{h}:\t#{res[h]}"} res.each { |h| @log.trace "#{h}:\t#{res[h]}" }
@log.trace "code\t=> #{res.code}" @log.trace "code\t=> #{res.code}"
@log.trace "msg\t=> #{res.message}" @log.trace "msg\t=> #{res.message}"
@log.trace "class\t=> #{res.class}" @log.trace "class\t=> #{res.class}"
@log.trace "body:", res.body @log.trace 'body:', res.body
end end
if res.kind_of?(Net::HTTPSuccess) # res.code is 2XX if res.is_a?(Net::HTTPSuccess) # res.code is 2XX
#@log.info "ingested ok" # @log.info "ingested ok"
else else
@log.warn "FAIL:" @log.warn 'FAIL:'
res.value res.value
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment