require 'imperituroard/platforms/cps/qps_connector' require 'imperituroard/platforms/cps/cps_mongo_connector' class Kosmonavty_2 attr_accessor :file_of_changed_prof, :qps_connector, :cps_mongo, :filename_processed_added, :logfile, :filename_failed_add, :logfile_return, :filename_processed_return, :filename_failed_return def initialize(file_of_changed_prof) @file_of_changed_prof = file_of_changed_prof @qps_connector = Qps_2.new('http://172.24.220.65:8080/ua/wsdl/UnifiedApi.wsdl', 'http://172.24.220.65:8080/ua/soap', 'http://broadhop.com/unifiedapi/soap/types') @cps_mongo = MongoCPS_2.new('site1-ca-pri-sessionmgr01', '27720', 'spr') @filename_processed_added = 'testfile.txt' @filename_processed_return = 'testfile_return.txt' @logfile = 'day60log.txt' @logfile_return = 'day60log_return.txt' @filename_failed_add = 'testfile_failed.txt' @filename_failed_return = 'testfile_failed_return.txt' end def write_to_file_rewr(new_text) File.open(file_of_changed_prof + filename_processed_added, 'w') {|file| file.write(new_text)} end def add_line_to_file(new_line, filename) File.open(file_of_changed_prof + filename, 'a') do |file| line = new_line + "\n" file.write line end end def get_msisdn_from_file begin file = File.open(file_of_changed_prof + filename_processed_added) file_data = file.read output = [] splitted_lines = file_data.split("\n") splitted_lines.each do |aaa| if aaa != '' && aaa != "\n" && aaa.include?(';') msssisdn = aaa.split(';') output.push(msssisdn[0]) end end return output rescue return [] end end def get_msisdn_from_file_for_del begin file = File.open(file_of_changed_prof + filename_processed_added) file_data = file.read output = [] splitted_lines = file_data.split("\n") splitted_lines.each do |aaa| if aaa != '' && aaa != "\n" && aaa.include?(';') msssisdn = aaa.split(';') output.push({:msisdn => msssisdn[0], :devId => msssisdn[1]}) end end return output rescue return [] end end def main_processor_add_acl process_json = {} process_msisdn_list = [] #dat_cps = cps_mongo.get_minsk_fttx_fizlic dat_cps = cps_mongo.get_minsk_fttx_zone2 dat_cps.each do |t| gg = t.split(';') process_json[gg[0]] = gg[1] process_msisdn_list.push(gg[0]) end from_file = get_msisdn_from_file list_for_process = process_msisdn_list - from_file uniq_list_for_proc = list_for_process.uniq uniq_list_for_proc.each do |ddd| ans = qps_connector.add_avp_acl(ddd, 'GTFU_IN') #ans = {:change_subscriber_avps_response => {:error_code => '0'}} begin if ans[:change_subscriber_avps_response][:error_code] == '0' add_line_to_file(ddd + ';' + process_json[ddd], filename_processed_added) resp = qps_connector.stop_session_username(process_json[ddd]) add_line_to_file(ddd + ';' + process_json[ddd] + 'stop_session: ' + resp.to_s, logfile) else add_line_to_file(ddd + ';' + process_json[ddd], filename_failed_add) add_line_to_file(ddd + ';' + process_json[ddd] + 'add_avps: ' + ans.to_s, logfile) end rescue add_line_to_file(ddd + ';' + process_json[ddd], filename_failed_add) add_line_to_file(ddd + ';' + process_json[ddd] + 'add_avps: ' + ans.to_s, logfile) end end end def main_processor_del_acl from_file = get_msisdn_from_file_for_del from_file.each do |ddd1| ans = qps_connector.delete_avp_acl(ddd1[:msisdn]) if ans[:change_subscriber_avps_response][:error_code] == '0' add_line_to_file(ddd1.to_s, filename_processed_return) resp = qps_connector.stop_session_username(ddd1[:devId]) add_line_to_file(ddd1.to_s + ';' + ddd1[:devId] + 'stop_session: ' + resp.to_s, logfile_return) else add_line_to_file(ddd1.to_s, filename_failed_return) add_line_to_file(ddd1.to_s + ';' + ddd1[:devId] + 'del_avp: ' + ans.to_s, logfile_return) end end end def test qps_connector.stop_session_username('Ethernet1/0/7:1907.0 Min_Rokossovskogo_145_5/0/0/1/0/7') end def test_mongo dat_cps = cps_mongo.get_minsk_fttx_zone2 dat_cps2 = cps_mongo.get_minsk_fttx_zone3_rokos dat_cps3 = cps_mongo.get_minsk_fttx_zone4_mega dat_cps4 = cps_mongo.get_minsk_fttx_zone5_koles dat_cps5 = cps_mongo.get_minsk_fttx_zone6_all dat_cps7 = cps_mongo.get_minsk_fttx_zone7_3last #1 p "get_minsk_fttx_zone2" p dat_cps p dat_cps.length #2 p "get_minsk_fttx_zone3_rokos" p dat_cps2 p dat_cps2.length #3 p "get_minsk_fttx_zone4_mega" p dat_cps3 p dat_cps3.length #4 p "get_minsk_fttx_zone5_koles" p dat_cps4 p dat_cps4.length #5 p "get_minsk_fttx_zone6_all" p dat_cps5 p dat_cps5.length p "get_minsk_fttx_zone7_3last" p dat_cps7 p dat_cps7.length end end #p test.delete_avp_acl("375298766719") #p test.add_avp_acl("375298766719", "ffgfg2") #test2 = Kosmonavty_2.new('/Users/imperituroard/Desktop/') #test2.main_processor_add_acl #test2.main_processor_del_acl #test2.test_mongo