module BlackStack::Pampa

Constants

SLEEP_SECONDS

Public Class Methods

api_domain() click to toggle source
# File lib/pampa_workers.rb, line 74
def self.api_domain
  @@api_domain
end
api_key() click to toggle source
# File lib/pampa_workers.rb, line 58
def self.api_key()
  @@api_key 
end
api_port() click to toggle source
# File lib/pampa_workers.rb, line 82
def self.api_port
  @@api_port
end
api_protocol() click to toggle source
# File lib/pampa_workers.rb, line 66
def self.api_protocol
  @@api_protocol
end
api_url() click to toggle source

get the full URL of the worker api server

# File lib/pampa_workers.rb, line 87
def self.api_url()
  "#{BlackStack::Pampa::api_protocol}://#{BlackStack::Pampa::api_domain}:#{BlackStack::Pampa::api_port}"
end
connection_descriptor() click to toggle source

TODO: doc me!

# File lib/pampa_workers.rb, line 210
def self.connection_descriptor()           
  ret = nil
  
  # validar que el formato no sea nulo
  if (self.division_name.to_s.length == 0)
    raise "Division name expected."
  end
  
  if (self.division_name == "local") 
    ret = {
      :adapter => 'tinytds',
      :dataserver => BlackStack::Pampa::db_url, # IP or hostname
      :port => BlackStack::Pampa::db_port, # Required when using other that 1433 (default)
      :database => BlackStack::Pampa::db_name,
      :user => BlackStack::Pampa::db_user,
      :password => BlackStack::Pampa::db_password,
      :timeout => BlackStack::Pampa::timeout
      }      
  else
    url = "#{BlackStack::Pampa::api_url}/api1.2/division/get.json"
    res = BlackStack::Netting::call_post(url, {
      'api_key' => BlackStack::Pampa::api_key, 
      'dname' => "#{self.division_name}",
    })
    parsed = JSON.parse(res.body)
    
    if (parsed["status"] != BlackStack::Netting::SUCCESS)
      raise "Error getting connection string: #{parsed["status"]}"
    else
      wid = parsed["value"]
      
      ret = {
        :adapter => 'tinytds',
        :dataserver => parsed["db_url"], # IP or hostname
        :port => parsed["db_port"], # only required if port is different than 1433
        :database => parsed["db_name"],
        :user => parsed["db_user"],
        :password => parsed["db_password"],
        :timeout => BlackStack::Pampa::timeout
      }
    end
  end
  
  ret
end
db_connection() click to toggle source
# File lib/pampa_workers.rb, line 257
def self.db_connection()
  Sequel.connect(BlackStack::Pampa::connection_descriptor)
end
db_name() click to toggle source
# File lib/pampa_workers.rb, line 186
def self.db_name
  @@db_name
end
db_password() click to toggle source
# File lib/pampa_workers.rb, line 196
def self.db_password
  @@db_password
end
db_port() click to toggle source
# File lib/pampa_workers.rb, line 181
def self.db_port
  @@db_port
end
db_url() click to toggle source
# File lib/pampa_workers.rb, line 176
def self.db_url
  @@db_url
end
db_user() click to toggle source
# File lib/pampa_workers.rb, line 191
def self.db_user
  @@db_user
end
division_name() click to toggle source
# File lib/pampa_workers.rb, line 37
def self.division_name() 
  @@division_name
end
farm_external_ip_addresses() click to toggle source
# File lib/pampa_workers.rb, line 149
def self.farm_external_ip_addresses()
  @@farm_external_ip_addresses
end
get_guid() click to toggle source
# File lib/pampa_workers.rb, line 159
def self.get_guid
  res = BlackStack::Netting::call_post(
    "#{self.api_url}/api1.4/get_guid.json",
    {'api_key' => @@api_key}
  )
  parsed = JSON.parse(res.body)
  parsed['value']        
end
id_timezone_default() click to toggle source
# File lib/pampa_workers.rb, line 132
def self.id_timezone_default()
  @@id_timezone_default
end
require_db_classes() click to toggle source
# File lib/pampa_workers.rb, line 262
def self.require_db_classes()
  # You have to load all the Sinatra classes after connect the database.
  require_relative '../lib/pampa-local.rb'
end
set_api_key(s) click to toggle source
# File lib/pampa_workers.rb, line 92
def self.set_api_key(s)
  @@api_key = s
end
set_api_url(h) click to toggle source
# File lib/pampa_workers.rb, line 97
def self.set_api_url(h)
  @@api_key = h[:api_key]
  @@api_protocol = h[:api_protocol]
  @@api_domain = h[:api_domain]
  @@api_port = h[:api_port]
end
set_db_params(h) click to toggle source

Set connection params to the central database

# File lib/pampa_workers.rb, line 201
def self.set_db_params(h)
  @@db_url = h[:db_url]
  @@db_port = h[:db_port]
  @@db_name = h[:db_name]
  @@db_user = h[:db_user]
  @@db_password = h[:db_password]
end
set_division_name(s) click to toggle source
# File lib/pampa_workers.rb, line 42
def self.set_division_name(s) 
  @@division_name = s
end
set_farm_external_ip_addresses(a) click to toggle source
# File lib/pampa_workers.rb, line 154
def self.set_farm_external_ip_addresses(a)
  @@farm_external_ip_addresses = a
end
set_id_timezone_default(id) click to toggle source
# File lib/pampa_workers.rb, line 137
def self.set_id_timezone_default(id)
  @@id_timezone_default = id
end
set_storage_folder(path) click to toggle source
# File lib/pampa_workers.rb, line 117
def self.set_storage_folder(path)
  @@storage_folder = path
end
set_storage_sub_folders(a) click to toggle source
# File lib/pampa_workers.rb, line 120
def self.set_storage_sub_folders(a)
  @@storage_sub_folders = a
end
set_timeout(n) click to toggle source
# File lib/pampa_workers.rb, line 51
def self.set_timeout(n) 
  @@timeout = n
end
storage_folder() click to toggle source
# File lib/pampa_workers.rb, line 109
def self.storage_folder()
  @@storage_folder
end
storage_sub_folders() click to toggle source
# File lib/pampa_workers.rb, line 112
def self.storage_sub_folders()
  @@storage_sub_folders
end
timeout() click to toggle source
# File lib/pampa_workers.rb, line 46
def self.timeout() 
  @@timeout
end