Create reference term links for an artifact in DNG is struck after processing for some artifacts
Hi Everyone,
We have a requirement to create a link for reference term using api.
What we are doing now is the following:
POST to: <RM_SERVER_ADDRESS>/rm/links
headers:
{'DoorsRP-Request-Type': 'private',
'Content-Type': 'application/rdf+xml',
'oslc.configuration': '<GC_SERVER_ADDRESS>/gc/configuration/145', 'net.jazz.jfs.owning-context': '<RM_SERVER_ADDRESS>/rm/rm-projects/IrrUYfOtEealZ_zm_SstCA/components/_na2ccCWuEeu1LM6pSS3uxg',
'X-Requested-With': 'XMLHttpRequest'}
<rdf:RDF xmlns:rm="http://www.ibm.com/xmlns/rdm/rdf/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rm:Link rdf:about=""> <rdf:subject rdf:resource=""/> <rdf:object rdf:resource="_"/> <rdf:predicate rdf:resource="http://www.ibm.com/xmlns/rdm/types/ArtifactTermReferenceLink"/> <rm:suspectSubjectCleared/> <rm:suspectObjectCleared/> <rdf:type rdf:resource="http://www.ibm.com/xmlns/rdm/rdf/Link"/> <rdf:value rdf:datatype="http://www.w3.org/2001/XMLSchema#string"></rdf:value> </rm:Link> </rdf:RDF>
We are calling this api to 'n' artifacts in a loop This POST call is working and creating reference term links for 'n' artifacts , but when we try to update same 'n' artifacts again then it is not creating and hanging around 5th call , we are not getting error as well in return.
Please help us !
Thanks in advance, Jyothsna. |
2 answers
Ian Barnard (2.1k●6●13)
| answered Nov 07 '23, 11:36 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER > 'DoorsRP-Request-Type': 'private'
This is a private API
Comments
lakshmi jyothsna
commented Nov 10 '23, 1:04 a.m.
Hi Ian,
Thanks for reply. Can't we use Private apis? Is there any restrictions to use?
Thanks,
Jyothsna.
|
Suzume Ai (11●1)
| answered Nov 13 '23, 3:40 a.m.
edited Jan 12, 4:44 a.m. by Ralph Schoon (63.4k●3●36●46) Hi Jyothsna,
I think this issue happened because of the way RM API handles concurrent requests. To avoid this, create a batch of link objects in memory and call the rm/links endpoint once to create all of them.
Following the code:
import requests
def create_reference_term_links(rm_server_address, gc_server_address, artifacts):
"""Creates reference term links for the given artifacts.
Args:
rm_server_address: The address of the RM server.
gc_server_address: The address of the GC server.
artifacts: A list of artifact IDs.
"""
# Create a batch of link objects in memory.
link_objects = []
for artifact_id in artifacts:
link_object = {
"subject": "http://%s/_%s" % (rm_server_address, artifact_id),
"object": "",
"suspectSubjectCleared": True,
"suspectObjectCleared": True,
"value": ""
}
link_objects.append(link_object)
# Call the rm/links endpoint once to create all of the link objects in the batch.
response = requests.post(
"%s/rm/links" % rm_server_address,
headers={
"DoorsRP-Request-Type": "private",
"Content-Type": "application/rdf+xml",
"oslc.configuration": "%s/gc/configuration/145" % gc_server_address,
"net.jazz.jfs.owning-context": "%s/rm/rm-projects/IrrUYfOtEealZ_zm_SstCA/components/_na2ccCWuEeu1LM6pSS3uxg" % rm_server_address,
"X-Requested-With": "XMLHttpRequest"
},
data="".join([
"<rdf:RDF xmlns:rm=\"http://www.ibm.com/xmlns/rdm/rdf/\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">",
"".join([
"<rm:Link rdf:about=\"\">",
"<rdf:subject rdf:resource=\"%s\"/>" % link_object["subject"],
"<rdf:object rdf:resource=\"\"/>",
"<rdf:predicate rdf:resource=\"http://www.ibm.com/xmlns/rdm/types/ArtifactTermReferenceLink\"/>",
"<rm:suspectSubjectCleared/>",
"<rm:suspectObjectCleared/>",
"<rdf:type rdf:resource=\"http://www.ibm.com/xmlns/rdm/rdf/Link\"/>",
"<rdf:value rdf:datatype=\"http://www.w3.org/2001/XMLSchema#string\">%s</rdf:value>" % link_object["value"],
"</rm:Link>"
] for link_object in link_objects),
"</rdf:RDF>"
])
)
# Wait for the RM API to finish creating the link objects.
response.raise_for_status()
# Check the response content to make sure that all of the link objects were created successfully.
response_content = response.content.decode("utf-8")
if "error" in response_content:
raise Exception("Failed to create reference term links: %s" % response_content)
if name == "main":
|
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.