@utilities.arguments_not_none<EOL><INDENT>def assign_agent_to_resource(self, agent_id, resource_id):<DEDENT>
<EOL>collection = JSONClientValidated('<STR_LIT>',<EOL>collection='<STR_LIT>',<EOL>runtime=self._runtime)<EOL>resource = collection.find_one({'<STR_LIT>': ObjectId(resource_id.get_identifier())})<EOL>try:<EOL><INDENT>ResourceAgentSession(<EOL>self._catalog_id, self._proxy, self._runtime).get_resource_by_agent(agent_id)<EOL><DEDENT>except errors.NotFound:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>raise errors.AlreadyExists()<EOL><DEDENT>if '<STR_LIT>' not in resource:<EOL><INDENT>resource['<STR_LIT>'] = [str(agent_id)]<EOL><DEDENT>else:<EOL><INDENT>resource['<STR_LIT>'].append(str(agent_id))<EOL><DEDENT>collection.save(resource)<EOL>
Adds an existing ``Agent`` to a ``Resource``.

        arg:    agent_id (osid.id.Id): the ``Id`` of the ``Agent``
        arg:    resource_id (osid.id.Id): the ``Id`` of the ``Resource``
        raise:  AlreadyExists - ``agent_id`` is already assigned to
                ``resource_id``
        raise:  NotFound - ``agent_id`` or ``resource_id`` not found
        raise:  NullArgument - ``agent_id`` or ``resource_id`` is
                ``null``
        raise:  OperationFailed - unable to complete request
        raise:  PermissionDenied - authorization failure
        *compliance: mandatory -- This method must be implemented.*