{"action":"created","comment":{"url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments/67494204","id":67494204,"diff_hunk":"@@ -0,0 +1,102 @@\n+\"\"\"  The MQ Factory creates MQConnection objects\n+\"\"\"\n+from DIRAC                 import S_OK, S_ERROR, gLogger\n+from DIRAC.Core.Utilities  import ObjectLoader\n+from DIRAC.Resources.MessageQueue.Utilities import getMQueue\n+from DIRAC.Core.Utilities.DErrno import EMQUKN\n+\n+__RCSID__ = \"$Id$\"\n+\n+class MQConnectionFactory( object ):\n+\n+  #############################################################################\n+  def __init__(self, mqType=''):\n+    \"\"\" Standard constructor\n+    \"\"\"\n+    self.mqType = mqType\n+    self.log = gLogger.getSubLogger( self.mqType )\n+\n+  #############################################################################\n+  def __getMQConnection( self, queueName = None, parameters = None ):\n+    \"\"\" This method returns the MQConnection instance corresponding to the parameters and queue\n+\n+       :param str queueName: name of the queue. Can be provided as just queueName or <MQServer>::<queueName>\n+                             forms\n+       :param dict parameters: dictionary of connection parameters\n+       :return: S_OK(MQconnectionObject)/ S_ERROR\n+    \"\"\"\n+\n+    queueParameters = {}\n+    if queueName is not None:\n+      result = getMQueue( queueName )\n+      if not result['OK']:\n+        return result\n+      queueParameters = result['Value']\n+    if parameters is not None:\n+      queueParameters.update( parameters )\n+\n+    mqType = queueParameters.get( 'MQType' )\n+    if not mqType:\n+      mqType = self.mqType\n+    if not mqType:\n+      return S_ERROR( EMQUKN, 'No MQType specified' )\n+\n+    subClassName = mqType + 'MQConnection'\n+    objectLoader = ObjectLoader.ObjectLoader()\n+    result = objectLoader.loadObject( 'Resources.MessageQueue.%s' % subClassName, subClassName )\n+    if not result['OK']:\n+      self.log.error( 'Failed to load object', '%s: %s' % ( subClassName, result['Message'] ) )\n+      return result\n+\n+    ceClass = result['Value']\n+    try:\n+      mqConnection = ceClass()\n+      result = mqConnection.setParameters( queueParameters )\n+      if not result['OK']:\n+        return result\n+\n+    except Exception as exc:\n+      msg = 'MQConnectionFactory could not instantiate %s object: %s' % ( subClassName, str( exc ) )\n+      self.log.exception( 'Could not instantiate MQConnection object', IException = exc )\n+      self.log.warn( msg )\n+      return S_ERROR( msg )\n+\n+    return S_OK( mqConnection )\n+\n+  def getMQListener( self, queueName = None, parameters = None ):","path":"Resources/MessageQueue/MQConnectionFactory.py","position":66,"original_position":66,"commit_id":"c57db1ef79c8593b74542ea7ec141d31ee406b22","original_commit_id":"c57db1ef79c8593b74542ea7ec141d31ee406b22","user":{"login":"fstagni","id":785576,"avatar_url":"https://avatars.githubusercontent.com/u/785576?v=3","gravatar_id":"","url":"https://api.github.com/users/fstagni","html_url":"https://github.com/fstagni","followers_url":"https://api.github.com/users/fstagni/followers","following_url":"https://api.github.com/users/fstagni/following{/other_user}","gists_url":"https://api.github.com/users/fstagni/gists{/gist_id}","starred_url":"https://api.github.com/users/fstagni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fstagni/subscriptions","organizations_url":"https://api.github.com/users/fstagni/orgs","repos_url":"https://api.github.com/users/fstagni/repos","events_url":"https://api.github.com/users/fstagni/events{/privacy}","received_events_url":"https://api.github.com/users/fstagni/received_events","type":"User","site_admin":false},"body":"I think this method can be just coded\r\n```\r\nreturn __getMQConnection( queueName = queueName,  parameters = parameters )\r\n```","created_at":"2016-06-17T11:04:37Z","updated_at":"2016-06-17T11:04:37Z","html_url":"https://github.com/DIRACGrid/DIRAC/pull/2985#discussion_r67494204","pull_request_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985","_links":{"self":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments/67494204"},"html":{"href":"https://github.com/DIRACGrid/DIRAC/pull/2985#discussion_r67494204"},"pull_request":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985"}}},"pull_request":{"url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985","id":73746562,"html_url":"https://github.com/DIRACGrid/DIRAC/pull/2985","diff_url":"https://github.com/DIRACGrid/DIRAC/pull/2985.diff","patch_url":"https://github.com/DIRACGrid/DIRAC/pull/2985.patch","issue_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/2985","number":2985,"state":"open","locked":false,"title":"[v6r16] MessageQueue resources","user":{"login":"atsareg","id":679892,"avatar_url":"https://avatars.githubusercontent.com/u/679892?v=3","gravatar_id":"","url":"https://api.github.com/users/atsareg","html_url":"https://github.com/atsareg","followers_url":"https://api.github.com/users/atsareg/followers","following_url":"https://api.github.com/users/atsareg/following{/other_user}","gists_url":"https://api.github.com/users/atsareg/gists{/gist_id}","starred_url":"https://api.github.com/users/atsareg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atsareg/subscriptions","organizations_url":"https://api.github.com/users/atsareg/orgs","repos_url":"https://api.github.com/users/atsareg/repos","events_url":"https://api.github.com/users/atsareg/events{/privacy}","received_events_url":"https://api.github.com/users/atsareg/received_events","type":"User","site_admin":false},"body":"This PR contains classes for managing MQ connections as DIRAC Resources. The current implementation is only for the Stomp MQ protocol which is provided by the RabbitMQ. This is a wrapper over the MQConnection classes by Sergio as in #2974, and replaces this PR.\r\n\r\nUsers are supposed to use MQListener and MQPublisher classes which can be used as simply as the following:\r\n  \r\npublisher = MQPublisher( \"MyQueue\" )\r\nlistener = MQListener( \"MyQueue\" )\r\npublisher.put( message )\r\nlistener.get( message )\r\n\r\nOr:\r\npublisher = MQPublisher( \"MyQueue\" )\r\nlistener = MQListener( \"MyQueue\", callback = myCallback )\r\npublisher.put( message )\r\nlistener.run()\r\n\r\nExample of the MQ configuration description is the following:\r\n\r\nResources\r\n{\r\n  MQServices\r\n  {\r\n    mardirac3.in2p3.fr\r\n    {\r\n      MQType = Stomp\r\n      Host = mardirac3.in2p3.fr\r\n      Port = 9165\r\n      User = guest\r\n      Password = guest\r\n      Queues\r\n      {\r\n        TestQueue\r\n        {\r\n          Acknowledgement = True\r\n        }\r\n      }\r\n    }\r\n  }\r\n}\r\n\r\nThe queueName in the listener/publisher instantiation can be given as just the Queue name (if no ambiguities ) or fully qualified name like \"mardirac3.in2p3.fr::TestQueue\" to avoid ambiguities. ","created_at":"2016-06-14T14:08:58Z","updated_at":"2016-06-17T11:04:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"182270a646cc2d309b6ba8040fcf73901b4f7008","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985/commits","review_comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985/comments","review_comment_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/2985/comments","statuses_url":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/c57db1ef79c8593b74542ea7ec141d31ee406b22","head":{"label":"atsareg:dev-mq","ref":"dev-mq","sha":"c57db1ef79c8593b74542ea7ec141d31ee406b22","user":{"login":"atsareg","id":679892,"avatar_url":"https://avatars.githubusercontent.com/u/679892?v=3","gravatar_id":"","url":"https://api.github.com/users/atsareg","html_url":"https://github.com/atsareg","followers_url":"https://api.github.com/users/atsareg/followers","following_url":"https://api.github.com/users/atsareg/following{/other_user}","gists_url":"https://api.github.com/users/atsareg/gists{/gist_id}","starred_url":"https://api.github.com/users/atsareg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atsareg/subscriptions","organizations_url":"https://api.github.com/users/atsareg/orgs","repos_url":"https://api.github.com/users/atsareg/repos","events_url":"https://api.github.com/users/atsareg/events{/privacy}","received_events_url":"https://api.github.com/users/atsareg/received_events","type":"User","site_admin":false},"repo":{"id":1661846,"name":"DIRAC","full_name":"atsareg/DIRAC","owner":{"login":"atsareg","id":679892,"avatar_url":"https://avatars.githubusercontent.com/u/679892?v=3","gravatar_id":"","url":"https://api.github.com/users/atsareg","html_url":"https://github.com/atsareg","followers_url":"https://api.github.com/users/atsareg/followers","following_url":"https://api.github.com/users/atsareg/following{/other_user}","gists_url":"https://api.github.com/users/atsareg/gists{/gist_id}","starred_url":"https://api.github.com/users/atsareg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atsareg/subscriptions","organizations_url":"https://api.github.com/users/atsareg/orgs","repos_url":"https://api.github.com/users/atsareg/repos","events_url":"https://api.github.com/users/atsareg/events{/privacy}","received_events_url":"https://api.github.com/users/atsareg/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atsareg/DIRAC","description":"DIRAC Grid","fork":true,"url":"https://api.github.com/repos/atsareg/DIRAC","forks_url":"https://api.github.com/repos/atsareg/DIRAC/forks","keys_url":"https://api.github.com/repos/atsareg/DIRAC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atsareg/DIRAC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atsareg/DIRAC/teams","hooks_url":"https://api.github.com/repos/atsareg/DIRAC/hooks","issue_events_url":"https://api.github.com/repos/atsareg/DIRAC/issues/events{/number}","events_url":"https://api.github.com/repos/atsareg/DIRAC/events","assignees_url":"https://api.github.com/repos/atsareg/DIRAC/assignees{/user}","branches_url":"https://api.github.com/repos/atsareg/DIRAC/branches{/branch}","tags_url":"https://api.github.com/repos/atsareg/DIRAC/tags","blobs_url":"https://api.github.com/repos/atsareg/DIRAC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atsareg/DIRAC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atsareg/DIRAC/git/refs{/sha}","trees_url":"https://api.github.com/repos/atsareg/DIRAC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atsareg/DIRAC/statuses/{sha}","languages_url":"https://api.github.com/repos/atsareg/DIRAC/languages","stargazers_url":"https://api.github.com/repos/atsareg/DIRAC/stargazers","contributors_url":"https://api.github.com/repos/atsareg/DIRAC/contributors","subscribers_url":"https://api.github.com/repos/atsareg/DIRAC/subscribers","subscription_url":"https://api.github.com/repos/atsareg/DIRAC/subscription","commits_url":"https://api.github.com/repos/atsareg/DIRAC/commits{/sha}","git_commits_url":"https://api.github.com/repos/atsareg/DIRAC/git/commits{/sha}","comments_url":"https://api.github.com/repos/atsareg/DIRAC/comments{/number}","issue_comment_url":"https://api.github.com/repos/atsareg/DIRAC/issues/comments{/number}","contents_url":"https://api.github.com/repos/atsareg/DIRAC/contents/{+path}","compare_url":"https://api.github.com/repos/atsareg/DIRAC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atsareg/DIRAC/merges","archive_url":"https://api.github.com/repos/atsareg/DIRAC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atsareg/DIRAC/downloads","issues_url":"https://api.github.com/repos/atsareg/DIRAC/issues{/number}","pulls_url":"https://api.github.com/repos/atsareg/DIRAC/pulls{/number}","milestones_url":"https://api.github.com/repos/atsareg/DIRAC/milestones{/number}","notifications_url":"https://api.github.com/repos/atsareg/DIRAC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atsareg/DIRAC/labels{/name}","releases_url":"https://api.github.com/repos/atsareg/DIRAC/releases{/id}","deployments_url":"https://api.github.com/repos/atsareg/DIRAC/deployments","created_at":"2011-04-25T21:37:01Z","updated_at":"2015-12-12T17:32:56Z","pushed_at":"2016-06-16T16:16:48Z","git_url":"git://github.com/atsareg/DIRAC.git","ssh_url":"git@github.com:atsareg/DIRAC.git","clone_url":"https://github.com/atsareg/DIRAC.git","svn_url":"https://github.com/atsareg/DIRAC","homepage":"http://diracgrid.org","size":40235,"stargazers_count":2,"watchers_count":2,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":16,"forks":0,"open_issues":16,"watchers":2,"default_branch":"dev-fc"}},"base":{"label":"DIRACGrid:rel-v6r16","ref":"rel-v6r16","sha":"30738e2ce1b0a817ad5803b0530e056f6fbf3a40","user":{"login":"DIRACGrid","id":694842,"avatar_url":"https://avatars.githubusercontent.com/u/694842?v=3","gravatar_id":"","url":"https://api.github.com/users/DIRACGrid","html_url":"https://github.com/DIRACGrid","followers_url":"https://api.github.com/users/DIRACGrid/followers","following_url":"https://api.github.com/users/DIRACGrid/following{/other_user}","gists_url":"https://api.github.com/users/DIRACGrid/gists{/gist_id}","starred_url":"https://api.github.com/users/DIRACGrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DIRACGrid/subscriptions","organizations_url":"https://api.github.com/users/DIRACGrid/orgs","repos_url":"https://api.github.com/users/DIRACGrid/repos","events_url":"https://api.github.com/users/DIRACGrid/events{/privacy}","received_events_url":"https://api.github.com/users/DIRACGrid/received_events","type":"Organization","site_admin":false},"repo":{"id":1576831,"name":"DIRAC","full_name":"DIRACGrid/DIRAC","owner":{"login":"DIRACGrid","id":694842,"avatar_url":"https://avatars.githubusercontent.com/u/694842?v=3","gravatar_id":"","url":"https://api.github.com/users/DIRACGrid","html_url":"https://github.com/DIRACGrid","followers_url":"https://api.github.com/users/DIRACGrid/followers","following_url":"https://api.github.com/users/DIRACGrid/following{/other_user}","gists_url":"https://api.github.com/users/DIRACGrid/gists{/gist_id}","starred_url":"https://api.github.com/users/DIRACGrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DIRACGrid/subscriptions","organizations_url":"https://api.github.com/users/DIRACGrid/orgs","repos_url":"https://api.github.com/users/DIRACGrid/repos","events_url":"https://api.github.com/users/DIRACGrid/events{/privacy}","received_events_url":"https://api.github.com/users/DIRACGrid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DIRACGrid/DIRAC","description":"DIRAC Grid","fork":false,"url":"https://api.github.com/repos/DIRACGrid/DIRAC","forks_url":"https://api.github.com/repos/DIRACGrid/DIRAC/forks","keys_url":"https://api.github.com/repos/DIRACGrid/DIRAC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DIRACGrid/DIRAC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DIRACGrid/DIRAC/teams","hooks_url":"https://api.github.com/repos/DIRACGrid/DIRAC/hooks","issue_events_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/events{/number}","events_url":"https://api.github.com/repos/DIRACGrid/DIRAC/events","assignees_url":"https://api.github.com/repos/DIRACGrid/DIRAC/assignees{/user}","branches_url":"https://api.github.com/repos/DIRACGrid/DIRAC/branches{/branch}","tags_url":"https://api.github.com/repos/DIRACGrid/DIRAC/tags","blobs_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/refs{/sha}","trees_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/{sha}","languages_url":"https://api.github.com/repos/DIRACGrid/DIRAC/languages","stargazers_url":"https://api.github.com/repos/DIRACGrid/DIRAC/stargazers","contributors_url":"https://api.github.com/repos/DIRACGrid/DIRAC/contributors","subscribers_url":"https://api.github.com/repos/DIRACGrid/DIRAC/subscribers","subscription_url":"https://api.github.com/repos/DIRACGrid/DIRAC/subscription","commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/commits{/sha}","git_commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/commits{/sha}","comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/comments{/number}","issue_comment_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/comments{/number}","contents_url":"https://api.github.com/repos/DIRACGrid/DIRAC/contents/{+path}","compare_url":"https://api.github.com/repos/DIRACGrid/DIRAC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DIRACGrid/DIRAC/merges","archive_url":"https://api.github.com/repos/DIRACGrid/DIRAC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DIRACGrid/DIRAC/downloads","issues_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues{/number}","pulls_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls{/number}","milestones_url":"https://api.github.com/repos/DIRACGrid/DIRAC/milestones{/number}","notifications_url":"https://api.github.com/repos/DIRACGrid/DIRAC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DIRACGrid/DIRAC/labels{/name}","releases_url":"https://api.github.com/repos/DIRACGrid/DIRAC/releases{/id}","deployments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/deployments","created_at":"2011-04-06T11:47:53Z","updated_at":"2016-05-27T15:25:05Z","pushed_at":"2016-06-17T10:46:48Z","git_url":"git://github.com/DIRACGrid/DIRAC.git","ssh_url":"git@github.com:DIRACGrid/DIRAC.git","clone_url":"https://github.com/DIRACGrid/DIRAC.git","svn_url":"https://github.com/DIRACGrid/DIRAC","homepage":"http://diracgrid.org","size":61347,"stargazers_count":48,"watchers_count":48,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":94,"mirror_url":null,"open_issues_count":103,"forks":94,"open_issues":103,"watchers":48,"default_branch":"integration"}},"_links":{"self":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985"},"html":{"href":"https://github.com/DIRACGrid/DIRAC/pull/2985"},"issue":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/2985"},"comments":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/2985/comments"},"review_comments":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985/comments"},"review_comment":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/2985/commits"},"statuses":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/c57db1ef79c8593b74542ea7ec141d31ee406b22"}}}}
{"actor":{"display_login":"fstagni"}}