7070import re
7171import logging
7272
73+ from pydantic import AnyHttpUrl
74+
75+ from src .settings import AGGREGATOR_SETTINGS , RECOMMENDER_SETTINGS , SETTINGS
7376from src .utils import (create_package_dict , get_session_retry , select_latest_version ,
74- GREMLIN_SERVER_URL_REST , LICENSE_SCORING_URL_REST ,
7577 convert_version_to_proper_semantic , get_response_data ,
7678 version_info_tuple , persist_data_in_db , post_http_request )
7779from src .stack_aggregator import extract_user_stack_package_licenses
@@ -112,7 +114,7 @@ def get_version_information(input_list, ecosystem):
112114 }
113115
114116 # Query Gremlin with packages list to get their version information
115- gremlin_response = post_http_request (url = GREMLIN_SERVER_URL_REST , payload = payload )
117+ gremlin_response = post_http_request (url = SETTINGS . gremlin_url , payload = payload )
116118 if gremlin_response is None :
117119 return []
118120 response = get_response_data (gremlin_response , [{0 : 0 }])
@@ -289,7 +291,7 @@ class License:
289291 @staticmethod
290292 def invoke_license_analysis_service (user_stack_packages , alt_packages , comp_packages ):
291293 """Pass given args to stack_license analysis."""
292- license_url = LICENSE_SCORING_URL_REST + "/api/v1/stack_license"
294+ license_url = AGGREGATOR_SETTINGS . license_analysis_base_url + "/api/v1/stack_license"
293295
294296 payload = {
295297 "packages" : user_stack_packages ,
@@ -413,41 +415,20 @@ def set_valid_cooccurrence_probability(package_list=[]):
413415 return new_package_list
414416
415417
416- class RecommendationTask :
417- """Recommendation task."""
418+ def _prepare_insights_url (base_url : AnyHttpUrl ) -> AnyHttpUrl :
419+ assert base_url
420+ return "{url}/api/v1/companion_recommendation" .format (url = base_url )
418421
419- _analysis_name = 'recommendation_v2'
420- description = 'Get Recommendation'
421- kronos_ecosystems = ['maven' ]
422- chester_ecosystems = ['npm' ]
423- hpf_ecosystems = ['maven' ]
424- pypi_ecosystems = ['pypi' ]
425- golang_ecosystem = ['golang' ]
426422
427- @staticmethod
428- def get_insights_url (payload ):
429- """Get the insights url based on the ecosystem."""
430- if payload and 'ecosystem' in payload [0 ]:
431- if payload [0 ]['ecosystem' ] in RecommendationTask .chester_ecosystems :
432- INSIGHTS_SERVICE_HOST = os .getenv ("CHESTER_SERVICE_HOST" )
433- elif payload [0 ]['ecosystem' ] in RecommendationTask .pypi_ecosystems :
434- INSIGHTS_SERVICE_HOST = os .getenv ("PYPI_SERVICE_HOST" )
435- elif payload [0 ]['ecosystem' ] in RecommendationTask .golang_ecosystem :
436- INSIGHTS_SERVICE_HOST = os .environ .get ("GOLANG_SERVICE_HOST" )
437- else :
438- INSIGHTS_SERVICE_HOST = os .getenv ("HPF_SERVICE_HOST" ) + "-" + payload [0 ][
439- 'ecosystem' ]
423+ ECOSYSTEM_TO_INSIGHTS_URL = {
424+ "pypi" : _prepare_insights_url (RECOMMENDER_SETTINGS .pypi_insights_base_url ),
425+ "npm" : _prepare_insights_url (RECOMMENDER_SETTINGS .npm_insights_base_url ),
426+ "maven" : _prepare_insights_url (RECOMMENDER_SETTINGS .maven_insights_base_url ),
427+ }
440428
441- INSIGHTS_URL_REST = "http://{host}:{port}" .format (host = INSIGHTS_SERVICE_HOST ,
442- port = os .getenv ("SERVICE_PORT" ))
443429
444- insights_url = INSIGHTS_URL_REST + "/api/v1/companion_recommendation"
445-
446- return insights_url
447-
448- else :
449- logger .error ('Payload information not passed in the call, Quitting! inights '
450- 'recommender\' s call' )
430+ class RecommendationTask :
431+ """Recommendation task."""
451432
452433 @staticmethod
453434 def call_insights_recommender (payload ):
@@ -459,7 +440,8 @@ def call_insights_recommender(payload):
459440 try :
460441 # TODO remove hardcodedness for payloads with multiple ecosystems
461442
462- insights_url = RecommendationTask .get_insights_url (payload )
443+ insights_url = ECOSYSTEM_TO_INSIGHTS_URL .get (payload [0 ]['ecosystem' ], None )
444+ assert insights_url
463445 response = get_session_retry ().post (insights_url , json = payload )
464446
465447 if response .status_code != 200 :
@@ -519,13 +501,6 @@ def execute(self, arguments=None, persist=True, check_license=False):
519501 'comp_package_count_threshold' : int (os .environ .get (
520502 'MAX_COMPANION_PACKAGES' , 5 ))
521503 }
522- if details ['ecosystem' ] in self .kronos_ecosystems :
523- insights_payload .update ({
524- 'alt_package_count_threshold' : int (os .environ .get ('MAX_ALTERNATE_PACKAGES' , 2 )),
525- 'outlier_probability_threshold' : float (os .environ .get ('OUTLIER_THRESHOLD' ,
526- 0.6 )),
527- 'user_persona' : "1" , # TODO - remove janus hardcoded value
528- })
529504 input_task_for_insights_recommender = [insights_payload ]
530505
531506 # Call PGM and get the response
0 commit comments