Changeset 620

Show
Ignore:
Timestamp:
05/03/07 14:29:56 (2 years ago)
Author:
sacha
Message:

Added ebXML Message Tracker

Ticket #100

This changeset adds:

o user ebXML Message Tracker code to command center
o Berkeley XML Database support
o installation script to download, compile and install the Berkeley XML Database

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/bin/make-install-c.sh

    r502 r620  
    3030############################################################################## 
    3131 
     32############################################################################## 
     33# This script is used to compile and install any C code for the target system. 
     34# 
     35# Currently there are two main users of this: 
     36# 
     37# o the XML encryption and XML digital signature taskers 
     38# o the Berkeley XML Database 
     39# 
     40############################################################################## 
     41 
     42 
    3243# Installation script 
    3344SRC_DIR=.. 
     
    5263} 
    5364 
     65DBXML_SOURCE_PATH=/usr/local/src 
     66DBXML_BIN_PATH=install/bin 
     67DBXML_URL=http://download-uk.oracle.com/berkeley-db/dbxml-2.3.10.tar.gz 
     68DBXML_PATH=dbxml-2.3.10 
     69 
     70check_installed_dbxml() 
     71{ 
     72    which dbxml 1>/dev/null 
     73    if [ $? -eq 0 ]; then 
     74        echo "dbxml binary is available. good." 
     75        return 0 
     76    else 
     77        echo "The dbxml binary (Berkeley XML Database) is not available." 
     78        if [ -d $DBXML_SOURCE_PATH/$DBXML_PATH ]; then 
     79            if [ -e $DBXML_SOURCE_PATH/$DBXML_PATH/$DBXML_TEST_PATH/dbxml ]; then 
     80                echo "The dbXML binary is installed in $DBXML_SOURCE_PATH/$DBXML_PATH/$DBXML_TEST_PATH/. That is good." 
     81                return 0 
     82            else 
     83                return -1 
     84            fi 
     85            return 0 
     86        else 
     87            return -1 
     88        fi 
     89    fi 
     90     
     91} 
     92 
     93blah() 
     94{ 
    5495check_installed_package gcc 
    5596check_installed_package libgmime-2.0-2 
     
    60101check_installed_package libxmlsec1-dev 
    61102check_installed_package libxmlsec1-openssl 
     103} 
     104 
     105install_berkeley_xml_database() 
     106{ 
     107    apt-get update 
     108    apt-get install -y binutils gcc g++ flex make 
     109 
     110    current=$(pwd) 
     111    cd $DBXML_SOURCE_PATH 
     112    echo "Downloading Berekely XML Database" 
     113    wget DBXML_URL 
     114#    cp $current/../xml-db/dbxml-2.3.10.tar.gz . 
     115    tar xvfz dbxml-2.3.10.tar.gz 
     116    cd $DBXML_PATH 
     117    echo "Continue building ? The compilation will take about 20 minutes (Core 2 Duo with 2GB Ram reference machine)." 
     118    read blah 
     119    sh buildall.sh 
     120    cd $current 
     121} 
     122 
     123check_installed_dbxml 
     124if [ $? -eq 0 ]; then 
     125    echo "Berkeley XML Database is installed." 
     126else 
     127    echo "Berkeley XML Database is not installed." 
     128    install_berkeley_xml_database 
     129fi 
     130 
     131exit 
     132 
    62133 
    63134WD=$(pwd) 
  • trunk/bin/run-command-center.rb

    r587 r620  
    3434require 'logger' 
    3535require 'fileutils' 
     36require 'rubygems' 
     37require 'xmlsimple' 
     38 
    3639config_file = "../defaults/hefeweizen-defaults" 
    3740 
     
    176179end 
    177180 
     181#################################################################################### 
     182#################################################################################### 
     183 
     184def message_tracker config 
     185  puts "                       HefeWeizen Message Tracker                   :: #{Time.now}" 
     186  puts "--------------------------------------------------------------------------------------------" 
     187  puts "                       PARTY  :: #{config['party_name']}" 
     188   
     189  puts "B - Back to Menu" 
     190  if FileTest.exists? config['xmldb_location'] then 
     191    puts "D - Delete XML Database                  U - Update XML Database of ebXML Messages." 
     192    puts "" 
     193    puts "# - Number of ebXML messages (unfiltered -> total)" 
     194    puts "A - All ebXML message ids of this party (filtered)" 
     195    puts "E - All ebXML messages that failed to be processed" 
     196    #    puts "L   Last messages L 5M -> last 5 minutes; L5D -> last 5 days" 
     197    puts "M <id> - Show details of message with id x" 
     198    puts "C <id> - Show all messages with conversatio id x" 
     199    puts "F - View Filter                          FF - Edit Filter                R - Run Filter" 
     200    #    puts "XML - Direct XML database access" 
     201  else 
     202    puts "" 
     203    puts "NO XML Database of ebXML Messages exists." 
     204    puts "" 
     205    puts "N - Create XML Database" 
     206  end 
     207  puts "" 
     208  puts "--------------------------------------------------------------------------------------------" 
     209  if !config['previous'].nil? then 
     210    puts "previous selection '#{config['previous']}'" 
     211    if !config['output'].nil? then 
     212      puts config['output'] 
     213    end 
     214  end 
     215   
     216end  
     217 
     218def x string, length 
     219  length = length * -1 if length < 0 
     220  if string.first.to_s.size > length then 
     221    return string.first[0..(length-2)] + "." 
     222  end 
     223  return string.first 
     224end 
     225 
     226def render_content content, elements 
     227  out  = "" 
     228 
     229  width = OpenStruct.new( { 'show_id' => 7, 'message_id' => 45, 'from' => 15,  
     230                            'to' => 15, 'service' => 35, 'action' => 20, 'timestamp' => 20, 'cpaid' => 15, 
     231                            'conversation_id' => 25 
     232                          } ) 
     233   
     234  all = [] 
     235  elements.each{ | element | 
     236    if width.send(element) then 
     237      all << (width.send element) 
     238    else 
     239      puts "Element '#{element}' not yet declared with a width." 
     240      all << 7 
     241      width.send "#{element}=", 7 
     242    end 
     243  } 
     244 
     245  total_string_length = all.inject(1){|total, i| total + i}+(all.size-1) 
     246  out += "-" * total_string_length + "\n" 
     247  format = "" 
     248  # + 1 because we add a short key (index) for the enduser 
     249  ((elements.size)+1).times{ | time | 
     250    time += 1 
     251    first = time + (time -1) 
     252    second = first + 1 
     253    format += "%#{first}$*#{second}$s " 
     254  } 
     255  format += "\n" 
     256   
     257  elements_and_size  = [ 'show', -7] 
     258  elements.each{ | ele | 
     259    size = (-(width.send ele)) rescue 7 
     260    elements_and_size << ele 
     261    size = size * -1 if size > 0 
     262    elements_and_size << size 
     263  } 
     264   
     265  out += "-"*total_string_length + "\n" 
     266  out += sprintf( format, *elements_and_size ) 
     267   
     268  message = XmlSimple.xml_in content 
     269  if message['messages'] then 
     270    ids = File.new "/tmp/message_ids", "w" 
     271    counter = 1 
     272     
     273    # popping show and show size 
     274    dud = elements_and_size.reverse 
     275    dud.pop; dud.pop 
     276    elements_and_size = dud.reverse 
     277     
     278    # pp message['messages'] 
     279 
     280    message['messages'].each{ | message | 
     281       
     282      content_output = Array.new 
     283      content_output << "D #{counter}" 
     284      content_output << -5 
     285 
     286      ids << ( (message['message_id'].first.to_s) +"\n") 
     287       
     288      value = size = nil 
     289      elements_and_size.each_index{ | index | 
     290        xml_element = elements_and_size[index] 
     291        if index % 2 == 0 then 
     292          # even 
     293          value = (message[xml_element])  
     294        else 
     295          # odd 
     296          content_output << (x(value, xml_element)) 
     297          xml_element = xml_element * -1 if xml_element > 0 
     298          content_output << xml_element 
     299          value = size = nil 
     300        end 
     301      } 
     302      counter += 1 
     303      out += sprintf( format , *content_output ) 
     304       
     305    } 
     306    ids.close 
     307  else 
     308    out += "No messages found.\n" 
     309  end 
     310  return out 
     311end 
     312 
     313def render_filter filter = nil 
     314  out = "" 
     315  out += "\n" 
     316  out += sprintf("%1$*2$s %3$*4$s\n", "Filter name:", -35, filter['name'], -40) 
     317  out += sprintf("%1$*2$s %3$*4$s\n", "Elements displayed:", -35, filter['elements'].join(", "), -40) 
     318  out += sprintf("%1$*2$s %3$*4$s\n", "Sorting done by:   ", -35, filter['sort'], -40) 
     319  out += "Conditions: (they are all AND filters)\n" 
     320  filter['conditions'].each_pair{ | key, value | 
     321    out += sprintf("   %1$*2$s %3$*4$s\n", "Filter for key #{key}: ", -35, value.to_s, -20) 
     322  } 
     323  return out 
     324end 
     325 
     326def edit_filter_menu filter 
     327  out = "" 
     328  out += "Current filter: " + render_filter( filter ) 
     329  out += "\n" 
     330  out += "Change filter:\n" 
     331#  out += "L Load a stored filter\n" 
     332#  out += "S Save this filter\n" 
     333#  out += "1 Edit elements to display\n" 
     334  out += "O Edit sorting\n" 
     335  out += "F Edit 'from' condition\n" 
     336  out += "T Edit 'to' condition\n" 
     337  out += "S Edit 'service' condition\n" 
     338  out += "A Edit 'action' condition\n" 
     339#  out += "D1 Edit 'starting date' condition\n" 
     340#  out += "D2 Edit 'ending date' condition\n" 
     341  out += "C Edit 'CPA Id' condition\n" 
     342  out += "X Back" 
     343  out   
     344end 
     345 
     346def edit_filter filter = nil 
     347  system "clear" 
     348  puts edit_filter_menu filter 
     349  while true do 
     350    input = gets.chomp 
     351    case input.upcase 
     352    when "LOAD" 
     353      output = "Choice: L\n" 
     354      output += "Not implemented.\n" 
     355    when "SAVE" 
     356      output = "Choice: S\n" 
     357      output += "Not implemented.\n" 
     358    when "1" # elements to edit 
     359    when "O" # sort 
     360      puts "Enter name of element to sort:" 
     361      input = gets.chomp 
     362      puts "Your choice:  #{input}\n" 
     363      filter['sort'] = input.empty? ? nil : [ input ] 
     364    when "F" # from  
     365      puts "Enter the sendings party's name:" 
     366      input = gets.chomp 
     367      puts "Your choice:  #{input}\n" 
     368      filter['conditions']['from'] = input.empty? ? nil : [ input ] 
     369    when "T" # to 
     370      puts "Enter the receiving party's name:" 
     371      input = gets.chomp 
     372      puts "Your choice:  #{input}\n" 
     373      filter['conditions']['to'] = input.empty? ? nil : [ input ] 
     374    when "S" # service 
     375      puts "Enter the service of the ebXML message:" 
     376      puts "Helpful service (ebMS): urn:oasis:names:tc:ebxml-msg:service" 
     377      input = gets.chomp 
     378      puts "Your choice:  #{input}\n" 
     379      filter['conditions']['service'] = input.empty? ? nil : [ input ] 
     380    when "A" # action 
     381      puts "Enter the action of the ebXML message:" 
     382      puts "Helpful actions: #{["MessageError", "Ping", "Pong", "StatusRequest", "StatusResponse", "Acknowledgment"].join(", ")}" 
     383      input = gets.chomp 
     384      puts "Your choice:  #{input}\n" 
     385      filter['conditions']['action'] = input.empty? ? nil : [ input ] 
     386    when "D1" # starting date 
     387    when "D2" # ending date 
     388    when "C" # cpa id 
     389      puts "Enter the CPA id to search for:" 
     390      input = gets.chomp 
     391      puts "Your choice:  #{input}\n" 
     392      filter['conditions']['cpaid'] = input.empty? ? nil : [ input ] 
     393    when "X" # go back 
     394      return filter, "Filter edited." 
     395    end 
     396    system "clear" 
     397    puts edit_filter_menu filter 
     398    puts output 
     399  end 
     400     
     401end 
     402 
     403def work_message_tracker party_name 
     404#  require "#{@config['LIB_DIR']}/hefeweizen_library_xmldb" 
     405  require "../src/hefeweizen_library_xmldb" 
     406#  require "#{@config['LIB_DIR']}/hefeweizen_library_message_state" 
     407  require "../src/hefeweizen_library_message_state" 
     408 
     409  party_location = "#{@config['MESSAGE_DIR']}/#{party_name}/" 
     410  db_location = "#{party_location}/#{party_name}_ebMS.xmldb" 
     411  bin_dir = @config['BDXML_BIN_DIR'] 
     412  party_id = party_name 
     413  xmldb = HefeWeizen::HefeWeizenLibrary::BerkeleyDBXMLHelper.new @config, party_id, party_location, db_location, bin_dir 
     414  config = {  
     415    'party_name' => party_name,  
     416    'previous' => nil,  
     417    'output' => nil, 
     418    'xmldb_location' => db_location 
     419  } 
     420 
     421  system "clear" 
     422  message_tracker config 
     423 
     424  elements = ['message_id', 'timestamp', 'service', 'from', 'to', 'action', 'cpaid'] 
     425  filter = {  
     426    'name' => "Default Filter", 
     427    'elements' => elements, 
     428    'conditions' => { 
     429      'from' => ['gnaraloo'], 
     430      'to' => nil, 
     431      'service' => nil, 
     432      'action' => nil, 
     433      'date_from' => nil, 
     434      'date_to' => nil, 
     435      'cpaid' => nil, 
     436      'conversation_id' => nil 
     437    }, 
     438    'sort' => 'timestamp' 
     439  } 
     440   
     441  while true do 
     442    config = {  
     443      'party_name' => party_name,  
     444      'output' => nil, 
     445      'xmldb_location' => db_location, 
     446      'filter' => nil 
     447    } 
     448 
     449 
     450    input = gets.chomp 
     451    case input.upcase 
     452    when "R" 
     453      config['output'] = "Run filter.\n" 
     454      the_condition = Hash.new 
     455      filter['conditions'].each{ | key, value | 
     456 
     457        # puts "#{key}: #{value.class.to_s}" 
     458         
     459        if not(value.nil? or value.empty?) then 
     460          the_condition[key] = [ '=', value.first ] 
     461        end 
     462      } 
     463 
     464      sorting = nil 
     465      if filter['sort'].class == Array then 
     466        sorting = filter['sort'].first 
     467      elsif filter['sort'].nil? then 
     468        sorting = nil 
     469      else 
     470        sorting = filter['sort'] 
     471      end 
     472 
     473      the_condition = nil if the_condition.size == 0 
     474      content = xmldb.all_ebXML_message_ids( { :format => "xml", :sort => sorting, 
     475                                               :elements => filter['elements'],  
     476                                               :condition => the_condition,  
     477                                             } ) 
     478      config['output'] += render_content content, filter['elements'] 
     479    when "F" 
     480      config['output'] = "Viewing filter.\n" 
     481      config['output'] += render_filter filter 
     482    when "FF" 
     483      config['output'] = "Edit filter.\n" 
     484      filter, config['output'] = edit_filter filter 
     485    when "XML" 
     486#      command = "cd #{db_location} && #{bin_dir} && cd -" 
     487#      system command 
     488    when "B" 
     489      return 
     490    when "N" 
     491      config['output'] = "Creating new xml database for Party '#{party_name}'.\n" 
     492      config['output'] += xmldb.create_new_ebMS_db 
     493    when "D" 
     494      if FileTest.exists? db_location then 
     495        FileUtils.rm db_location  
     496        config['output'] = "Removed XML database for Party '#{party_name}'.\n" 
     497      else 
     498        config['output'] = "There is no XML database for Party '#{party_name}'.\n" 
     499      end 
     500      config['xmldb'] = FileTest.exists? db_location 
     501    when "U" 
     502      config['output'] = "Updating xml database for Party '#{party_name}'.\n" 
     503      config['output'] += xmldb.update_xml_database 
     504    when "E" 
     505      ################################ 
     506      ## Is this working??? 
     507      ################################ 
     508      config['output'] = "All messages that failed to be processed.\n" 
     509      ebMSStateMgr = HefeWeizen::HefeWeizenLibrary::HefeWeizenMessageStateManager.new @config, "#{party_name}" 
     510      result = ebMSStateMgr.get_failed_messages_information 
     511      config['output'] += sprintf("%1$*2$s %3$*4$s\n", "Number of failed user messages: ", -35, result['number_failed_user_messages'].to_s, -20) 
     512      config['output'] += sprintf("%1$*2$s %3$*4$s\n", "Number of failed signals: ", -35, result['number_failed_signal_messages'].to_s, -20) 
     513      content = "<messages>" 
     514      result['signal_failed_ids'].each{| id | 
     515        content += "<message>" 
     516        content += "<message_id>#{id}</message_id>" 
     517        content += "</message>" 
     518      } 
     519      content += "</messages>" 
     520      puts content 
     521      elements = ['message_id'] 
     522      config['output'] += render_content content, elements 
     523 
     524      content = "<messages>" 
     525      result['user_failed_ids'].each{| id | 
     526        content += "<messages>" 
     527        content += "<message_id>#{id}</message_id>" 
     528        content += "</messages>" 
     529      } 
     530      content += "</messages>" 
     531      puts content 
     532      elements = ['message_id'] 
     533      config['output'] += render_content content, elements 
     534    when "A" 
     535      config['output'] = "All messages found with filter.\n" 
     536      # last day 
     537      diff = Time.now.to_f - 24*60*60*1 
     538      new_time = Time.at diff 
     539      new_time = new_time.strftime('%Y-%m-%dT%H:%M:%SZ') 
     540       
     541      # + add paginate 
     542      # :exclude => { 'service' => ['urn:oasis:names:tc:ebxml-msg:service'], 'action' => 'send_a_message_4'},  
     543      # :condition => { 'timestamp' => [ '>=', new_time ] },  
     544      elements = ['message_id', 'timestamp', 'service', 'from', 'to', 'action', 'cpaid'] 
     545      content = xmldb.all_ebXML_message_ids( { :format => "xml", :sort => "timestamp",  
     546                                               :elements => elements, 
     547                                             } ) 
     548      config['output'] += render_content content, elements 
     549    when "#" 
     550      config['output'] = "Number of total messages: " 
     551      config['output'] += xmldb.number_ebXML_messages 
     552    when "X" 
     553      exit 
     554      input = "M ID24db82b8edf911dbb0c500dc10007ca1Coronation" 
     555    when "Y" 
     556      input = "I 23971278edf911dba93200dc10007ca1" 
     557    end 
     558 
     559     
     560    if input =~ /[Cc] (.*)/ then 
     561      config['output'] = "All messages with conversation id '#{$1}'\n" 
     562      elements = ['message_id', 'conversation_id', 'timestamp', 'service', 'from', 'to', 'action', 'cpaid'] 
     563      elements = ['message_id', 'conversation_id', 'service', 'from', 'to', 'action'] 
     564      content = xmldb.all_ebXML_message_ids( { :format => "xml", :sort => "timestamp",  
     565                                               :elements => elements,  
     566                                               :condition => { 'conversation_id' => [ '=', "#{$1}" ] },  
     567                                             } ) 
     568      config['output'] += render_content content, elements 
     569    end 
     570    if input =~ /[Dd] (\d*)/ then 
     571      config['output'] = "Message detail of message with index '#{$1}'\n" 
     572      config['output'] += "---------------------------------------------\n" 
     573      if FileTest.exists? '/tmp/message_ids' then 
     574        ids = IO.readlines '/tmp/message_ids' 
     575        puts ids.size.to_s 
     576        puts $1 
     577        if $1.to_i > ids.size then 
     578          config['output'] += "There is no message via shortcut id '#{$1}'.\n" 
     579        else 
     580          message_id = ids[$1.to_i-1].strip 
     581          # puts "#{party_location}/messages/#{message_id}/ebXML_message.ebMS2" 
     582          begin 
     583            ebMS = HefeWeizen::HefeWeizenLibrary::EBMessage2.new @config, "#{party_location}/messages/#{message_id}/ebXML_message.ebMS2" 
     584            config['output'] += ebMS.long_summary 
     585          rescue Exception => e 
     586            config['output'] += e.inspect 
     587            config['output'] += "There is no message with ID '#{message_id}'" 
     588          end 
     589        end 
     590        FileUtils.rm '/tmp/message_ids' 
     591      else 
     592        config['output'] += "There is no message index. Please get a list of messages to view the detail of a message or \n" 
     593        config['output'] += "if you have the message id then use the M option" 
     594      end 
     595    end 
     596    if input =~ /[Mm] (.*)/ then 
     597      config['output'] = "Message detail of message with id '#{$1}'\n" 
     598      config['output'] += "---------------------------------------------\n" 
     599      puts "#{party_location}/messages/#{$1}/ebXML_message.ebMS2" 
     600      begin 
     601        ebMS = HefeWeizen::HefeWeizenLibrary::EBMessage2.new @config, "#{party_location}/messages/#{$1}/ebXML_message.ebMS2" 
     602        config['output'] += ebMS.long_summary 
     603      rescue Exception => e 
     604        config['output'] += e.inspect 
     605        config['output'] += "There is no message with ID '#{$1}'" 
     606      end 
     607    end 
     608  
     609    if input =~ /[Ll] (.*)/ then 
     610      if $1 =~ /(\d)M/ then 
     611        # minutes 
     612      elsif $1 =~ /\dH/ then 
     613        # hourse 
     614      end 
     615    end 
     616    config['previous'] = input 
     617    system "clear" 
     618    message_tracker config 
     619  end 
     620 
     621end 
     622 
     623 
     624#################################################################################### 
     625#################################################################################### 
     626#################################################################################### 
     627 
    178628def directive_dynamic_menu party_name, cpa_id, cpas_command, previous = nil, output = nil, number_directives = 1, payload_size = "small", resend_interval = 0 
    179629  puts "                       HefeWeizen Main Directive Dynamic Menu        :: #{Time.now}" 
     
    185635  puts "N - number of directives: #{number_directives}   R - Resends (after seconds): #{resend_interval}" 
    186636  puts "K - Show kids          K <Process Id> - Kill process           KA - Kill all kids" 
    187   puts "C - clear systems
     637  puts "C - clear systems      M Message Tracker
    188638  puts "" 
    189639  cpas_command.sort.each{ | entry | 
     
    257707        resend_interval = 0 
    258708      end 
     709    when "M" 
     710      work_message_tracker party_name 
    259711    when "L" 
    260712      payload_size = payload_size == "small" ? "large" : "small" 
     
    283735      children.each{ | pid | 
    284736        Process.kill 9, pid.to_i rescue nil 
    285         output += "Killed Process with id '#{pid.to_s}'
     737        output += "Killed Process with id '#{pid.to_s}'\n
    286738      } 
    287739      children = Array.new 
  • trunk/defaults/hefeweizen-defaults

    r553 r620  
    1515LIB_DIR=/usr/lib 
    1616BIN_DIR=/usr/sbin 
     17 
     18BDXML_BIN_DIR=/usr/local/src/dbxml-2.3.10/install/bin 
     19 
    1720CONFIG_DIR=/etc/hefeweizen 
    1821LOG_DIR=/home/hefeweizen-env/var/log/hefeweizen