def get_context_namespaces(request, interface): response = {'dynamicClusters': False} namespaces = [] clusters = get_clusters(request.user).values() if interface == 'hive' or interface == 'impala' or interface == 'report': namespaces.extend([ { 'id': cluster['id'], 'name': cluster['name'], 'status': 'CREATED', 'computes': [cluster] } for cluster in clusters if cluster.get('type') == 'direct' # and interface == 'hive' ]) # From Altus SDX if [cluster for cluster in clusters if cluster['type'] == 'altus']: # Note: attaching computes to namespaces might be done via the frontend in the future if interface == 'impala': adb_clusters = AnalyticDbApi( request.user).list_clusters()['clusters'] for _cluster in adb_clusters: # Add "fake" namespace if needed if not _cluster.get('namespaceCrn'): _cluster['namespaceCrn'] = _cluster['crn'] _cluster['id'] = _cluster['crn'] _cluster['namespaceName'] = _cluster['clusterName'] _cluster['name'] = _cluster['clusterName'] else: adb_clusters = [] namespaces.extend([ { 'id': namespace.get('crn', 'None'), 'name': namespace.get('namespaceName'), 'status': namespace.get('status'), 'computes': [ _cluster for _cluster in adb_clusters if _cluster.get('namespaceCrn') == namespace.get('crn') ] } for namespace in SdxApi(request.user).list_namespaces() + # Adding "fake" namespace for cluster without one [ _cluster for _cluster in adb_clusters if not cluster.get('namespaceCrn') and _cluster.get('status') == 'CREATED' ] ]) response['dynamicClusters'] = True response[interface] = namespaces response['status'] = 0 return JsonResponse(response)
def get_context_namespaces(request, interface): ''' Namespaces are node cluster contexts (e.g. Hive + Ranger) that can be queried by computes. ''' response = {} namespaces = [] clusters = list(get_clusters(request.user).values()) # Currently broken if not sent namespaces.extend([{ 'id': cluster['id'], 'name': cluster['name'], 'status': 'CREATED', 'computes': [cluster] } for cluster in clusters if cluster.get('type') == 'direct' ]) if interface == 'hive' or interface == 'impala' or interface == 'report': if get_cluster_config(request.user)['has_computes']: # Note: attaching computes to namespaces might be done via the frontend in the future if interface == 'impala': if IS_K8S_ONLY.get(): adb_clusters = DataWarehouse2Api(request.user).list_clusters()['clusters'] else: adb_clusters = AnalyticDbApi(request.user).list_clusters()['clusters'] for _cluster in adb_clusters: # Add "fake" namespace if needed if not _cluster.get('namespaceCrn'): _cluster['namespaceCrn'] = _cluster['crn'] _cluster['id'] = _cluster['crn'] _cluster['namespaceName'] = _cluster['clusterName'] _cluster['name'] = _cluster['clusterName'] _cluster['compute_end_point'] = '%(publicHost)s' % _cluster['coordinatorEndpoint'] if IS_K8S_ONLY.get() else '', else: adb_clusters = [] if IS_K8S_ONLY.get(): sdx_namespaces = [] else: sdx_namespaces = SdxApi(request.user).list_namespaces() # Adding "fake" namespace for cluster without one sdx_namespaces.extend([_cluster for _cluster in adb_clusters if not _cluster.get('namespaceCrn') or (IS_K8S_ONLY.get() and 'TERMINAT' not in _cluster['status'])]) namespaces.extend([{ 'id': namespace.get('crn', 'None'), 'name': namespace.get('namespaceName'), 'status': namespace.get('status'), 'computes': [_cluster for _cluster in adb_clusters if _cluster.get('namespaceCrn') == namespace.get('crn')] } for namespace in sdx_namespaces if namespace.get('status') == 'CREATED' or IS_K8S_ONLY.get() ]) response[interface] = namespaces response['status'] = 0 return JsonResponse(response)
def get_context_namespaces(request, interface): response = {} namespaces = [] clusters = get_clusters(request.user).values() namespaces.extend([{ 'id': cluster['id'], 'name': cluster['name'], 'status': 'CREATED', 'computes': [cluster] } for cluster in clusters if cluster.get('type') == 'direct' and cluster['interface'] in (interface, 'all') ]) if interface == 'hive' or interface == 'impala' or interface == 'report': # From Altus SDX if [cluster for cluster in clusters if 'altus' in cluster['type']]: # Note: attaching computes to namespaces might be done via the frontend in the future if interface == 'impala': if IS_K8S_ONLY.get(): adb_clusters = DataWarehouse2Api(request.user).list_clusters()['clusters'] else: adb_clusters = AnalyticDbApi(request.user).list_clusters()['clusters'] for _cluster in adb_clusters: # Add "fake" namespace if needed if not _cluster.get('namespaceCrn'): _cluster['namespaceCrn'] = _cluster['crn'] _cluster['id'] = _cluster['crn'] _cluster['namespaceName'] = _cluster['clusterName'] _cluster['name'] = _cluster['clusterName'] _cluster['compute_end_point'] = '%(publicHost)s' % _cluster['coordinatorEndpoint'] if IS_K8S_ONLY.get() else '', else: adb_clusters = [] if IS_K8S_ONLY.get(): sdx_namespaces = [] else: sdx_namespaces = SdxApi(request.user).list_namespaces() # Adding "fake" namespace for cluster without one sdx_namespaces.extend([_cluster for _cluster in adb_clusters if not _cluster.get('namespaceCrn') or (IS_K8S_ONLY.get() and 'TERMINAT' not in _cluster['status'])]) namespaces.extend([{ 'id': namespace.get('crn', 'None'), 'name': namespace.get('namespaceName'), 'status': namespace.get('status'), 'computes': [_cluster for _cluster in adb_clusters if _cluster.get('namespaceCrn') == namespace.get('crn')] } for namespace in sdx_namespaces if namespace.get('status') == 'CREATED' or IS_K8S_ONLY.get() ]) response[interface] = namespaces response['status'] = 0 return JsonResponse(response)