Skip to content

Commit efe6b03

Browse files
committed
oslcquery: added clean handling of archived components/configs (no 404 error!)
1 parent b52ccaa commit efe6b03

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

elmclient/_app.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ def resolve_project_nametouri(self, name, raiseifinvalid=True):
310310
logger.debug( f"resolve_project_nametouri {name} {result}" )
311311
return result
312312

313+
# return True if the uri can be accessed (used e.g. to detect archived components/configs)
314+
def is_accessible( self, uri ):
315+
try:
316+
res = self.execute_get( uri )
317+
return True
318+
except requests.exceptions.HTTPError as e:
319+
return False
320+
313321
#################################################################################################
314322

315323
class JTSApp(_App):

elmclient/_rm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,22 @@ def load_components_and_configurations(self,force=False):
380380
self._confs_to_load.extend(self._components[cu]['confs_to_load'])
381381
self._components[cu]['component'] = c
382382
return (ncomps, nconfs)
383+
384+
def add_external_component(self,compu):
385+
# this is only ever used for opt-in projects!
386+
compx = self.execute_get_rdf_xml(compu, intent="Retrieve component definition to find all configurations", action="Retrieve each configuration")
387+
comptitle = rdfxml.xmlrdf_get_resource_text(compx, './/dcterms:title')
388+
confu = rdfxml.xmlrdf_get_resource_uri(compx, './/oslc_config:configurations')
389+
self._components[compu] = {'name': comptitle, 'configurations': {}, 'confs_to_load': [confu]}
390+
391+
cname = comptitle
392+
cconfs_to_load = [confu]
393+
c = self._create_component_api(compu, cname, cconfs_to_load)
394+
c._configurations = self._components[compu]['configurations']
395+
c._confs_to_load = self._components[compu]['confs_to_load']
396+
self._confs_to_load.extend(self._components[compu]['confs_to_load'])
397+
self._components[compu]['component'] = c
398+
return c
383399

384400
def load_configs(self):
385401
# load configurations

elmclient/examples/oslcquery.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def do_oslc_query(inputargs=None):
109109
parser.add_argument('--saveprocessedresults', default=None, help="Save the processed results as JSON to this path/file" )
110110
parser.add_argument('--percontribution', action="store_true", help="When querying a GC, query once for each app-domain contribution in the GC tree, with added component and configuration columns in the result")
111111
parser.add_argument('--cacheable', action="store_true", help="Query results can be cached - use when you know the data isn't changing and you need faster re-run")
112+
parser.add_argument('--crossproject', action="store_true", help="For --percontriubtion GC queries follow gc contributions to other projects and query those too (requires access permission of course)")
112113

113114
# saved credentials
114115
parser.add_argument('-0', '--savecreds', default=None, help="Save obfuscated credentials file for use with readcreds, then exit - this stores jazzurl, appstring, username and password")
@@ -479,7 +480,25 @@ def do_oslc_query(inputargs=None):
479480
queryon = p.find_local_component(compuri)
480481
if queryon is None:
481482
print( f"Component not found from {compuri}" )
483+
if args.crossproject:
484+
# this component isn't in our current project
485+
# try to create a component for it and add to current project
486+
queryon = p.add_external_component(compuri)
487+
if queryon is None:
488+
burp
489+
continue
490+
else:
491+
print( f"Added external component {queryon=}" )
492+
# check the comonent is accessible (may have been achived!)
493+
if not app.is_accessible( compuri ):
494+
print( f"Archived component {compuri} !")
482495
continue
496+
# check if the config is accessible (may have been archived!)
497+
if not app.is_accessible( contriburi ):
498+
print( f"Archived configuration {contriburi} !")
499+
continue
500+
501+
# set the config ready to do the query
483502
queryon.set_local_config(contriburi)
484503
# now do a query for each contribution
485504
thisresults = queryon.do_complex_query( args.resourcetype, querystring=args.query, searchterms=args.searchterms, select=args.select, isnulls=args.null, isnotnulls=args.value

0 commit comments

Comments
 (0)