Loading client/vos_import 0 → 100644 +75 −0 Original line number Diff line number Diff line #!/usr/bin/env python import pika import uuid import json import os import sys class AMQPClient(object): def __init__(self): self.rpcQueue = "import_queue" self.connection = pika.BlockingConnection(pika.ConnectionParameters(host = "rabbitmq")) self.channel = self.connection.channel() result = self.channel.queue_declare(queue = '', exclusive = True) self.callback_queue = result.method.queue self.channel.basic_consume(queue = self.callback_queue, on_message_callback = self.on_response, auto_ack = True) def on_response(self, ch, method, props, body): if self.corr_id == props.correlation_id: self.response = json.loads(body) def call(self, msg): self.response = None self.corr_id = str(uuid.uuid4()) self.channel.basic_publish(exchange = '', routing_key = self.rpcQueue, properties = pika.BasicProperties(reply_to = self.callback_queue, correlation_id = self.corr_id, ), body = json.dumps(msg)) while self.response is None: self.connection.process_data_events() return self.response def load(self, path, username): importRequest = { "requestType": "NODE_IMPORT", "path": path, "userName": username } importResponse = self.call(importRequest) def help(self): sys.exit(""" NAME vos_import SYNOPSYS vos_import PATH DESCRIPTION This tool imports external data on the VOSpace file catalog. Only one parameter is required: PATH the file/directory physical path. It can be a file or a directory. If the path is a directory, the command will scan it recursively. """) # Create new AMQPClient object vosImportCli = AMQPClient() # Check the number of input args if len(sys.argv) == 3: script, path, username = sys.argv else: vosImportCli.help() # Check the parameter passed by the user #if os.path.exists(path): vosImportCli.load(path, username) #else: # vosImportCli.help() Loading
client/vos_import 0 → 100644 +75 −0 Original line number Diff line number Diff line #!/usr/bin/env python import pika import uuid import json import os import sys class AMQPClient(object): def __init__(self): self.rpcQueue = "import_queue" self.connection = pika.BlockingConnection(pika.ConnectionParameters(host = "rabbitmq")) self.channel = self.connection.channel() result = self.channel.queue_declare(queue = '', exclusive = True) self.callback_queue = result.method.queue self.channel.basic_consume(queue = self.callback_queue, on_message_callback = self.on_response, auto_ack = True) def on_response(self, ch, method, props, body): if self.corr_id == props.correlation_id: self.response = json.loads(body) def call(self, msg): self.response = None self.corr_id = str(uuid.uuid4()) self.channel.basic_publish(exchange = '', routing_key = self.rpcQueue, properties = pika.BasicProperties(reply_to = self.callback_queue, correlation_id = self.corr_id, ), body = json.dumps(msg)) while self.response is None: self.connection.process_data_events() return self.response def load(self, path, username): importRequest = { "requestType": "NODE_IMPORT", "path": path, "userName": username } importResponse = self.call(importRequest) def help(self): sys.exit(""" NAME vos_import SYNOPSYS vos_import PATH DESCRIPTION This tool imports external data on the VOSpace file catalog. Only one parameter is required: PATH the file/directory physical path. It can be a file or a directory. If the path is a directory, the command will scan it recursively. """) # Create new AMQPClient object vosImportCli = AMQPClient() # Check the number of input args if len(sys.argv) == 3: script, path, username = sys.argv else: vosImportCli.help() # Check the parameter passed by the user #if os.path.exists(path): vosImportCli.load(path, username) #else: # vosImportCli.help()