def log_invoked_service(payload, invoked_service): rvi_node = "http://localhost:8801" service = "jlr.com/backend/logging/report/serviceinvoked" print "args:", payload # json_args = json.loads(payload) # print "json_args:", json_args rvi_args = [ { 'username': payload['username'], 'vehicleVIN': payload['vehicleVIN'], 'service': invoked_service, 'latitude': payload['latitude'], 'longitude': payload['longitude'], 'timestamp': datetime.now().strftime('%Y-%m-%dT%H:%M:%S.000Z'), }, ] print "rvi_args:", rvi_args rvi = RVI(rvi_node) rvi.message(service, rvi_args)
elif o == '-s': speedup = float(a) else: usage() # Welcome message print "RVI Big Data Device Simulator" print "RVI Node: ", rvi_url print "File(s): ", file_names print "Loop data: ", loop_data print "Speedup: ", speedup print "Adjust time stamp: ", adjust_ts # Setup outbound JSON-RPC connection to the RVI Service Edge rvi = RVI(rvi_url) # Setup data sender data_sender = DataSender("jlr.com/backend/logging/report", rvi) for file_name in file_names: try: file_reader = TaxiFileReader(file_name, data_sender, speedup, loop_data, adjust_ts) except IOError: print "Failed to open file {}. Skipped.".format(file_name) file_reader.start() # catch signals for proper shutdown for sig in (SIGABRT, SIGTERM, SIGINT):
opts, args = getopt.getopt(sys.argv[1:], "n:") rvi_node_url = "http://localhost:8801" for o, a in opts: if o == "-n": rvi_node_url = a else: usage() if len(args) != 1: usage() service_name = args[0] # Setup a connection to the local RVI node rvi = RVI(rvi_node_url) # Starting the thread that handles incoming calls is # not really necessary since register_service will do it for us. rvi.start_serve_thread() rvi.set_services_available_callback(services_available) rvi.set_services_unavailable_callback(services_unavailable) # Register our service and invoke 'service_invoked' if we # get an incoming JSON-RPC call to it from the RVI node # full_service_name = rvi.register_service(service_name, service_invoked) print "RVI General Service."
print print "Example: ./callrvi.py http://rvi1.nginfotpdx.net:8801" print sys.exit(255) # # Check that we have the correct arguments # if len(sys.argv) != 1 and len(sys.argv) != 2: usage() progname = sys.argv[0] if len(sys.argv) == 2: rvi_node = sys.argv[1] else: rvi_node = "http://localhost:8801" # # Setup an outbound JSON-RPC connection to the backend RVI node # Service Edge. # rvi = RVI(rvi_node) # # Retreieve services # for i in rvi.get_available_services(): print i