def invoke_license_analysis_service(user_stack_packages, alt_packages, comp_packages): """Pass given args to stack_license analysis.""" license_url = LICENSE_SCORING_URL_REST + "/api/v1/stack_license" payload = { "packages": user_stack_packages, "alternate_packages": alt_packages, "companion_packages": comp_packages } json_response = {} try: # Call License service to get license data lic_response = get_session_retry().post(license_url, data=json.dumps(payload)) if lic_response.status_code != 200: lic_response.raise_for_status( ) # raise exception for bad http-status codes json_response = lic_response.json() except requests.exceptions.RequestException: logger.exception( "Unexpected error happened while invoking license analysis!") pass return json_response
def call_insights_recommender(payload): """Call the PGM model. Calls the PGM model with the normalized manifest information to get the relevant packages. """ try: # TODO remove hardcodedness for payloads with multiple ecosystems insights_url = RecommendationTask.get_insights_url(payload) response = get_session_retry().post(insights_url, json=payload) if response.status_code != 200: logger.error( "HTTP error {}. Error retrieving insights data.".format( response.status_code)) return None else: json_response = response.json() return json_response except Exception as e: logger.error("Failed retrieving insights data.") logger.error("%s" % e) return None
def _call(insights_url: str, payload: InsightsRequest): """Call the PGM model. Calls the PGM model with the normalized manifest information to get the relevant packages. """ assert insights_url try: started_at = time.time() response = get_session_retry().post(insights_url, json=[payload.dict()]) response.raise_for_status() except Exception as e: raise InsightsCallException() from e else: json_response = response.json() logger.info( "Recommendation [%s] req.pkgs [%d] elapsed time [%0.2f] sec", payload.ecosystem.value, len(payload.package_list), time.time() - started_at, ) return json_response
def test_get_session_retry(): """Test get_session_retry.""" resp = get_session_retry() assert resp is not None