def GetUserPendingJobs(userName, vcName): jobs = [] allJobs = DataManager.GetAllPendingJobs(vcName) for job in allJobs: if userName == "all" or userName == job["userName"]: jobs.append(job) return jobs
def GetIdentityInfoFromDB(name): lst = DataManager.GetIdentityInfo(name) if lst: return lst[0] else: logger.warning("Identity name %s not found in DB", name) return INVALID_INFO
def ListVCs(userName): ret = [] vcList = DataManager.ListVCs() for vc in vcList: if AuthorizationManager.HasAccess(userName, ResourceType.VC, vc["vcName"], Permission.User): ret.append(vc) # web portal (client) can filter out Default VC return ret
def GetVC(userName, vcName): ret = None clusterStatus, dummy = DataManager.GetClusterStatus() clusterTotalRes = ResourceInfo(clusterStatus["gpu_capacity"]) clusterReservedRes = ResourceInfo(clusterStatus["gpu_unschedulable"]) user_status = {} vcList = DataManager.ListVCs() for vc in vcList: if vc["vcName"] == vcName and AuthorizationManager.HasAccess(userName, ResourceType.VC, vcName, Permission.User): vcTotalRes = ResourceInfo(json.loads(vc["quota"])) vcConsumedRes = ResourceInfo() jobs = DataManager.GetAllPendingJobs(vcName) for job in jobs: if job["jobStatus"] == "running": username = job["userName"] jobParam = json.loads(base64.b64decode(job["jobParams"])) if "gpuType" in jobParam and not jobParam["preemptionAllowed"]: vcConsumedRes.Add(ResourceInfo({jobParam["gpuType"] : GetJobTotalGpu(jobParam)})) if username not in user_status: user_status[username] = ResourceInfo() user_status[username].Add(ResourceInfo({jobParam["gpuType"] : GetJobTotalGpu(jobParam)})) vcReservedRes = clusterReservedRes.GetFraction(vcTotalRes, clusterTotalRes) vcAvailableRes = ResourceInfo.Difference(ResourceInfo.Difference(vcTotalRes, vcConsumedRes), vcReservedRes) vc["gpu_capacity"] = vcTotalRes.ToSerializable() vc["gpu_used"] = vcConsumedRes.ToSerializable() vc["gpu_unschedulable"] = vcReservedRes.ToSerializable() vc["gpu_avaliable"] = vcAvailableRes.ToSerializable() vc["AvaliableJobNum"] = len(jobs) vc["node_status"] = clusterStatus["node_status"] vc["user_status"] = [] for user_name, user_gpu in user_status.iteritems(): # TODO: job_manager.getAlias should be put in a util file user_name = user_name.split("@")[0].strip() vc["user_status"].append({"userName":user_name, "userGPU":user_gpu.ToSerializable()}) ret = vc break return ret
def GetIdentityInfoFromDB(identityName): lst = DataManager.GetIdentityInfo(identityName) if lst: return lst[0] else: logger.warn("GetIdentityInfo : Identity %s not found in DB" % identityName) info = {} info["uid"] = INVALID_ID info["gid"] = INVALID_ID info["groups"] = [INVALID_ID] return info
def getClusterVCs(): vcList = None try: with vc_cache_lock: vcList = copy.deepcopy(vc_cache.values()) except Exception: pass if not vcList: vcList = DataManager.ListVCs() with vc_cache_lock: for vc in vcList: vc_cache[vc["vcName"]] = vc return vcList
def _HasAccess(identityName, resourceAclPath, permissions): start_time = timeit.default_timer() requestedAccess = '%s;%s;%s' % (str(identityName), resourceAclPath, str(permissions)) try: identities = [] identities.extend( IdentityManager.GetIdentityInfoFromDB(identityName)["groups"]) #TODO: handle isDeny while resourceAclPath: #logger.debug('resourceAclPath ' + resourceAclPath) acl = DataManager.GetResourceAcl(resourceAclPath) for ace in acl: for identity in identities: #logger.debug('identity %s' % identity) if ace["identityName"] == identityName or ( str(ace["identityId"]) == str(identity) and (int(identity) < INVALID_RANGE_START or int(identity) > INVALID_RANGE_END)): permissions = permissions & (~ace["permissions"]) if not permissions: logger.info( 'Yes for %s in time %s' % (requestedAccess, str(timeit.default_timer() - start_time))) return True resourceAclPath = AuthorizationManager.__GetParentPath( resourceAclPath) logger.info( 'No for %s in time %s' % (requestedAccess, str(timeit.default_timer() - start_time))) return False except Exception as e: logger.error('Exception: ' + str(e)) logger.warn( 'No (exception) for %s in time %s' % (requestedAccess, str(timeit.default_timer() - start_time))) return False
def GetClusterStatus(): cluster_status,last_update_time = DataManager.GetClusterStatus() return cluster_status,last_update_time
def InvalidateJobListCache(vcName): CacheManager.Invalidate("GetAllPendingJobs", vcName) DataManager.GetAllPendingJobs(vcName)