66 BIGQUERY_RECOMMENDERS ,
77 RECOMMENDATION_TYPE_DOCS_URL ,
88 UNAVAILABLE_RECOMMENDER_IDS ,
9- RECOMMENDATION_MAP ,
109)
1110from abc import abstractmethod
1211from cloudforet .plugin .connector .recommender .recommendation import (
1716from bs4 import BeautifulSoup
1817from cloudforet .plugin .utils .converter import Converter
1918
20- _LOGGER = logging .getLogger (__name__ )
19+ # _LOGGER = logging.getLogger(__name__)
20+ _LOGGER = logging .getLogger ("spaceone" )
2121
2222
2323class AllRecommendationsManager (ResourceManager ):
@@ -90,6 +90,7 @@ def create_cloud_service(self, options, secret_data, schema):
9090 for rec_parent in self .rec_parent_to_recs :
9191 if not self ._is_category (self .rec_parent_to_recs [rec_parent ][0 ]):
9292 continue
93+
9394 recommender_id = rec_parent .split ("/" )[- 1 ]
9495 product , product_service = recommender_id .split ("." )[:2 ]
9596 product = self .converter .convert_product_or_product_service_name (product )
@@ -206,14 +207,15 @@ def set_recommendation_id_map_by_crawling(self):
206207
207208 for recommender_id in recommender_ids :
208209 _LOGGER .debug (f"category: { category } , recommender_id: { recommender_id } , name: { name } , short_description: { short_description } " )
210+ # print(f"recommender_id(key): {recommender_id}, category: {category}, name: {name}, short_description: {short_description}")
209211 self .recommender_map [recommender_id ] = {
210212 "category" : category ,
211213 "name" : name ,
212214 "shortDescription" : short_description ,
213215 }
214216 except Exception as e :
215217 _LOGGER .error (f"Error occurred while crawling recommendation type docs: { e } " )
216- self .recommender_map = RECOMMENDATION_MAP
218+ # self.recommender_map = RECOMMENDATION_MAP
217219
218220 def _parse_recommendation (self , rec : dict ) -> dict :
219221
@@ -333,26 +335,14 @@ def _create_parents_and_location_map_by_cloud_asset_api(assets):
333335 cloud_service_group , postfix = service .split ("." , 1 )
334336 cloud_service_type = cloud_service_type .lower ()
335337
336- if cloud_service_group not in parents_and_locations_map :
337- parents_and_locations_map [cloud_service_group ] = {}
338- else :
339- if (
340- cloud_service_type
341- not in parents_and_locations_map [cloud_service_group ]
342- ):
343- parents_and_locations_map [cloud_service_group ][
344- cloud_service_type
345- ] = [locations ]
338+ if cloud_service_group in parents_and_locations_map :
339+ if cloud_service_type in parents_and_locations_map [cloud_service_group ]:
340+ if locations not in parents_and_locations_map [cloud_service_group ][cloud_service_type ]:
341+ parents_and_locations_map [cloud_service_group ][cloud_service_type ].append (locations )
346342 else :
347- if (
348- locations
349- not in parents_and_locations_map [cloud_service_group ][
350- cloud_service_type
351- ]
352- ):
353- parents_and_locations_map [cloud_service_group ][
354- cloud_service_type
355- ].append (locations )
343+ parents_and_locations_map [cloud_service_group ][cloud_service_type ] = [locations ]
344+ else :
345+ parents_and_locations_map [cloud_service_group ] = {cloud_service_type : [locations ]}
356346
357347 for group , cst_and_locations in parents_and_locations_map .items ():
358348 all_locations = set ()
@@ -367,12 +357,10 @@ def _add_group_and_service_to_recommender_map(self):
367357 recommender_map = self .recommender_map
368358 for key , value in recommender_map .items ():
369359 prefix , cloud_service_group , cloud_service_type , * others = key .split ("." )
370- if not (
371- cloud_service_type .endswith ("Commitments" )
372- or cloud_service_type .endswith ("Recommender" )
373- ):
360+ if not (cloud_service_type .endswith ("Commitments" ) or cloud_service_type .endswith ("Recommender" )):
374361 if cloud_service_group == "cloudsql" :
375362 cloud_service_group = "sqladmin"
363+
376364 recommender_map [key ]["cloudServiceGroup" ] = cloud_service_group
377365 recommender_map [key ]["cloudServiceType" ] = cloud_service_type .lower ()
378366 else :
@@ -381,46 +369,49 @@ def _add_group_and_service_to_recommender_map(self):
381369
382370 def _add_locations_to_recommender_map (self , parents_and_locations_map ):
383371 recommender_map = self .recommender_map
384- delete_services = []
372+ delete_services = set ()
385373 for service , cst in parents_and_locations_map .items ():
386374 if not cst :
387- delete_services .append (service )
375+ _LOGGER .warning (f"parents_and_locations_map: cloud_service_group: { service } has no cloud_service_type" )
376+ delete_services .add (service )
388377
389378 for service in delete_services :
390379 del parents_and_locations_map [service ]
391380
381+ _LOGGER .debug (f"--------------------------------------------------------" )
382+ for group , cst_and_locations in parents_and_locations_map .items ():
383+ _LOGGER .debug (f"parents_and_locations_map: key: { group } , value: { cst_and_locations } " )
384+
385+
392386 for key , value in self .recommender_map .items ():
393- cloud_service_group = value ["cloudServiceGroup" ]
394- cloud_service_type = value ["cloudServiceType" ]
395-
396- for service , cst_and_locations in parents_and_locations_map .items ():
397- if cloud_service_group == service :
398- for service_key , locations in cst_and_locations .items ():
399- if cloud_service_type == service_key :
400- recommender_map [key ]["locations" ] = locations
401-
402- if (
403- "locations" not in recommender_map [key ]
404- and cloud_service_group == "compute"
405- ):
406- recommender_map [key ]["locations" ] = cst_and_locations [
407- "instance"
408- ]
409-
410- if cloud_service_type == "commitment" :
411- recommender_map [key ]["locations" ] = (
412- self .converter .convert_zone_to_region (
413- cst_and_locations ["instance" ]
414- )
415- )
416-
417- if "locations" not in recommender_map [key ]:
418- recommender_map [key ]["locations" ] = cst_and_locations [
419- "all_locations"
420- ]
387+ cloud_service_group = value ["cloudServiceGroup" ] # compute
388+ cloud_service_type = value ["cloudServiceType" ] # commitment, image, address, disk, instance, None, instancegroupmanager, instance,
389+
390+ cst_and_locations = parents_and_locations_map .get (cloud_service_group , None )
391+ if not cst_and_locations :
392+ _LOGGER .warning (f"No matching cloud_service_group: { cloud_service_group } found in parents_and_locations_map for recommender_id: { key } " )
393+ continue
394+
395+ locations = cst_and_locations .get (cloud_service_type , None )
396+ if locations :
397+ recommender_map [key ]["locations" ] = locations
398+
399+ if ("locations" not in recommender_map [key ] and cloud_service_group == "compute" ):
400+ if cst_and_locations .get ("instance" , None ):
401+ if cloud_service_type == "commitment" :
402+ recommender_map [key ]["locations" ] = (self .converter .convert_zone_to_region (cst_and_locations ["instance" ]))
403+ else :
404+ recommender_map [key ]["locations" ] = cst_and_locations ["instance" ]
405+
406+ if "locations" not in recommender_map [key ]:
407+ recommender_map [key ]["locations" ] = cst_and_locations ["all_locations" ]
421408
422409 if "locations" not in recommender_map [key ]:
423410 recommender_map [key ]["locations" ] = ["global" ]
424411
425412 if "global" not in recommender_map [key ]["locations" ]:
426413 recommender_map [key ]["locations" ].append ("global" )
414+
415+ _LOGGER .debug (f"--------------------------------------------------------" )
416+ for key , value in recommender_map .items ():
417+ _LOGGER .debug (f"recommender_map key: { key } , value: { value } " )
0 commit comments